1/* 2 * Copyright (c) 2025 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.2 20 */ 21 22/** 23 * Obtains battery information of a device. 24 * <p>Battery information includes the remaining battery power, 25 * voltage, temperature, model, and charger type. 26 * 27 * @namespace batteryInfo 28 * @syscap SystemCapability.PowerManager.BatteryManager.Core 29 * @since 20 30 */ 31declare namespace batteryInfo { 32 /** 33 * Sets the battery config by scene name. 34 * 35 * @param { string } sceneName - Indicates the battery charging scene name. 36 * sceneName parameter must be of type string. 37 * @param { string } sceneValue - Indicates the battery charging scene value. 38 * sceneValue parameter must be of type string. 39 * @returns { int } Return to set the charging configuration result. 40 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 41 * @throws { BusinessError } 5100101 - Failed to connect to the service. 42 * @syscap SystemCapability.PowerManager.BatteryManager.Core 43 * @systemapi 44 * @since 20 45 */ 46 function setBatteryConfig(sceneName: string, sceneValue: string): int; 47 48 /** 49 * Queries the battery config by scene name. 50 * 51 * @param { string } sceneName - Indicates the battery charging scene name. 52 * sceneName parameter must be of type string. 53 * @returns { string } Returns the battery charging configuration, returns "" otherwise. 54 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 55 * @throws { BusinessError } 5100101 - Failed to connect to the service. 56 * @syscap SystemCapability.PowerManager.BatteryManager.Core 57 * @systemapi 58 * @since 20 59 */ 60 function getBatteryConfig(sceneName: string): string; 61 62 /** 63 * Checks the battery config is enable by scene name. 64 * 65 * @param { string } sceneName - Indicates the battery charging scene name. 66 * sceneName parameter must be of type string. 67 * @returns { boolean } Returns true if the device supports the charging scene, returns false otherwise. 68 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 69 * @throws { BusinessError } 5100101 - Failed to connect to the service. 70 * @syscap SystemCapability.PowerManager.BatteryManager.Core 71 * @systemapi 72 * @since 20 73 */ 74 function isBatteryConfigSupported(sceneName: string): boolean; 75 76 /** 77 * Battery state of charge (SoC) of the current device, in percent. 78 * 79 * @returns { int } Returns the battery state of charge (SoC) of the current device, in percent. 80 * @syscap SystemCapability.PowerManager.BatteryManager.Core 81 * @since 20 82 */ 83 function batterySOC(): int; 84 85 /** 86 * Battery charging status of the current device. 87 * 88 * @returns { BatteryChargeState } Returns the battery charging status of the current device. 89 * @syscap SystemCapability.PowerManager.BatteryManager.Core 90 * @since 20 91 */ 92 function chargingStatus(): BatteryChargeState; 93 94 /** 95 * Battery health state of the current device. 96 * 97 * @returns { BatteryHealthState } Returns the battery health state of the current device. 98 * @syscap SystemCapability.PowerManager.BatteryManager.Core 99 * @since 20 100 */ 101 function healthStatus(): BatteryHealthState; 102 103 /** 104 * Charger type of the current device. 105 * 106 * @returns { BatteryPluggedType } Returns the charger type of the current device. 107 * @syscap SystemCapability.PowerManager.BatteryManager.Core 108 * @since 20 109 */ 110 function pluggedType(): BatteryPluggedType; 111 112 /** 113 * Battery voltage of the current device, in µV. 114 * 115 * @returns { int } Returns the battery voltage of the current device, in µV. 116 * @syscap SystemCapability.PowerManager.BatteryManager.Core 117 * @since 20 118 */ 119 function voltage(): int; 120 121 /** 122 * Battery technology of the current device. 123 * 124 * @returns { string } Returns the battery technology of the current device. 125 * @syscap SystemCapability.PowerManager.BatteryManager.Core 126 * @since 20 127 */ 128 function technology(): string; 129 130 /** 131 * Battery temperature of the current device, in 0.1℃. 132 * 133 * @returns { int } Returns the battery temperature of the current device, in 0.1℃. 134 * @syscap SystemCapability.PowerManager.BatteryManager.Core 135 * @since 20 136 */ 137 function batteryTemperature(): int; 138 139 /** 140 * Battery present state of the current device. 141 * 142 * @returns { boolean } Returns true if the battery is present; returns false if the battery is absent. 143 * @syscap SystemCapability.PowerManager.BatteryManager.Core 144 * @since 20 145 */ 146 function isBatteryPresent(): boolean; 147 148 /** 149 * Battery capacity level of the current device. 150 * 151 * @returns { BatteryCapacityLevel } Returns the battery capacity level of the current device. 152 * @syscap SystemCapability.PowerManager.BatteryManager.Core 153 * @since 20 154 */ 155 function batteryCapacityLevel(): BatteryCapacityLevel; 156 157 /** 158 * Estimated remaining time for the current device to be fully charged, in ms. 159 * 160 * @returns { long } Returns the estimated remaining time for the current device to be fully charged, in ms. 161 * @syscap SystemCapability.PowerManager.BatteryManager.Core 162 * @systemapi 163 * @since 20 164 */ 165 function estimatedRemainingChargeTime(): long; 166 167 /** 168 * Battery total energy of the current device, in mAh. 169 * 170 * @returns { int } Returns the battery total energy of the current device, in mAh. 171 * @syscap SystemCapability.PowerManager.BatteryManager.Core 172 * @systemapi 173 * @since 20 174 */ 175 function totalEnergy(): int; 176 177 /** 178 * Battery immediate current of the current device, in mA. 179 * 180 * @returns { int } Returns the battery immediate current of the current device, in mA. 181 * @syscap SystemCapability.PowerManager.BatteryManager.Core 182 * @since 20 183 */ 184 function nowCurrent(): int; 185 186 /** 187 * Battery remaining energy of the current device, in mAh. 188 * 189 * @returns { int } Returns the battery remaining energy of the current device, in mAh. 190 * @syscap SystemCapability.PowerManager.BatteryManager.Core 191 * @systemapi 192 * @since 20 193 */ 194 function remainingEnergy(): int; 195 196 /** 197 * Charger type of a device. 198 * 199 * @enum { int } 200 * @syscap SystemCapability.PowerManager.BatteryManager.Core 201 * @since 20 202 */ 203 export enum BatteryPluggedType { 204 /** 205 * Unknown type 206 * 207 * @syscap SystemCapability.PowerManager.BatteryManager.Core 208 * @since 20 209 */ 210 NONE, 211 /** 212 * AC charger 213 * 214 * @syscap SystemCapability.PowerManager.BatteryManager.Core 215 * @since 20 216 */ 217 AC, 218 /** 219 * USB charger 220 * 221 * @syscap SystemCapability.PowerManager.BatteryManager.Core 222 * @since 20 223 */ 224 USB, 225 /** 226 * Wireless charger 227 * 228 * @syscap SystemCapability.PowerManager.BatteryManager.Core 229 * @since 20 230 */ 231 WIRELESS 232 } 233 234 /** 235 * Battery charging status of a device. 236 * 237 * @enum { int } 238 * @syscap SystemCapability.PowerManager.BatteryManager.Core 239 * @since 20 240 */ 241 export enum BatteryChargeState { 242 /** 243 * Unknown state. 244 * 245 * @syscap SystemCapability.PowerManager.BatteryManager.Core 246 * @since 20 247 */ 248 NONE, 249 /** 250 * The battery is being charged. 251 * 252 * @syscap SystemCapability.PowerManager.BatteryManager.Core 253 * @since 20 254 */ 255 ENABLE, 256 /** 257 * The battery is not being charged. 258 * 259 * @syscap SystemCapability.PowerManager.BatteryManager.Core 260 * @since 20 261 */ 262 DISABLE, 263 /** 264 * The battery is fully charged. 265 * 266 * @syscap SystemCapability.PowerManager.BatteryManager.Core 267 * @since 20 268 */ 269 FULL 270 } 271 272 /** 273 * Battery health status of a device. 274 * 275 * @enum { int } 276 * @syscap SystemCapability.PowerManager.BatteryManager.Core 277 * @since 20 278 */ 279 export enum BatteryHealthState { 280 /** 281 * Unknown state. 282 * 283 * @syscap SystemCapability.PowerManager.BatteryManager.Core 284 * @since 20 285 */ 286 UNKNOWN, 287 /** 288 * The battery is in healthy state. 289 * 290 * @syscap SystemCapability.PowerManager.BatteryManager.Core 291 * @since 20 292 */ 293 GOOD, 294 /** 295 * The battery is overheated. 296 * 297 * @syscap SystemCapability.PowerManager.BatteryManager.Core 298 * @since 20 299 */ 300 OVERHEAT, 301 /** 302 * The battery voltage is over high. 303 * 304 * @syscap SystemCapability.PowerManager.BatteryManager.Core 305 * @since 20 306 */ 307 OVERVOLTAGE, 308 /** 309 * The battery temperature is low. 310 * 311 * @syscap SystemCapability.PowerManager.BatteryManager.Core 312 * @since 20 313 */ 314 COLD, 315 /** 316 * The battery is dead. 317 * 318 * @syscap SystemCapability.PowerManager.BatteryManager.Core 319 * @since 20 320 */ 321 DEAD 322 } 323 324 /** 325 * Battery capacity level of a device. 326 * 327 * @enum { int } 328 * @syscap SystemCapability.PowerManager.BatteryManager.Core 329 * @since 20 330 */ 331 export enum BatteryCapacityLevel { 332 /** 333 * The battery is in full capacity level. 334 * 335 * @syscap SystemCapability.PowerManager.BatteryManager.Core 336 * @since 20 337 */ 338 LEVEL_FULL, 339 /** 340 * The battery is in high capacity level. 341 * 342 * @syscap SystemCapability.PowerManager.BatteryManager.Core 343 * @since 20 344 */ 345 LEVEL_HIGH, 346 /** 347 * The battery is in normal capacity level. 348 * 349 * @syscap SystemCapability.PowerManager.BatteryManager.Core 350 * @since 20 351 */ 352 LEVEL_NORMAL, 353 /** 354 * The battery is in low capacity level. 355 * 356 * @syscap SystemCapability.PowerManager.BatteryManager.Core 357 * @since 20 358 */ 359 LEVEL_LOW, 360 /** 361 * The battery is in warning low capacity level. 362 * 363 * @syscap SystemCapability.PowerManager.BatteryManager.Core 364 * @since 20 365 */ 366 LEVEL_WARNING, 367 /** 368 * The battery is in critical low capacity level. 369 * 370 * @syscap SystemCapability.PowerManager.BatteryManager.Core 371 * @since 20 372 */ 373 LEVEL_CRITICAL, 374 /** 375 * The battery is in the lowest capacity level, system will shut down automatically in a few seconds. 376 * 377 * @syscap SystemCapability.PowerManager.BatteryManager.Core 378 * @since 20 379 */ 380 LEVEL_SHUTDOWN 381 } 382 383 /** 384 * Extra key of common event COMMON_EVENT_BATTERY_CHANGED. 385 * 386 * @enum { string } 387 * @syscap SystemCapability.PowerManager.BatteryManager.Core 388 * @since 20 389 */ 390 export enum CommonEventBatteryChangedKey { 391 /** 392 * Extra code of batterySOC. 393 * 394 * @syscap SystemCapability.PowerManager.BatteryManager.Core 395 * @since 20 396 */ 397 EXTRA_SOC = 'soc', 398 /** 399 * Extra code of chargingStatus. 400 * 401 * @syscap SystemCapability.PowerManager.BatteryManager.Core 402 * @since 20 403 */ 404 EXTRA_CHARGE_STATE = 'chargeState', 405 /** 406 * Extra code of healthStatus. 407 * 408 * @syscap SystemCapability.PowerManager.BatteryManager.Core 409 * @since 20 410 */ 411 EXTRA_HEALTH_STATE = 'healthState', 412 /** 413 * Extra code of pluggedType. 414 * 415 * @syscap SystemCapability.PowerManager.BatteryManager.Core 416 * @since 20 417 */ 418 EXTRA_PLUGGED_TYPE = 'pluggedType', 419 /** 420 * Extra code of voltage. 421 * 422 * @syscap SystemCapability.PowerManager.BatteryManager.Core 423 * @since 20 424 */ 425 EXTRA_VOLTAGE = 'voltage', 426 /** 427 * Extra code of technology. 428 * 429 * @syscap SystemCapability.PowerManager.BatteryManager.Core 430 * @since 20 431 */ 432 EXTRA_TECHNOLOGY = 'technology', 433 /** 434 * Extra code of batteryTemperature. 435 * 436 * @syscap SystemCapability.PowerManager.BatteryManager.Core 437 * @since 20 438 */ 439 EXTRA_TEMPERATURE = 'temperature', 440 /** 441 * Extra code of isBatteryPresent. 442 * 443 * @syscap SystemCapability.PowerManager.BatteryManager.Core 444 * @since 20 445 */ 446 EXTRA_PRESENT = 'present', 447 /** 448 * Extra code of batteryCapacityLevel. 449 * 450 * @syscap SystemCapability.PowerManager.BatteryManager.Core 451 * @since 20 452 */ 453 EXTRA_CAPACITY_LEVEL = 'capacityLevel' 454 } 455} 456export default batteryInfo; 457