161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit BasicServicesKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport { AsyncCallback, BusinessError } from './@ohos.base';
2261847f8eSopenharmony_ci
2361847f8eSopenharmony_ci/**
2461847f8eSopenharmony_ci * Provides methods to get power consumption information.
2561847f8eSopenharmony_ci *
2661847f8eSopenharmony_ci * @namespace batteryStats
2761847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.BatteryStatistics
2861847f8eSopenharmony_ci * @systemapi
2961847f8eSopenharmony_ci * @since 8
3061847f8eSopenharmony_ci */
3161847f8eSopenharmony_cideclare namespace batteryStats {
3261847f8eSopenharmony_ci  /**
3361847f8eSopenharmony_ci   * Describes the consumption type.
3461847f8eSopenharmony_ci   *
3561847f8eSopenharmony_ci   * @enum { number }
3661847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
3761847f8eSopenharmony_ci   * @systemapi
3861847f8eSopenharmony_ci   * @since 8
3961847f8eSopenharmony_ci   */
4061847f8eSopenharmony_ci  export enum ConsumptionType {
4161847f8eSopenharmony_ci    /** Indicates an invalid consumption type
4261847f8eSopenharmony_ci     *
4361847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
4461847f8eSopenharmony_ci     * @systemapi
4561847f8eSopenharmony_ci     * @since 8
4661847f8eSopenharmony_ci    */
4761847f8eSopenharmony_ci    CONSUMPTION_TYPE_INVALID = -17,
4861847f8eSopenharmony_ci
4961847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by APP
5061847f8eSopenharmony_ci     *
5161847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
5261847f8eSopenharmony_ci     * @systemapi
5361847f8eSopenharmony_ci     * @since 8
5461847f8eSopenharmony_ci    */
5561847f8eSopenharmony_ci    CONSUMPTION_TYPE_APP,
5661847f8eSopenharmony_ci
5761847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by bluetooth
5861847f8eSopenharmony_ci     *
5961847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
6061847f8eSopenharmony_ci     * @systemapi
6161847f8eSopenharmony_ci     * @since 8
6261847f8eSopenharmony_ci    */
6361847f8eSopenharmony_ci    CONSUMPTION_TYPE_BLUETOOTH,
6461847f8eSopenharmony_ci
6561847f8eSopenharmony_ci    /** Indicates the battery power consumption generated when the CPU is idle
6661847f8eSopenharmony_ci     *
6761847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
6861847f8eSopenharmony_ci     * @systemapi
6961847f8eSopenharmony_ci     * @since 8
7061847f8eSopenharmony_ci    */
7161847f8eSopenharmony_ci    CONSUMPTION_TYPE_IDLE,
7261847f8eSopenharmony_ci
7361847f8eSopenharmony_ci    /** Indicates the battery power consumption generated when phone call is active
7461847f8eSopenharmony_ci     *
7561847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
7661847f8eSopenharmony_ci     * @systemapi
7761847f8eSopenharmony_ci     * @since 8
7861847f8eSopenharmony_ci    */
7961847f8eSopenharmony_ci    CONSUMPTION_TYPE_PHONE,
8061847f8eSopenharmony_ci
8161847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by radio
8261847f8eSopenharmony_ci     *
8361847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
8461847f8eSopenharmony_ci     * @systemapi
8561847f8eSopenharmony_ci     * @since 8
8661847f8eSopenharmony_ci    */
8761847f8eSopenharmony_ci    CONSUMPTION_TYPE_RADIO,
8861847f8eSopenharmony_ci
8961847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by screen
9061847f8eSopenharmony_ci     *
9161847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
9261847f8eSopenharmony_ci     * @systemapi
9361847f8eSopenharmony_ci     * @since 8
9461847f8eSopenharmony_ci    */
9561847f8eSopenharmony_ci    CONSUMPTION_TYPE_SCREEN,
9661847f8eSopenharmony_ci
9761847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by user
9861847f8eSopenharmony_ci     *
9961847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
10061847f8eSopenharmony_ci     * @systemapi
10161847f8eSopenharmony_ci     * @since 8
10261847f8eSopenharmony_ci    */
10361847f8eSopenharmony_ci    CONSUMPTION_TYPE_USER,
10461847f8eSopenharmony_ci
10561847f8eSopenharmony_ci    /** Indicates the battery power consumption generated by WIFI
10661847f8eSopenharmony_ci     *
10761847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
10861847f8eSopenharmony_ci     * @systemapi
10961847f8eSopenharmony_ci     * @since 8
11061847f8eSopenharmony_ci    */
11161847f8eSopenharmony_ci    CONSUMPTION_TYPE_WIFI
11261847f8eSopenharmony_ci  }
11361847f8eSopenharmony_ci
11461847f8eSopenharmony_ci  /**
11561847f8eSopenharmony_ci   * Obtains the power consumption information list.
11661847f8eSopenharmony_ci   *
11761847f8eSopenharmony_ci   * @returns { Promise<Array<BatteryStatsInfo>> } Power consumption information list.
11861847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
11961847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
12061847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
12161847f8eSopenharmony_ci   * @systemapi
12261847f8eSopenharmony_ci   * @since 8
12361847f8eSopenharmony_ci   */
12461847f8eSopenharmony_ci  function getBatteryStats(): Promise<Array<BatteryStatsInfo>>;
12561847f8eSopenharmony_ci
12661847f8eSopenharmony_ci  /**
12761847f8eSopenharmony_ci   * Obtains the power consumption information list.
12861847f8eSopenharmony_ci   *
12961847f8eSopenharmony_ci   * @param { AsyncCallback<Array<BatteryStatsInfo>> } callback Indicates the callback of power consumption information list.
13061847f8eSopenharmony_ci   * AsyncCallback encapsulates an interface of BatteryStatsInfo type.
13161847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
13261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
13361847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
13461847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
13561847f8eSopenharmony_ci   * @systemapi
13661847f8eSopenharmony_ci   * @since 8
13761847f8eSopenharmony_ci   */
13861847f8eSopenharmony_ci  function getBatteryStats(callback: AsyncCallback<Array<BatteryStatsInfo>>): void;
13961847f8eSopenharmony_ci
14061847f8eSopenharmony_ci  /**
14161847f8eSopenharmony_ci   * Obtains power consumption information(mAh) for a given uid.
14261847f8eSopenharmony_ci   *
14361847f8eSopenharmony_ci   * @param { number } uid Indicates the uid.
14461847f8eSopenharmony_ci   * @returns { number } Power consumption information(mAh).
14561847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
14661847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
14761847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
14861847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
14961847f8eSopenharmony_ci   * @systemapi
15061847f8eSopenharmony_ci   * @since 8
15161847f8eSopenharmony_ci   */
15261847f8eSopenharmony_ci  function getAppPowerValue(uid: number): number;
15361847f8eSopenharmony_ci
15461847f8eSopenharmony_ci  /**
15561847f8eSopenharmony_ci   * Obtains power consumption information(Percent) for a given uid.
15661847f8eSopenharmony_ci   *
15761847f8eSopenharmony_ci   * @param { number } uid Indicates the uid.
15861847f8eSopenharmony_ci   * @returns { number } Power consumption information(Percent).
15961847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
16061847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
16161847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
16261847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
16361847f8eSopenharmony_ci   * @systemapi
16461847f8eSopenharmony_ci   * @since 8
16561847f8eSopenharmony_ci   */
16661847f8eSopenharmony_ci  function getAppPowerPercent(uid: number): number;
16761847f8eSopenharmony_ci
16861847f8eSopenharmony_ci  /**
16961847f8eSopenharmony_ci   * Obtains power consumption information(mAh) for a given type.
17061847f8eSopenharmony_ci   *
17161847f8eSopenharmony_ci   * @param { ConsumptionType } type Indicates the hardware type.
17261847f8eSopenharmony_ci   * the ConsumptionType type is an enumeration class.
17361847f8eSopenharmony_ci   * @returns { number } Power consumption information(mAh).
17461847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
17561847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
17661847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
17761847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
17861847f8eSopenharmony_ci   * @systemapi
17961847f8eSopenharmony_ci   * @since 8
18061847f8eSopenharmony_ci   */
18161847f8eSopenharmony_ci  function getHardwareUnitPowerValue(type: ConsumptionType): number;
18261847f8eSopenharmony_ci
18361847f8eSopenharmony_ci  /**
18461847f8eSopenharmony_ci   * Obtains power consumption information(Percent) for a given type.
18561847f8eSopenharmony_ci   *
18661847f8eSopenharmony_ci   * @param { ConsumptionType } type Indicates the hardware type.
18761847f8eSopenharmony_ci   * the ConsumptionType type is an enumeration class.
18861847f8eSopenharmony_ci   * @returns { number } Power consumption information(Percent).
18961847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
19061847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
19161847f8eSopenharmony_ci   * @throws { BusinessError } 4600101 - Failed to connect to the service.
19261847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
19361847f8eSopenharmony_ci   * @systemapi
19461847f8eSopenharmony_ci   * @since 8
19561847f8eSopenharmony_ci   */
19661847f8eSopenharmony_ci  function getHardwareUnitPowerPercent(type: ConsumptionType): number;
19761847f8eSopenharmony_ci
19861847f8eSopenharmony_ci  /**
19961847f8eSopenharmony_ci   * Contains power consumption information of a device.
20061847f8eSopenharmony_ci   * <p>Power consumption information includes the uid, type and power consumption value.
20161847f8eSopenharmony_ci   *
20261847f8eSopenharmony_ci   * @typedef BatteryStatsInfo
20361847f8eSopenharmony_ci   * @syscap SystemCapability.PowerManager.BatteryStatistics
20461847f8eSopenharmony_ci   * @systemapi
20561847f8eSopenharmony_ci   * @since 8
20661847f8eSopenharmony_ci   */
20761847f8eSopenharmony_ci  interface BatteryStatsInfo {
20861847f8eSopenharmony_ci    /** The uid related with the power consumption info.
20961847f8eSopenharmony_ci     *
21061847f8eSopenharmony_ci     * @type { number }
21161847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
21261847f8eSopenharmony_ci     * @systemapi
21361847f8eSopenharmony_ci     * @since 8
21461847f8eSopenharmony_ci    */
21561847f8eSopenharmony_ci    uid: number;
21661847f8eSopenharmony_ci
21761847f8eSopenharmony_ci    /** The type related with the power consumption info.
21861847f8eSopenharmony_ci     *
21961847f8eSopenharmony_ci     * @type { ConsumptionType }
22061847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
22161847f8eSopenharmony_ci     * @systemapi
22261847f8eSopenharmony_ci     * @since 8
22361847f8eSopenharmony_ci    */
22461847f8eSopenharmony_ci    type: ConsumptionType;
22561847f8eSopenharmony_ci
22661847f8eSopenharmony_ci    /** The power consumption value(mAh).
22761847f8eSopenharmony_ci     *
22861847f8eSopenharmony_ci     * @type { number }
22961847f8eSopenharmony_ci     * @syscap SystemCapability.PowerManager.BatteryStatistics
23061847f8eSopenharmony_ci     * @systemapi
23161847f8eSopenharmony_ci     * @since 8
23261847f8eSopenharmony_ci    */
23361847f8eSopenharmony_ci    power: number;
23461847f8eSopenharmony_ci  }
23561847f8eSopenharmony_ci}
23661847f8eSopenharmony_ci
23761847f8eSopenharmony_ci/**
23861847f8eSopenharmony_ci * Provides methods to get power consumption information.
23961847f8eSopenharmony_ci *
24061847f8eSopenharmony_ci * @namespace batteryStats
24161847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.BatteryStatistics
24261847f8eSopenharmony_ci * @systemapi
24361847f8eSopenharmony_ci * @since 8
24461847f8eSopenharmony_ci*/
24561847f8eSopenharmony_ciexport default batteryStats;
246