• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 * @syscap SystemCapability.PowerManager.BatteryManager.Core
18 * @since 3
19 */
20 export interface BatteryResponse {
21    /**
22     * Whether the battery is being charged.
23     * @since 3
24     */
25    charging: boolean;
26
27    /**
28     * Current battery level, which ranges from 0.00 to 1.00.
29     * @since 3
30     */
31    level: number;
32}
33
34/**
35 * @syscap SystemCapability.PowerManager.BatteryManager.Core
36 * @since 3
37 */
38export interface GetStatusOptions {
39    /**
40     * Called when the current charging state and battery level are obtained.
41     * @since 3
42     */
43    success?: (data: BatteryResponse) => void;
44
45    /**
46     * Called when the current charging state and battery level fail to be obtained.
47     * @since 3
48     */
49    fail?: (data: string, code: number) => void;
50
51    /**
52     * Called when the execution is completed.
53     * @since 3
54     */
55    complete?: () => void;
56}
57
58/**
59 * @syscap SystemCapability.PowerManager.BatteryManager.Core
60 * @since 3
61 * @import battery from '@system.battery';
62 */
63export default class Battery {
64    /**
65     * Obtains the current charging state and battery level.
66     * @param options Options.
67     * @since 3
68     */
69    static getStatus(options?: GetStatusOptions): void;
70}