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;
21 using System.Threading.Tasks;
22 using System.ComponentModel;
24 namespace Tizen.System
27 /// The RuntimeInformation provides functions to obtain runtime information of various system preferences.
29 public static class RuntimeInformation
31 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothEnabled;
32 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_wifiHotspotEnabled;
33 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothTetheringEnabled;
34 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_usbTetheringEnabled;
35 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_packetDataEnabled;
36 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_dataRoamingEnabled;
37 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_vibrationEnabled;
38 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnected;
39 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_gpsStatusChanged;
40 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_batteryIsCharging;
41 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_tvOutConnected;
42 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnectorChanged;
43 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_chargerConnected;
44 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_autoRotationEnabled;
46 private static readonly Interop.RuntimeInfo.RuntimeInformationChangedCallback s_runtimeInfoChangedCallback = (RuntimeInformationKey key, IntPtr userData) =>
48 RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs()
54 case RuntimeInformationKey.Bluetooth:
56 s_bluetoothEnabled?.Invoke(null, eventArgs);
59 case RuntimeInformationKey.WifiHotspot:
61 s_wifiHotspotEnabled?.Invoke(null, eventArgs);
64 case RuntimeInformationKey.BluetoothTethering:
66 s_bluetoothTetheringEnabled?.Invoke(null, eventArgs);
69 case RuntimeInformationKey.UsbTethering:
71 s_usbTetheringEnabled?.Invoke(null, eventArgs);
74 case RuntimeInformationKey.PacketData:
76 s_packetDataEnabled?.Invoke(null, eventArgs);
79 case RuntimeInformationKey.DataRoaming:
81 s_dataRoamingEnabled?.Invoke(null, eventArgs);
84 case RuntimeInformationKey.Vibration:
86 s_vibrationEnabled?.Invoke(null, eventArgs);
89 case RuntimeInformationKey.AudioJack:
91 s_audioJackConnected?.Invoke(null, eventArgs);
94 case RuntimeInformationKey.Gps:
96 s_gpsStatusChanged?.Invoke(null, eventArgs);
99 case RuntimeInformationKey.BatteryIsCharging:
101 s_batteryIsCharging?.Invoke(null, eventArgs);
104 case RuntimeInformationKey.TvOut:
106 s_tvOutConnected?.Invoke(null, eventArgs);
109 case RuntimeInformationKey.AudioJackConnector:
111 s_audioJackConnectorChanged?.Invoke(null, eventArgs);
114 case RuntimeInformationKey.Charger:
116 s_chargerConnected?.Invoke(null, eventArgs);
119 case RuntimeInformationKey.AutoRotation:
121 s_autoRotationEnabled?.Invoke(null, eventArgs);
129 internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
131 [RuntimeInformationKey.Bluetooth] = typeof(bool),
132 [RuntimeInformationKey.WifiHotspot] = typeof(bool),
133 [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
134 [RuntimeInformationKey.UsbTethering] = typeof(bool),
135 [RuntimeInformationKey.PacketData] = typeof(bool),
136 [RuntimeInformationKey.DataRoaming] = typeof(bool),
137 [RuntimeInformationKey.Vibration] = typeof(bool),
138 [RuntimeInformationKey.AudioJack] = typeof(bool),
139 [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
140 [RuntimeInformationKey.TvOut] = typeof(bool),
141 [RuntimeInformationKey.Charger] = typeof(bool),
142 [RuntimeInformationKey.AutoRotation] = typeof(bool),
143 [RuntimeInformationKey.Gps] = typeof(int),
144 [RuntimeInformationKey.AudioJackConnector] = typeof(int)
147 internal static readonly Dictionary<RuntimeInformationKey, int> s_keyTVkeyMapping = new Dictionary<RuntimeInformationKey, int>
\r
149 [RuntimeInformationKey.Bluetooth] = 5,
150 [RuntimeInformationKey.WifiHotspot] = 6,
151 [RuntimeInformationKey.BluetoothTethering] = 7,
152 [RuntimeInformationKey.UsbTethering] = 8,
153 [RuntimeInformationKey.PacketData] = 13,
154 [RuntimeInformationKey.DataRoaming] = 14,
155 [RuntimeInformationKey.Vibration] = 16,
156 [RuntimeInformationKey.AudioJack] = 20,
157 [RuntimeInformationKey.BatteryIsCharging] = 22,
158 [RuntimeInformationKey.TvOut] = 18,
159 [RuntimeInformationKey.Charger] = 26,
160 [RuntimeInformationKey.AutoRotation] = 28,
161 [RuntimeInformationKey.Gps] = 21,
162 [RuntimeInformationKey.AudioJackConnector] = 20
\r
165 internal static int is_TV_product = -1;
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 /// This function is for TV product. It will be removed
169 internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key)
\r
171 bool is_key_existed = false;
\r
175 if (is_TV_product == -1)
\r
177 is_key_existed = SystemInfo.TryGetValue<string>("http://com.samsung/build_config/product_type", out profile);
\r
178 if (is_key_existed && String.Compare(profile, "TV") == 0)
\r
188 if (is_TV_product == 0)
\r
194 if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV))
\r
196 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
\r
198 return (RuntimeInformationKey)key_TV;
\r
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 internal static object GetStatus(RuntimeInformationKey key)
206 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
208 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
211 if (s_keyDataTypeMapping[key] == typeof(int))
214 int ret = Interop.RuntimeInfo.GetValue(ConvertKeyIfTvProduct(key), out status);
215 if (ret != (int)RuntimeInfoError.None)
217 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
218 RuntimeInfoErrorFactory.ThrowException(ret);
226 int ret = Interop.RuntimeInfo.GetValue(ConvertKeyIfTvProduct(key), out status);
227 if (ret != (int)RuntimeInfoError.None)
229 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
230 RuntimeInfoErrorFactory.ThrowException(ret);
238 /// Validates the data type of the status represented by Runtime Key.
239 /// Note that this is a generic method.
241 /// <typeparam name="T">The generic type to validate.</typeparam>
242 /// <param name="key">The runtime information key for which the status type is validated </param>
243 /// <returns>true if the data type matches</returns>.
244 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
245 public static bool Is<T>(RuntimeInformationKey key)
247 if (!s_keyDataTypeMapping.ContainsKey(key))
249 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
250 throw new ArgumentException("Invalid parameter");
253 return s_keyDataTypeMapping[key] == typeof(T);
257 /// Gets the status of Runtime Key.
258 /// Note that this is a generic method.
260 /// <typeparam name="T">The generic type to return.</typeparam>
261 /// <param name="key">The runtime information key for which the current should be read </param>
262 /// <returns>The current status of the given key</returns>.
263 /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid or I/O error is occurred while reading from system.</exception>
264 /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
265 public static T GetStatus<T>(RuntimeInformationKey key)
267 return (T)GetStatus(key);
271 /// Gets system memory information
273 /// <returns>The system memory information structure.</returns>
274 /// <exception cref="ArgumentException">Thrown when I/O error is occurred while reading from system.</exception>
275 public static SystemMemoryInformation GetSystemMemoryInformation()
277 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
278 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
279 if (ret != (int)RuntimeInfoError.None)
281 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
282 RuntimeInfoErrorFactory.ThrowException(ret);
285 return new SystemMemoryInformation(info);
289 /// Gets memory information per processes
291 /// <param name="pid">List of unique process ids </param>
292 /// <returns>List of memory information per processes</returns>
293 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
294 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty or I/O error is occurred while reading from system or requesting to resource management daemon.</exception>
295 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
296 /// <exception cref="UnauthorizedAccessException">Thrown when caller doesn't have a privilege to use this method.</exception>
297 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
299 int[] processArray = pid.ToArray<int>();
300 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
301 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
302 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
303 if (ret != (int)RuntimeInfoError.None)
305 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
306 RuntimeInfoErrorFactory.ThrowException(ret);
310 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
312 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
313 map.Add(processArray[idx], processMemory);
321 /// Gets system CPU usage time
323 /// <returns>The system CPU usage time structure.</returns>
324 /// <exception cref="ArgumentException">Thrown when I/O error is occurred while reading from system.</exception>
325 public static CpuUsage GetCpuUsage()
327 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
328 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
329 if (ret != (int)RuntimeInfoError.None)
331 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
332 RuntimeInfoErrorFactory.ThrowException(ret);
334 return new CpuUsage(usage);
338 /// Gets the CPU usage time per process
340 /// <param name="pid">List of unique process ids </param>
341 /// <returns>List of CPU usage information per processes</returns>
342 /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
343 /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty or I/O error is occurred while reading from system or requesting to resource management daemon.</exception>
344 /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
345 /// <exception cref="UnauthorizedAccessException">Thrown when caller doesn't have a privilege to use this method.</exception>
346 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
348 int[] processArray = pid.ToArray<int>();
349 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
350 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
351 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
352 if (ret != (int)RuntimeInfoError.None)
354 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
355 RuntimeInfoErrorFactory.ThrowException(ret);
359 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
361 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
362 map.Add(processArray[idx], processUsage);
370 /// Gets the number of processors
372 /// <value>The number of processors</value>
373 /// <exception cref="ArgumentException">Thrown when I/O error is occurred while reading from system.</exception>
374 public static int ProcessorCount
379 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
380 if (ret != (int)RuntimeInfoError.None)
382 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
383 RuntimeInfoErrorFactory.ThrowException(ret);
391 /// Gets the current frequency of processor
393 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
394 /// <returns>The current frequency(MHz) of processor</returns>
395 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid or I/O error is occurred while reading from system.</exception>
396 /// <exception cref="NotSupportedException">Thrown when this system doesn't store CPU current frequency.</exception>
397 public static int GetProcessorCurrentFrequency(int coreId)
400 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
401 if (ret != (int)RuntimeInfoError.None)
403 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
404 RuntimeInfoErrorFactory.ThrowException(ret);
410 /// Gets the max frequency of processor
412 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
413 /// <returns>The max frequency(MHz) of processor</returns>
414 /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid or I/O error is occurred while reading from system.</exception>
415 /// <exception cref="NotSupportedException">Thrown when this system doesn't store CPU max frequency.</exception>
416 public static int GetProcessorMaxFrequency(int coreId)
419 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
420 if (ret != (int)RuntimeInfoError.None)
422 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
423 RuntimeInfoErrorFactory.ThrowException(ret);
429 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
431 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
435 if (s_bluetoothEnabled == null)
437 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth), s_runtimeInfoChangedCallback, IntPtr.Zero);
438 if (ret != (int)RuntimeInfoError.None)
440 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
441 RuntimeInfoErrorFactory.ThrowException(ret);
444 s_bluetoothEnabled += value;
448 s_bluetoothEnabled -= value;
449 if (s_bluetoothEnabled == null)
451 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Bluetooth));
452 if (ret != (int)RuntimeInfoError.None)
454 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
455 RuntimeInfoErrorFactory.ThrowException(ret);
461 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
463 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
467 if (s_wifiHotspotEnabled == null)
469 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot), s_runtimeInfoChangedCallback, IntPtr.Zero);
470 if (ret != (int)RuntimeInfoError.None)
472 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
473 RuntimeInfoErrorFactory.ThrowException(ret);
476 s_wifiHotspotEnabled += value;
480 s_wifiHotspotEnabled -= value;
481 if (s_wifiHotspotEnabled == null)
483 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.WifiHotspot));
484 if (ret != (int)RuntimeInfoError.None)
486 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
487 RuntimeInfoErrorFactory.ThrowException(ret);
493 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
495 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
499 if (s_bluetoothTetheringEnabled == null)
501 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
502 if (ret != (int)RuntimeInfoError.None)
504 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
505 RuntimeInfoErrorFactory.ThrowException(ret);
508 s_bluetoothTetheringEnabled += value;
512 s_bluetoothTetheringEnabled -= value;
513 if (s_bluetoothTetheringEnabled == null)
515 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BluetoothTethering));
516 if (ret != (int)RuntimeInfoError.None)
518 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
519 RuntimeInfoErrorFactory.ThrowException(ret);
525 /// (event) UsbTetheringEnabled is raised when system preference for USB tethering is changed.
527 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
531 if (s_usbTetheringEnabled == null)
533 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering), s_runtimeInfoChangedCallback, IntPtr.Zero);
534 if (ret != (int)RuntimeInfoError.None)
536 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
537 RuntimeInfoErrorFactory.ThrowException(ret);
540 s_usbTetheringEnabled += value;
544 s_usbTetheringEnabled -= value;
545 if (s_usbTetheringEnabled == null)
547 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.UsbTethering));
548 if (ret != (int)RuntimeInfoError.None)
550 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
551 RuntimeInfoErrorFactory.ThrowException(ret);
557 /// (event) PacketDataEnabled is raised when system preference for package data through 3G network is changed.
559 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
563 if (s_packetDataEnabled == null)
565 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData), s_runtimeInfoChangedCallback, IntPtr.Zero);
566 if (ret != (int)RuntimeInfoError.None)
568 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
569 RuntimeInfoErrorFactory.ThrowException(ret);
572 s_packetDataEnabled += value;
576 s_packetDataEnabled -= value;
577 if (s_packetDataEnabled == null)
579 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.PacketData));
580 if (ret != (int)RuntimeInfoError.None)
582 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
583 RuntimeInfoErrorFactory.ThrowException(ret);
589 /// (event) DataRoamingEnabled is raised when system preference for data roaming is changed.
591 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
595 if (s_dataRoamingEnabled == null)
597 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming), s_runtimeInfoChangedCallback, IntPtr.Zero);
598 if (ret != (int)RuntimeInfoError.None)
600 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
601 RuntimeInfoErrorFactory.ThrowException(ret);
604 s_dataRoamingEnabled += value;
608 s_dataRoamingEnabled -= value;
609 if (s_dataRoamingEnabled == null)
611 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.DataRoaming));
612 if (ret != (int)RuntimeInfoError.None)
614 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
615 RuntimeInfoErrorFactory.ThrowException(ret);
621 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
623 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
627 if (s_vibrationEnabled == null)
629 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration), s_runtimeInfoChangedCallback, IntPtr.Zero);
630 if (ret != (int)RuntimeInfoError.None)
632 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
633 RuntimeInfoErrorFactory.ThrowException(ret);
636 s_vibrationEnabled += value;
640 s_vibrationEnabled -= value;
641 if (s_vibrationEnabled == null)
643 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Vibration));
644 if (ret != (int)RuntimeInfoError.None)
646 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
647 RuntimeInfoErrorFactory.ThrowException(ret);
653 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
655 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
659 if (s_audioJackConnected == null)
661 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack), s_runtimeInfoChangedCallback, IntPtr.Zero);
662 if (ret != (int)RuntimeInfoError.None)
664 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
665 RuntimeInfoErrorFactory.ThrowException(ret);
668 s_audioJackConnected += value;
672 s_audioJackConnected -= value;
673 if (s_audioJackConnected == null)
675 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJack));
676 if (ret != (int)RuntimeInfoError.None)
678 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
679 RuntimeInfoErrorFactory.ThrowException(ret);
685 /// (event) GpsStatusChanged is raised when status of GPS is changed.
687 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
691 if (s_gpsStatusChanged == null)
693 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps), s_runtimeInfoChangedCallback, IntPtr.Zero);
694 if (ret != (int)RuntimeInfoError.None)
696 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
697 RuntimeInfoErrorFactory.ThrowException(ret);
700 s_gpsStatusChanged += value;
704 s_gpsStatusChanged -= value;
705 if (s_gpsStatusChanged == null)
707 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Gps));
708 if (ret != (int)RuntimeInfoError.None)
710 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
711 RuntimeInfoErrorFactory.ThrowException(ret);
717 /// (event) BatteryIsCharging is raised battery is currently charging.
719 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
723 if (s_batteryIsCharging == null)
725 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging), s_runtimeInfoChangedCallback, IntPtr.Zero);
726 if (ret != (int)RuntimeInfoError.None)
728 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
729 RuntimeInfoErrorFactory.ThrowException(ret);
732 s_batteryIsCharging += value;
736 s_batteryIsCharging -= value;
737 if (s_batteryIsCharging == null)
739 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.BatteryIsCharging));
740 if (ret != (int)RuntimeInfoError.None)
742 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
743 RuntimeInfoErrorFactory.ThrowException(ret);
749 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
751 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
755 if (s_tvOutConnected == null)
757 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut), s_runtimeInfoChangedCallback, IntPtr.Zero);
758 if (ret != (int)RuntimeInfoError.None)
760 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
761 RuntimeInfoErrorFactory.ThrowException(ret);
764 s_tvOutConnected += value;
768 s_tvOutConnected -= value;
769 if (s_tvOutConnected == null)
771 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.TvOut));
772 if (ret != (int)RuntimeInfoError.None)
774 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
775 RuntimeInfoErrorFactory.ThrowException(ret);
781 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
783 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
787 if (s_audioJackConnectorChanged == null)
789 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector), s_runtimeInfoChangedCallback, IntPtr.Zero);
790 if (ret != (int)RuntimeInfoError.None)
792 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
793 RuntimeInfoErrorFactory.ThrowException(ret);
796 s_audioJackConnectorChanged += value;
800 s_audioJackConnectorChanged -= value;
801 if (s_audioJackConnectorChanged == null)
803 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AudioJackConnector));
804 if (ret != (int)RuntimeInfoError.None)
806 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
807 RuntimeInfoErrorFactory.ThrowException(ret);
813 /// (event) ChargerConnected is raised when charger is connected/disconnected.
815 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
819 if (s_chargerConnected == null)
821 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger), s_runtimeInfoChangedCallback, IntPtr.Zero);
822 if (ret != (int)RuntimeInfoError.None)
824 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
825 RuntimeInfoErrorFactory.ThrowException(ret);
828 s_chargerConnected += value;
832 s_chargerConnected -= value;
833 if (s_chargerConnected == null)
835 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.Charger));
836 if (ret != (int)RuntimeInfoError.None)
838 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
839 RuntimeInfoErrorFactory.ThrowException(ret);
845 /// (event) AutoRotationEnabled is raised when system preference for auto rotation is changed.
847 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
851 if (s_autoRotationEnabled == null)
853 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation), s_runtimeInfoChangedCallback, IntPtr.Zero);
854 if (ret != (int)RuntimeInfoError.None)
856 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
857 RuntimeInfoErrorFactory.ThrowException(ret);
860 s_autoRotationEnabled += value;
864 s_autoRotationEnabled -= value;
865 if (s_autoRotationEnabled == null)
867 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(ConvertKeyIfTvProduct(RuntimeInformationKey.AutoRotation));
868 if (ret != (int)RuntimeInfoError.None)
870 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
871 RuntimeInfoErrorFactory.ThrowException(ret);