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 * @file 18 * @kit BasicServicesKit 19 */ 20 21import { AsyncCallback, BusinessError } from './@ohos.base'; 22 23/** 24 * Provides methods to get power consumption information. 25 * 26 * @namespace batteryStats 27 * @syscap SystemCapability.PowerManager.BatteryStatistics 28 * @systemapi 29 * @since 8 30 */ 31declare namespace batteryStats { 32 /** 33 * Describes the consumption type. 34 * 35 * @enum { number } 36 * @syscap SystemCapability.PowerManager.BatteryStatistics 37 * @systemapi 38 * @since 8 39 */ 40 export enum ConsumptionType { 41 /** Indicates an invalid consumption type 42 * 43 * @syscap SystemCapability.PowerManager.BatteryStatistics 44 * @systemapi 45 * @since 8 46 */ 47 CONSUMPTION_TYPE_INVALID = -17, 48 49 /** Indicates the battery power consumption generated by APP 50 * 51 * @syscap SystemCapability.PowerManager.BatteryStatistics 52 * @systemapi 53 * @since 8 54 */ 55 CONSUMPTION_TYPE_APP, 56 57 /** Indicates the battery power consumption generated by bluetooth 58 * 59 * @syscap SystemCapability.PowerManager.BatteryStatistics 60 * @systemapi 61 * @since 8 62 */ 63 CONSUMPTION_TYPE_BLUETOOTH, 64 65 /** Indicates the battery power consumption generated when the CPU is idle 66 * 67 * @syscap SystemCapability.PowerManager.BatteryStatistics 68 * @systemapi 69 * @since 8 70 */ 71 CONSUMPTION_TYPE_IDLE, 72 73 /** Indicates the battery power consumption generated when phone call is active 74 * 75 * @syscap SystemCapability.PowerManager.BatteryStatistics 76 * @systemapi 77 * @since 8 78 */ 79 CONSUMPTION_TYPE_PHONE, 80 81 /** Indicates the battery power consumption generated by radio 82 * 83 * @syscap SystemCapability.PowerManager.BatteryStatistics 84 * @systemapi 85 * @since 8 86 */ 87 CONSUMPTION_TYPE_RADIO, 88 89 /** Indicates the battery power consumption generated by screen 90 * 91 * @syscap SystemCapability.PowerManager.BatteryStatistics 92 * @systemapi 93 * @since 8 94 */ 95 CONSUMPTION_TYPE_SCREEN, 96 97 /** Indicates the battery power consumption generated by user 98 * 99 * @syscap SystemCapability.PowerManager.BatteryStatistics 100 * @systemapi 101 * @since 8 102 */ 103 CONSUMPTION_TYPE_USER, 104 105 /** Indicates the battery power consumption generated by WIFI 106 * 107 * @syscap SystemCapability.PowerManager.BatteryStatistics 108 * @systemapi 109 * @since 8 110 */ 111 CONSUMPTION_TYPE_WIFI 112 } 113 114 /** 115 * Obtains the power consumption information list. 116 * 117 * @returns { Promise<Array<BatteryStatsInfo>> } Power consumption information list. 118 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 119 * @throws { BusinessError } 4600101 - Failed to connect to the service. 120 * @syscap SystemCapability.PowerManager.BatteryStatistics 121 * @systemapi 122 * @since 8 123 */ 124 function getBatteryStats(): Promise<Array<BatteryStatsInfo>>; 125 126 /** 127 * Obtains the power consumption information list. 128 * 129 * @param { AsyncCallback<Array<BatteryStatsInfo>> } callback Indicates the callback of power consumption information list. 130 * AsyncCallback encapsulates an interface of BatteryStatsInfo type. 131 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 132 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 133 * @throws { BusinessError } 4600101 - Failed to connect to the service. 134 * @syscap SystemCapability.PowerManager.BatteryStatistics 135 * @systemapi 136 * @since 8 137 */ 138 function getBatteryStats(callback: AsyncCallback<Array<BatteryStatsInfo>>): void; 139 140 /** 141 * Obtains power consumption information(mAh) for a given uid. 142 * 143 * @param { number } uid Indicates the uid. 144 * @returns { number } Power consumption information(mAh). 145 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 146 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 147 * @throws { BusinessError } 4600101 - Failed to connect to the service. 148 * @syscap SystemCapability.PowerManager.BatteryStatistics 149 * @systemapi 150 * @since 8 151 */ 152 function getAppPowerValue(uid: number): number; 153 154 /** 155 * Obtains power consumption information(Percent) for a given uid. 156 * 157 * @param { number } uid Indicates the uid. 158 * @returns { number } Power consumption information(Percent). 159 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 160 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 161 * @throws { BusinessError } 4600101 - Failed to connect to the service. 162 * @syscap SystemCapability.PowerManager.BatteryStatistics 163 * @systemapi 164 * @since 8 165 */ 166 function getAppPowerPercent(uid: number): number; 167 168 /** 169 * Obtains power consumption information(mAh) for a given type. 170 * 171 * @param { ConsumptionType } type Indicates the hardware type. 172 * the ConsumptionType type is an enumeration class. 173 * @returns { number } Power consumption information(mAh). 174 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 175 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 176 * @throws { BusinessError } 4600101 - Failed to connect to the service. 177 * @syscap SystemCapability.PowerManager.BatteryStatistics 178 * @systemapi 179 * @since 8 180 */ 181 function getHardwareUnitPowerValue(type: ConsumptionType): number; 182 183 /** 184 * Obtains power consumption information(Percent) for a given type. 185 * 186 * @param { ConsumptionType } type Indicates the hardware type. 187 * the ConsumptionType type is an enumeration class. 188 * @returns { number } Power consumption information(Percent). 189 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 190 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 191 * @throws { BusinessError } 4600101 - Failed to connect to the service. 192 * @syscap SystemCapability.PowerManager.BatteryStatistics 193 * @systemapi 194 * @since 8 195 */ 196 function getHardwareUnitPowerPercent(type: ConsumptionType): number; 197 198 /** 199 * Contains power consumption information of a device. 200 * <p>Power consumption information includes the uid, type and power consumption value. 201 * 202 * @typedef BatteryStatsInfo 203 * @syscap SystemCapability.PowerManager.BatteryStatistics 204 * @systemapi 205 * @since 8 206 */ 207 interface BatteryStatsInfo { 208 /** The uid related with the power consumption info. 209 * 210 * @type { number } 211 * @syscap SystemCapability.PowerManager.BatteryStatistics 212 * @systemapi 213 * @since 8 214 */ 215 uid: number; 216 217 /** The type related with the power consumption info. 218 * 219 * @type { ConsumptionType } 220 * @syscap SystemCapability.PowerManager.BatteryStatistics 221 * @systemapi 222 * @since 8 223 */ 224 type: ConsumptionType; 225 226 /** The power consumption value(mAh). 227 * 228 * @type { number } 229 * @syscap SystemCapability.PowerManager.BatteryStatistics 230 * @systemapi 231 * @since 8 232 */ 233 power: number; 234 } 235} 236 237/** 238 * Provides methods to get power consumption information. 239 * 240 * @namespace batteryStats 241 * @syscap SystemCapability.PowerManager.BatteryStatistics 242 * @systemapi 243 * @since 8 244*/ 245export default batteryStats; 246