• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ohbattery_info.h
2
3<!--Kit: Basic Services Kit-->
4<!--Subsystem: PowerManager-->
5<!--Owner: @zhang-yinglie; @volcano_wang-->
6<!--Designer: @wangyantian0-->
7<!--Tester: @alien0208-->
8<!--Adviser: @w_Machine_cc-->
9
10## Overview
11
12Declares the battery APIs that are used to obtain the current battery capacity and power supply type and define common battery events.
13
14**Library**: libohbattery_info.so
15
16**System capability**: SystemCapability.PowerManager.BatteryManager.Core
17
18**Since**: 13
19
20**Related modules**: [OH_BatteryInfo](capi-oh-batteryinfo.md)
21
22## Summary
23
24### Enums
25
26| Name| typedef Keyword| Description|
27| -- | -- | -- |
28| [BatteryInfo_BatteryPluggedType](#batteryinfo_batterypluggedtype) | BatteryInfo_BatteryPluggedType | Enumerates the battery plugged types.|
29
30### Functions
31
32| Name| Description|
33| -- | -- |
34| [int32_t OH_BatteryInfo_GetCapacity()](#oh_batteryinfo_getcapacity) | Obtains the current battery capacity.|
35| [BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType()](#oh_batteryinfo_getpluggedtype) | Obtains the battery plugged type.|
36
37### Variables
38
39| Name| Description|
40| -- | -- |
41| static const char * COMMON_EVENT_KEY_CAPACITY = "soc" | Defines the common event indicating a battery capacity change.<br>**Since**: 13<br>**System capability**: SystemCapability.PowerManager.BatteryManager.Core|
42| static const char * COMMON_EVENT_KEY_CHARGE_STATE = "chargeState" | Defines the common event indicating a charging status change.<br>**Since**: 13|
43| static const char * COMMON_EVENT_KEY_PLUGGED_TYPE = "pluggedType" | Defines the common event indicating a battery plugged type change.<br>**Since**: 13|
44
45## Enum Description
46
47### BatteryInfo_BatteryPluggedType
48
49```
50enum BatteryInfo_BatteryPluggedType
51```
52
53**Description**
54
55Enumerates the battery plugged types.
56
57**Since**: 13
58
59| Enum Item| Description|
60| -- | -- |
61| PLUGGED_TYPE_NONE | No power supply.|
62| PLUGGED_TYPE_AC | AC charging.|
63| PLUGGED_TYPE_USB | USB DC charging.|
64| PLUGGED_TYPE_WIRELESS | Wireless charging.|
65| PLUGGED_TYPE_BUTT | Reserved.|
66
67
68## Function Description
69
70### OH_BatteryInfo_GetCapacity()
71
72```
73int32_t OH_BatteryInfo_GetCapacity()
74```
75
76**Description**
77
78Obtains the current battery capacity.
79
80**System capability**: SystemCapability.PowerManager.BatteryManager.Core
81
82**Since**: 13
83
84**Returns**
85
86| Type| Description|
87| -- | -- |
88| int32_t | A number in the range from 0 to 100.|
89
90### OH_BatteryInfo_GetPluggedType()
91
92```
93BatteryInfo_BatteryPluggedType OH_BatteryInfo_GetPluggedType()
94```
95
96**Description**
97
98Obtains the battery plugged type.
99
100**System capability**: SystemCapability.PowerManager.BatteryManager.Core
101
102**Since**: 13
103
104**Returns**
105
106| Type| Description|
107| -- | -- |
108| [BatteryInfo_BatteryPluggedType](#batteryinfo_batterypluggedtype) | Returns {@link BatteryInfo_BatteryPluggedType#PLUGGED_TYPE_NONE} if there is no power supply;<br>returns [PLUGGED_TYPE_AC](capi-ohbattery-info-h.md#batteryinfo_batterypluggedtype) if the power supply is in AC charging mode;<br>returns [PLUGGED_TYPE_USB](capi-ohbattery-info-h.md#batteryinfo_batterypluggedtype) if the power supply is in USB DC charging mode;<br>returns [PLUGGED_TYPE_WIRELESS](capi-ohbattery-info-h.md#batteryinfo_batterypluggedtype) if the power supply is in wireless charging mode;<br>returns [PLUGGED_TYPE_BUTT](capi-ohbattery-info-h.md#batteryinfo_batterypluggedtype) if the battery plugged type is unknown. |
109