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 [EditorBrowsable(EditorBrowsableState.Never)]
148 internal static object GetStatus(RuntimeInformationKey key)
151 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
153 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
155 if (s_keyDataTypeMapping[key] == typeof(int))
158 int ret = Interop.RuntimeInfo.GetValue(key, out status);
159 if (ret != (int)RuntimeInfoError.None)
161 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
162 RuntimeInfoErrorFactory.ThrowException(ret);
170 int ret = Interop.RuntimeInfo.GetValue(key, out status);
171 if (ret != (int)RuntimeInfoError.None)
173 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
174 RuntimeInfoErrorFactory.ThrowException(ret);
182 /// Validates the data type of the status represented by Runtime Key.
183 /// Note that this is a generic method.
185 /// <typeparam name="T">The generic type to validate.</typeparam>
186 /// <param name="key">The runtime information key for which the status type is validated </param>
187 /// <returns>true if the data type matches</returns>.
188 public static bool Is<T>(RuntimeInformationKey key)
190 if (!s_keyDataTypeMapping.ContainsKey(key))
192 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
193 throw new ArgumentException("Invalid parameter");
196 return s_keyDataTypeMapping[key] == typeof(T);
200 /// Gets the status of Runtime Key.
201 /// Note that this is a generic method.
203 /// <typeparam name="T">The generic type to return.</typeparam>
204 /// <param name="key">The runtime information key for which the current should be read </param>
205 /// <returns>The current status of the given key</returns>.
206 public static T GetStatus<T>(RuntimeInformationKey key)
208 return (T)GetStatus(key);
212 /// The System memory information
214 public static SystemMemoryInformation GetSystemMemoryInformation()
216 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
217 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
218 if (ret != (int)RuntimeInfoError.None)
220 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
221 RuntimeInfoErrorFactory.ThrowException(ret);
224 return new SystemMemoryInformation(info);
228 /// Gets memory information per processes
230 /// <param name="pid">List of unique process ids </param>
231 /// <returns>List of memory information per processes</returns>
232 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
234 int[] processArray = pid.ToArray<int>();
235 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
236 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
237 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
238 if (ret != (int)RuntimeInfoError.None)
240 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
241 RuntimeInfoErrorFactory.ThrowException(ret);
245 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
247 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
248 map.Add(processArray[idx], processMemory);
258 public static CpuUsage GetCpuUsage()
260 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
261 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
262 if (ret != (int)RuntimeInfoError.None)
264 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
265 RuntimeInfoErrorFactory.ThrowException(ret);
267 return new CpuUsage(usage);
271 /// The CPU run time per process
273 /// <param name="pid">List of unique process ids </param>
274 /// <returns>List of CPU usage information per processes</returns>
275 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
277 int[] processArray = pid.ToArray<int>();
278 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
279 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
280 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
281 if (ret != (int)RuntimeInfoError.None)
283 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
284 RuntimeInfoErrorFactory.ThrowException(ret);
288 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
290 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
291 map.Add(processArray[idx], processUsage);
299 /// The number of processors
301 public static int ProcessorCount
306 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
307 if (ret != (int)RuntimeInfoError.None)
309 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
310 RuntimeInfoErrorFactory.ThrowException(ret);
318 /// Gets the current frequency of processor
320 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
321 /// <returns>The current frequency(MHz) of processor</returns>
322 public static int GetProcessorCurrentFrequency(int coreId)
325 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
326 if (ret != (int)RuntimeInfoError.None)
328 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
329 RuntimeInfoErrorFactory.ThrowException(ret);
335 /// Gets the max 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 max frequency(MHz) of processor</returns>
339 public static int GetProcessorMaxFrequency(int coreId)
342 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
343 if (ret != (int)RuntimeInfoError.None)
345 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
346 RuntimeInfoErrorFactory.ThrowException(ret);
352 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
354 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
358 if (s_bluetoothEnabled == null)
360 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth, s_runtimeInfoChangedCallback, IntPtr.Zero);
361 if (ret != (int)RuntimeInfoError.None)
363 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
364 RuntimeInfoErrorFactory.ThrowException(ret);
367 s_bluetoothEnabled += value;
371 s_bluetoothEnabled -= value;
372 if (s_bluetoothEnabled == null)
374 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth);
375 if (ret != (int)RuntimeInfoError.None)
377 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
378 RuntimeInfoErrorFactory.ThrowException(ret);
384 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
386 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
390 if (s_wifiHotspotEnabled == null)
392 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot, s_runtimeInfoChangedCallback, IntPtr.Zero);
393 if (ret != (int)RuntimeInfoError.None)
395 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
396 RuntimeInfoErrorFactory.ThrowException(ret);
399 s_wifiHotspotEnabled += value;
403 s_wifiHotspotEnabled -= value;
404 if (s_wifiHotspotEnabled == null)
406 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot);
407 if (ret != (int)RuntimeInfoError.None)
409 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
410 RuntimeInfoErrorFactory.ThrowException(ret);
416 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
418 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
422 if (s_bluetoothTetheringEnabled == null)
424 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
425 if (ret != (int)RuntimeInfoError.None)
427 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
428 RuntimeInfoErrorFactory.ThrowException(ret);
431 s_bluetoothTetheringEnabled += value;
435 s_bluetoothTetheringEnabled -= value;
436 if (s_bluetoothTetheringEnabled == null)
438 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering);
439 if (ret != (int)RuntimeInfoError.None)
441 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
442 RuntimeInfoErrorFactory.ThrowException(ret);
448 /// (event) UsbTetheringEnabled is raised when system preference for USB tethering is changed.
450 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
454 if (s_usbTetheringEnabled == null)
456 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
457 if (ret != (int)RuntimeInfoError.None)
459 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
460 RuntimeInfoErrorFactory.ThrowException(ret);
463 s_usbTetheringEnabled += value;
467 s_usbTetheringEnabled -= value;
468 if (s_usbTetheringEnabled == null)
470 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering);
471 if (ret != (int)RuntimeInfoError.None)
473 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
474 RuntimeInfoErrorFactory.ThrowException(ret);
480 /// (event) PacketDataEnabled is raised when system preference for package data through 3G network is changed.
482 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
486 if (s_packetDataEnabled == null)
488 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData, s_runtimeInfoChangedCallback, IntPtr.Zero);
489 if (ret != (int)RuntimeInfoError.None)
491 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
492 RuntimeInfoErrorFactory.ThrowException(ret);
495 s_packetDataEnabled += value;
499 s_packetDataEnabled -= value;
500 if (s_packetDataEnabled == null)
502 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData);
503 if (ret != (int)RuntimeInfoError.None)
505 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
506 RuntimeInfoErrorFactory.ThrowException(ret);
512 /// (event) DataRoamingEnabled is raised when system preference for data roaming is changed.
514 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
518 if (s_dataRoamingEnabled == null)
520 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming, s_runtimeInfoChangedCallback, IntPtr.Zero);
521 if (ret != (int)RuntimeInfoError.None)
523 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
524 RuntimeInfoErrorFactory.ThrowException(ret);
527 s_dataRoamingEnabled += value;
531 s_dataRoamingEnabled -= value;
532 if (s_dataRoamingEnabled == null)
534 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming);
535 if (ret != (int)RuntimeInfoError.None)
537 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
538 RuntimeInfoErrorFactory.ThrowException(ret);
544 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
546 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
550 if (s_vibrationEnabled == null)
552 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration, s_runtimeInfoChangedCallback, IntPtr.Zero);
553 if (ret != (int)RuntimeInfoError.None)
555 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
556 RuntimeInfoErrorFactory.ThrowException(ret);
559 s_vibrationEnabled += value;
563 s_vibrationEnabled -= value;
564 if (s_vibrationEnabled == null)
566 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration);
567 if (ret != (int)RuntimeInfoError.None)
569 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
570 RuntimeInfoErrorFactory.ThrowException(ret);
576 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
578 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
582 if (s_audioJackConnected == null)
584 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack, s_runtimeInfoChangedCallback, IntPtr.Zero);
585 if (ret != (int)RuntimeInfoError.None)
587 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
588 RuntimeInfoErrorFactory.ThrowException(ret);
591 s_audioJackConnected += value;
595 s_audioJackConnected -= value;
596 if (s_audioJackConnected == null)
598 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack);
599 if (ret != (int)RuntimeInfoError.None)
601 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
602 RuntimeInfoErrorFactory.ThrowException(ret);
608 /// (event) GpsStatusChanged is raised when status of GPS is changed.
610 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
614 if (s_gpsStatusChanged == null)
616 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps, s_runtimeInfoChangedCallback, IntPtr.Zero);
617 if (ret != (int)RuntimeInfoError.None)
619 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
620 RuntimeInfoErrorFactory.ThrowException(ret);
623 s_gpsStatusChanged += value;
627 s_gpsStatusChanged -= value;
628 if (s_gpsStatusChanged == null)
630 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps);
631 if (ret != (int)RuntimeInfoError.None)
633 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
634 RuntimeInfoErrorFactory.ThrowException(ret);
640 /// (event) BatteryIsCharging is raised battery is currently charging.
642 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
646 if (s_batteryIsCharging == null)
648 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging, s_runtimeInfoChangedCallback, IntPtr.Zero);
649 if (ret != (int)RuntimeInfoError.None)
651 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
652 RuntimeInfoErrorFactory.ThrowException(ret);
655 s_batteryIsCharging += value;
659 s_batteryIsCharging -= value;
660 if (s_batteryIsCharging == null)
662 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging);
663 if (ret != (int)RuntimeInfoError.None)
665 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
666 RuntimeInfoErrorFactory.ThrowException(ret);
672 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
674 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
678 if (s_tvOutConnected == null)
680 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut, s_runtimeInfoChangedCallback, IntPtr.Zero);
681 if (ret != (int)RuntimeInfoError.None)
683 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
684 RuntimeInfoErrorFactory.ThrowException(ret);
687 s_tvOutConnected += value;
691 s_tvOutConnected -= value;
692 if (s_tvOutConnected == null)
694 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut);
695 if (ret != (int)RuntimeInfoError.None)
697 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
698 RuntimeInfoErrorFactory.ThrowException(ret);
704 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
706 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
710 if (s_audioJackConnectorChanged == null)
712 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector, s_runtimeInfoChangedCallback, IntPtr.Zero);
713 if (ret != (int)RuntimeInfoError.None)
715 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
716 RuntimeInfoErrorFactory.ThrowException(ret);
719 s_audioJackConnectorChanged += value;
723 s_audioJackConnectorChanged -= value;
724 if (s_audioJackConnectorChanged == null)
726 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector);
727 if (ret != (int)RuntimeInfoError.None)
729 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
730 RuntimeInfoErrorFactory.ThrowException(ret);
736 /// (event) ChargerConnected is raised when charger is connected/disconnected.
738 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
742 if (s_chargerConnected == null)
744 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger, s_runtimeInfoChangedCallback, IntPtr.Zero);
745 if (ret != (int)RuntimeInfoError.None)
747 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
748 RuntimeInfoErrorFactory.ThrowException(ret);
751 s_chargerConnected += value;
755 s_chargerConnected -= value;
756 if (s_chargerConnected == null)
758 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger);
759 if (ret != (int)RuntimeInfoError.None)
761 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
762 RuntimeInfoErrorFactory.ThrowException(ret);
768 /// (event) AutoRotationEnabled is raised when system preference for auto rotation is changed.
770 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
774 if (s_autoRotationEnabled == null)
776 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation, s_runtimeInfoChangedCallback, IntPtr.Zero);
777 if (ret != (int)RuntimeInfoError.None)
779 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
780 RuntimeInfoErrorFactory.ThrowException(ret);
783 s_autoRotationEnabled += value;
787 s_autoRotationEnabled -= value;
788 if (s_autoRotationEnabled == null)
790 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation);
791 if (ret != (int)RuntimeInfoError.None)
793 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
794 RuntimeInfoErrorFactory.ThrowException(ret);