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_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.LocationService:
77 s_locationServiceEnabled?.Invoke(null, eventArgs);
80 case RuntimeInformationKey.LocationNetworkPosition:
82 s_locationNetworkPositionEnabled?.Invoke(null, eventArgs);
85 case RuntimeInformationKey.PacketData:
87 s_packetDataEnabled?.Invoke(null, eventArgs);
90 case RuntimeInformationKey.DataRoaming:
92 s_dataRoamingEnabled?.Invoke(null, eventArgs);
95 case RuntimeInformationKey.Vibration:
97 s_vibrationEnabled?.Invoke(null, eventArgs);
100 case RuntimeInformationKey.AudioJack:
102 s_audioJackConnected?.Invoke(null, eventArgs);
105 case RuntimeInformationKey.Gps:
107 s_gpsStatusChanged?.Invoke(null, eventArgs);
110 case RuntimeInformationKey.BatteryIsCharging:
112 s_batteryIsCharging?.Invoke(null, eventArgs);
115 case RuntimeInformationKey.TvOut:
117 s_tvOutConnected?.Invoke(null, eventArgs);
120 case RuntimeInformationKey.AudioJackConnector:
122 s_audioJackConnectorChanged?.Invoke(null, eventArgs);
125 case RuntimeInformationKey.Charger:
127 s_chargerConnected?.Invoke(null, eventArgs);
130 case RuntimeInformationKey.AutoRotation:
132 s_autoRotationEnabled?.Invoke(null, eventArgs);
140 internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
142 [RuntimeInformationKey.Bluetooth] = typeof(bool),
143 [RuntimeInformationKey.WifiHotspot] = typeof(bool),
144 [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
145 [RuntimeInformationKey.UsbTethering] = typeof(bool),
146 [RuntimeInformationKey.LocationService] = typeof(bool),
147 [RuntimeInformationKey.LocationNetworkPosition] = typeof(bool),
148 [RuntimeInformationKey.PacketData] = typeof(bool),
149 [RuntimeInformationKey.DataRoaming] = typeof(bool),
150 [RuntimeInformationKey.Vibration] = typeof(bool),
151 [RuntimeInformationKey.AudioJack] = typeof(bool),
152 [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
153 [RuntimeInformationKey.TvOut] = typeof(bool),
154 [RuntimeInformationKey.Charger] = typeof(bool),
155 [RuntimeInformationKey.AutoRotation] = typeof(bool),
156 [RuntimeInformationKey.Gps] = typeof(int),
157 [RuntimeInformationKey.AudioJackConnector] = typeof(int)
161 /// This function gets current state of the given key which represents specific runtime information
163 /// <param name="key">The runtime information key for which the current should be read </param>
164 /// <returns>The current status of the given key</returns>
165 internal static object GetStatus(RuntimeInformationKey key)
168 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
170 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
172 if (s_keyDataTypeMapping[key] == typeof(int))
175 int ret = Interop.RuntimeInfo.GetValue(key, out status);
176 if (ret != (int)RuntimeInfoError.None)
178 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
179 RuntimeInfoErrorFactory.ThrowException(ret);
187 int ret = Interop.RuntimeInfo.GetValue(key, out status);
188 if (ret != (int)RuntimeInfoError.None)
190 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
191 RuntimeInfoErrorFactory.ThrowException(ret);
199 /// Validates the data type of the status represented by Runtime Key.
200 /// Note that this is a generic method.
202 /// <typeparam name="T">The generic type to validate.</typeparam>
203 /// <param name="key">The runtime information key for which the status type is validated </param>
204 /// <returns>true if the data type matches</returns>.
205 public static bool Is<T>(RuntimeInformationKey key)
207 if (!s_keyDataTypeMapping.ContainsKey(key))
209 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
210 throw new ArgumentException("Invalid parameter");
213 return s_keyDataTypeMapping[key] == typeof(T);
217 /// Gets the status of Runtime Key.
218 /// Note that this is a generic method.
220 /// <typeparam name="T">The generic type to return.</typeparam>
221 /// <param name="key">The runtime information key for which the current should be read </param>
222 /// <returns>The current status of the given key</returns>.
223 public static T GetStatus<T>(RuntimeInformationKey key)
225 return (T)GetStatus(key);
229 /// The System memory information
231 public static SystemMemoryInformation GetSystemMemoryInformation()
233 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
234 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
235 if (ret != (int)RuntimeInfoError.None)
237 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
238 RuntimeInfoErrorFactory.ThrowException(ret);
241 return new SystemMemoryInformation(info);
245 /// Gets memory information per processes
247 /// <param name="pid">List of unique process ids </param>
248 /// <returns>List of memory information per processes</returns>
249 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
251 int[] processArray = pid.ToArray<int>();
252 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
253 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
254 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
255 if (ret != (int)RuntimeInfoError.None)
257 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
258 RuntimeInfoErrorFactory.ThrowException(ret);
262 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
264 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
265 map.Add(processArray[idx], processMemory);
275 public static CpuUsage GetCpuUsage()
277 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
278 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
279 if (ret != (int)RuntimeInfoError.None)
281 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
282 RuntimeInfoErrorFactory.ThrowException(ret);
284 return new CpuUsage(usage);
288 /// The CPU run time per process
290 /// <param name="pid">List of unique process ids </param>
291 /// <returns>List of CPU usage information per processes</returns>
292 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
294 int[] processArray = pid.ToArray<int>();
295 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
296 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
297 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
298 if (ret != (int)RuntimeInfoError.None)
300 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
301 RuntimeInfoErrorFactory.ThrowException(ret);
305 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
307 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
308 map.Add(processArray[idx], processUsage);
316 /// The number of processors
318 public static int ProcessorCount
323 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
324 if (ret != (int)RuntimeInfoError.None)
326 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
327 RuntimeInfoErrorFactory.ThrowException(ret);
335 /// Gets the current frequency of processor
337 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
338 /// <returns>The current frequency(MHz) of processor</returns>
339 public static int GetProcessorCurrentFrequency(int coreId)
342 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
343 if (ret != (int)RuntimeInfoError.None)
345 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
346 RuntimeInfoErrorFactory.ThrowException(ret);
352 /// Gets the max frequency of processor
354 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
355 /// <returns>The max frequency(MHz) of processor</returns>
356 public static int GetProcessorMaxFrequency(int coreId)
359 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
360 if (ret != (int)RuntimeInfoError.None)
362 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
363 RuntimeInfoErrorFactory.ThrowException(ret);
369 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
371 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
375 if (s_bluetoothEnabled == null)
377 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth, s_runtimeInfoChangedCallback, IntPtr.Zero);
378 if (ret != (int)RuntimeInfoError.None)
380 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
381 RuntimeInfoErrorFactory.ThrowException(ret);
384 s_bluetoothEnabled += value;
388 s_bluetoothEnabled -= value;
389 if (s_bluetoothEnabled == null)
391 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth);
392 if (ret != (int)RuntimeInfoError.None)
394 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
395 RuntimeInfoErrorFactory.ThrowException(ret);
401 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
403 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
407 if (s_wifiHotspotEnabled == null)
409 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot, s_runtimeInfoChangedCallback, IntPtr.Zero);
410 if (ret != (int)RuntimeInfoError.None)
412 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
413 RuntimeInfoErrorFactory.ThrowException(ret);
416 s_wifiHotspotEnabled += value;
420 s_wifiHotspotEnabled -= value;
421 if (s_wifiHotspotEnabled == null)
423 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot);
424 if (ret != (int)RuntimeInfoError.None)
426 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
427 RuntimeInfoErrorFactory.ThrowException(ret);
433 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
435 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
439 if (s_bluetoothTetheringEnabled == null)
441 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
442 if (ret != (int)RuntimeInfoError.None)
444 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
445 RuntimeInfoErrorFactory.ThrowException(ret);
448 s_bluetoothTetheringEnabled += value;
452 s_bluetoothTetheringEnabled -= value;
453 if (s_bluetoothTetheringEnabled == null)
455 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering);
456 if (ret != (int)RuntimeInfoError.None)
458 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
459 RuntimeInfoErrorFactory.ThrowException(ret);
465 /// (event) UsbTetheringEnabled is raised when system preference for USB terhering is changed.
467 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
471 if (s_usbTetheringEnabled == null)
473 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
474 if (ret != (int)RuntimeInfoError.None)
476 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
477 RuntimeInfoErrorFactory.ThrowException(ret);
480 s_usbTetheringEnabled += value;
484 s_usbTetheringEnabled -= value;
485 if (s_usbTetheringEnabled == null)
487 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering);
488 if (ret != (int)RuntimeInfoError.None)
490 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
491 RuntimeInfoErrorFactory.ThrowException(ret);
497 /// (event) LocationServiceEnabled is raised when system preference for location service is changed.
499 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> LocationServiceEnabled
503 if (s_locationServiceEnabled == null)
505 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationService, s_runtimeInfoChangedCallback, IntPtr.Zero);
506 if (ret != (int)RuntimeInfoError.None)
508 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
509 RuntimeInfoErrorFactory.ThrowException(ret);
512 s_locationServiceEnabled += value;
516 s_locationServiceEnabled -= value;
517 if (s_locationServiceEnabled == null)
519 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationService);
520 RuntimeInfoErrorFactory.ThrowException(ret);
525 /// (event) LocationNetworkPositionEnabled is raised when system preference for allowing location service to use location data from cellular and Wi-Fi is changed.
527 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> LocationNetworkPositionEnabled
531 if (s_locationNetworkPositionEnabled == null)
533 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationNetworkPosition, 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_locationNetworkPositionEnabled += value;
544 s_locationNetworkPositionEnabled -= value;
545 if (s_locationNetworkPositionEnabled == null)
547 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.LocationNetworkPosition);
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(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(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.
592 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
596 if (s_dataRoamingEnabled == null)
598 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming, s_runtimeInfoChangedCallback, IntPtr.Zero);
599 if (ret != (int)RuntimeInfoError.None)
601 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
602 RuntimeInfoErrorFactory.ThrowException(ret);
605 s_dataRoamingEnabled += value;
609 s_dataRoamingEnabled -= value;
610 if (s_dataRoamingEnabled == null)
612 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming);
613 if (ret != (int)RuntimeInfoError.None)
615 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
616 RuntimeInfoErrorFactory.ThrowException(ret);
622 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
624 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
628 if (s_vibrationEnabled == null)
630 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration, s_runtimeInfoChangedCallback, IntPtr.Zero);
631 if (ret != (int)RuntimeInfoError.None)
633 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
634 RuntimeInfoErrorFactory.ThrowException(ret);
637 s_vibrationEnabled += value;
641 s_vibrationEnabled -= value;
642 if (s_vibrationEnabled == null)
644 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration);
645 if (ret != (int)RuntimeInfoError.None)
647 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
648 RuntimeInfoErrorFactory.ThrowException(ret);
654 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
656 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
660 if (s_audioJackConnected == null)
662 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack, s_runtimeInfoChangedCallback, IntPtr.Zero);
663 if (ret != (int)RuntimeInfoError.None)
665 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
666 RuntimeInfoErrorFactory.ThrowException(ret);
669 s_audioJackConnected += value;
673 s_audioJackConnected -= value;
674 if (s_audioJackConnected == null)
676 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack);
677 if (ret != (int)RuntimeInfoError.None)
679 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
680 RuntimeInfoErrorFactory.ThrowException(ret);
686 /// (event) GpsStatusChanged is raised when status of GPS is changed.
688 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
692 if (s_gpsStatusChanged == null)
694 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps, s_runtimeInfoChangedCallback, IntPtr.Zero);
695 if (ret != (int)RuntimeInfoError.None)
697 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
698 RuntimeInfoErrorFactory.ThrowException(ret);
701 s_gpsStatusChanged += value;
705 s_gpsStatusChanged -= value;
706 if (s_gpsStatusChanged == null)
708 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps);
709 if (ret != (int)RuntimeInfoError.None)
711 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
712 RuntimeInfoErrorFactory.ThrowException(ret);
718 /// (event) BatteryIsCharging is raised battery is currently charging.
720 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
724 if (s_batteryIsCharging == null)
726 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging, s_runtimeInfoChangedCallback, IntPtr.Zero);
727 if (ret != (int)RuntimeInfoError.None)
729 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
730 RuntimeInfoErrorFactory.ThrowException(ret);
733 s_batteryIsCharging += value;
737 s_batteryIsCharging -= value;
738 if (s_batteryIsCharging == null)
740 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging);
741 if (ret != (int)RuntimeInfoError.None)
743 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
744 RuntimeInfoErrorFactory.ThrowException(ret);
750 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
752 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
756 if (s_tvOutConnected == null)
758 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut, s_runtimeInfoChangedCallback, IntPtr.Zero);
759 if (ret != (int)RuntimeInfoError.None)
761 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
762 RuntimeInfoErrorFactory.ThrowException(ret);
765 s_tvOutConnected += value;
769 s_tvOutConnected -= value;
770 if (s_tvOutConnected == null)
772 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut);
773 if (ret != (int)RuntimeInfoError.None)
775 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
776 RuntimeInfoErrorFactory.ThrowException(ret);
782 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
784 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
788 if (s_audioJackConnectorChanged == null)
790 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector, s_runtimeInfoChangedCallback, IntPtr.Zero);
791 if (ret != (int)RuntimeInfoError.None)
793 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
794 RuntimeInfoErrorFactory.ThrowException(ret);
797 s_audioJackConnectorChanged += value;
801 s_audioJackConnectorChanged -= value;
802 if (s_audioJackConnectorChanged == null)
804 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector);
805 if (ret != (int)RuntimeInfoError.None)
807 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
808 RuntimeInfoErrorFactory.ThrowException(ret);
814 /// (event) ChargerConnected is raised when charger is connected/disconnected.
816 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
820 if (s_chargerConnected == null)
822 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger, s_runtimeInfoChangedCallback, IntPtr.Zero);
823 if (ret != (int)RuntimeInfoError.None)
825 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
826 RuntimeInfoErrorFactory.ThrowException(ret);
829 s_chargerConnected += value;
833 s_chargerConnected -= value;
834 if (s_chargerConnected == null)
836 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger);
837 if (ret != (int)RuntimeInfoError.None)
839 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
840 RuntimeInfoErrorFactory.ThrowException(ret);
846 /// (event) AutoRotationEnabled is raised when system preference for auto rotaion is changed.
848 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
852 if (s_autoRotationEnabled == null)
854 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation, s_runtimeInfoChangedCallback, IntPtr.Zero);
855 if (ret != (int)RuntimeInfoError.None)
857 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
858 RuntimeInfoErrorFactory.ThrowException(ret);
861 s_autoRotationEnabled += value;
865 s_autoRotationEnabled -= value;
866 if (s_autoRotationEnabled == null)
868 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation);
869 if (ret != (int)RuntimeInfoError.None)
871 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
872 RuntimeInfoErrorFactory.ThrowException(ret);