2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
22 using System.Threading.Tasks;
23 using System.ComponentModel;
25 namespace Tizen.System
28 /// The RuntimeInformation provides functions to obtain runtime information of various system preferences.
30 public static class RuntimeInformation
32 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothEnabled;
33 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_wifiHotspotEnabled;
34 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothTetheringEnabled;
35 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_usbTetheringEnabled;
36 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_packetDataEnabled;
37 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_dataRoamingEnabled;
38 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_vibrationEnabled;
39 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnected;
40 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_gpsStatusChanged;
41 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_batteryIsCharging;
42 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_tvOutConnected;
43 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnectorChanged;
44 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_chargerConnected;
45 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_autoRotationEnabled;
47 private static readonly Interop.RuntimeInfo.RuntimeInformationChangedCallback s_runtimeInfoChangedCallback = (RuntimeInformationKey key, IntPtr userData) =>
49 RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs()
55 case RuntimeInformationKey.Bluetooth:
57 s_bluetoothEnabled?.Invoke(null, eventArgs);
60 case RuntimeInformationKey.WifiHotspot:
62 s_wifiHotspotEnabled?.Invoke(null, eventArgs);
65 case RuntimeInformationKey.BluetoothTethering:
67 s_bluetoothTetheringEnabled?.Invoke(null, eventArgs);
70 case RuntimeInformationKey.UsbTethering:
72 s_usbTetheringEnabled?.Invoke(null, eventArgs);
75 case RuntimeInformationKey.PacketData:
77 s_packetDataEnabled?.Invoke(null, eventArgs);
80 case RuntimeInformationKey.DataRoaming:
82 s_dataRoamingEnabled?.Invoke(null, eventArgs);
85 case RuntimeInformationKey.Vibration:
87 s_vibrationEnabled?.Invoke(null, eventArgs);
90 case RuntimeInformationKey.AudioJack:
92 s_audioJackConnected?.Invoke(null, eventArgs);
95 case RuntimeInformationKey.Gps:
97 s_gpsStatusChanged?.Invoke(null, eventArgs);
100 case RuntimeInformationKey.BatteryIsCharging:
102 s_batteryIsCharging?.Invoke(null, eventArgs);
105 case RuntimeInformationKey.TvOut:
107 s_tvOutConnected?.Invoke(null, eventArgs);
110 case RuntimeInformationKey.AudioJackConnector:
112 s_audioJackConnectorChanged?.Invoke(null, eventArgs);
115 case RuntimeInformationKey.Charger:
117 s_chargerConnected?.Invoke(null, eventArgs);
120 case RuntimeInformationKey.AutoRotation:
122 s_autoRotationEnabled?.Invoke(null, eventArgs);
130 internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
132 [RuntimeInformationKey.Bluetooth] = typeof(bool),
133 [RuntimeInformationKey.WifiHotspot] = typeof(bool),
134 [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
135 [RuntimeInformationKey.UsbTethering] = typeof(bool),
136 [RuntimeInformationKey.PacketData] = typeof(bool),
137 [RuntimeInformationKey.DataRoaming] = typeof(bool),
138 [RuntimeInformationKey.Vibration] = typeof(bool),
139 [RuntimeInformationKey.AudioJack] = typeof(bool),
140 [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
141 [RuntimeInformationKey.TvOut] = typeof(bool),
142 [RuntimeInformationKey.Charger] = typeof(bool),
143 [RuntimeInformationKey.AutoRotation] = typeof(bool),
144 [RuntimeInformationKey.Gps] = typeof(int),
145 [RuntimeInformationKey.AudioJackConnector] = typeof(int)
148 internal static readonly Dictionary<RuntimeInformationKey, int> s_keyTVkeyMapping = new Dictionary<RuntimeInformationKey, int>
\r
150 [RuntimeInformationKey.Bluetooth] = 5,
151 [RuntimeInformationKey.WifiHotspot] = 6,
152 [RuntimeInformationKey.BluetoothTethering] = 7,
153 [RuntimeInformationKey.UsbTethering] = 8,
154 [RuntimeInformationKey.PacketData] = 13,
155 [RuntimeInformationKey.DataRoaming] = 14,
156 [RuntimeInformationKey.Vibration] = 16,
157 [RuntimeInformationKey.AudioJack] = 20,
158 [RuntimeInformationKey.BatteryIsCharging] = 22,
159 [RuntimeInformationKey.TvOut] = 18,
160 [RuntimeInformationKey.Charger] = 26,
161 [RuntimeInformationKey.AutoRotation] = 28,
162 [RuntimeInformationKey.Gps] = 21,
163 [RuntimeInformationKey.AudioJackConnector] = 20
\r
166 internal static int is_TV_product = -1;
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 /// This function is for TV product. It will be removed
170 internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key)
\r
172 bool is_key_existed = false;
\r
176 if (is_TV_product == -1)
\r
178 is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
\r
179 if (is_key_existed && String.Compare(profile, "TV") == 0)
\r
189 if (is_TV_product == 0)
\r
195 if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV))
\r
197 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
\r
199 return (RuntimeInformationKey)key_TV;
\r
203 [EditorBrowsable(EditorBrowsableState.Never)]
204 internal static object GetStatus(RuntimeInformationKey key)
207 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
209 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
212 if (s_keyDataTypeMapping[key] == typeof(int))
215 int ret = Interop.RuntimeInfo.GetValue(ConvertKeyIfTvProduct(key), out status);
216 if (ret != (int)RuntimeInfoError.None)
218 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
219 RuntimeInfoErrorFactory.ThrowException(ret);
227 int ret = Interop.RuntimeInfo.GetValue(ConvertKeyIfTvProduct(key), out status);
228 if (ret != (int)RuntimeInfoError.None)
230 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
231 RuntimeInfoErrorFactory.ThrowException(ret);
239 /// Validates the data type of the status represented by Runtime Key.
240 /// Note that this is a generic method.
242 /// <typeparam name="T">The generic type to validate.</typeparam>
243 /// <param name="key">The runtime information key for which the status type is validated </param>
244 /// <returns>true if the data type matches</returns>.
245 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
246 public static bool Is<T>(RuntimeInformationKey key)
248 if (!s_keyDataTypeMapping.ContainsKey(key))
250 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
251 throw new ArgumentException("Invalid parameter");
254 return s_keyDataTypeMapping[key] == typeof(T);
258 /// Gets the status of Runtime Key.
259 /// Note that this is a generic method.
261 /// <typeparam name="T">The generic type to return.</typeparam>
262 /// <param name="key">The runtime information key for which the current should be read </param>
263 /// <returns>The current status of the given key</returns>.
264 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
265 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
266 /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
267 public static T GetStatus<T>(RuntimeInformationKey key)
269 return (T)GetStatus(key);
273 /// Gets system memory information
275 /// <returns>The system memory information structure.</returns>
276 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
277 public static SystemMemoryInformation GetSystemMemoryInformation()
279 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
280 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
281 if (ret != (int)RuntimeInfoError.None)
283 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
284 RuntimeInfoErrorFactory.ThrowException(ret);
287 return new SystemMemoryInformation(info);
291 /// Gets memory information per processes
293 /// <param name="pid">List of unique process ids </param>
294 /// <returns>List of memory information per processes</returns>
295 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
296 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
297 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system or requesting to resource management daemon.</exception>
298 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
299 /// <exception cref="UnauthorizedAccessException">Thrown when caller doesn't have a privilege to use this method.</exception>
300 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
302 int[] processArray = pid.ToArray<int>();
303 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
304 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
305 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
306 if (ret != (int)RuntimeInfoError.None)
308 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
309 RuntimeInfoErrorFactory.ThrowException(ret);
313 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
315 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
316 map.Add(processArray[idx], processMemory);
324 /// Gets system CPU usage time
326 /// <returns>The system CPU usage time structure.</returns>
327 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
328 public static CpuUsage GetCpuUsage()
330 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
331 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
332 if (ret != (int)RuntimeInfoError.None)
334 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
335 RuntimeInfoErrorFactory.ThrowException(ret);
337 return new CpuUsage(usage);
341 /// Gets the CPU usage time per process
343 /// <param name="pid">List of unique process ids </param>
344 /// <returns>List of CPU usage information per processes</returns>
345 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
346 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
347 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system or requesting to resource management daemon.</exception>
348 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
349 /// <exception cref="UnauthorizedAccessException">Thrown when caller doesn't have a privilege to use this method.</exception>
350 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
352 int[] processArray = pid.ToArray<int>();
353 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
354 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
355 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
356 if (ret != (int)RuntimeInfoError.None)
358 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
359 RuntimeInfoErrorFactory.ThrowException(ret);
363 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
365 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
366 map.Add(processArray[idx], processUsage);
374 /// Gets the number of processors
376 /// <value>The number of processors</value>
377 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
378 public static int ProcessorCount
383 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
384 if (ret != (int)RuntimeInfoError.None)
386 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
387 RuntimeInfoErrorFactory.ThrowException(ret);
395 /// Gets the current frequency of processor
397 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
398 /// <returns>The current frequency(MHz) of processor</returns>
399 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
400 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
401 /// <exception cref="NotSupportedException">Thrown when this system doesn't store CPU current frequency.</exception>
402 public static int GetProcessorCurrentFrequency(int coreId)
405 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
406 if (ret != (int)RuntimeInfoError.None)
408 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
409 RuntimeInfoErrorFactory.ThrowException(ret);
415 /// Gets the max frequency of processor
417 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
418 /// <returns>The max frequency(MHz) of processor</returns>
419 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
420 /// <exception cref="IOException">Thrown when I/O error is occurred while reading from system.</exception>
421 /// <exception cref="NotSupportedException">Thrown when this system doesn't store CPU max frequency.</exception>
422 public static int GetProcessorMaxFrequency(int coreId)
425 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
426 if (ret != (int)RuntimeInfoError.None)
428 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
429 RuntimeInfoErrorFactory.ThrowException(ret);
435 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
437 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
441 if (s_bluetoothEnabled == null)
443 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth), s_runtimeInfoChangedCallback, IntPtr.Zero);
444 if (ret != (int)RuntimeInfoError.None)
446 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
447 RuntimeInfoErrorFactory.ThrowException(ret);
450 s_bluetoothEnabled += value;
454 s_bluetoothEnabled -= value;
455 if (s_bluetoothEnabled == null)
457 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth));
458 if (ret != (int)RuntimeInfoError.None)
460 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
461 RuntimeInfoErrorFactory.ThrowException(ret);
467 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
469 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
473 if (s_wifiHotspotEnabled == null)
475 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot), s_runtimeInfoChangedCallback, IntPtr.Zero);
476 if (ret != (int)RuntimeInfoError.None)
478 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
479 RuntimeInfoErrorFactory.ThrowException(ret);
482 s_wifiHotspotEnabled += value;
486 s_wifiHotspotEnabled -= value;
487 if (s_wifiHotspotEnabled == null)
489 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot));
490 if (ret != (int)RuntimeInfoError.None)
492 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
493 RuntimeInfoErrorFactory.ThrowException(ret);
499 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
501 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
505 if (s_bluetoothTetheringEnabled == null)
507 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
508 if (ret != (int)RuntimeInfoError.None)
510 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
511 RuntimeInfoErrorFactory.ThrowException(ret);
514 s_bluetoothTetheringEnabled += value;
518 s_bluetoothTetheringEnabled -= value;
519 if (s_bluetoothTetheringEnabled == null)
521 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering));
522 if (ret != (int)RuntimeInfoError.None)
524 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
525 RuntimeInfoErrorFactory.ThrowException(ret);
531 /// (event) UsbTetheringEnabled is raised when system preference for USB tethering is changed.
533 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
537 if (s_usbTetheringEnabled == null)
539 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
540 if (ret != (int)RuntimeInfoError.None)
542 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
543 RuntimeInfoErrorFactory.ThrowException(ret);
546 s_usbTetheringEnabled += value;
550 s_usbTetheringEnabled -= value;
551 if (s_usbTetheringEnabled == null)
553 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering));
554 if (ret != (int)RuntimeInfoError.None)
556 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
557 RuntimeInfoErrorFactory.ThrowException(ret);
563 /// (event) PacketDataEnabled is raised when system preference for package data through 3G network is changed.
565 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
569 if (s_packetDataEnabled == null)
571 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData), s_runtimeInfoChangedCallback, IntPtr.Zero);
572 if (ret != (int)RuntimeInfoError.None)
574 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
575 RuntimeInfoErrorFactory.ThrowException(ret);
578 s_packetDataEnabled += value;
582 s_packetDataEnabled -= value;
583 if (s_packetDataEnabled == null)
585 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData));
586 if (ret != (int)RuntimeInfoError.None)
588 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
589 RuntimeInfoErrorFactory.ThrowException(ret);
595 /// (event) DataRoamingEnabled is raised when system preference for data roaming is changed.
597 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
601 if (s_dataRoamingEnabled == null)
603 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming), s_runtimeInfoChangedCallback, IntPtr.Zero);
604 if (ret != (int)RuntimeInfoError.None)
606 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
607 RuntimeInfoErrorFactory.ThrowException(ret);
610 s_dataRoamingEnabled += value;
614 s_dataRoamingEnabled -= value;
615 if (s_dataRoamingEnabled == null)
617 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming));
618 if (ret != (int)RuntimeInfoError.None)
620 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
621 RuntimeInfoErrorFactory.ThrowException(ret);
627 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
629 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
633 if (s_vibrationEnabled == null)
635 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration), s_runtimeInfoChangedCallback, IntPtr.Zero);
636 if (ret != (int)RuntimeInfoError.None)
638 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
639 RuntimeInfoErrorFactory.ThrowException(ret);
642 s_vibrationEnabled += value;
646 s_vibrationEnabled -= value;
647 if (s_vibrationEnabled == null)
649 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration));
650 if (ret != (int)RuntimeInfoError.None)
652 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
653 RuntimeInfoErrorFactory.ThrowException(ret);
659 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
661 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
665 if (s_audioJackConnected == null)
667 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack), s_runtimeInfoChangedCallback, IntPtr.Zero);
668 if (ret != (int)RuntimeInfoError.None)
670 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
671 RuntimeInfoErrorFactory.ThrowException(ret);
674 s_audioJackConnected += value;
678 s_audioJackConnected -= value;
679 if (s_audioJackConnected == null)
681 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack));
682 if (ret != (int)RuntimeInfoError.None)
684 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
685 RuntimeInfoErrorFactory.ThrowException(ret);
691 /// (event) GpsStatusChanged is raised when status of GPS is changed.
693 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
697 if (s_gpsStatusChanged == null)
699 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps), s_runtimeInfoChangedCallback, IntPtr.Zero);
700 if (ret != (int)RuntimeInfoError.None)
702 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
703 RuntimeInfoErrorFactory.ThrowException(ret);
706 s_gpsStatusChanged += value;
710 s_gpsStatusChanged -= value;
711 if (s_gpsStatusChanged == null)
713 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps));
714 if (ret != (int)RuntimeInfoError.None)
716 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
717 RuntimeInfoErrorFactory.ThrowException(ret);
723 /// (event) BatteryIsCharging is raised battery is currently charging.
725 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
729 if (s_batteryIsCharging == null)
731 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging), s_runtimeInfoChangedCallback, IntPtr.Zero);
732 if (ret != (int)RuntimeInfoError.None)
734 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
735 RuntimeInfoErrorFactory.ThrowException(ret);
738 s_batteryIsCharging += value;
742 s_batteryIsCharging -= value;
743 if (s_batteryIsCharging == null)
745 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging));
746 if (ret != (int)RuntimeInfoError.None)
748 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
749 RuntimeInfoErrorFactory.ThrowException(ret);
755 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
757 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
761 if (s_tvOutConnected == null)
763 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut), s_runtimeInfoChangedCallback, IntPtr.Zero);
764 if (ret != (int)RuntimeInfoError.None)
766 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
767 RuntimeInfoErrorFactory.ThrowException(ret);
770 s_tvOutConnected += value;
774 s_tvOutConnected -= value;
775 if (s_tvOutConnected == null)
777 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut));
778 if (ret != (int)RuntimeInfoError.None)
780 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
781 RuntimeInfoErrorFactory.ThrowException(ret);
787 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
789 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
793 if (s_audioJackConnectorChanged == null)
795 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector), s_runtimeInfoChangedCallback, IntPtr.Zero);
796 if (ret != (int)RuntimeInfoError.None)
798 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
799 RuntimeInfoErrorFactory.ThrowException(ret);
802 s_audioJackConnectorChanged += value;
806 s_audioJackConnectorChanged -= value;
807 if (s_audioJackConnectorChanged == null)
809 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector));
810 if (ret != (int)RuntimeInfoError.None)
812 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
813 RuntimeInfoErrorFactory.ThrowException(ret);
819 /// (event) ChargerConnected is raised when charger is connected/disconnected.
821 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
825 if (s_chargerConnected == null)
827 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger), s_runtimeInfoChangedCallback, IntPtr.Zero);
828 if (ret != (int)RuntimeInfoError.None)
830 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
831 RuntimeInfoErrorFactory.ThrowException(ret);
834 s_chargerConnected += value;
838 s_chargerConnected -= value;
839 if (s_chargerConnected == null)
841 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger));
842 if (ret != (int)RuntimeInfoError.None)
844 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
845 RuntimeInfoErrorFactory.ThrowException(ret);
851 /// (event) AutoRotationEnabled is raised when system preference for auto rotation is changed.
853 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
857 if (s_autoRotationEnabled == null)
859 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation), s_runtimeInfoChangedCallback, IntPtr.Zero);
860 if (ret != (int)RuntimeInfoError.None)
862 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
863 RuntimeInfoErrorFactory.ThrowException(ret);
866 s_autoRotationEnabled += value;
870 s_autoRotationEnabled -= value;
871 if (s_autoRotationEnabled == null)
873 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation));
874 if (ret != (int)RuntimeInfoError.None)
876 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
877 RuntimeInfoErrorFactory.ThrowException(ret);