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 the 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>
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
166 internal static int is_TV_product = -1;
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 /// This function is for a TV product. It will be removed.
170 internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key)
172 bool is_key_existed = false;
176 if (is_TV_product == -1)
178 is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
179 if (is_key_existed && String.Compare(profile, "TV") == 0)
189 if (is_TV_product == 0)
195 if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV))
197 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
199 return (RuntimeInformationKey)key_TV;
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 the runtime key.
240 /// Note that this is a generic method.
242 /// <since_tizen> 3 </since_tizen>
243 /// <typeparam name="T">The generic type to validate.</typeparam>
244 /// <param name="key">The runtime information key for which the status type is validated.</param>
245 /// <returns>True if the data type matches.</returns>
246 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
247 public static bool Is<T>(RuntimeInformationKey key)
249 if (!s_keyDataTypeMapping.ContainsKey(key))
251 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
252 throw new ArgumentException("Invalid parameter");
255 return s_keyDataTypeMapping[key] == typeof(T);
259 /// Gets the status of runtime key.
260 /// Note that this is a generic method.
262 /// <since_tizen> 3 </since_tizen>
263 /// <typeparam name="T">The generic type to return.</typeparam>
264 /// <param name="key">The runtime information key for which the current should be read.</param>
265 /// <returns>The current status of the given key.</returns>.
266 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
267 /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
268 /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
269 public static T GetStatus<T>(RuntimeInformationKey key)
271 return (T)GetStatus(key);
275 /// Gets the system memory information.
277 /// <since_tizen> 3 </since_tizen>
278 /// <returns>The system memory information structure.</returns>
279 /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
280 public static SystemMemoryInformation GetSystemMemoryInformation()
282 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
283 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
284 if (ret != (int)RuntimeInfoError.None)
286 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
287 RuntimeInfoErrorFactory.ThrowException(ret);
290 return new SystemMemoryInformation(info);
294 /// Gets the memory information per process.
296 /// <since_tizen> 3 </since_tizen>
297 /// <param name="pid">List of unique process ids.</param>
298 /// <returns>List of memory information per process.</returns>
299 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
300 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
301 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
302 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
303 /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
304 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
306 int[] processArray = pid.ToArray<int>();
307 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
308 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
309 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
310 if (ret != (int)RuntimeInfoError.None)
312 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
313 RuntimeInfoErrorFactory.ThrowException(ret);
317 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
319 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
320 map.Add(processArray[idx], processMemory);
328 /// Gets the system CPU usage time.
330 /// <since_tizen> 3 </since_tizen>
331 /// <returns>The system CPU usage time structure.</returns>
332 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
333 public static CpuUsage GetCpuUsage()
335 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
336 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
337 if (ret != (int)RuntimeInfoError.None)
339 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
340 RuntimeInfoErrorFactory.ThrowException(ret);
342 return new CpuUsage(usage);
346 /// Gets the CPU usage time per process.
348 /// <since_tizen> 3 </since_tizen>
349 /// <param name="pid">List of unique process ids.</param>
350 /// <returns>List of CPU usage information per process.</returns>
351 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
352 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
353 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
354 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
355 /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
356 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
358 int[] processArray = pid.ToArray<int>();
359 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
360 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
361 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
362 if (ret != (int)RuntimeInfoError.None)
364 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
365 RuntimeInfoErrorFactory.ThrowException(ret);
369 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
371 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
372 map.Add(processArray[idx], processUsage);
380 /// Gets the number of processors.
382 /// <value>The number of processors.</value>
383 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
384 public static int ProcessorCount
389 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
390 if (ret != (int)RuntimeInfoError.None)
392 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
393 RuntimeInfoErrorFactory.ThrowException(ret);
401 /// Gets the current frequency of the processor.
403 /// <since_tizen> 3 </since_tizen>
404 /// <param name="coreId">The index (from 0) of the CPU core that you want to know the frequency of.</param>
405 /// <returns>The current frequency(MHz) of processor.</returns>
406 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
407 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
408 /// <exception cref="NotSupportedException">Thrown when this system does not store the current CPU frequency.</exception>
409 public static int GetProcessorCurrentFrequency(int coreId)
412 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
413 if (ret != (int)RuntimeInfoError.None)
415 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
416 RuntimeInfoErrorFactory.ThrowException(ret);
422 /// Gets the max frequency of the processor.
424 /// <since_tizen> 3 </since_tizen>
425 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency of.</param>
426 /// <returns>The max frequency(MHz) of processor.</returns>
427 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
428 /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
429 /// <exception cref="NotSupportedException">Thrown when this system does not store the max CPU frequency.</exception>
430 public static int GetProcessorMaxFrequency(int coreId)
433 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
434 if (ret != (int)RuntimeInfoError.None)
436 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
437 RuntimeInfoErrorFactory.ThrowException(ret);
443 /// (event) BluetoothEnabled is raised when the system preference for Bluetooth is changed.
445 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
449 if (s_bluetoothEnabled == null)
451 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth), s_runtimeInfoChangedCallback, IntPtr.Zero);
452 if (ret != (int)RuntimeInfoError.None)
454 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
455 RuntimeInfoErrorFactory.ThrowException(ret);
458 s_bluetoothEnabled += value;
462 s_bluetoothEnabled -= value;
463 if (s_bluetoothEnabled == null)
465 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth));
466 if (ret != (int)RuntimeInfoError.None)
468 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
469 RuntimeInfoErrorFactory.ThrowException(ret);
475 /// (event) WifiHotspotEnabled is raised when the system preference for Wi-Fi is changed.
477 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
481 if (s_wifiHotspotEnabled == null)
483 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot), s_runtimeInfoChangedCallback, IntPtr.Zero);
484 if (ret != (int)RuntimeInfoError.None)
486 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
487 RuntimeInfoErrorFactory.ThrowException(ret);
490 s_wifiHotspotEnabled += value;
494 s_wifiHotspotEnabled -= value;
495 if (s_wifiHotspotEnabled == null)
497 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot));
498 if (ret != (int)RuntimeInfoError.None)
500 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
501 RuntimeInfoErrorFactory.ThrowException(ret);
507 /// (event) BluetoothTetheringEnabled is raised when the system preference for bluetooth tethering is changed.
509 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
513 if (s_bluetoothTetheringEnabled == null)
515 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
516 if (ret != (int)RuntimeInfoError.None)
518 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
519 RuntimeInfoErrorFactory.ThrowException(ret);
522 s_bluetoothTetheringEnabled += value;
526 s_bluetoothTetheringEnabled -= value;
527 if (s_bluetoothTetheringEnabled == null)
529 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering));
530 if (ret != (int)RuntimeInfoError.None)
532 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
533 RuntimeInfoErrorFactory.ThrowException(ret);
539 /// (event) UsbTetheringEnabled is raised when the system preference for USB tethering is changed.
541 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
545 if (s_usbTetheringEnabled == null)
547 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
548 if (ret != (int)RuntimeInfoError.None)
550 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
551 RuntimeInfoErrorFactory.ThrowException(ret);
554 s_usbTetheringEnabled += value;
558 s_usbTetheringEnabled -= value;
559 if (s_usbTetheringEnabled == null)
561 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering));
562 if (ret != (int)RuntimeInfoError.None)
564 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
565 RuntimeInfoErrorFactory.ThrowException(ret);
571 /// (event) PacketDataEnabled is raised when the system preference for package data through 3G network is changed.
573 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
577 if (s_packetDataEnabled == null)
579 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData), s_runtimeInfoChangedCallback, IntPtr.Zero);
580 if (ret != (int)RuntimeInfoError.None)
582 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
583 RuntimeInfoErrorFactory.ThrowException(ret);
586 s_packetDataEnabled += value;
590 s_packetDataEnabled -= value;
591 if (s_packetDataEnabled == null)
593 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData));
594 if (ret != (int)RuntimeInfoError.None)
596 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
597 RuntimeInfoErrorFactory.ThrowException(ret);
603 /// (event) DataRoamingEnabled is raised when the system preference for data roaming is changed.
605 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
609 if (s_dataRoamingEnabled == null)
611 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming), s_runtimeInfoChangedCallback, IntPtr.Zero);
612 if (ret != (int)RuntimeInfoError.None)
614 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
615 RuntimeInfoErrorFactory.ThrowException(ret);
618 s_dataRoamingEnabled += value;
622 s_dataRoamingEnabled -= value;
623 if (s_dataRoamingEnabled == null)
625 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming));
626 if (ret != (int)RuntimeInfoError.None)
628 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
629 RuntimeInfoErrorFactory.ThrowException(ret);
635 /// (event) VibrationEnabled is raised when the system preference for vibration is changed.
637 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
641 if (s_vibrationEnabled == null)
643 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration), s_runtimeInfoChangedCallback, IntPtr.Zero);
644 if (ret != (int)RuntimeInfoError.None)
646 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
647 RuntimeInfoErrorFactory.ThrowException(ret);
650 s_vibrationEnabled += value;
654 s_vibrationEnabled -= value;
655 if (s_vibrationEnabled == null)
657 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration));
658 if (ret != (int)RuntimeInfoError.None)
660 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
661 RuntimeInfoErrorFactory.ThrowException(ret);
667 /// (event) AudioJackConnected is raised when the audio jack is connected/disconnected.
669 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
673 if (s_audioJackConnected == null)
675 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack), s_runtimeInfoChangedCallback, IntPtr.Zero);
676 if (ret != (int)RuntimeInfoError.None)
678 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
679 RuntimeInfoErrorFactory.ThrowException(ret);
682 s_audioJackConnected += value;
686 s_audioJackConnected -= value;
687 if (s_audioJackConnected == null)
689 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack));
690 if (ret != (int)RuntimeInfoError.None)
692 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
693 RuntimeInfoErrorFactory.ThrowException(ret);
699 /// (event) GpsStatusChanged is raised when the status of GPS is changed.
701 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
705 if (s_gpsStatusChanged == null)
707 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps), s_runtimeInfoChangedCallback, IntPtr.Zero);
708 if (ret != (int)RuntimeInfoError.None)
710 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
711 RuntimeInfoErrorFactory.ThrowException(ret);
714 s_gpsStatusChanged += value;
718 s_gpsStatusChanged -= value;
719 if (s_gpsStatusChanged == null)
721 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps));
722 if (ret != (int)RuntimeInfoError.None)
724 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
725 RuntimeInfoErrorFactory.ThrowException(ret);
731 /// (event) BatteryIsCharging is raised when the battery is currently charging.
733 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
737 if (s_batteryIsCharging == null)
739 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging), s_runtimeInfoChangedCallback, IntPtr.Zero);
740 if (ret != (int)RuntimeInfoError.None)
742 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
743 RuntimeInfoErrorFactory.ThrowException(ret);
746 s_batteryIsCharging += value;
750 s_batteryIsCharging -= value;
751 if (s_batteryIsCharging == null)
753 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging));
754 if (ret != (int)RuntimeInfoError.None)
756 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
757 RuntimeInfoErrorFactory.ThrowException(ret);
763 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
765 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
769 if (s_tvOutConnected == null)
771 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut), s_runtimeInfoChangedCallback, IntPtr.Zero);
772 if (ret != (int)RuntimeInfoError.None)
774 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
775 RuntimeInfoErrorFactory.ThrowException(ret);
778 s_tvOutConnected += value;
782 s_tvOutConnected -= value;
783 if (s_tvOutConnected == null)
785 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut));
786 if (ret != (int)RuntimeInfoError.None)
788 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
789 RuntimeInfoErrorFactory.ThrowException(ret);
795 /// (event) AudioJackConnectorChanged is raised when the audio jack connection changes.
797 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
801 if (s_audioJackConnectorChanged == null)
803 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector), s_runtimeInfoChangedCallback, IntPtr.Zero);
804 if (ret != (int)RuntimeInfoError.None)
806 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
807 RuntimeInfoErrorFactory.ThrowException(ret);
810 s_audioJackConnectorChanged += value;
814 s_audioJackConnectorChanged -= value;
815 if (s_audioJackConnectorChanged == null)
817 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector));
818 if (ret != (int)RuntimeInfoError.None)
820 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
821 RuntimeInfoErrorFactory.ThrowException(ret);
827 /// (event) ChargerConnected is raised when the charger is connected/disconnected.
829 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
833 if (s_chargerConnected == null)
835 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger), s_runtimeInfoChangedCallback, IntPtr.Zero);
836 if (ret != (int)RuntimeInfoError.None)
838 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
839 RuntimeInfoErrorFactory.ThrowException(ret);
842 s_chargerConnected += value;
846 s_chargerConnected -= value;
847 if (s_chargerConnected == null)
849 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger));
850 if (ret != (int)RuntimeInfoError.None)
852 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
853 RuntimeInfoErrorFactory.ThrowException(ret);
859 /// (event) AutoRotationEnabled is raised when the system preference for auto rotation is changed.
861 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
865 if (s_autoRotationEnabled == null)
867 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation), s_runtimeInfoChangedCallback, IntPtr.Zero);
868 if (ret != (int)RuntimeInfoError.None)
870 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
871 RuntimeInfoErrorFactory.ThrowException(ret);
874 s_autoRotationEnabled += value;
878 s_autoRotationEnabled -= value;
879 if (s_autoRotationEnabled == null)
881 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation));
882 if (ret != (int)RuntimeInfoError.None)
884 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
885 RuntimeInfoErrorFactory.ThrowException(ret);