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_packetDataEnabled;
35 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_dataRoamingEnabled;
36 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_vibrationEnabled;
37 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnected;
38 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_gpsStatusChanged;
39 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_batteryIsCharging;
40 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_tvOutConnected;
41 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_audioJackConnectorChanged;
42 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_chargerConnected;
43 private static event EventHandler<RuntimeKeyStatusChangedEventArgs> s_autoRotationEnabled;
45 private static readonly Interop.RuntimeInfo.RuntimeInformationChangedCallback s_runtimeInfoChangedCallback = (RuntimeInformationKey key, IntPtr userData) =>
47 RuntimeKeyStatusChangedEventArgs eventArgs = new RuntimeKeyStatusChangedEventArgs()
53 case RuntimeInformationKey.Bluetooth:
55 s_bluetoothEnabled?.Invoke(null, eventArgs);
58 case RuntimeInformationKey.WifiHotspot:
60 s_wifiHotspotEnabled?.Invoke(null, eventArgs);
63 case RuntimeInformationKey.BluetoothTethering:
65 s_bluetoothTetheringEnabled?.Invoke(null, eventArgs);
68 case RuntimeInformationKey.UsbTethering:
70 s_usbTetheringEnabled?.Invoke(null, eventArgs);
73 case RuntimeInformationKey.PacketData:
75 s_packetDataEnabled?.Invoke(null, eventArgs);
78 case RuntimeInformationKey.DataRoaming:
80 s_dataRoamingEnabled?.Invoke(null, eventArgs);
83 case RuntimeInformationKey.Vibration:
85 s_vibrationEnabled?.Invoke(null, eventArgs);
88 case RuntimeInformationKey.AudioJack:
90 s_audioJackConnected?.Invoke(null, eventArgs);
93 case RuntimeInformationKey.Gps:
95 s_gpsStatusChanged?.Invoke(null, eventArgs);
98 case RuntimeInformationKey.BatteryIsCharging:
100 s_batteryIsCharging?.Invoke(null, eventArgs);
103 case RuntimeInformationKey.TvOut:
105 s_tvOutConnected?.Invoke(null, eventArgs);
108 case RuntimeInformationKey.AudioJackConnector:
110 s_audioJackConnectorChanged?.Invoke(null, eventArgs);
113 case RuntimeInformationKey.Charger:
115 s_chargerConnected?.Invoke(null, eventArgs);
118 case RuntimeInformationKey.AutoRotation:
120 s_autoRotationEnabled?.Invoke(null, eventArgs);
128 internal static readonly Dictionary<RuntimeInformationKey, Type> s_keyDataTypeMapping = new Dictionary<RuntimeInformationKey, Type>
130 [RuntimeInformationKey.Bluetooth] = typeof(bool),
131 [RuntimeInformationKey.WifiHotspot] = typeof(bool),
132 [RuntimeInformationKey.BluetoothTethering] = typeof(bool),
133 [RuntimeInformationKey.UsbTethering] = typeof(bool),
134 [RuntimeInformationKey.PacketData] = typeof(bool),
135 [RuntimeInformationKey.DataRoaming] = typeof(bool),
136 [RuntimeInformationKey.Vibration] = typeof(bool),
137 [RuntimeInformationKey.AudioJack] = typeof(bool),
138 [RuntimeInformationKey.BatteryIsCharging] = typeof(bool),
139 [RuntimeInformationKey.TvOut] = typeof(bool),
140 [RuntimeInformationKey.Charger] = typeof(bool),
141 [RuntimeInformationKey.AutoRotation] = typeof(bool),
142 [RuntimeInformationKey.Gps] = typeof(int),
143 [RuntimeInformationKey.AudioJackConnector] = typeof(int)
147 /// This function gets current state of the given key which represents specific runtime information
149 /// <param name="key">The runtime information key for which the current should be read </param>
150 /// <returns>The current status of the given key</returns>
151 internal static object GetStatus(RuntimeInformationKey key)
154 if (!s_keyDataTypeMapping.TryGetValue(key, out value))
156 RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
158 if (s_keyDataTypeMapping[key] == typeof(int))
161 int ret = Interop.RuntimeInfo.GetValue(key, out status);
162 if (ret != (int)RuntimeInfoError.None)
164 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
165 RuntimeInfoErrorFactory.ThrowException(ret);
173 int ret = Interop.RuntimeInfo.GetValue(key, out status);
174 if (ret != (int)RuntimeInfoError.None)
176 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get value for key {0}", key.ToString());
177 RuntimeInfoErrorFactory.ThrowException(ret);
185 /// Validates the data type of the status represented by Runtime Key.
186 /// Note that this is a generic method.
188 /// <typeparam name="T">The generic type to validate.</typeparam>
189 /// <param name="key">The runtime information key for which the status type is validated </param>
190 /// <returns>true if the data type matches</returns>.
191 public static bool Is<T>(RuntimeInformationKey key)
193 if (!s_keyDataTypeMapping.ContainsKey(key))
195 Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid data type");
196 throw new ArgumentException("Invalid parameter");
199 return s_keyDataTypeMapping[key] == typeof(T);
203 /// Gets the status of Runtime Key.
204 /// Note that this is a generic method.
206 /// <typeparam name="T">The generic type to return.</typeparam>
207 /// <param name="key">The runtime information key for which the current should be read </param>
208 /// <returns>The current status of the given key</returns>.
209 public static T GetStatus<T>(RuntimeInformationKey key)
211 return (T)GetStatus(key);
215 /// The System memory information
217 public static SystemMemoryInformation GetSystemMemoryInformation()
219 Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
220 int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
221 if (ret != (int)RuntimeInfoError.None)
223 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
224 RuntimeInfoErrorFactory.ThrowException(ret);
227 return new SystemMemoryInformation(info);
231 /// Gets memory information per processes
233 /// <param name="pid">List of unique process ids </param>
234 /// <returns>List of memory information per processes</returns>
235 public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
237 int[] processArray = pid.ToArray<int>();
238 Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
239 Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
240 int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
241 if (ret != (int)RuntimeInfoError.None)
243 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information");
244 RuntimeInfoErrorFactory.ThrowException(ret);
248 foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
250 ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
251 map.Add(processArray[idx], processMemory);
261 public static CpuUsage GetCpuUsage()
263 Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
264 int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
265 if (ret != (int)RuntimeInfoError.None)
267 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
268 RuntimeInfoErrorFactory.ThrowException(ret);
270 return new CpuUsage(usage);
274 /// The CPU run time per process
276 /// <param name="pid">List of unique process ids </param>
277 /// <returns>List of CPU usage information per processes</returns>
278 public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
280 int[] processArray = pid.ToArray<int>();
281 Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
282 Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
283 int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
284 if (ret != (int)RuntimeInfoError.None)
286 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
287 RuntimeInfoErrorFactory.ThrowException(ret);
291 foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
293 ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
294 map.Add(processArray[idx], processUsage);
302 /// The number of processors
304 public static int ProcessorCount
309 int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
310 if (ret != (int)RuntimeInfoError.None)
312 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
313 RuntimeInfoErrorFactory.ThrowException(ret);
321 /// Gets the current frequency of processor
323 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
324 /// <returns>The current frequency(MHz) of processor</returns>
325 public static int GetProcessorCurrentFrequency(int coreId)
328 int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
329 if (ret != (int)RuntimeInfoError.None)
331 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
332 RuntimeInfoErrorFactory.ThrowException(ret);
338 /// Gets the max frequency of processor
340 /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency</param>
341 /// <returns>The max frequency(MHz) of processor</returns>
342 public static int GetProcessorMaxFrequency(int coreId)
345 int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
346 if (ret != (int)RuntimeInfoError.None)
348 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
349 RuntimeInfoErrorFactory.ThrowException(ret);
355 /// (event) BluetoothEnabled is raised when system preference for bluetooth is changed.
357 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
361 if (s_bluetoothEnabled == null)
363 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth, s_runtimeInfoChangedCallback, IntPtr.Zero);
364 if (ret != (int)RuntimeInfoError.None)
366 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
367 RuntimeInfoErrorFactory.ThrowException(ret);
370 s_bluetoothEnabled += value;
374 s_bluetoothEnabled -= value;
375 if (s_bluetoothEnabled == null)
377 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Bluetooth);
378 if (ret != (int)RuntimeInfoError.None)
380 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
381 RuntimeInfoErrorFactory.ThrowException(ret);
387 /// (event) WifiHotspotEnabled is raised when system preference for Wi-Fi is changed.
389 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> WifiHotspotEnabled
393 if (s_wifiHotspotEnabled == null)
395 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot, s_runtimeInfoChangedCallback, IntPtr.Zero);
396 if (ret != (int)RuntimeInfoError.None)
398 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
399 RuntimeInfoErrorFactory.ThrowException(ret);
402 s_wifiHotspotEnabled += value;
406 s_wifiHotspotEnabled -= value;
407 if (s_wifiHotspotEnabled == null)
409 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.WifiHotspot);
410 if (ret != (int)RuntimeInfoError.None)
412 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
413 RuntimeInfoErrorFactory.ThrowException(ret);
419 /// (event) BluetoothTetheringEnabled is raised when system preference for bluetooth tethering is changed.
421 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothTetheringEnabled
425 if (s_bluetoothTetheringEnabled == null)
427 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
428 if (ret != (int)RuntimeInfoError.None)
430 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
431 RuntimeInfoErrorFactory.ThrowException(ret);
434 s_bluetoothTetheringEnabled += value;
438 s_bluetoothTetheringEnabled -= value;
439 if (s_bluetoothTetheringEnabled == null)
441 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BluetoothTethering);
442 if (ret != (int)RuntimeInfoError.None)
444 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
445 RuntimeInfoErrorFactory.ThrowException(ret);
451 /// (event) UsbTetheringEnabled is raised when system preference for USB tethering is changed.
453 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> UsbTetheringEnabled
457 if (s_usbTetheringEnabled == null)
459 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering, s_runtimeInfoChangedCallback, IntPtr.Zero);
460 if (ret != (int)RuntimeInfoError.None)
462 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
463 RuntimeInfoErrorFactory.ThrowException(ret);
466 s_usbTetheringEnabled += value;
470 s_usbTetheringEnabled -= value;
471 if (s_usbTetheringEnabled == null)
473 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.UsbTethering);
474 if (ret != (int)RuntimeInfoError.None)
476 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
477 RuntimeInfoErrorFactory.ThrowException(ret);
483 /// (event) PacketDataEnabled is raised when system preference for package data through 3G network is changed.
485 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> PacketDataEnabled
489 if (s_packetDataEnabled == null)
491 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData, s_runtimeInfoChangedCallback, IntPtr.Zero);
492 if (ret != (int)RuntimeInfoError.None)
494 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
495 RuntimeInfoErrorFactory.ThrowException(ret);
498 s_packetDataEnabled += value;
502 s_packetDataEnabled -= value;
503 if (s_packetDataEnabled == null)
505 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.PacketData);
506 if (ret != (int)RuntimeInfoError.None)
508 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
509 RuntimeInfoErrorFactory.ThrowException(ret);
515 /// (event) DataRoamingEnabled is raised when system preference for data roaming is changed.
517 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> DataRoamingEnabled
521 if (s_dataRoamingEnabled == null)
523 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming, s_runtimeInfoChangedCallback, IntPtr.Zero);
524 if (ret != (int)RuntimeInfoError.None)
526 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
527 RuntimeInfoErrorFactory.ThrowException(ret);
530 s_dataRoamingEnabled += value;
534 s_dataRoamingEnabled -= value;
535 if (s_dataRoamingEnabled == null)
537 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.DataRoaming);
538 if (ret != (int)RuntimeInfoError.None)
540 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
541 RuntimeInfoErrorFactory.ThrowException(ret);
547 /// (event) VibrationEnabled is raised when system preference for vibration is changed.
549 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> VibrationEnabled
553 if (s_vibrationEnabled == null)
555 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration, s_runtimeInfoChangedCallback, IntPtr.Zero);
556 if (ret != (int)RuntimeInfoError.None)
558 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
559 RuntimeInfoErrorFactory.ThrowException(ret);
562 s_vibrationEnabled += value;
566 s_vibrationEnabled -= value;
567 if (s_vibrationEnabled == null)
569 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Vibration);
570 if (ret != (int)RuntimeInfoError.None)
572 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
573 RuntimeInfoErrorFactory.ThrowException(ret);
579 /// (event) AudioJackConnected is raised when audio jack is connected/disconnected.
581 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnected
585 if (s_audioJackConnected == null)
587 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack, s_runtimeInfoChangedCallback, IntPtr.Zero);
588 if (ret != (int)RuntimeInfoError.None)
590 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
591 RuntimeInfoErrorFactory.ThrowException(ret);
594 s_audioJackConnected += value;
598 s_audioJackConnected -= value;
599 if (s_audioJackConnected == null)
601 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJack);
602 if (ret != (int)RuntimeInfoError.None)
604 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
605 RuntimeInfoErrorFactory.ThrowException(ret);
611 /// (event) GpsStatusChanged is raised when status of GPS is changed.
613 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> GpsStatusChanged
617 if (s_gpsStatusChanged == null)
619 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps, s_runtimeInfoChangedCallback, IntPtr.Zero);
620 if (ret != (int)RuntimeInfoError.None)
622 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
623 RuntimeInfoErrorFactory.ThrowException(ret);
626 s_gpsStatusChanged += value;
630 s_gpsStatusChanged -= value;
631 if (s_gpsStatusChanged == null)
633 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Gps);
634 if (ret != (int)RuntimeInfoError.None)
636 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
637 RuntimeInfoErrorFactory.ThrowException(ret);
643 /// (event) BatteryIsCharging is raised battery is currently charging.
645 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BatteryIsCharging
649 if (s_batteryIsCharging == null)
651 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging, s_runtimeInfoChangedCallback, IntPtr.Zero);
652 if (ret != (int)RuntimeInfoError.None)
654 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
655 RuntimeInfoErrorFactory.ThrowException(ret);
658 s_batteryIsCharging += value;
662 s_batteryIsCharging -= value;
663 if (s_batteryIsCharging == null)
665 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.BatteryIsCharging);
666 if (ret != (int)RuntimeInfoError.None)
668 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
669 RuntimeInfoErrorFactory.ThrowException(ret);
675 /// (event) TvOutConnected is raised when TV out is connected/disconnected.
677 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> TvOutConnected
681 if (s_tvOutConnected == null)
683 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut, s_runtimeInfoChangedCallback, IntPtr.Zero);
684 if (ret != (int)RuntimeInfoError.None)
686 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
687 RuntimeInfoErrorFactory.ThrowException(ret);
690 s_tvOutConnected += value;
694 s_tvOutConnected -= value;
695 if (s_tvOutConnected == null)
697 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.TvOut);
698 if (ret != (int)RuntimeInfoError.None)
700 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
701 RuntimeInfoErrorFactory.ThrowException(ret);
707 /// (event) AudioJackConnectorChanged is raised when audio jack connection changes.
709 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AudioJackConnectorChanged
713 if (s_audioJackConnectorChanged == null)
715 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector, s_runtimeInfoChangedCallback, IntPtr.Zero);
716 if (ret != (int)RuntimeInfoError.None)
718 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
719 RuntimeInfoErrorFactory.ThrowException(ret);
722 s_audioJackConnectorChanged += value;
726 s_audioJackConnectorChanged -= value;
727 if (s_audioJackConnectorChanged == null)
729 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AudioJackConnector);
730 if (ret != (int)RuntimeInfoError.None)
732 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
733 RuntimeInfoErrorFactory.ThrowException(ret);
739 /// (event) ChargerConnected is raised when charger is connected/disconnected.
741 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> ChargerConnected
745 if (s_chargerConnected == null)
747 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger, s_runtimeInfoChangedCallback, IntPtr.Zero);
748 if (ret != (int)RuntimeInfoError.None)
750 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
751 RuntimeInfoErrorFactory.ThrowException(ret);
754 s_chargerConnected += value;
758 s_chargerConnected -= value;
759 if (s_chargerConnected == null)
761 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.Charger);
762 if (ret != (int)RuntimeInfoError.None)
764 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
765 RuntimeInfoErrorFactory.ThrowException(ret);
771 /// (event) AutoRotationEnabled is raised when system preference for auto rotation is changed.
773 public static event EventHandler<RuntimeKeyStatusChangedEventArgs> AutoRotationEnabled
777 if (s_autoRotationEnabled == null)
779 int ret = Interop.RuntimeInfo.SetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation, s_runtimeInfoChangedCallback, IntPtr.Zero);
780 if (ret != (int)RuntimeInfoError.None)
782 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
783 RuntimeInfoErrorFactory.ThrowException(ret);
786 s_autoRotationEnabled += value;
790 s_autoRotationEnabled -= value;
791 if (s_autoRotationEnabled == null)
793 int ret = Interop.RuntimeInfo.UnsetRuntimeInfoChangedCallback(RuntimeInformationKey.AutoRotation);
794 if (ret != (int)RuntimeInfoError.None)
796 Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to add event handler");
797 RuntimeInfoErrorFactory.ThrowException(ret);