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