• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit BasicServicesKit
19 */
20
21/**
22 * Obtains battery information of a device.
23 * <p>Battery information includes the remaining battery power,
24 * voltage, temperature, model, and charger type.
25 *
26 * @namespace batteryInfo
27 * @syscap SystemCapability.PowerManager.BatteryManager.Core
28 * @since 6
29 */
30/**
31 * Obtains battery information of a device.
32 * <p>Battery information includes the remaining battery power,
33 * voltage, temperature, model, and charger type.
34 *
35 * @namespace batteryInfo
36 * @syscap SystemCapability.PowerManager.BatteryManager.Core
37 * @atomicservice
38 * @since 12
39 */
40declare namespace batteryInfo {
41  /**
42   * Sets the battery config by scene name.
43   *
44   * @param { string } sceneName - Indicates the battery charging scene name.
45   * sceneName parameter must be of type string.
46   * @param { string } sceneValue - Indicates the battery charging scene value.
47   * sceneValue parameter must be of type string.
48   * @returns { number } Return to set the charging configuration result.
49   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
50   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
51   * @throws { BusinessError } 5100101 - Failed to connect to the service.
52   * @syscap SystemCapability.PowerManager.BatteryManager.Core
53   * @systemapi
54   * @since 11
55   */
56  function setBatteryConfig(sceneName: string, sceneValue: string): number;
57
58  /**
59   * Queries the battery config by scene name.
60   *
61   * @param { string } sceneName - Indicates the battery charging scene name.
62   * sceneName parameter must be of type string.
63   * @returns { string } Returns the battery charging configuration, returns "" otherwise.
64   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
65   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
66   * @throws { BusinessError } 5100101 - Failed to connect to the service.
67   * @syscap SystemCapability.PowerManager.BatteryManager.Core
68   * @systemapi
69   * @since 11
70   */
71  function getBatteryConfig(sceneName: string): string;
72
73  /**
74   * Checks the battery config is enable by scene name.
75   *
76   * @param { string } sceneName - Indicates the battery charging scene name.
77   * sceneName parameter must be of type string.
78   * @returns { boolean } Returns true if the device supports the charging scene, returns false otherwise.
79   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
80   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
81   * @throws { BusinessError } 5100101 - Failed to connect to the service.
82   * @syscap SystemCapability.PowerManager.BatteryManager.Core
83   * @systemapi
84   * @since 11
85   */
86  function isBatteryConfigSupported(sceneName: string): boolean;
87
88  /**
89   * Battery state of charge (SoC) of the current device, in percent.
90   *
91   * @constant
92   * @syscap SystemCapability.PowerManager.BatteryManager.Core
93   * @since 6
94   */
95  /**
96   * Battery state of charge (SoC) of the current device, in percent.
97   *
98   * @syscap SystemCapability.PowerManager.BatteryManager.Core
99   * @atomicservice
100   * @since 12
101   */
102  const batterySOC: number;
103
104  /**
105   * Battery charging status of the current device.
106   *
107   * @constant
108   * @syscap SystemCapability.PowerManager.BatteryManager.Core
109   * @since 6
110   */
111  /**
112   * Battery charging status of the current device.
113   *
114   * @syscap SystemCapability.PowerManager.BatteryManager.Core
115   * @atomicservice
116   * @since 12
117   */
118  const chargingStatus: BatteryChargeState;
119
120  /**
121   * Battery health state of the current device.
122   *
123   * @syscap SystemCapability.PowerManager.BatteryManager.Core
124   * @since 6
125   */
126  const healthStatus: BatteryHealthState;
127
128  /**
129   * Charger type of the current device.
130   *
131   * @syscap SystemCapability.PowerManager.BatteryManager.Core
132   * @since 6
133   */
134  const pluggedType: BatteryPluggedType;
135
136  /**
137   * Battery voltage of the current device, in µV.
138   *
139   * @syscap SystemCapability.PowerManager.BatteryManager.Core
140   * @since 6
141   */
142  const voltage: number;
143
144  /**
145   * Battery technology of the current device.
146   *
147   * @syscap SystemCapability.PowerManager.BatteryManager.Core
148   * @since 6
149   */
150  const technology: string;
151
152  /**
153   * Battery temperature of the current device, in 0.1℃.
154   *
155   * @syscap SystemCapability.PowerManager.BatteryManager.Core
156   * @since 6
157   */
158  const batteryTemperature: number;
159
160  /**
161   * Battery present state of the current device.
162   *
163   * @syscap SystemCapability.PowerManager.BatteryManager.Core
164   * @since 7
165   */
166  const isBatteryPresent: boolean;
167
168  /**
169   * Battery capacity level of the current device.
170   *
171   * @syscap SystemCapability.PowerManager.BatteryManager.Core
172   * @since 9
173   */
174  const batteryCapacityLevel: BatteryCapacityLevel;
175
176  /**
177   * Estimated remaining time for the current device to be fully charged, in ms.
178   *
179   * @syscap SystemCapability.PowerManager.BatteryManager.Core
180   * @systemapi
181   * @since 9
182   */
183  const estimatedRemainingChargeTime: number;
184
185  /**
186   * Battery total energy of the current device, in mAh.
187   *
188   * @syscap SystemCapability.PowerManager.BatteryManager.Core
189   * @systemapi
190   * @since 9
191   */
192  const totalEnergy: number;
193
194  /**
195   * Battery immediate current of the current device, in mA.
196   *
197   * @syscap SystemCapability.PowerManager.BatteryManager.Core
198   * @since 12
199   */
200  const nowCurrent: number;
201
202  /**
203   * Battery remaining energy of the current device, in mAh.
204   *
205   * @syscap SystemCapability.PowerManager.BatteryManager.Core
206   * @systemapi
207   * @since 9
208   */
209  const remainingEnergy: number;
210
211  /**
212   * Charger type of a device.
213   *
214   * @enum { number }
215   * @syscap SystemCapability.PowerManager.BatteryManager.Core
216   * @since 6
217   */
218  export enum BatteryPluggedType {
219    /**
220     * Unknown type
221     *
222     * @syscap SystemCapability.PowerManager.BatteryManager.Core
223     * @since 6
224     */
225    NONE,
226    /**
227     * AC charger
228     *
229     * @syscap SystemCapability.PowerManager.BatteryManager.Core
230     * @since 6
231     */
232    AC,
233    /**
234     * USB charger
235     *
236     * @syscap SystemCapability.PowerManager.BatteryManager.Core
237     * @since 6
238     */
239    USB,
240    /**
241     * Wireless charger
242     *
243     * @syscap SystemCapability.PowerManager.BatteryManager.Core
244     * @since 6
245     */
246    WIRELESS
247  }
248
249  /**
250   * Battery charging status of a device.
251   *
252   * @enum { number }
253   * @syscap SystemCapability.PowerManager.BatteryManager.Core
254   * @since 6
255   */
256  /**
257   * Battery charging status of a device.
258   *
259   * @enum { number }
260   * @syscap SystemCapability.PowerManager.BatteryManager.Core
261   * @atomicservice
262   * @since 12
263   */
264  export enum BatteryChargeState {
265    /**
266     * Unknown state.
267     *
268     * @syscap SystemCapability.PowerManager.BatteryManager.Core
269     * @since 6
270     */
271    /**
272     * Unknown state.
273     *
274     * @syscap SystemCapability.PowerManager.BatteryManager.Core
275     * @atomicservice
276     * @since 12
277     */
278    NONE,
279    /**
280     * The battery is being charged.
281     *
282     * @syscap SystemCapability.PowerManager.BatteryManager.Core
283     * @since 6
284     */
285    /**
286     * The battery is being charged.
287     *
288     * @syscap SystemCapability.PowerManager.BatteryManager.Core
289     * @atomicservice
290     * @since 12
291     */
292    ENABLE,
293    /**
294     * The battery is not being charged.
295     *
296     * @syscap SystemCapability.PowerManager.BatteryManager.Core
297     * @since 6
298     */
299    /**
300     * The battery is not being charged.
301     *
302     * @syscap SystemCapability.PowerManager.BatteryManager.Core
303     * @atomicservice
304     * @since 12
305     */
306    DISABLE,
307    /**
308     * The battery is fully charged.
309     *
310     * @syscap SystemCapability.PowerManager.BatteryManager.Core
311     * @since 6
312     */
313    /**
314     * The battery is fully charged.
315     *
316     * @syscap SystemCapability.PowerManager.BatteryManager.Core
317     * @atomicservice
318     * @since 12
319     */
320    FULL
321  }
322
323  /**
324   * Battery health status of a device.
325   *
326   * @enum { number }
327   * @syscap SystemCapability.PowerManager.BatteryManager.Core
328   * @since 6
329   */
330  export enum BatteryHealthState {
331    /**
332     * Unknown state.
333     *
334     * @syscap SystemCapability.PowerManager.BatteryManager.Core
335     * @since 6
336     */
337    UNKNOWN,
338    /**
339     * The battery is in healthy state.
340     *
341     * @syscap SystemCapability.PowerManager.BatteryManager.Core
342     * @since 6
343     */
344    GOOD,
345    /**
346     * The battery is overheated.
347     *
348     * @syscap SystemCapability.PowerManager.BatteryManager.Core
349     * @since 6
350     */
351    OVERHEAT,
352    /**
353     * The battery voltage is over high.
354     *
355     * @syscap SystemCapability.PowerManager.BatteryManager.Core
356     * @since 6
357     */
358    OVERVOLTAGE,
359    /**
360     * The battery temperature is low.
361     *
362     * @syscap SystemCapability.PowerManager.BatteryManager.Core
363     * @since 6
364     */
365    COLD,
366    /**
367     * The battery is dead.
368     *
369     * @syscap SystemCapability.PowerManager.BatteryManager.Core
370     * @since 6
371     */
372    DEAD
373  }
374
375  /**
376   * Battery capacity level of a device.
377   *
378   * @enum { number }
379   * @syscap SystemCapability.PowerManager.BatteryManager.Core
380   * @since 9
381   */
382  export enum BatteryCapacityLevel {
383    /**
384     * The battery is in full capacity level.
385     *
386     * @syscap SystemCapability.PowerManager.BatteryManager.Core
387     * @since 9
388     */
389    LEVEL_FULL,
390    /**
391     * The battery is in high capacity level.
392     *
393     * @syscap SystemCapability.PowerManager.BatteryManager.Core
394     * @since 9
395     */
396    LEVEL_HIGH,
397    /**
398     * The battery is in normal capacity level.
399     *
400     * @syscap SystemCapability.PowerManager.BatteryManager.Core
401     * @since 9
402     */
403    LEVEL_NORMAL,
404    /**
405     * The battery is in low capacity level.
406     *
407     * @syscap SystemCapability.PowerManager.BatteryManager.Core
408     * @since 9
409     */
410    LEVEL_LOW,
411    /**
412     * The battery is in warning low capacity level.
413     *
414     * @syscap SystemCapability.PowerManager.BatteryManager.Core
415     * @since 9
416     */
417    LEVEL_WARNING,
418    /**
419     * The battery is in critical low capacity level.
420     *
421     * @syscap SystemCapability.PowerManager.BatteryManager.Core
422     * @since 9
423     */
424    LEVEL_CRITICAL,
425    /**
426     * The battery is in the lowest capacity level, system will shut down automatically in a few seconds.
427     *
428     * @syscap SystemCapability.PowerManager.BatteryManager.Core
429     * @since 9
430     */
431    LEVEL_SHUTDOWN
432  }
433
434  /**
435   * Extra key of common event COMMON_EVENT_BATTERY_CHANGED.
436   *
437   * @enum { string }
438   * @syscap SystemCapability.PowerManager.BatteryManager.Core
439   * @since 9
440   */
441  export enum CommonEventBatteryChangedKey {
442    /**
443     * Extra code of batterySOC.
444     *
445     * @syscap SystemCapability.PowerManager.BatteryManager.Core
446     * @since 9
447     */
448    EXTRA_SOC = 'soc',
449    /**
450     * Extra code of chargingStatus.
451     *
452     * @syscap SystemCapability.PowerManager.BatteryManager.Core
453     * @since 9
454     */
455    EXTRA_CHARGE_STATE = 'chargeState',
456    /**
457     * Extra code of healthStatus.
458     *
459     * @syscap SystemCapability.PowerManager.BatteryManager.Core
460     * @since 9
461     */
462    EXTRA_HEALTH_STATE = 'healthState',
463    /**
464     * Extra code of pluggedType.
465     *
466     * @syscap SystemCapability.PowerManager.BatteryManager.Core
467     * @since 9
468     */
469    EXTRA_PLUGGED_TYPE = 'pluggedType',
470    /**
471     * Extra code of voltage.
472     *
473     * @syscap SystemCapability.PowerManager.BatteryManager.Core
474     * @since 9
475     */
476    EXTRA_VOLTAGE = 'voltage',
477    /**
478     * Extra code of technology.
479     *
480     * @syscap SystemCapability.PowerManager.BatteryManager.Core
481     * @since 9
482     */
483    EXTRA_TECHNOLOGY = 'technology',
484    /**
485     * Extra code of batteryTemperature.
486     *
487     * @syscap SystemCapability.PowerManager.BatteryManager.Core
488     * @since 9
489     */
490    EXTRA_TEMPERATURE = 'temperature',
491    /**
492     * Extra code of isBatteryPresent.
493     *
494     * @syscap SystemCapability.PowerManager.BatteryManager.Core
495     * @since 9
496     */
497    EXTRA_PRESENT = 'present',
498    /**
499     * Extra code of batteryCapacityLevel.
500     *
501     * @syscap SystemCapability.PowerManager.BatteryManager.Core
502     * @since 9
503     */
504    EXTRA_CAPACITY_LEVEL = 'capacityLevel'
505  }
506}
507export default batteryInfo;
508