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 16import {AsyncCallback, BusinessError} from "./basic"; 17 18/** 19 * Provides methods to get power consumption information. 20 * 21 * @syscap SystemCapability.PowerManager.BatteryStatistics 22 * @systemapi 23 * @since 8 24 */ 25declare namespace batteryStats { 26 /** 27 * Describes the consumption type. 28 * 29 * @systemapi 30 * @since 8 31 */ 32 export enum ConsumptionType { 33 /** Indicates an invalid consumption type */ 34 CONSUMPTION_TYPE_INVALID = -17, 35 36 /** Indicates the battery power consumption generated by APP */ 37 CONSUMPTION_TYPE_APP, 38 39 /** Indicates the battery power consumption generated by bluetooth */ 40 CONSUMPTION_TYPE_BLUETOOTH, 41 42 /** Indicates the battery power consumption generated when the CPU is idle */ 43 CONSUMPTION_TYPE_IDLE, 44 45 /** Indicates the battery power consumption generated when phone call is active */ 46 CONSUMPTION_TYPE_PHONE, 47 48 /** Indicates the battery power consumption generated by radio */ 49 CONSUMPTION_TYPE_RADIO, 50 51 /** Indicates the battery power consumption generated by screen */ 52 CONSUMPTION_TYPE_SCREEN, 53 54 /** Indicates the battery power consumption generated by user */ 55 CONSUMPTION_TYPE_USER, 56 57 /** Indicates the battery power consumption generated by WIFI */ 58 CONSUMPTION_TYPE_WIFI 59 } 60 61 /** 62 * Obtains the power consumption information list. 63 * 64 * @return {Promise<Array<BatteryStatsInfo>>} Power consumption information list. 65 * @systemapi 66 * @since 8 67 */ 68 function getBatteryStats(): Promise<Array<BatteryStatsInfo>>; 69 70 /** 71 * Obtains the power consumption information list. 72 * 73 * @param {AsyncCallback} callback Indicates the callback of power consumption information list. 74 * @throws {BusinessError} 401 - If the callback is not valid. 75 * @systemapi 76 * @since 8 77 */ 78 function getBatteryStats(callback: AsyncCallback<Array<BatteryStatsInfo>>): void; 79 80 /** 81 * Obtains power consumption information(Mah) for a given uid. 82 * 83 * @param {number} uid Indicates the uid. 84 * @return {number} Power consumption information(Mah). 85 * @throws {BusinessError} 4600101 - If connecting to the service failed. 86 * @systemapi 87 * @since 8 88 */ 89 function getAppPowerValue(uid: number): number; 90 91 /** 92 * Obtains power consumption information(Percent) for a given uid. 93 * 94 * @param {number} uid Indicates the uid. 95 * @return {number} Power consumption information(Percent). 96 * @throws {BusinessError} 4600101 - If connecting to the service failed. 97 * @systemapi 98 * @since 8 99 */ 100 function getAppPowerPercent(uid: number): number; 101 102 /** 103 * Obtains power consumption information(Mah) for a given type. 104 * 105 * @param {ConsumptionType} type Indicates the hardware type. 106 * @return {number} Power consumption information(Mah). 107 * @throws {BusinessError} 401 - If the type is not valid. 108 * @throws {BusinessError} 4600101 - If connecting to the service failed. 109 * @systemapi 110 * @since 8 111 */ 112 function getHardwareUnitPowerValue(type: ConsumptionType): number; 113 114 /** 115 * Obtains power consumption information(Percent) for a given type. 116 * 117 * @param {ConsumptionType} type Indicates the hardware type. 118 * @return {number} Power consumption information(Percent). 119 * @throws {BusinessError} 401 - If the type is not valid. 120 * @throws {BusinessError} 4600101 - If connecting to the service failed. 121 * @systemapi 122 * @since 8 123 */ 124 function getHardwareUnitPowerPercent(type: ConsumptionType): number; 125 126 /** 127 * Contains power consumption information of a device. 128 * 129 * <p>Power consumption information includes the uid, type and power consumption value. 130 * 131 * @systemapi 132 * @since 8 133 */ 134 interface BatteryStatsInfo { 135 /** The uid related with the power consumption info. */ 136 uid: number; 137 138 /** The type related with the power consumption info. */ 139 type: ConsumptionType; 140 141 /** The power consumption value(mah). */ 142 power: number; 143 } 144} 145export default batteryStats;