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;
23 namespace Tizen.System
26 /// The RuntimeInformation provides functions to obtain runtime information of various system preferences.
28 public static class RuntimeInformation
30 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothEnabled;
31 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_wifiHotspotEnabled;
32 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_bluetoothTetheringEnabled;
33 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_usbTetheringEnabled;
34 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_locationServiceEnabled;
35 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_locationNetworkPositionEnabled;
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_usbConnected;
45 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_chargerConnected;
46 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_autoRotationEnabled;
48 private static readonly Interop.RuntimeInfo.RuntimeInformationChangedCallback s_runtimeInfoChangedCallback = (RuntimeInformationKey key, IntPtr userData) =>
50 RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs()
56 case RuntimeInformationKey.Bluetooth:
58 s_bluetoothEnabled?.Invoke(null, eventArgs);
61 case RuntimeInformationKey.WifiHotspot:
63 s_wifiHotspotEnabled?.Invoke(null, eventArgs);
66 case RuntimeInformationKey.BluetoothTethering:
68 s_bluetoothTetheringEnabled?.Invoke(null, eventArgs);
71 case RuntimeInformationKey.UsbTethering:
73 s_usbTetheringEnabled?.Invoke(null, eventArgs);
76 case RuntimeInformationKey.LocationService:
78 s_locationServiceEnabled?.Invoke(null, eventArgs);
81 case RuntimeInformationKey.LocationNetworkPosition:
83 s_locationNetworkPositionEnabled?.Invoke(null, eventArgs);
86 case RuntimeInformationKey.PacketData:
88 s_packetDataEnabled?.Invoke(null, eventArgs);
91 case RuntimeInformationKey.DataRoaming:
93 s_dataRoamingEnabled?.Invoke(null, eventArgs);
96 case RuntimeInformationKey.Vibration:
98 s_vibrationEnabled?.Invoke(null, eventArgs);
101 case RuntimeInformationKey.AudioJack:
103 s_audioJackConnected?.Invoke(null, eventArgs);
106 case RuntimeInformationKey.Gps:
108 s_gpsStatusChanged?.Invoke(null, eventArgs);
111 case RuntimeInformationKey.BatteryIsCharging:
113 s_batteryIsCharging?.Invoke(null, eventArgs);
116 case RuntimeInformationKey.TvOut:
118 s_tvOutConnected?.Invoke(null, eventArgs);
121 case RuntimeInformationKey.AudioJackConnector:
123 s_audioJackConnectorChanged?.Invoke(null, eventArgs);
126 case RuntimeInformationKey.Usb:
128 s_usbConnected?.Invoke(null, eventArgs);
131 case RuntimeInformationKey.Charger:
133 s_chargerConnected?.Invoke(null, eventArgs);
136 case RuntimeInformationKey.AutoRotation:
138 s_autoRotationEnabled?.Invoke(null, eventArgs);
146 internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
148 [RuntimeInformationKey.Bluetooth] = typeof(bool),
149 [RuntimeInformationKey.WifiHotspot] = typeof(bool),
150 [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
151 [RuntimeInformationKey.UsbTethering] = typeof(bool),
152 [RuntimeInformationKey.LocationService] = typeof(bool),
153 [RuntimeInformationKey.LocationNetworkPosition] = typeof(bool),
154 [RuntimeInformationKey.PacketData] = typeof(bool),
155 [RuntimeInformationKey.DataRoaming] = typeof(bool),
156 [RuntimeInformationKey.Vibration] = typeof(bool),
157 [RuntimeInformationKey.AudioJack] = typeof(bool),
158 [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
159 [RuntimeInformationKey.TvOut] = typeof(bool),
160 [RuntimeInformationKey.Usb] = typeof(bool),
161 [RuntimeInformationKey.Charger] = typeof(bool),
162 [RuntimeInformationKey.AutoRotation] = typeof(bool),
163 [RuntimeInformationKey.Gps] = typeof(int),
164 [RuntimeInformationKey.AudioJackConnector] = typeof(int)
168 /// This function gets current state of the given key which represents specific runtime information
170 /// <param name="key">The runtime information key for which the current should be read </param>
171 /// <returns>The current status of the given key</returns>
172 internal static object GetStatus(RuntimeInformationKey key)
175 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
177 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
179 if (s_keyDataTypeMapping[key] == typeof(int))
182 int ret = Interop.RuntimeInfo.GetValue(key, out status);
183 if (ret != (int)RuntimeInfoError.None)
185 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
186 RuntimeInfoErrorFactory.ThrowException(ret);
194 int ret = Interop.RuntimeInfo.GetValue(key, out status);
195 if (ret != (int)RuntimeInfoError.None)
197 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
198 RuntimeInfoErrorFactory.ThrowException(ret);
206 /// Validates the data type of the status represented by Runtime Key.
207 /// Note that this is a generic method.
209 /// <typeparam name="T">The generic type to validate.</typeparam>
210 /// <param name="key">The runtime information key for which the status type is validated </param>
211 /// <returns>true if the data type matches</returns>.
212 public static bool Is<T>(RuntimeInformationKey key)
214 if (!s_keyDataTypeMapping.ContainsKey(key))
216 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
217 throw new ArgumentException("Invalid parameter");
220 return s_keyDataTypeMapping[key] == typeof(T);
224 /// Gets the status of Runtime Key.
225 /// Note that this is a generic method.
227 /// <typeparam name="T">The generic type to return.</typeparam>
228 /// <param name="key">The runtime information key for which the current should be read </param>
229 /// <returns>The current status of the given key</returns>.
230 public static T GetStatus<T>(RuntimeInformationKey key)
232 return (T)GetStatus(key);
236 /// The System memory information
238 public static SystemMemoryInformation GetSystemMemoryInformation()
240 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
241 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
242 if (ret != (int)RuntimeInfoError.None)
244 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
245 RuntimeInfoErrorFactory.ThrowException(ret);
248 return new SystemMemoryInformation(info);
252 /// Gets memory information per processes
254 /// <param name="pid">List of unique process ids </param>
255 /// <returns>List of memory information per processes</returns>
256 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
258 int[] processArray = pid.ToArray<int>();
259 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
260 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
261 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
262 if (ret != (int)RuntimeInfoError.None)
264 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
265 RuntimeInfoErrorFactory.ThrowException(ret);
269 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
271 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
272 map.Add(processArray[idx], processMemory);
282 public static CpuUsage GetCpuUsage()
284 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
285 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
286 if (ret != (int)RuntimeInfoError.None)
288 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
289 RuntimeInfoErrorFactory.ThrowException(ret);
291 return new CpuUsage(usage);
295 /// The CPU run time per process
297 /// <param name="pid">List of unique process ids </param>
298 /// <returns>List of CPU usage information per processes</returns>
299 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
301 int[] processArray = pid.ToArray<int>();
302 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
303 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
304 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
305 if (ret != (int)RuntimeInfoError.None)
307 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
308 RuntimeInfoErrorFactory.ThrowException(ret);
312 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
314 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
315 map.Add(processArray[idx], processUsage);
323 /// The number of processors
325 public static int ProcessorCount
330 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
331 if (ret != (int)RuntimeInfoError.None)
333 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
334 RuntimeInfoErrorFactory.ThrowException(ret);
342 /// Gets the current frequency of processor
344 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
345 /// <returns>The current frequency(MHz) of processor</returns>
346 public static int GetProcessorCurrentFrequency(int coreId)
349 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
350 if (ret != (int)RuntimeInfoError.None)
352 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
353 RuntimeInfoErrorFactory.ThrowException(ret);
359 /// Gets the max frequency of processor
361 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
362 /// <returns>The max frequency(MHz) of processor</returns>
363 public static int GetProcessorMaxFrequency(int coreId)
366 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
367 if (ret != (int)RuntimeInfoError.None)
369 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
370 RuntimeInfoErrorFactory.ThrowException(ret);
376 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
378 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
382 if (s_bluetoothEnabled == null)
384 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth, s_runtimeInfoChangedCallback, IntPtr.Zero);
385 if (ret != (int)RuntimeInfoError.None)
387 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
388 RuntimeInfoErrorFactory.ThrowException(ret);
391 s_bluetoothEnabled += value;
395 s_bluetoothEnabled -= value;
396 if (s_bluetoothEnabled == null)
398 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth);
399 if (ret != (int)RuntimeInfoError.None)
401 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
402 RuntimeInfoErrorFactory.ThrowException(ret);
408 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
410 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
414 if (s_wifiHotspotEnabled == null)
416 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot, s_runtimeInfoChangedCallback, IntPtr.Zero);
417 if (ret != (int)RuntimeInfoError.None)
419 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
420 RuntimeInfoErrorFactory.ThrowException(ret);
423 s_wifiHotspotEnabled += value;
427 s_wifiHotspotEnabled -= value;
428 if (s_wifiHotspotEnabled == null)
430 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot);
431 if (ret != (int)RuntimeInfoError.None)
433 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
434 RuntimeInfoErrorFactory.ThrowException(ret);
440 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
442 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
446 if (s_bluetoothTetheringEnabled == null)
448 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
449 if (ret != (int)RuntimeInfoError.None)
451 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
452 RuntimeInfoErrorFactory.ThrowException(ret);
455 s_bluetoothTetheringEnabled += value;
459 s_bluetoothTetheringEnabled -= value;
460 if (s_bluetoothTetheringEnabled == null)
462 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering);
463 if (ret != (int)RuntimeInfoError.None)
465 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
466 RuntimeInfoErrorFactory.ThrowException(ret);
472 /// (event) UsbTetheringEnabled is raised when system preference for USB terhering is changed.
474 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
478 if (s_usbTetheringEnabled == null)
480 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
481 if (ret != (int)RuntimeInfoError.None)
483 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
484 RuntimeInfoErrorFactory.ThrowException(ret);
487 s_usbTetheringEnabled += value;
491 s_usbTetheringEnabled -= value;
492 if (s_usbTetheringEnabled == null)
494 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering);
495 if (ret != (int)RuntimeInfoError.None)
497 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
498 RuntimeInfoErrorFactory.ThrowException(ret);
504 /// (event) LocationServiceEnabled is raised when system preference for location service is changed.
506 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> LocationServiceEnabled
510 if (s_locationServiceEnabled == null)
512 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationService, s_runtimeInfoChangedCallback, IntPtr.Zero);
513 if (ret != (int)RuntimeInfoError.None)
515 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
516 RuntimeInfoErrorFactory.ThrowException(ret);
519 s_locationServiceEnabled += value;
523 s_locationServiceEnabled -= value;
524 if (s_locationServiceEnabled == null)
526 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationService);
527 RuntimeInfoErrorFactory.ThrowException(ret);
532 /// (event) LocationNetworkPositionEnabled is raised when system preference for allowing location service to use location data from cellular and Wi-Fi is changed.
534 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> LocationNetworkPositionEnabled
538 if (s_locationNetworkPositionEnabled == null)
540 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationNetworkPosition, s_runtimeInfoChangedCallback, IntPtr.Zero);
541 if (ret != (int)RuntimeInfoError.None)
543 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
544 RuntimeInfoErrorFactory.ThrowException(ret);
547 s_locationNetworkPositionEnabled += value;
551 s_locationNetworkPositionEnabled -= value;
552 if (s_locationNetworkPositionEnabled == null)
554 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationNetworkPosition);
555 if (ret != (int)RuntimeInfoError.None)
557 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
558 RuntimeInfoErrorFactory.ThrowException(ret);
564 /// (event) PacketDataEnabled is raised when system preference for package data through 3G network is changed.
566 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
570 if (s_packetDataEnabled == null)
572 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData, s_runtimeInfoChangedCallback, IntPtr.Zero);
573 if (ret != (int)RuntimeInfoError.None)
575 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
576 RuntimeInfoErrorFactory.ThrowException(ret);
579 s_packetDataEnabled += value;
583 s_packetDataEnabled -= value;
584 if (s_packetDataEnabled == null)
586 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData);
587 if (ret != (int)RuntimeInfoError.None)
589 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
590 RuntimeInfoErrorFactory.ThrowException(ret);
596 /// (event) DataRoamingEnabled is raised when system preference for data roaming is changed.
599 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
603 if (s_dataRoamingEnabled == null)
605 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming, s_runtimeInfoChangedCallback, IntPtr.Zero);
606 if (ret != (int)RuntimeInfoError.None)
608 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
609 RuntimeInfoErrorFactory.ThrowException(ret);
612 s_dataRoamingEnabled += value;
616 s_dataRoamingEnabled -= value;
617 if (s_dataRoamingEnabled == null)
619 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming);
620 if (ret != (int)RuntimeInfoError.None)
622 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
623 RuntimeInfoErrorFactory.ThrowException(ret);
629 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
631 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
635 if (s_vibrationEnabled == null)
637 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration, s_runtimeInfoChangedCallback, IntPtr.Zero);
638 if (ret != (int)RuntimeInfoError.None)
640 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
641 RuntimeInfoErrorFactory.ThrowException(ret);
644 s_vibrationEnabled += value;
648 s_vibrationEnabled -= value;
649 if (s_vibrationEnabled == null)
651 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration);
652 if (ret != (int)RuntimeInfoError.None)
654 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
655 RuntimeInfoErrorFactory.ThrowException(ret);
661 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
663 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
667 if (s_audioJackConnected == null)
669 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack, s_runtimeInfoChangedCallback, IntPtr.Zero);
670 if (ret != (int)RuntimeInfoError.None)
672 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
673 RuntimeInfoErrorFactory.ThrowException(ret);
676 s_audioJackConnected += value;
680 s_audioJackConnected -= value;
681 if (s_audioJackConnected == null)
683 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack);
684 if (ret != (int)RuntimeInfoError.None)
686 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
687 RuntimeInfoErrorFactory.ThrowException(ret);
693 /// (event) GpsStatusChanged is raised when status of GPS is changed.
695 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
699 if (s_gpsStatusChanged == null)
701 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps, s_runtimeInfoChangedCallback, IntPtr.Zero);
702 if (ret != (int)RuntimeInfoError.None)
704 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
705 RuntimeInfoErrorFactory.ThrowException(ret);
708 s_gpsStatusChanged += value;
712 s_gpsStatusChanged -= value;
713 if (s_gpsStatusChanged == null)
715 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps);
716 if (ret != (int)RuntimeInfoError.None)
718 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
719 RuntimeInfoErrorFactory.ThrowException(ret);
725 /// (event) BatteryIsCharging is raised battery is currently charging.
727 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
731 if (s_batteryIsCharging == null)
733 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging, s_runtimeInfoChangedCallback, IntPtr.Zero);
734 if (ret != (int)RuntimeInfoError.None)
736 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
737 RuntimeInfoErrorFactory.ThrowException(ret);
740 s_batteryIsCharging += value;
744 s_batteryIsCharging -= value;
745 if (s_batteryIsCharging == null)
747 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging);
748 if (ret != (int)RuntimeInfoError.None)
750 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
751 RuntimeInfoErrorFactory.ThrowException(ret);
757 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
759 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
763 if (s_tvOutConnected == null)
765 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut, s_runtimeInfoChangedCallback, IntPtr.Zero);
766 if (ret != (int)RuntimeInfoError.None)
768 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
769 RuntimeInfoErrorFactory.ThrowException(ret);
772 s_tvOutConnected += value;
776 s_tvOutConnected -= value;
777 if (s_tvOutConnected == null)
779 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut);
780 if (ret != (int)RuntimeInfoError.None)
782 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
783 RuntimeInfoErrorFactory.ThrowException(ret);
789 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
791 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
795 if (s_audioJackConnectorChanged == null)
797 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector, s_runtimeInfoChangedCallback, IntPtr.Zero);
798 if (ret != (int)RuntimeInfoError.None)
800 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
801 RuntimeInfoErrorFactory.ThrowException(ret);
804 s_audioJackConnectorChanged += value;
808 s_audioJackConnectorChanged -= value;
809 if (s_audioJackConnectorChanged == null)
811 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector);
812 if (ret != (int)RuntimeInfoError.None)
814 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
815 RuntimeInfoErrorFactory.ThrowException(ret);
821 /// (event) UsbConnected is raised when USB is connected/disconnected.
823 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbConnected
827 if (s_usbConnected == null)
829 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Usb, s_runtimeInfoChangedCallback, IntPtr.Zero);
830 if (ret != (int)RuntimeInfoError.None)
832 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
833 RuntimeInfoErrorFactory.ThrowException(ret);
836 s_usbConnected += value;
840 s_usbConnected -= value;
841 if (s_usbConnected == null)
843 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Usb);
844 if (ret != (int)RuntimeInfoError.None)
846 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
847 RuntimeInfoErrorFactory.ThrowException(ret);
853 /// (event) ChargerConnected is raised when charger is connected/disconnected.
855 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
859 if (s_chargerConnected == null)
861 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger, s_runtimeInfoChangedCallback, IntPtr.Zero);
862 if (ret != (int)RuntimeInfoError.None)
864 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
865 RuntimeInfoErrorFactory.ThrowException(ret);
868 s_chargerConnected += value;
872 s_chargerConnected -= value;
873 if (s_chargerConnected == null)
875 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger);
876 if (ret != (int)RuntimeInfoError.None)
878 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
879 RuntimeInfoErrorFactory.ThrowException(ret);
885 /// (event) AutoRotationEnabled is raised when system preference for auto rotaion is changed.
887 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
891 if (s_autoRotationEnabled == null)
893 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation, s_runtimeInfoChangedCallback, IntPtr.Zero);
894 if (ret != (int)RuntimeInfoError.None)
896 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
897 RuntimeInfoErrorFactory.ThrowException(ret);
900 s_autoRotationEnabled += value;
904 s_autoRotationEnabled -= value;
905 if (s_autoRotationEnabled == null)
907 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation);
908 if (ret != (int)RuntimeInfoError.None)
910 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
911 RuntimeInfoErrorFactory.ThrowException(ret);