• 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 } 4900101 - 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 } 4900101 - 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 } 4900101 - 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   * @constant
99   * @syscap SystemCapability.PowerManager.BatteryManager.Core
100   * @atomicservice
101   * @since 12
102   */
103  const batterySOC: number;
104
105  /**
106   * Battery charging status of the current device.
107   *
108   * @constant
109   * @syscap SystemCapability.PowerManager.BatteryManager.Core
110   * @since 6
111   */
112  /**
113   * Battery charging status of the current device.
114   *
115   * @constant
116   * @syscap SystemCapability.PowerManager.BatteryManager.Core
117   * @atomicservice
118   * @since 12
119   */
120  const chargingStatus: BatteryChargeState;
121
122  /**
123   * Battery health state of the current device.
124   *
125   * @constant
126   * @syscap SystemCapability.PowerManager.BatteryManager.Core
127   * @since 6
128   */
129  const healthStatus: BatteryHealthState;
130
131  /**
132   * Charger type of the current device.
133   *
134   * @constant
135   * @syscap SystemCapability.PowerManager.BatteryManager.Core
136   * @since 6
137   */
138  const pluggedType: BatteryPluggedType;
139
140  /**
141   * Battery voltage of the current device, in µV.
142   *
143   * @constant
144   * @syscap SystemCapability.PowerManager.BatteryManager.Core
145   * @since 6
146   */
147  const voltage: number;
148
149  /**
150   * Battery technology of the current device.
151   *
152   * @constant
153   * @syscap SystemCapability.PowerManager.BatteryManager.Core
154   * @since 6
155   */
156  const technology: string;
157
158  /**
159   * Battery temperature of the current device, in 0.1℃.
160   *
161   * @constant
162   * @syscap SystemCapability.PowerManager.BatteryManager.Core
163   * @since 6
164   */
165  const batteryTemperature: number;
166
167  /**
168   * Battery present state of the current device.
169   *
170   * @constant
171   * @syscap SystemCapability.PowerManager.BatteryManager.Core
172   * @since 7
173   */
174  const isBatteryPresent: boolean;
175
176  /**
177   * Battery capacity level of the current device.
178   *
179   * @constant
180   * @syscap SystemCapability.PowerManager.BatteryManager.Core
181   * @since 9
182   */
183  const batteryCapacityLevel: BatteryCapacityLevel;
184
185  /**
186   * Estimated remaining time for the current device to be fully charged, in ms.
187   *
188   * @constant
189   * @syscap SystemCapability.PowerManager.BatteryManager.Core
190   * @systemapi
191   * @since 9
192   */
193  const estimatedRemainingChargeTime: number;
194
195  /**
196   * Battery total energy of the current device, in mAh.
197   *
198   * @constant
199   * @syscap SystemCapability.PowerManager.BatteryManager.Core
200   * @systemapi
201   * @since 9
202   */
203  const totalEnergy: number;
204
205  /**
206   * Battery immediate current of the current device, in mA.
207   *
208   * @constant
209   * @syscap SystemCapability.PowerManager.BatteryManager.Core
210   * @since 12
211   */
212  const nowCurrent: number;
213
214  /**
215   * Battery remaining energy of the current device, in mAh.
216   *
217   * @constant
218   * @syscap SystemCapability.PowerManager.BatteryManager.Core
219   * @systemapi
220   * @since 9
221   */
222  const remainingEnergy: number;
223
224  /**
225   * Charger type of a device.
226   *
227   * @enum { number }
228   * @syscap SystemCapability.PowerManager.BatteryManager.Core
229   * @since 6
230   */
231  export enum BatteryPluggedType {
232    /**
233     * Unknown type
234     *
235     * @syscap SystemCapability.PowerManager.BatteryManager.Core
236     * @since 6
237     */
238    NONE,
239    /**
240     * AC charger
241     *
242     * @syscap SystemCapability.PowerManager.BatteryManager.Core
243     * @since 6
244     */
245    AC,
246    /**
247     * USB charger
248     *
249     * @syscap SystemCapability.PowerManager.BatteryManager.Core
250     * @since 6
251     */
252    USB,
253    /**
254     * Wireless charger
255     *
256     * @syscap SystemCapability.PowerManager.BatteryManager.Core
257     * @since 6
258     */
259    WIRELESS
260  }
261
262  /**
263   * Battery charging status of a device.
264   *
265   * @enum { number }
266   * @syscap SystemCapability.PowerManager.BatteryManager.Core
267   * @since 6
268   */
269  /**
270   * Battery charging status of a device.
271   *
272   * @enum { number }
273   * @syscap SystemCapability.PowerManager.BatteryManager.Core
274   * @atomicservice
275   * @since 12
276   */
277  export enum BatteryChargeState {
278    /**
279     * Unknown state.
280     *
281     * @syscap SystemCapability.PowerManager.BatteryManager.Core
282     * @since 6
283     */
284    /**
285     * Unknown state.
286     *
287     * @syscap SystemCapability.PowerManager.BatteryManager.Core
288     * @atomicservice
289     * @since 12
290     */
291    NONE,
292    /**
293     * The battery is being charged.
294     *
295     * @syscap SystemCapability.PowerManager.BatteryManager.Core
296     * @since 6
297     */
298    /**
299     * The battery is being charged.
300     *
301     * @syscap SystemCapability.PowerManager.BatteryManager.Core
302     * @atomicservice
303     * @since 12
304     */
305    ENABLE,
306    /**
307     * The battery is not being charged.
308     *
309     * @syscap SystemCapability.PowerManager.BatteryManager.Core
310     * @since 6
311     */
312    /**
313     * The battery is not being charged.
314     *
315     * @syscap SystemCapability.PowerManager.BatteryManager.Core
316     * @atomicservice
317     * @since 12
318     */
319    DISABLE,
320    /**
321     * The battery is fully charged.
322     *
323     * @syscap SystemCapability.PowerManager.BatteryManager.Core
324     * @since 6
325     */
326    /**
327     * The battery is fully charged.
328     *
329     * @syscap SystemCapability.PowerManager.BatteryManager.Core
330     * @atomicservice
331     * @since 12
332     */
333    FULL
334  }
335
336  /**
337   * Battery health status of a device.
338   *
339   * @enum { number }
340   * @syscap SystemCapability.PowerManager.BatteryManager.Core
341   * @since 6
342   */
343  export enum BatteryHealthState {
344    /**
345     * Unknown state.
346     *
347     * @syscap SystemCapability.PowerManager.BatteryManager.Core
348     * @since 6
349     */
350    UNKNOWN,
351    /**
352     * The battery is in healthy state.
353     *
354     * @syscap SystemCapability.PowerManager.BatteryManager.Core
355     * @since 6
356     */
357    GOOD,
358    /**
359     * The battery is overheated.
360     *
361     * @syscap SystemCapability.PowerManager.BatteryManager.Core
362     * @since 6
363     */
364    OVERHEAT,
365    /**
366     * The battery voltage is over high.
367     *
368     * @syscap SystemCapability.PowerManager.BatteryManager.Core
369     * @since 6
370     */
371    OVERVOLTAGE,
372    /**
373     * The battery temperature is low.
374     *
375     * @syscap SystemCapability.PowerManager.BatteryManager.Core
376     * @since 6
377     */
378    COLD,
379    /**
380     * The battery is dead.
381     *
382     * @syscap SystemCapability.PowerManager.BatteryManager.Core
383     * @since 6
384     */
385    DEAD
386  }
387
388  /**
389   * Battery capacity level of a device.
390   *
391   * @enum { number }
392   * @syscap SystemCapability.PowerManager.BatteryManager.Core
393   * @since 9
394   */
395  export enum BatteryCapacityLevel {
396    /**
397     * The battery is in full capacity level.
398     *
399     * @syscap SystemCapability.PowerManager.BatteryManager.Core
400     * @since 9
401     */
402    LEVEL_FULL,
403    /**
404     * The battery is in high capacity level.
405     *
406     * @syscap SystemCapability.PowerManager.BatteryManager.Core
407     * @since 9
408     */
409    LEVEL_HIGH,
410    /**
411     * The battery is in normal capacity level.
412     *
413     * @syscap SystemCapability.PowerManager.BatteryManager.Core
414     * @since 9
415     */
416    LEVEL_NORMAL,
417    /**
418     * The battery is in low capacity level.
419     *
420     * @syscap SystemCapability.PowerManager.BatteryManager.Core
421     * @since 9
422     */
423    LEVEL_LOW,
424    /**
425     * The battery is in warning low capacity level.
426     *
427     * @syscap SystemCapability.PowerManager.BatteryManager.Core
428     * @since 9
429     */
430    LEVEL_WARNING,
431    /**
432     * The battery is in critical low capacity level.
433     *
434     * @syscap SystemCapability.PowerManager.BatteryManager.Core
435     * @since 9
436     */
437    LEVEL_CRITICAL,
438    /**
439     * The battery is in the lowest capacity level, system will shut down automatically in a few seconds.
440     *
441     * @syscap SystemCapability.PowerManager.BatteryManager.Core
442     * @since 9
443     */
444    LEVEL_SHUTDOWN
445  }
446
447  /**
448   * Extra key of common event COMMON_EVENT_BATTERY_CHANGED.
449   *
450   * @enum { string }
451   * @syscap SystemCapability.PowerManager.BatteryManager.Core
452   * @since 9
453   */
454  export enum CommonEventBatteryChangedKey {
455    /**
456     * Extra code of batterySOC.
457     *
458     * @syscap SystemCapability.PowerManager.BatteryManager.Core
459     * @since 9
460     */
461    EXTRA_SOC = 'soc',
462    /**
463     * Extra code of chargingStatus.
464     *
465     * @syscap SystemCapability.PowerManager.BatteryManager.Core
466     * @since 9
467     */
468    EXTRA_CHARGE_STATE = 'chargeState',
469    /**
470     * Extra code of healthStatus.
471     *
472     * @syscap SystemCapability.PowerManager.BatteryManager.Core
473     * @since 9
474     */
475    EXTRA_HEALTH_STATE = 'healthState',
476    /**
477     * Extra code of pluggedType.
478     *
479     * @syscap SystemCapability.PowerManager.BatteryManager.Core
480     * @since 9
481     */
482    EXTRA_PLUGGED_TYPE = 'pluggedType',
483    /**
484     * Extra code of voltage.
485     *
486     * @syscap SystemCapability.PowerManager.BatteryManager.Core
487     * @since 9
488     */
489    EXTRA_VOLTAGE = 'voltage',
490    /**
491     * Extra code of technology.
492     *
493     * @syscap SystemCapability.PowerManager.BatteryManager.Core
494     * @since 9
495     */
496    EXTRA_TECHNOLOGY = 'technology',
497    /**
498     * Extra code of batteryTemperature.
499     *
500     * @syscap SystemCapability.PowerManager.BatteryManager.Core
501     * @since 9
502     */
503    EXTRA_TEMPERATURE = 'temperature',
504    /**
505     * Extra code of isBatteryPresent.
506     *
507     * @syscap SystemCapability.PowerManager.BatteryManager.Core
508     * @since 9
509     */
510    EXTRA_PRESENT = 'present',
511    /**
512     * Extra code of batteryCapacityLevel.
513     *
514     * @syscap SystemCapability.PowerManager.BatteryManager.Core
515     * @since 9
516     */
517    EXTRA_CAPACITY_LEVEL = 'capacityLevel'
518  }
519}
520export default batteryInfo;
521