From c4c6a8630002031017005fa01c9a34fc298d9c07 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Fri, 15 Sep 2017 20:03:03 +0900 Subject: [PATCH] [TCSACR-87][Information] Modify guide in accordance with refactored API PS2: Reviewed Change-Id: Icfffd7e325384ed6973d4ffb6eb197dad67b3641 Signed-off-by: Kichan Kwon --- org.tizen.guides/html/dotnet/information.htm | 239 +++++++++++++++++---------- 1 file changed, 155 insertions(+), 84 deletions(-) diff --git a/org.tizen.guides/html/dotnet/information.htm b/org.tizen.guides/html/dotnet/information.htm index 64d89a7..9a0d069 100644 --- a/org.tizen.guides/html/dotnet/information.htm +++ b/org.tizen.guides/html/dotnet/information.htm @@ -11,12 +11,10 @@ -System and Runtime Information +System Information - -
-

System and Runtime Information

+

System Information

You can access various information about your device system and its runtime status.

-

The main features of the Tizen.System.SystemInfo and Tizen.System.RuntimeInformation classes include:

+

The main system information features include:

+

System information features are classified as either static features, which are device features whose value does not change, or runtime features, whose value can change according to, for example, what peripherals are currently connected to the device. The features are identified using feature keys.

Prerequisites

-

To access per-process resource information (to use the GetProcessCpuUsage() and GetProcessMemoryInformation() methods of the Tizen.System.RuntimeInformation class), the application has to request permission by adding the following privileges to the tizen-manifest.xml file:

+

To use the system information features in your application:

+
    +
  1. To access per-process resource information (to use the Tizen.System.ProcessCpuUsage and Tizen.System.ProcessMemoryUsage classes), the application has to request permission by adding the following privilege to the tizen-manifest.xml file:
     <privileges>
        <privilege>http://tizen.org/privilege/systemmonitor</privilege>
     </privileges>
     
    +
  2. +
  3. To use the methods and properties of the Tizen.System.Information, Tizen.System.ProcessCpuUsage, Tizen.System.ProcessMemoryUsage, Tizen.System.SystemCpuUsage, and Tizen.System.SystemMemoryUsage classes, include the Tizen.System namespace in your application: +
    +using Tizen.System;
    +
    +
  4. +
-

Retrieving Static Information

-

You can access static system information by using the TryGetValue() method of the Tizen.System.SystemInfo class. To define the feature you want to access, use a system information key as a parameter.

+

Retrieving System Information

-

To access the device name and check whether the device has a battery:

+

