Smart Traffic Control

Smart Traffic Control (STC) provides extensible packet-level control services, including per-app data usage, total data quota, and background app data saving.

The main features of the Tizen.Network.Stc namespace includes the following:

Note

You can test the STC functionality on a target device only. The emulator does not support this feature.

Prerequisites

To enable your application to use the STC functionality, follow the steps below:

  1. To use the Tizen.Network.Stc namespace, the application has to request permission by adding the following privileges to the tizen-manifest.xml file:

    XML
    Copy
    <privileges> <privilege>http://tizen.org/privilege/network.get</privilege> </privileges>
  2. To use the methods and properties of the Tizen.Network.Stc namespace, include it in your application:

    C#
    Copy
    using Tizen.Network.Stc;

Retrieve data usage for system

To retrieve the statistics about total network data consumed by the system, follow the steps below:

  1. Create a filter for retrieving data usage.

    This filter will be passed as a method parameter in GetStatisticsAsync() call:

    C#
    Copy
    public static StatisticsFilter MakeFilter() { Tizen.Log.Info(Globals.LogTag, "StcSetup.MakeFilter"); StatisticsFilter _filter = new StatisticsFilter { AppId = null, From = DateTime.Now.AddMonths(-1), To = DateTime.Now, InterfaceType = NetworkInterface.All, TimePeriod = TimePeriodType.Week }; return _filter; }
  2. Call the GetStatisticsAsync() method:

    C#
    Copy
    try { StatisticsFilter _filter = StcSetup.MakeFilter(); Task<IEnumerable<NetworkStatistics>> _task = StcManager.GetStatisticsAsync(_filter); var _stats = await _task; await Task.Delay(1000); using (IEnumerator<NetworkStatistics> _iter = _stats.GetEnumerator()) { _iter.MoveNext(); /* Do the processing on received data */ } } catch (NotSupportedException) { Assert.IsTrue(s_isStcSupported == false, "Invalid NotSupportedException"); } catch (TypeInitializationException e) { Assert.IsTrue(s_isStcSupported == false && e.InnerException.GetType() == typeof(NotSupportedException), "Invalid NotSupportedException or TypeInitializationException"); } catch (NullReferenceException) { Log.Info(Globals.LogTag, "Inside NullReferenceException: 'stats' is null"); Assert.True(true, "Inside NullReferenceException: 'stats' is null"); } catch (Exception ex) { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } Log.Info(Globals.LogTag, "Successfully done");

Retrieve data usage for applications

To retrieve the statistics about total network data consumed by the applications, follow the steps below:

  1. Create a filter for retrieving the application data usage.

    This filter will be passed as a method parameter in GetStatisticsAsync() call:

    C#
    Copy
    public static StatisticsFilter MakeFilter() { Tizen.Log.Info(Globals.LogTag, "StcSetup.MakeFilter"); StatisticsFilter _filter = new StatisticsFilter { AppId = "TOTAL_IPV4", From = DateTime.Now.AddMonths(-1), To = DateTime.Now, InterfaceType = NetworkInterface.All, TimePeriod = TimePeriodType.Week }; return _filter; }
  2. Call the GetStatisticsAsync() method:

    C#
    Copy
    try { StatisticsFilter _filter = StcSetup.MakeFilter(); Task<IEnumerable<NetworkStatistics>> _task = StcManager.GetStatisticsAsync(_filter); var _stats = await _task; await Task.Delay(1000); using (IEnumerator<NetworkStatistics> _iter = _stats.GetEnumerator()) { _iter.MoveNext(); /* Do the processing on received data */ } } catch (NotSupportedException) { Assert.IsTrue(s_isStcSupported == false, "Invalid NotSupportedException"); } catch (TypeInitializationException e) { Assert.IsTrue(s_isStcSupported == false && e.InnerException.GetType() == typeof(NotSupportedException), "Invalid NotSupportedException or TypeInitializationException"); } catch (NullReferenceException) { Log.Info(Globals.LogTag, "Inside NullReferenceException: 'stats' is null"); Assert.True(true, "Inside NullReferenceException: 'stats' is null"); } catch (Exception ex) { Assert.True(false, "Exception occurs. Msg : " + ex.ToString()); } Log.Info(Globals.LogTag, "Successfully done");
  • Dependencies
    • Tizen 5.5 and Higher
Smart Card
Next IoT Connectivity
Submit your feedback to GitHub