--- /dev/null
+/*
+* Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// The Information class provides functions to obtain various system information.
+ /// </summary>
+ public static class Information
+ {
+ internal const string HttpPrefix = "http://";
+ internal const string RuntimeInfoStringKeyPrefix = "tizen.org/runtimefeature/";
+
+ internal const string RuntimeInfoStringKeyBluetooth = "bluetooth";
+ internal const string RuntimeInfoStringKeyTetheringWiFi = "tethering.wifi";
+ internal const string RuntimeInfoStringKeyTetheringBluetooth = "tethering.bluetooth";
+ internal const string RuntimeInfoStringKeyTetheringUsb = "tethering.usb";
+ internal const string RuntimeInfoStringKeyPacketData = "packetdata";
+ internal const string RuntimeInfoStringKeyDataRoaming = "dataroaming";
+ internal const string RuntimeInfoStringKeyVibration = "vibration";
+ internal const string RuntimeInfoStringKeyAudioJackConnected = "audiojack.connected";
+ internal const string RuntimeInfoStringKeyBatteryCharging = "battery.charging";
+ internal const string RuntimeInfoStringKeyTvOut = "tvout";
+ internal const string RuntimeInfoStringKeyCharger = "charger";
+ internal const string RuntimeInfoStringKeyAutoRotation = "autorotation";
+ internal const string RuntimeInfoStringKeyGps = "gps";
+ internal const string RuntimeInfoStringKeyAudioJackType = "audiojack.type";
+
+
+ private static readonly Dictionary<string, RuntimeInfoKey> StringEnumMapping = new Dictionary<string, RuntimeInfoKey>
+ {
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyBluetooth] = RuntimeInfoKey.Bluetooth,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringWiFi] = RuntimeInfoKey.WifiHotspot,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringBluetooth] = RuntimeInfoKey.BluetoothTethering,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTetheringUsb] = RuntimeInfoKey.UsbTethering,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyPacketData] = RuntimeInfoKey.PacketData,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyDataRoaming] = RuntimeInfoKey.DataRoaming,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyVibration] = RuntimeInfoKey.Vibration,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAudioJackConnected] = RuntimeInfoKey.AudioJack,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyBatteryCharging] = RuntimeInfoKey.BatteryIsCharging,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyTvOut] = RuntimeInfoKey.TvOut,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyCharger] = RuntimeInfoKey.Charger,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAutoRotation] = RuntimeInfoKey.AutoRotation,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyGps] = RuntimeInfoKey.Gps,
+ [RuntimeInfoStringKeyPrefix + RuntimeInfoStringKeyAudioJackType] = RuntimeInfoKey.AudioJackConnector
+ };
+
+ internal static readonly Dictionary<RuntimeInfoKey, string> EnumStringMapping = new Dictionary<RuntimeInfoKey, string>
+ {
+ [RuntimeInfoKey.Bluetooth] = RuntimeInfoStringKeyBluetooth,
+ [RuntimeInfoKey.WifiHotspot] = RuntimeInfoStringKeyTetheringWiFi,
+ [RuntimeInfoKey.BluetoothTethering] = RuntimeInfoStringKeyTetheringBluetooth,
+ [RuntimeInfoKey.UsbTethering] = RuntimeInfoStringKeyTetheringUsb,
+ [RuntimeInfoKey.PacketData] = RuntimeInfoStringKeyPacketData,
+ [RuntimeInfoKey.DataRoaming] = RuntimeInfoStringKeyDataRoaming,
+ [RuntimeInfoKey.Vibration] = RuntimeInfoStringKeyVibration,
+ [RuntimeInfoKey.AudioJack] = RuntimeInfoStringKeyAudioJackConnected,
+ [RuntimeInfoKey.BatteryIsCharging] = RuntimeInfoStringKeyBatteryCharging,
+ [RuntimeInfoKey.TvOut] = RuntimeInfoStringKeyTvOut,
+ [RuntimeInfoKey.Charger] = RuntimeInfoStringKeyCharger,
+ [RuntimeInfoKey.AutoRotation] = RuntimeInfoStringKeyAutoRotation,
+ [RuntimeInfoKey.Gps] = RuntimeInfoStringKeyGps,
+ [RuntimeInfoKey.AudioJackConnector] = RuntimeInfoStringKeyAudioJackType
+ };
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ private static bool ConvertStringToRuntimeInfoKey(string key, out RuntimeInfoKey feature)
+ {
+ string filteredKey = key.StartsWith(HttpPrefix) ? key.Substring(HttpPrefix.Length) : key;
+ feature = default(RuntimeInfoKey);
+
+ return StringEnumMapping.TryGetValue(filteredKey, out feature);
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ private static bool TryGetRuntimeInfoValue<T>(RuntimeInfoKey key, out T value)
+ {
+ value = default(T);
+
+ if (!RuntimeInfo.Is<T>(key))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid return type");
+ return false;
+ }
+
+ return RuntimeInfo.TryGetValue<T>(key, out value);
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ private static bool TryGetSystemInfoValue<T>(string key, out T value)
+ {
+ value = default(T);
+
+ if (!SystemInfo.IsValidKey(key))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ return false;
+ }
+
+ if (!SystemInfo.Is<T>(key))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid return type");
+ return false;
+ }
+
+ return SystemInfo.TryGetValue<T>(key, out value);
+ }
+
+ /// <summary>
+ /// Gets the value of the feature.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <typeparam name="T">The type of <paramref name="value"/>.</typeparam>
+ /// <param name="key">The name of the feature.</param>
+ /// <param name="value">The value of the given feature.</param>
+ /// <returns>Returns true on success, otherwise false.</returns>
+ public static bool TryGetValue<T>(string key, out T value)
+ {
+ RuntimeInfoKey runtimeFeature;
+
+ if (ConvertStringToRuntimeInfoKey(key, out runtimeFeature))
+ {
+ return TryGetRuntimeInfoValue<T>(runtimeFeature, out value);
+ }
+ else
+ {
+ return TryGetSystemInfoValue<T>(key, out value);
+ }
+ }
+
+ /// <summary>
+ /// Registers a change event callback for given runtime feature key.
+ /// </summary>
+ /// <remarks>
+ /// This function is only for runtime feature.
+ /// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="key">The name of runtime feature which wants to register callback.</param>
+ /// <param name="callback">The callback function to subscribe.</param>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
+ /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
+ public static void SetCallback(string key, EventHandler<RuntimeFeatureStatusChangedEventArgs> callback)
+ {
+ RuntimeInfoKey runtimeFeature;
+
+ if (!ConvertStringToRuntimeInfoKey(key, out runtimeFeature))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
+ }
+
+ RuntimeInfo.SetCallback(runtimeFeature, callback);
+ }
+
+ /// <summary>
+ /// Unregisters a change event callback for given runtime feature key.
+ /// </summary>
+ /// <remarks>
+ /// This function is only for runtime feature.
+ /// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="key">The name of runtime feature which wants to unregister callback.</param>
+ /// <param name="callback">The callback function to unsubscribe.</param>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
+ /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
+ public static void UnsetCallback(string key, EventHandler<RuntimeFeatureStatusChangedEventArgs> callback)
+ {
+ RuntimeInfoKey runtimeFeature;
+
+ if (!ConvertStringToRuntimeInfoKey(key, out runtimeFeature))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
+ }
+
+ RuntimeInfo.UnsetCallback(runtimeFeature, callback);
+ }
+ }
+}
{
internal static partial class RuntimeInfo
{
- public delegate void RuntimeInformationChangedCallback(RuntimeInformationKey key, IntPtr userData);
+ public delegate void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData);
[StructLayout(LayoutKind.Sequential)]
public struct MemoryInfo
}
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_int")]
- public static extern InformationError GetValue(RuntimeInformationKey key, out int status);
+ public static extern InformationError GetValue(RuntimeInfoKey key, out int status);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_bool")]
- public static extern InformationError GetValue(RuntimeInformationKey key, out bool status);
+ public static extern InformationError GetValue(RuntimeInfoKey key, out bool status);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_double")]
- public static extern InformationError GetValue(RuntimeInformationKey key, out double status);
+ public static extern InformationError GetValue(RuntimeInfoKey key, out double status);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_value_string")]
- public static extern InformationError GetValue(RuntimeInformationKey key, out string status);
+ public static extern InformationError GetValue(RuntimeInfoKey key, out string status);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_system_memory_info")]
public static extern InformationError GetSystemMemoryInfo(out MemoryInfo memoryInfo);
public static extern InformationError GetProcessorMaxFrequency(int coreId, out int cpuFreq);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_set_changed_cb")]
- public static extern InformationError SetRuntimeInfoChangedCallback(RuntimeInformationKey runtimeInfoKey, RuntimeInformationChangedCallback cb, IntPtr userData);
+ public static extern InformationError SetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey, RuntimeInformationChangedCallback cb, IntPtr userData);
[DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_unset_changed_cb")]
- public static extern InformationError UnsetRuntimeInfoChangedCallback(RuntimeInformationKey runtimeInfoKey);
+ public static extern InformationError UnsetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey);
}
}
* limitations under the License.
*/
-using System;
+using System.ComponentModel;
namespace Tizen.System
{
+ [EditorBrowsable(EditorBrowsableState.Never)]
/// <summary>
/// Enumeration for the runtime information key.
/// </summary>
- public enum RuntimeInformationKey
+ internal enum RuntimeInfoKey
{
/// <summary>
/// Indicates whether Bluetooth is enabled.
--- /dev/null
+/*
+* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// RuntimeFeatureStatusChangedEventArgs is an extended EventArgs class. This class contains event arguments for runtime event listeners.
+ /// </summary>
+ public class RuntimeFeatureStatusChangedEventArgs : EventArgs
+ {
+ /// <summary>
+ /// The key indicating the runtime system preference which was changed.
+ /// It includes the prefix "http://" though you don't use for registering callback.
+ /// </summary>
+ public String Key { get; internal set; }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.ComponentModel;
+
+namespace Tizen.System
+{
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal static class RuntimeInfo
+ {
+ private static RuntimeInfoEventHandler BluetoothEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.Bluetooth);
+ private static RuntimeInfoEventHandler WifiHotspotEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.WifiHotspot);
+ private static RuntimeInfoEventHandler BluetoothTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.BluetoothTethering);
+ private static RuntimeInfoEventHandler UsbTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.UsbTethering);
+ private static RuntimeInfoEventHandler PacketDataEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.PacketData);
+ private static RuntimeInfoEventHandler DataRoamingEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.DataRoaming);
+ private static RuntimeInfoEventHandler VibrationEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.Vibration);
+ private static RuntimeInfoEventHandler AudioJackConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.AudioJack);
+ private static RuntimeInfoEventHandler GpsStatusChanged = new RuntimeInfoEventHandler(RuntimeInfoKey.Gps);
+ private static RuntimeInfoEventHandler BatteryIsCharging = new RuntimeInfoEventHandler(RuntimeInfoKey.BatteryIsCharging);
+ private static RuntimeInfoEventHandler TvOutConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.TvOut);
+ private static RuntimeInfoEventHandler AudioJackConnectorChanged = new RuntimeInfoEventHandler(RuntimeInfoKey.AudioJackConnector);
+ private static RuntimeInfoEventHandler ChargerConnected = new RuntimeInfoEventHandler(RuntimeInfoKey.Charger);
+ private static RuntimeInfoEventHandler AutoRotationEnabled = new RuntimeInfoEventHandler(RuntimeInfoKey.AutoRotation);
+
+ internal static readonly Dictionary<RuntimeInfoKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInfoKey, Type>
+ {
+ [RuntimeInfoKey.Bluetooth] = typeof(bool),
+ [RuntimeInfoKey.WifiHotspot] = typeof(bool),
+ [RuntimeInfoKey.BluetoothTethering] = typeof(bool),
+ [RuntimeInfoKey.UsbTethering] = typeof(bool),
+ [RuntimeInfoKey.PacketData] = typeof(bool),
+ [RuntimeInfoKey.DataRoaming] = typeof(bool),
+ [RuntimeInfoKey.Vibration] = typeof(bool),
+ [RuntimeInfoKey.AudioJack] = typeof(bool),
+ [RuntimeInfoKey.BatteryIsCharging] = typeof(bool),
+ [RuntimeInfoKey.TvOut] = typeof(bool),
+ [RuntimeInfoKey.Charger] = typeof(bool),
+ [RuntimeInfoKey.AutoRotation] = typeof(bool),
+ [RuntimeInfoKey.Gps] = typeof(int),
+ [RuntimeInfoKey.AudioJackConnector] = typeof(int)
+ };
+
+ /// <summary>
+ /// Validates the data type of the status represented by the runtime key.
+ /// Note that this is a generic method.
+ /// </summary>
+ /// <typeparam name="T">The generic type to validate.</typeparam>
+ /// <param name="key">The runtime information key for which the status type is validated.</param>
+ /// <returns>True if the data type matches.</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
+ internal static bool Is<T>(RuntimeInfoKey key)
+ {
+ if (!s_keyDataTypeMapping.ContainsKey(key))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid data type");
+ throw new ArgumentException("Invalid parameter");
+ }
+
+ return s_keyDataTypeMapping[key] == typeof(T);
+ }
+
+ /// <summary>
+ /// Gets the status of runtime key.
+ /// Note that this is a generic method.
+ /// </summary>
+ /// <typeparam name="T">The generic type to return.</typeparam>
+ /// <param name="key">The runtime information key for which the current should be read.</param>
+ /// <param name="value">The value of the given feature.</param>
+ /// <returns>Returns true on success, otherwise false.</returns>
+ internal static bool TryGetValue<T>(RuntimeInfoKey key, out T value)
+ {
+ Type type;
+ value = default(T);
+
+ if (!s_keyDataTypeMapping.TryGetValue(key, out type))
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ return false;
+ }
+
+ if (type == typeof(bool))
+ {
+ InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out bool val);
+
+ if (ret != InformationError.None)
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
+ return false;
+ }
+
+ value = (T)(object)val;
+ }
+ else if(type == typeof(int))
+ {
+ InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out int val);
+
+ if (ret != InformationError.None)
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
+ return false;
+ }
+
+ value = (T)(object)val;
+ }
+
+ return true;
+ }
+
+ private static void FindEventHandler(RuntimeInfoKey key, ref RuntimeInfoEventHandler handler)
+ {
+ switch (key)
+ {
+ case RuntimeInfoKey.Bluetooth:
+ handler = BluetoothEnabled;
+ break;
+ case RuntimeInfoKey.WifiHotspot:
+ handler = WifiHotspotEnabled;
+ break;
+ case RuntimeInfoKey.BluetoothTethering:
+ handler = BluetoothTetheringEnabled;
+ break;
+ case RuntimeInfoKey.UsbTethering:
+ handler = UsbTetheringEnabled;
+ break;
+ case RuntimeInfoKey.PacketData:
+ handler = PacketDataEnabled;
+ break;
+ case RuntimeInfoKey.DataRoaming:
+ handler = DataRoamingEnabled;
+ break;
+ case RuntimeInfoKey.Vibration:
+ handler = VibrationEnabled;
+ break;
+ case RuntimeInfoKey.AudioJack:
+ handler = AudioJackConnected;
+ break;
+ case RuntimeInfoKey.Gps:
+ handler = GpsStatusChanged;
+ break;
+ case RuntimeInfoKey.BatteryIsCharging:
+ handler = BatteryIsCharging;
+ break;
+ case RuntimeInfoKey.TvOut:
+ handler = TvOutConnected;
+ break;
+ case RuntimeInfoKey.AudioJackConnector:
+ handler = AudioJackConnectorChanged;
+ break;
+ case RuntimeInfoKey.Charger:
+ handler = ChargerConnected;
+ break;
+ case RuntimeInfoKey.AutoRotation:
+ handler = AutoRotationEnabled;
+ break;
+ default:
+ handler = null;
+ break;
+ }
+ }
+
+ /// <summary>
+ /// Registers a change event callback for given key.
+ /// </summary>
+ /// <param name="key">The runtime information key which wants to register callback.</param>
+ /// <param name="callback">The callback function to subscribe.</param>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
+ /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
+ internal static void SetCallback(RuntimeInfoKey key, EventHandler<RuntimeFeatureStatusChangedEventArgs> callback)
+ {
+ RuntimeInfoEventHandler handler = null;
+
+ FindEventHandler(key, ref handler);
+ if (handler == null)
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
+ }
+
+ handler.EventHandler += callback;
+ }
+
+ /// <summary>
+ /// Unregisters a change event callback for given key.
+ /// </summary>
+ /// <param name="key">The runtime information key which wants to unregister callback.</param>
+ /// <param name="callback">The callback function to unsubscribe.</param>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
+ internal static void UnsetCallback(RuntimeInfoKey key, EventHandler<RuntimeFeatureStatusChangedEventArgs> callback)
+ {
+ RuntimeInfoEventHandler handler = null;
+
+ FindEventHandler(key, ref handler);
+ if (handler == null)
+ {
+ Log.Error(InformationErrorFactory.LogTag, "Invalid key");
+ InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
+ }
+
+ handler.EventHandler -= callback;
+ }
+ }
+}
[EditorBrowsable(EditorBrowsableState.Never)]
internal class RuntimeInfoEventHandler
{
- private RuntimeInformationKey Key;
- private event EventHandler<RuntimeKeyStatusChangedEventArgs> Handler;
+ private RuntimeInfoKey Key;
+ private event EventHandler<RuntimeFeatureStatusChangedEventArgs> Handler;
- internal RuntimeInfoEventHandler(RuntimeInformationKey key)
+ internal RuntimeInfoEventHandler(RuntimeInfoKey key)
{
Key = key;
Handler = null;
}
- internal event EventHandler<RuntimeKeyStatusChangedEventArgs> EventHandler
+ internal event EventHandler<RuntimeFeatureStatusChangedEventArgs> EventHandler
{
add
{
}
}
- private void RuntimeInformationChangedCallback(RuntimeInformationKey key, IntPtr userData)
+ private void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData)
{
- RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs()
+ RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs()
{
- Key = key
+ Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + (Information.EnumStringMapping.ContainsKey(key) ? Information.EnumStringMapping[key] : "Invalid")
};
Handler?.Invoke(null, eventArgs);
+++ /dev/null
-/*
-* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.ComponentModel;
-using System.Runtime.InteropServices;
-
-namespace Tizen.System
-{
- /// <summary>
- /// The RuntimeInformation provides functions to obtain the runtime information of various system preferences.
- /// </summary>
- public static class RuntimeInformation
- {
- private static RuntimeInfoEventHandler BluetoothEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.Bluetooth);
- private static RuntimeInfoEventHandler WifiHotspotEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.WifiHotspot);
- private static RuntimeInfoEventHandler BluetoothTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.BluetoothTethering);
- private static RuntimeInfoEventHandler UsbTetheringEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.UsbTethering);
- private static RuntimeInfoEventHandler PacketDataEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.PacketData);
- private static RuntimeInfoEventHandler DataRoamingEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.DataRoaming);
- private static RuntimeInfoEventHandler VibrationEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.Vibration);
- private static RuntimeInfoEventHandler AudioJackConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.AudioJack);
- private static RuntimeInfoEventHandler GpsStatusChanged = new RuntimeInfoEventHandler(RuntimeInformationKey.Gps);
- private static RuntimeInfoEventHandler BatteryIsCharging = new RuntimeInfoEventHandler(RuntimeInformationKey.BatteryIsCharging);
- private static RuntimeInfoEventHandler TvOutConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.TvOut);
- private static RuntimeInfoEventHandler AudioJackConnectorChanged = new RuntimeInfoEventHandler(RuntimeInformationKey.AudioJackConnector);
- private static RuntimeInfoEventHandler ChargerConnected = new RuntimeInfoEventHandler(RuntimeInformationKey.Charger);
- private static RuntimeInfoEventHandler AutoRotationEnabled = new RuntimeInfoEventHandler(RuntimeInformationKey.AutoRotation);
-
- internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
- {
- [RuntimeInformationKey.Bluetooth] = typeof(bool),
- [RuntimeInformationKey.WifiHotspot] = typeof(bool),
- [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
- [RuntimeInformationKey.UsbTethering] = typeof(bool),
- [RuntimeInformationKey.PacketData] = typeof(bool),
- [RuntimeInformationKey.DataRoaming] = typeof(bool),
- [RuntimeInformationKey.Vibration] = typeof(bool),
- [RuntimeInformationKey.AudioJack] = typeof(bool),
- [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
- [RuntimeInformationKey.TvOut] = typeof(bool),
- [RuntimeInformationKey.Charger] = typeof(bool),
- [RuntimeInformationKey.AutoRotation] = typeof(bool),
- [RuntimeInformationKey.Gps] = typeof(int),
- [RuntimeInformationKey.AudioJackConnector] = typeof(int)
- };
-
- /// <summary>
- /// Validates the data type of the status represented by the runtime key.
- /// Note that this is a generic method.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <typeparam name="T">The generic type to validate.</typeparam>
- /// <param name="key">The runtime information key for which the status type is validated.</param>
- /// <returns>True if the data type matches.</returns>
- /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
- public static bool Is<T>(RuntimeInformationKey key)
- {
- if (!s_keyDataTypeMapping.ContainsKey(key))
- {
- Log.Error(InformationErrorFactory.LogTag, "Invalid data type");
- throw new ArgumentException("Invalid parameter");
- }
-
- return s_keyDataTypeMapping[key] == typeof(T);
- }
-
- /// <summary>
- /// Gets the status of runtime key.
- /// Note that this is a generic method.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- /// <typeparam name="T">The generic type to return.</typeparam>
- /// <param name="key">The runtime information key for which the current should be read.</param>
- /// <param name="value">The value of the given feature.</param>
- /// <returns>Returns true on success, otherwise false.</returns>
- public static bool TryGetValue<T>(RuntimeInformationKey key, out T value)
- {
- Type type;
- value = default(T);
-
- if (!s_keyDataTypeMapping.TryGetValue(key, out type))
- {
- Log.Error(InformationErrorFactory.LogTag, "Invalid key");
- return false;
- }
-
- if (type == typeof(bool))
- {
- InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out bool val);
-
- if (ret != InformationError.None)
- {
- Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
- return false;
- }
-
- value = (T)(object)val;
- }
- else if(type == typeof(int))
- {
- InformationError ret = Interop.RuntimeInfo.GetValue(TvProductHelper.ConvertKeyIfTvProduct(key), out int val);
-
- if (ret != InformationError.None)
- {
- Log.Error(InformationErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
- return false;
- }
-
- value = (T)(object)val;
- }
-
- return true;
- }
-
- [EditorBrowsable(EditorBrowsableState.Never)]
- private static void FindEventHandler(RuntimeInformationKey key, ref RuntimeInfoEventHandler handler)
- {
- switch (key)
- {
- case RuntimeInformationKey.Bluetooth:
- handler = BluetoothEnabled;
- break;
- case RuntimeInformationKey.WifiHotspot:
- handler = WifiHotspotEnabled;
- break;
- case RuntimeInformationKey.BluetoothTethering:
- handler = BluetoothTetheringEnabled;
- break;
- case RuntimeInformationKey.UsbTethering:
- handler = UsbTetheringEnabled;
- break;
- case RuntimeInformationKey.PacketData:
- handler = PacketDataEnabled;
- break;
- case RuntimeInformationKey.DataRoaming:
- handler = DataRoamingEnabled;
- break;
- case RuntimeInformationKey.Vibration:
- handler = VibrationEnabled;
- break;
- case RuntimeInformationKey.AudioJack:
- handler = AudioJackConnected;
- break;
- case RuntimeInformationKey.Gps:
- handler = GpsStatusChanged;
- break;
- case RuntimeInformationKey.BatteryIsCharging:
- handler = BatteryIsCharging;
- break;
- case RuntimeInformationKey.TvOut:
- handler = TvOutConnected;
- break;
- case RuntimeInformationKey.AudioJackConnector:
- handler = AudioJackConnectorChanged;
- break;
- case RuntimeInformationKey.Charger:
- handler = ChargerConnected;
- break;
- case RuntimeInformationKey.AutoRotation:
- handler = AutoRotationEnabled;
- break;
- default:
- handler = null;
- break;
- }
- }
-
- /// <summary>
- /// Registers a change event callback for given key.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- /// <param name="key">The runtime information key which wants to register callback.</param>
- /// <param name="callback">The callback function to subscribe.</param>
- /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
- /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
- public static void SetCallback(RuntimeInformationKey key, EventHandler<RuntimeKeyStatusChangedEventArgs> callback)
- {
- RuntimeInfoEventHandler handler = null;
-
- FindEventHandler(key, ref handler);
- if (handler == null)
- {
- Log.Error(InformationErrorFactory.LogTag, "Invalid key");
- InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
- }
-
- handler.EventHandler += callback;
- }
-
- /// <summary>
- /// Unregisters a change event callback for given key.
- /// </summary>
- /// <since_tizen> 4 </since_tizen>
- /// <param name="key">The runtime information key which wants to unregister callback.</param>
- /// <param name="callback">The callback function to unsubscribe.</param>
- /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
- public static void UnsetCallback(RuntimeInformationKey key, EventHandler<RuntimeKeyStatusChangedEventArgs> callback)
- {
- RuntimeInfoEventHandler handler = null;
-
- FindEventHandler(key, ref handler);
- if (handler == null)
- {
- Log.Error(InformationErrorFactory.LogTag, "Invalid key");
- InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
- }
-
- handler.EventHandler -= callback;
- }
- }
-}
+++ /dev/null
-/*
-* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Tizen.System
-{
- /// <summary>
- /// RuntimeInfoChangedEventArgs is an extended EventArgs class. This class contains event arguments for runtime event listeners.
- /// </summary>
- public class RuntimeKeyStatusChangedEventArgs : EventArgs
- {
- /// <summary>
- /// The key indicating the runtime system preference which was changed.
- /// </summary>
- public RuntimeInformationKey Key { get; internal set; }
- }
-}
{
private static int is_TV_product = -1;
- private static readonly Dictionary<RuntimeInformationKey, int> s_keyTVkeyMapping = new Dictionary<RuntimeInformationKey, int>
+ private static readonly Dictionary<RuntimeInfoKey, int> s_keyTVkeyMapping = new Dictionary<RuntimeInfoKey, int>
{
- [RuntimeInformationKey.Bluetooth] = 5,
- [RuntimeInformationKey.WifiHotspot] = 6,
- [RuntimeInformationKey.BluetoothTethering] = 7,
- [RuntimeInformationKey.UsbTethering] = 8,
- [RuntimeInformationKey.PacketData] = 13,
- [RuntimeInformationKey.DataRoaming] = 14,
- [RuntimeInformationKey.Vibration] = 16,
- [RuntimeInformationKey.AudioJack] = 20,
- [RuntimeInformationKey.BatteryIsCharging] = 22,
- [RuntimeInformationKey.TvOut] = 18,
- [RuntimeInformationKey.Charger] = 26,
- [RuntimeInformationKey.AutoRotation] = 28,
- [RuntimeInformationKey.Gps] = 21,
- [RuntimeInformationKey.AudioJackConnector] = 20
+ [RuntimeInfoKey.Bluetooth] = 5,
+ [RuntimeInfoKey.WifiHotspot] = 6,
+ [RuntimeInfoKey.BluetoothTethering] = 7,
+ [RuntimeInfoKey.UsbTethering] = 8,
+ [RuntimeInfoKey.PacketData] = 13,
+ [RuntimeInfoKey.DataRoaming] = 14,
+ [RuntimeInfoKey.Vibration] = 16,
+ [RuntimeInfoKey.AudioJack] = 20,
+ [RuntimeInfoKey.BatteryIsCharging] = 22,
+ [RuntimeInfoKey.TvOut] = 18,
+ [RuntimeInfoKey.Charger] = 26,
+ [RuntimeInfoKey.AutoRotation] = 28,
+ [RuntimeInfoKey.Gps] = 21,
+ [RuntimeInfoKey.AudioJackConnector] = 20
};
/// This function is for a TV product. It will be removed.
- internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key)
+ internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
{
bool is_key_existed = false;
string profile;
{
InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
}
- return (RuntimeInformationKey)key_TV;
+ return (RuntimeInfoKey)key_TV;
}
}
}
namespace Tizen.System
{
- /// <summary>
- /// System Information class. This class has methods which can be used to obtain device information.
- /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
public static class SystemInfo
{
[EditorBrowsable(EditorBrowsableState.Never)]
/// <summary>
/// Checks if the type of value for the given feature is T.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <typeparam name="T">Type of value for the feature key.</typeparam>
/// <param name="key">The name of the feature.</param>
/// <returns>True if type of value for the given feature is T, otherwise false.</returns>
- public static bool Is<T>(string key)
+ internal static bool Is<T>(string key)
{
Interop.SystemInfo.SystemInfoValueType valueType;
Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType);
/// <summary>
/// Checks if the given key is a valid feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <param name="key">The name of the feature.</param>
/// <returns>True if the key is valid, otherwise false.</returns>
- public static bool IsValidKey(string key)
+ internal static bool IsValidKey(string key)
{
Interop.SystemInfo.SystemInfoValueType valueType;
return GetValueType(key, out valueType) != Interop.SystemInfo.SystemInfoType.None;
/// <summary>
/// Gets the value of the feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <typeparam name="T">Type of key value.</typeparam>
/// <param name="key">The name of the feature.</param>
/// <param name="value">The value of the given feature.</param>
/// <returns>Returns true on success, otherwise false.</returns>
- public static bool TryGetValue<T>(string key, out T value)
+ internal static bool TryGetValue<T>(string key, out T value)
{
bool res = false;
if (typeof(T) == typeof(bool))
/// <summary>
/// Gets the bool value of the feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <param name="key">The name of the feature.</param>
/// <param name="value">The value of the given feature.</param>
/// <returns>Returns true on success, otherwise false.</returns>
/// <summary>
/// Gets the int value of the feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <param name="key">The name of the feature.</param>
/// <param name="value">The value of the given feature.</param>
/// <returns>Returns true on success, otherwise false.</returns>
/// <summary>
/// Gets the double value of the feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <param name="key">The name of the feature.</param>
/// <param name="value">The value of the given feature.</param>
/// <returns>Returns true on success, otherwise false.</returns>
- public static bool TryGetValue(string key, out double value)
+ internal static bool TryGetValue(string key, out double value)
{
Interop.SystemInfo.SystemInfoValueType valueType;
Interop.SystemInfo.SystemInfoType keyType = GetValueType(key, out valueType);
/// <summary>
/// Gets the string value of the feature.
/// </summary>
- /// <since_tizen> 3 </since_tizen>
/// <param name="key">The name of the feature.</param>
/// <param name="value">The value of the given feature.</param>
/// <returns>Returns true on success, otherwise false.</returns>
/// </summary>
public class SystemCpuUsage
{
- internal Interop.RuntimeInfo.CpuUsage Usage;
- internal int[] CurrentFrequencies;
- internal int[] MaxFrequencies;
+ private Interop.RuntimeInfo.CpuUsage Usage;
+ private int[] CurrentFrequencies;
+ private int[] MaxFrequencies;
/// <summary>
/// The constructor of SystemCpuUsage class.
/// </summary>
public class SystemMemoryUsage
{
- internal Interop.RuntimeInfo.MemoryInfo Info;
+ private Interop.RuntimeInfo.MemoryInfo Info;
/// <summary>
/// The constructor of MemoryInformation class.