To retrieve system information, use the TryGetValue() method of the Tizen.System.Information class:

    -
  • Retrieve the device name: +
  • To retrieve a static feature:
    -public static string get_device_name()
    +/// Check whether the device has a battery
    +public static bool is_battery_powered_device()
     {
    -    const string DEVICE_NAME_KEY = "http://tizen.org/system/model_name";
    -    string ret;
    -
    -    if (SystemInfo.Is<string>(DEVICE_NAME_KEY) == false || SystemInfo.IsValidKey(DEVICE_NAME_KEY) == false)
    -    {
    -        /// Error handling
    -    }
    +    bool ret;
     
    -    if (SystemInfo.TryGetValue<string>(DEVICE_NAME_KEY, out ret) == false)
    +    if (Tizen.System.Information.TryGetValue<bool>("http://tizen.org/feature/battery", out ret) == false)
         {
             /// Error handling
         }
    @@ -96,19 +104,14 @@ public static string get_device_name()
     
  • -
  • Check whether the device has a battery: +
  • To retrieve the current value of a runtime feature:
    -public static bool is_battery_powered_device()
    +/// Check whether the battery is charging
    +public static bool is_charging()
     {
    -    const string BATTERY_FEATURE_KEY = "http://tizen.org/feature/battery";
         bool ret;
     
    -    if (SystemInfo.Is<bool>(BATTERY_FEATURE_KEY) == false || SystemInfo.IsValidKey(BATTERY_FEATURE_KEY) == false)
    -    {
    -        /// Error handling
    -    }
    -
    -    if (SystemInfo.TryGetValue<bool>(BATTERY_FEATURE_KEY, out ret) == false)
    +    if (Tizen.System.Information.TryGetValue<bool>("http://tizen.org/runtimefeature/battery.charging", out ret) == false)
         {
             /// Error handling
         }
    @@ -119,87 +122,155 @@ public static bool is_battery_powered_device()
     
+

Retrieving Resource Usage Details

+

To get resource usage details, use the Tizen.System.ProcessCpuUsage, Tizen.System.ProcessMemoryUsage, Tizen.System.SystemCpuUsage, and Tizen.System.SystemMemoryUsage classes. Since these classes collect information during their construction, you can simply make a new instance to access the resource usage details.

-

Checking the Current System Status

-

To check the current system status using the Tizen.System.RuntimeInformation class:

    -
  • You can use the GetStatus() method of the Tizen.System.RuntimeInformation class. To define the feature you want to check, use the Tizen.System.RuntimeInformationKey enumeration as a parameter. -

    To check whether the battery is charging:

    +
  • To retrieve system memory usage details:
    -public static bool is_charging()
    +public static int get_total_memory_size(void)
     {
    -    bool ret = false;
    +    Tizen.System.SystemMemoryUsage usage = new Tizen.System.SystemMemoryUsage();
     
    -    try
    -    {
    -        if (RuntimeInformation.Is<bool>(RuntimeInformationKey.BatteryIsCharging) == false)
    -        {
    -            /// Error handling
    -        }
    -
    -        ret = RuntimeInformation.GetStatus<bool>(RuntimeInformationKey.BatteryIsCharging);
    -    }
    -    catch (Exception e)
    -    {
    -        /// Error handling
    -    }
    -
    -    return ret;
    +    return usage.Total;
     }
     
  • -
  • You can also use a stand-alone method of the Tizen.System.RuntimeInformation class, such as GetCpuUsage(). -

    To check the percentage of time used to run kernel processes:

    +
  • To retrieve CPU usage details of a process:
    -public static double get_system_mode_ratio()
    +public static void print_family_cpu_usage(Familyinfo family)
     {
    -    double ret = -1;
    +    IList<int> processList;
    +    Tizen.System.ProcessCpuUsage usage;
     
    -    try
    -    {
    -        CpuUsage usage = RuntimeInformation.GetCpuUsage();
    -        ret = usage.System;
    -    }
    -    catch (Exception e)
    -    {
    -        /// Error handling
    -    }
    +    processList = new List<int>();
    +    processList.Add(family.me.pid);
    +    processList.Add(family.father.pid);
     
    -    return ret;
    +    usage = new Tizen.System.ProcessCpuUsage(processList);
    +
    +    Tizen.Log.Info("MY_HOUSE", "My CPU UTime = " + usage.GetUTime(family.me.pid));
    +    Tizen.Log.Info("MY_HOUSE", "Father's CPU STime = " + usage.GetSTime(family.father.pid));
     }
     
+

Monitoring Runtime Changes

+

You can monitor the changes in the runtime feature key values by registering event handlers for the corresponding events.

-

Monitoring Runtime Changes

-

You can monitor various runtime events by registering a callback for them.

-

To monitor when an audio jack is attached to the device, to allow you to turn down the volume to safe levels:

+

For example, to monitor whether an audio jack is connected, and to turn the device volume to safe levels when it is:

-public static void TurnDownTheVolumeCallback(object sender, RuntimeKeyStatusChangedEventArgs args)
+private const string RuntimeFeatureAudiojackConnected = "http://tizen.org/runtimefeature/audiojack.connected";
+
+/// Event handler for the audio jack connection event
+public static void TurnDownTheVolumeCallback(object sender, RuntimeFeatureStatusChangedEventArgs args)
 {
-    if (MySpeaker.GetVolume() > 10)
+    if (MySpeaker.GetVolume() > 10)
     {
         MySpeaker.SetVolume(10);
     }
 }
 
-/// To begin monitoring, register the callback for the AudioJackConnectorChanged event
+/// To begin monitoring, register the event handler for the audiojack.connected event
 public static void init()
 {
-    RuntimeInformation.AudioJackConnectorChanged += TurnDownTheVolumeCallback;
+    Tizen.System.Information.SetCallback(RuntimeFeatureAudiojackConnected, TurnDownTheVolumeCallback);
 }
 
-/// When monitoring is no longer needed, deregister the callback
+/// When monitoring is no longer needed, deregister the event handler
 public static void deinit()
 {
-    RuntimeInformation.AudioJackConnectorChanged -= TurnDownTheVolumeCallback;
+    Tizen.System.Information.UnsetCallback(RuntimeFeatureAudiojackConnected, TurnDownTheVolumeCallback);
 }
 
-

For a list of events that you can monitor, see theTizen.System.RuntimeInformation class properties.

+

Feature Keys

+ +

The static feature keys are identical to the ones used in Tizen native applications. For more information, see the native System Information guide.

+

The runtime feature keys have the runtimefeature prefix. The available runtime feature keys are listed in the following table.

+

Table: Runtime feature keys

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KeyTypeDescription
http://tizen.org/runtimefeature/audiojack.connectedboolIndicates whether an audio jack is connected.
http://tizen.org/runtimefeature/audiojack.typeintIndicates the audio jack connector type. For available values, see the Tizen.System.AudioJackConnectionType enumeration.
http://tizen.org/runtimefeature/autorotationboolIndicates whether auto-rotation is enabled.
http://tizen.org/runtimefeature/battery.chargingboolIndicates whether the battery is currently charging.
http://tizen.org/runtimefeature/bluetoothboolIndicates whether Bluetooth is enabled.
http://tizen.org/runtimefeature/chargerboolIndicates whether a charger is connected.
http://tizen.org/runtimefeature/dataroamingboolIndicates whether data roaming is enabled.
http://tizen.org/runtimefeature/gpsintIndicates the current GPS status. For available values, see the Tizen.System.GpsStatus enumeration.
http://tizen.org/runtimefeature/packetdataboolIndicates whether packet data is enabled through the 3G network.
http://tizen.org/runtimefeature/tethering.bluetoothboolIndicates whether Bluetooth tethering is enabled.
http://tizen.org/runtimefeature/tethering.usbboolIndicates whether USB tethering is enabled.
http://tizen.org/runtimefeature/tethering.wifiboolIndicates whether a Wi-Fi hotspot is enabled.
http://tizen.org/runtimefeature/tvoutboolIndicates whether the TV out is connected.
http://tizen.org/runtimefeature/vibrationboolIndicates whether vibration is enabled.
-- 2.7.4