internal static RuntimeInfoKey ReconvertKeyIfTvProduct(RuntimeInfoKey key) { if (is_TV_product == -1) { CheckTvProduct(); } if (is_TV_product == 1) { foreach (KeyValuePair <RuntimeInfoKey, int> kvp in s_keyTVkeyMapping) { if (kvp.Value == (int)key) { return(kvp.Key); } } Log.Error(InformationErrorFactory.LogTag, "Key mapping failed"); return(0); } else { return(key); } }
/// This function is for a TV product. It will be removed. internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key) { bool is_key_existed = false; string profile; int key_TV = -1; if (is_TV_product == -1) { #pragma warning disable CS0618 // Type or member is obsolete is_key_existed = SystemInfo.TryGetValue <string>("http://com.samsung/build_config/product_type", out profile); #pragma warning restore CS0618 // Type or member is obsolete if (is_key_existed && String.Compare(profile, "TV") == 0) { is_TV_product = 1; } else { is_TV_product = 0; } } if (is_TV_product == 0) { return(key); } else { if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV)) { InformationErrorFactory.ThrowException(InformationError.InvalidParameter); } return((RuntimeInfoKey)key_TV); } }
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)); }
private void RuntimeInformationChangedCallback(RuntimeInfoKey key, IntPtr userData) { RuntimeFeatureStatusChangedEventArgs eventArgs = new RuntimeFeatureStatusChangedEventArgs() { Key = Information.HttpPrefix + Information.RuntimeInfoStringKeyPrefix + (Information.EnumStringMapping.ContainsKey(key) ? Information.EnumStringMapping[key] : "Invalid") }; Handler?.Invoke(null, eventArgs); }
/// <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)); }
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)); }
/// <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; }
internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key) { if (is_TV_product == -1) { CheckTvProduct(); } if (is_TV_product == 1) { if (!s_keyTVkeyMapping.TryGetValue(key, out int key_TV)) { InformationErrorFactory.ThrowException(InformationError.InvalidParameter); } return((RuntimeInfoKey)key_TV); } else { return(key); } }
/// <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); }
internal RuntimeInfoEventHandler(RuntimeInfoKey key) { Key = key; Handler = null; }
public static extern InformationError SetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey, RuntimeInformationChangedCallback cb, IntPtr userData);
public static extern InformationError GetValue(RuntimeInfoKey key, out string status);
public static extern InformationError UnsetRuntimeInfoChangedCallback(RuntimeInfoKey runtimeInfoKey);
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; } }