From 8ae37030336622a6f25f306f5ade486dc52e170a Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 19 Nov 2024 14:47:18 +0900 Subject: [PATCH] [Tizen.System.Device] Add battery power source property To support using device_battery_get_power_source(), this battery powersource property addition is necessary. Below enum and property is added. - public enum BatteryPowerSource -> It represents battery power source charger type. - public static BatteryPowerSource PowerSource -> It is possible to get battery power source type as BatteryPowerSource enum value. Signed-off-by: Yunhee Seo --- src/Tizen.System/Device/Battery.cs | 61 ++++++++++++++++++++++ src/Tizen.System/Interop/Interop.Device.cs | 2 + 2 files changed, 63 insertions(+) diff --git a/src/Tizen.System/Device/Battery.cs b/src/Tizen.System/Device/Battery.cs index 94bc5bbc5db..0bb9bf73d2a 100755 --- a/src/Tizen.System/Device/Battery.cs +++ b/src/Tizen.System/Device/Battery.cs @@ -58,6 +58,35 @@ public enum BatteryLevelStatus Full } + /// + /// Enumeration for the current device's power source information from the battery. + /// These represent the current battery power source type (e.g., ac, usb, etc). + /// + /// 12 + public enum BatteryPowerSource + { + /// + /// These is no power source. + /// + /// 12 + None = 0, + /// + /// AC power cable is connected. + /// + /// 12 + Ac = 1, + /// + /// USB power cable is connected. + /// + /// 12 + Usb = 2, + /// + /// Power is provided by a wireless source. + /// + /// 12 + Wireless = 3 + } + /// /// The Battery class provides the properties and events for the device battery. /// @@ -164,6 +193,38 @@ public static bool IsCharging return charging; } } + /// + /// Gets the current device's power source information from the battery. + /// + /// + /// Retrieves the current battery power source information (e.g., ac, usb, etc). + /// + /// 12 + /// The battery power source type. + /// + /// + /// using Tizen.System; + /// ... + /// BatteryPowerSource PowerSourceType = Battery.PowerSource; + /// if (PowerSourceType == BatteryPowerSource.None) + /// ... + /// ... + /// + /// + /// + public static BatteryPowerSource PowerSource + { + get + { + int power_source_type = 0; + DeviceError res = (DeviceError)Interop.Device.DeviceBatteryGetPowerSource(out power_source_type); + if (res != DeviceError.None) + { + Log.Warn(DeviceExceptionFactory.LogTag, "unable to get battery power source type."); + } + return (BatteryPowerSource)power_source_type; + } + } private static event EventHandler s_capacityChanged; /// diff --git a/src/Tizen.System/Interop/Interop.Device.cs b/src/Tizen.System/Interop/Interop.Device.cs index c60c0d6d401..9bb2254b23e 100644 --- a/src/Tizen.System/Interop/Interop.Device.cs +++ b/src/Tizen.System/Interop/Interop.Device.cs @@ -117,6 +117,8 @@ internal enum PowerLockState public static extern int DeviceBatteryIsCharging(out bool charging); [DllImport(Libraries.Device, EntryPoint = "device_battery_get_level_status", CallingConvention = CallingConvention.Cdecl)] public static extern int DeviceBatteryGetLevelStatus(out int status); + [DllImport(Libraries.Device, EntryPoint = "device_battery_get_power_source", CallingConvention = CallingConvention.Cdecl)] + public static extern int DeviceBatteryGetPowerSource(out int power_source_type); // Display [DllImport(Libraries.Device, EntryPoint = "device_display_get_numbers", CallingConvention = CallingConvention.Cdecl)]