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