Skip to content

Commit 8f4beb0

Browse files
Yunhee Seochanwoochoi
Yunhee Seo
authored andcommitted
[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 <[email protected]>
1 parent 30dd484 commit 8f4beb0

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/Tizen.System/Device/Battery.cs

+61
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ public enum BatteryLevelStatus
5858
Full
5959
}
6060

61+
/// <summary>
62+
/// Enumeration for the current device's power source information from the battery.
63+
/// These represent the current battery power source type (e.g., ac, usb, etc).
64+
/// </summary>
65+
/// <since_tizen> 12 </since_tizen>
66+
public enum BatteryPowerSource
67+
{
68+
/// <summary>
69+
/// These is no power source.
70+
/// </summary>
71+
/// <since_tizen> 12 </since_tizen>
72+
None = 0,
73+
/// <summary>
74+
/// AC power cable is connected.
75+
/// </summary>
76+
/// <since_tizen> 12 </since_tizen>
77+
Ac = 1,
78+
/// <summary>
79+
/// USB power cable is connected.
80+
/// </summary>
81+
/// <since_tizen> 12 </since_tizen>
82+
Usb = 2,
83+
/// <summary>
84+
/// Power is provided by a wireless source.
85+
/// </summary>
86+
/// <since_tizen> 12 </since_tizen>
87+
Wireless = 3
88+
}
89+
6190
/// <summary>
6291
/// The Battery class provides the properties and events for the device battery.
6392
/// </summary>
@@ -164,6 +193,38 @@ public static bool IsCharging
164193
return charging;
165194
}
166195
}
196+
/// <summary>
197+
/// Gets the current device's power source information from the battery.
198+
/// </summary>
199+
/// <remarks>
200+
/// Retrieves the current battery power source information (e.g., ac, usb, etc).
201+
/// </remarks>
202+
/// <since_tizen> 12 </since_tizen>
203+
/// <value>The battery power source type.</value>
204+
/// <example>
205+
/// <code>
206+
/// using Tizen.System;
207+
/// ...
208+
/// BatteryPowerSource PowerSourceType = Battery.PowerSource;
209+
/// if (PowerSourceType == BatteryPowerSource.None)
210+
/// ...
211+
/// ...
212+
/// </code>
213+
/// </example>
214+
/// <seealso cref="BatteryPowerSource"/>
215+
public static BatteryPowerSource PowerSource
216+
{
217+
get
218+
{
219+
int power_source_type = 0;
220+
DeviceError res = (DeviceError)Interop.Device.DeviceBatteryGetPowerSource(out power_source_type);
221+
if (res != DeviceError.None)
222+
{
223+
Log.Warn(DeviceExceptionFactory.LogTag, "unable to get battery power source type.");
224+
}
225+
return (BatteryPowerSource)power_source_type;
226+
}
227+
}
167228

168229
private static event EventHandler<BatteryPercentChangedEventArgs> s_capacityChanged;
169230
/// <summary>

src/Tizen.System/Interop/Interop.Device.cs

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ internal enum PowerLockState
117117
public static extern int DeviceBatteryIsCharging(out bool charging);
118118
[DllImport(Libraries.Device, EntryPoint = "device_battery_get_level_status", CallingConvention = CallingConvention.Cdecl)]
119119
public static extern int DeviceBatteryGetLevelStatus(out int status);
120+
[DllImport(Libraries.Device, EntryPoint = "device_battery_get_power_source", CallingConvention = CallingConvention.Cdecl)]
121+
public static extern int DeviceBatteryGetPowerSource(out int power_source_type);
120122

121123
// Display
122124
[DllImport(Libraries.Device, EntryPoint = "device_display_get_numbers", CallingConvention = CallingConvention.Cdecl)]

0 commit comments

Comments
 (0)