未验证 提交 6c595c38 编写于 作者: O openharmony_ci 提交者: Gitee

!12766 翻译已完成 10722

Merge pull request !12766 from shawn_he/10722-a
# Battery Info # Battery Info
>**NOTE**
>
>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The Battery Info module provides APIs for querying the charger type, battery health status, and battery charging status. The Battery Info module provides APIs for querying the charger type, battery health status, and battery charging status.
> **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,67 +12,100 @@ The Battery Info module provides APIs for querying the charger type, battery hea ...@@ -13,67 +12,100 @@ The Battery Info module provides APIs for querying the charger type, battery hea
import batteryInfo from '@ohos.batteryInfo'; import batteryInfo from '@ohos.batteryInfo';
``` ```
## System Capabilities
SystemCapability.PowerManager.BatteryManager
## Attributes ## Attributes
Describes battery information. Describes battery information.
| Name | Type | Readable | Writable | Description | **System capability**: SystemCapability.PowerManager.BatteryManager.Core
| ----------------------------- | ----------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
| batterySOC | number | Yes | No | Battery state of charge (SoC) of the current device, in unit of percentage. | | Name | Type | Readable| Writable| Description |
| chargingStatus | [BatteryChargeState](#batterychargestate) | Yes | No | Battery charging state of the current device. | | --------------- | ------------------- | ---- | ---- | ---------------------|
| healthStatus | [BatteryHealthState](#batteryhealthstate) | Yes | No | Battery health state of the current device. | | batterySOC | number | Yes | No | Battery state of charge (SoC) of the device, in unit of percentage. |
| pluggedType | [BatteryPluggedType](#batterypluggedtype) | Yes | No | Charger type of the current device. | | chargingStatus | [BatteryChargeState](#batterychargestate) | Yes | No | Battery charging state of the device. |
| voltage | number | Yes | No | Battery voltage of the current device, in unit of microvolt. | | healthStatus | [BatteryHealthState](#batteryhealthstate) | Yes | No | Battery health state of the device. |
| technology | string | Yes | No | Battery technology of the current device. | | pluggedType | [BatteryPluggedType](#batterypluggedtype) | Yes | No | Charger type of the device. |
| batteryTemperature | number | Yes | No | Battery temperature of the current device, in unit of 0.1°C. | | voltage | number | Yes | No | Battery voltage of the device, in unit of microvolt. |
| isBatteryPresent<sup>7+</sup> | boolean | Yes | No | Whether the battery is supported or present. | | technology | string | Yes | No | Battery technology of the device. |
| batteryTemperature | number | Yes | No | Battery temperature of the device, in unit of 0.1°C. |
**Example** | isBatteryPresent<sup>7+</sup> | boolean | Yes | No | Whether the battery is supported or present. |
| batteryCapacityLevel<sup>9+</sup> | [BatteryCapacityLevel](#batterycapacitylevel9) | Yes | No | Battery level of the device. |
```js | estimatedRemainingChargeTime<sup>9+</sup> | number | Yes | No | Estimated time for fully charging the current device, in unit of milliseconds. |
import batteryInfo from '@ohos.batteryInfo'; | totalEnergy<sup>9+</sup> | number | Yes | No | Total battery capacity of the device, in unit of mAh. This is a system API. |
var batterySoc = batteryInfo.batterySOC; | nowCurrent<sup>9+</sup> | number | Yes | No | Battery current of the device, in unit of mA. This is a system API. |
``` | remainingEnergy<sup>9+</sup> | number | Yes | No | Remaining battery capacity of the device, in unit of mAh. This is a system API.|
## BatteryPluggedType ## BatteryPluggedType
Enumerates charger types. Enumerates charger types.
| Name | Default Value | Description | **System capability**: SystemCapability.PowerManager.BatteryManager.Core
| -------- | ------------- | ----------------- |
| NONE | 0 | Unknown type. |
| AC | 1 | AC charger. |
| USB | 2 | USB charger. |
| WIRELESS | 3 | Wireless charger. |
| Name | Value | Description |
| -------- | ---- | ----------------- |
| NONE | 0 | Unknown type |
| AC | 1 | AC charger|
| USB | 2 | USB charger |
| WIRELESS | 3 | Wireless charger|
## BatteryChargeState ## BatteryChargeState
Enumerates charging states. Enumerates charging states.
| Name | Default Value | Description | **System capability**: SystemCapability.PowerManager.BatteryManager.Core
| ------- | ------------- | --------------------------------- |
| NONE | 0 | Unknown state. |
| ENABLE | 1 | The battery is being charged. |
| DISABLE | 2 | The battery is not being charged. |
| FULL | 3 | The battery is fully charged. |
| Name | Value | Description |
| ------- | ---- | --------------- |
| NONE | 0 | Unknown state. |
| ENABLE | 1 | The battery is being charged. |
| DISABLE | 2 | The battery is not being charged. |
| FULL | 3 | The battery is fully charged.|
## BatteryHealthState ## BatteryHealthState
Enumerates battery health states. Enumerates battery health states.
| Name | Default Value | Description | **System capability**: SystemCapability.PowerManager.BatteryManager.Core
| ----------- | ------------- | ------------------------------------ |
| UNKNOWN | 0 | Unknown state. | | Name | Value | Description |
| GOOD | 1 | The battery is in the healthy state. | | ----------- | ---- | -------------- |
| OVERHEAT | 2 | The battery is overheated. | | UNKNOWN | 0 | Unknown state. |
| OVERVOLTAGE | 3 | The battery voltage is over high. | | GOOD | 1 | The battery is in the healthy state. |
| COLD | 4 | The battery temperature is low. | | OVERHEAT | 2 | The battery is overheated. |
| DEAD | 5 | The battery is dead. | | OVERVOLTAGE | 3 | The battery voltage is over high. |
| COLD | 4 | The battery temperature is low. |
| DEAD | 5 | The battery is dead.|
## BatteryCapacityLevel<sup>9+</sup>
Enumerates battery levels.
**System capability**: SystemCapability.PowerManager.BatteryManager.Core
| Name | Value| Description |
| -------------- | ------ | ---------------------------- |
| LEVEL_NONE | 0 | Unknown battery level. |
| LEVEL_FULL | 1 | Full battery level. |
| LEVEL_HIGH | 2 | High battery level. |
| LEVEL_NORMAL | 3 | Normal battery level.|
| LEVEL_LOW | 4 | Low battery level. |
| LEVEL_CRITICAL | 5 | Ultra-low battery level.|
## CommonEventBatteryChangedCode<sup>9+</sup>
Enumerates keys for querying the additional information about the **COMMON_EVENT_BATTERY_CHANGED** event.
**System capability**: SystemCapability.PowerManager.BatteryManager.Core
| Name | Value| Description |
| -------------------- | ------ | -------------------------------------------------- |
| EXTRA_SOC | 0 | Remaining battery level in percentage. |
| EXTRA_VOLTAGE | 1 | Battery voltage of the device. |
| EXTRA_TEMPERATURE | 2 | Battery temperature of the device. |
| EXTRA_HEALTH_STATE | 3 | Battery health status of the device. |
| EXTRA_PLUGGED_TYPE | 4 | Type of the charger connected to the device. |
| EXTRA_MAX_CURRENT | 5 | Maximum battery current of the device. |
| EXTRA_MAX_VOLTAGE | 6 | Maximum battery voltage of the device. |
| EXTRA_CHARGE_STATE | 7 | Battery charging status of the device. |
| EXTRA_CHARGE_COUNTER | 8 | Number of battery charging times of the device. |
| EXTRA_PRESENT | 9 | Whether the battery is supported by the device or installed.|
| EXTRA_TECHNOLOGY | 10 | Battery technology of the device. |
# Battery Statistics
This module provides APIs for querying software and hardware power consumption statistics.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs.
## Modules to Import
```js
import batteryStats from '@ohos.batteryStatistics';
```
## batteryStats.getBatteryStats
getBatteryStats(): Promise<Array&lt;BatteryStatsInfo&gt;>
Obtains the power consumption information list, using a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Return value**
| Type | Description |
| ----------------------------------------------------- | ------------------------------- |
| Promise<Array<[BatteryStatsInfo](#batterystatsinfo)>> | Promise used to return the power consumption information list.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
batteryStats.getBatteryStats()
.then(data => {
console.info('battery statistics info: ' + data);
})
.catch(err => {
console.error('get battery statisitics failed, err: ' + err);
});
```
## batteryStats.getBatteryStats
getBatteryStats(callback: AsyncCallback<Array&lt;BatteryStatsInfo&gt;>): void
Obtains the power consumption information list. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback<Array<[BatteryStatsInfo](#batterystatsinfo)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of power consumption information obtained. If the operation failed, **err** is an error object.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
batteryStats.getBatteryStats((err, data) => {
if (typeof err === 'undefined') {
console.info('battery statistics info: ' + data);
} else {
console.error('get battery statisitics failed, err: ' + err);
}
});
```
## batteryStats.getAppPowerValue
getAppPowerValue(uid: number): number
Obtains the power consumption of an application.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------- |
| uid | number | Yes | Application UID.|
**Return value**
| Type | Description |
| ------ | --------------------------------- |
| number | Power consumption of the application with this UID, in unit of mAh.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var value = batteryStats.getAppPowerValue(10021);
console.info('battery statistics value of app is: ' + value);
} catch(err) {
console.error('get battery statisitics value of app failed, err: ' + err);
}
```
## batteryStats.getAppPowerPercent
getAppPowerPercent(uid: number): number
Obtains the proportion of the power consumption of an application.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------- |
| uid | number | Yes | Application UID.|
**Return value**
| Type | Description |
| ------ | ------------------------- |
| number | Proportion of the power consumption of an application with this UID.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var percent = batteryStats.getAppPowerPercent(10021);
console.info('battery statistics percent of app is: ' + percent);
} catch(err) {
console.error('get battery statisitics percent of app failed, err: ' + err);
}
```
## batteryStats.getHardwareUnitPowerValue
getHardwareUnitPowerValue(type: ConsumptionType): number
Obtains the power consumption of a hardware unit according to the consumption type.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------------- | ---- | -------------- |
| type | [ConsumptionType](#consumptiontype) | Yes | Power consumption type.|
**Return value**
| Type | Description |
| ------ | ------------------------------------------ |
| number | Power consumption of the hardware unit corresponding to the power consumption type, in unit of mAh.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var value = batteryStats.getHardwareUnitPowerValue(ConsumptionType.CONSUMPTION_TYPE_SCREEN);
console.info('battery statistics percent of hardware is: ' + percent);
} catch(err) {
console.error('get battery statisitics percent of hardware failed, err: ' + err);
}
```
## batteryStats.getHardwareUnitPowerPercent
getHardwareUnitPowerPercent(type: ConsumptionType): number
Obtains the proportion of the power consumption of a hardware unit according to the power consumption type.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------------- | ---- | -------------- |
| type | [ConsumptionType](#consumptiontype) | Yes | Power consumption type.|
**Return value**
| Type | Description |
| ------ | ---------------------------------- |
| number | Proportion of the power consumption of the hardware unit corresponding to the power consumption type.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
| Code| Error Message |
| -------- | -------------- |
| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var value = batteryStats.getHardwareUnitPowerPercent(ConsumptionType.CONSUMPTION_TYPE_SCREEN);
console.info('battery statistics percent of hardware is: ' + percent);
} catch(err) {
console.error('get battery statisitics percent of hardware failed, err: ' + err);
}
```
## BatteryStatsInfo
Describes the device power consumption information.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
### Attributes
| Name | Type | Readable| Writable| Description |
| ----- | ----------------------------------- | ---- | ---- | ---------------------- |
| uid | number | Yes | No | UID related to power consumption information. |
| type | [ConsumptionType](#consumptiontype) | Yes | No | Power consumption type. |
| power | number | Yes | No | Power consumption, in unit of mAh.|
## ConsumptionType
Enumerates power consumption types.
**System API**: This is a system API.
**System capability**: SystemCapability.PowerManager.BatteryStatistics
| Name | Value | Description |
| -------------------------- | ---- | ----------------------------- |
| CONSUMPTION_TYPE_INVALID | -17 | Unknown type. |
| CONSUMPTION_TYPE_APP | -16 | Power consumption of an application. |
| CONSUMPTION_TYPE_BLUETOOTH | -15 | Power consumption of Bluetooth. |
| CONSUMPTION_TYPE_IDLE | -14 | Power consumption when the CPU is idle.|
| CONSUMPTION_TYPE_PHONE | -13 | Power consumption of a phone call. |
| CONSUMPTION_TYPE_RADIO | -12 | Power consumption of wireless communication. |
| CONSUMPTION_TYPE_SCREEN | -11 | Power consumption of the screen. |
| CONSUMPTION_TYPE_USER | -10 | Power consumption of the user. |
| CONSUMPTION_TYPE_WIFI | -9 | Power consumption of Wi-Fi. |
# Brightness # Screen Brightness
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The Brightness module provides an API for setting the screen brightness. The Brightness module provides an API for setting the screen brightness.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> - The APIs provided by this module are system APIs.
## Modules to Import ## Modules to Import
...@@ -18,18 +20,30 @@ setValue(value: number): void ...@@ -18,18 +20,30 @@ setValue(value: number): void
Sets the screen brightness. Sets the screen brightness.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**System capability:** SystemCapability.PowerManager.DisplayPowerManager **System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ----- | ------ | ---- | ----------- | | ------ | ------ | ---- | ----------------------- |
| value | number | Yes | Brightness value, ranging from **0** to **255**.| | value | number | Yes | Brightness value. The value ranges from 0 to 255.|
**Error codes**
For details about the error codes, see [Screen Brightness Error Codes](../errorcodes/errorcode-brightness.md).
| Code | Error Message |
|---------|---------|
| 4700101 | Operation failed. Cannot connect to service.|
**Example** **Example**
```js ```js
brightness.setValue(128); try {
brightness.setValue(128);
} catch(err) {
console.error('set brightness failed, err: ' + err);
}
``` ```
# Power Manager # Power Manager
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The Power Manager module provides APIs for rebooting and shutting down the system, as well as querying the screen status. The Power Manager module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
> **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -12,42 +11,294 @@ The Power Manager module provides APIs for rebooting and shutting down the syste ...@@ -12,42 +11,294 @@ The Power Manager module provides APIs for rebooting and shutting down the syste
import power from '@ohos.power'; import power from '@ohos.power';
``` ```
## System Capability ## power.shutdown
SystemCapability.PowerManager.PowerManager.Core
## power.shutdownDevice shutdown(reason: string): void
shutdownDevice(reason: string): void
Shuts down the system. Shuts down the system.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Required permission**: ohos.permission.REBOOT **Required permission**: ohos.permission.REBOOT
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- | | ------ | ------ | ---- | ----- |
| reason | string | Yes | Reason for system shutdown.| | reason | string | Yes | Reason for system shutdown.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example** **Example**
```js ```js
power.shutdownDevice("shutdown_test"); try {
console.info('power_shutdown_device_test success') power.shutdown('shutdown_test');
} catch(err) {
console.error('shutdown failed, err: ' + err);
}
``` ```
## power.reboot<sup>9+</sup>
reboot(reason: string): void
Reboots the system.
**System API**: This is a system API.
**Required permission**: ohos.permission.REBOOT
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------- |
| reason | string | Yes | Reason for system reboot.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
power.reboot('reboot_test');
} catch(err) {
console.error('reboot failed, err: ' + err);
}
```
## power.isActive<sup>9+</sup>
isActive(): boolean
Checks whether the current device is active.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var isActive = power.isActive();
console.info('power is active: ' + isActive);
} catch(err) {
console.error('check active status failed, err: ' + err);
}
```
## power.wakeup<sup>9+</sup>
wakeup(detail: string): void
Wakes up a device.
**System API**: This is a system API.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------- |
| detail | string | Yes | Reason for wakeup.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
power.wakeup('wakeup_test');
} catch(err) {
console.error('wakeup failed, err: ' + err);
}
```
## power.suspend<sup>9+</sup>
suspend(): void
Hibernates a device.
**System API**: This is a system API.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
power.suspend();
} catch(err) {
console.error('suspend failed, err: ' + err);
}
```
## power.rebootDevice ## power.getPowerMode<sup>9+</sup>
getPowerMode(): DevicePowerMode
Obtains the power mode of this device.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Return value**
| Type | Description |
| ------------------------------------ | ---------- |
| [DevicePowerMode](#devicepowermode9) | Power mode.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var mode = power.getPowerMode();
console.info('power mode: ' + mode);
} catch(err) {
console.error('get power mode failed, err: ' + err);
}
```
## power.setPowerMode<sup>9+</sup>
setPowerMode(mode: DevicePowerMode, callback: AsyncCallback&lt;void&gt;): void
Sets the power mode of this device. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permission**: ohos.permission.POWER_OPTIMIZATION
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| mode | [DevicePowerMode](#devicepowermode9) | Yes | Power mode. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the power mode is successfully set, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, err => {
if (typeof err === 'undefined') {
console.info('set power mode to MODE_PERFORMANCE');
} else {
console.error('set power mode failed, err: ' + err);
}
});
```
## power.setPowerMode<sup>9+</sup>
setPowerMode(mode: DevicePowerMode): Promise&lt;void&gt;
Sets the power mode of this device. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permission**: ohos.permission.POWER_OPTIMIZATION
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------ | ---- | ---------- |
| mode | [DevicePowerMode](#devicepowermode9) | Yes | Power mode.|
**Return value**
| Type | Description |
| ------------------- | -------------------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
| Code | Error Message |
|---------|---------|
| 4900101 | Operation failed. Cannot connect to service.|
**Example**
```js
power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE)
.then(() => {
console.info('set power mode to MODE_PERFORMANCE');
})
.catch(err => {
console.error('set power mode failed, err: ' + err);
});
```
## power.rebootDevice<sup>(deprecated)</sup>
rebootDevice(reason: string): void rebootDevice(reason: string): void
> This API is deprecated since API version 9. You are advised to use [power.reboot](#powerreboot9) instead.
Reboots the system. Reboots the system.
**Required permission**: ohos.permission.REBOOT (to reboot) or ohos.permission.REBOOT_RECOVERY (to reboot and enter the recovery or updater mode) **Required permission**: ohos.permission.REBOOT
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters** **Parameters**
...@@ -58,55 +309,73 @@ Reboots the system. ...@@ -58,55 +309,73 @@ Reboots the system.
**Example** **Example**
```js ```js
power.rebootDevice("reboot_test"); power.rebootDevice('reboot_test');
console.info('power_reboot_device_test success')
``` ```
## power.isScreenOn<sup>(deprecated)</sup>
## power.isScreenOn
isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
Checks the screen status of the current device. > This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
Checks the screen status of the current device. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to obtain the return value.<br>Return value: The value **true** indicates that the screen is on, and the value **false** indicates the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the screen status obtained, where the value **true** indicates on and the value **false** indicates the opposite. Otherwise, **err** is an error object.|
**Example** **Example**
```js ```js
power.isScreenOn((error, screenOn) => { power.isScreenOn((err, data) => {
if (typeof error === "undefined") { if (typeof err === 'undefined') {
console.info('screenOn status is ' + screenOn); console.info('screen on status is ' + data);
} else { } else {
console.log('error: ' + error); console.error('check screen status failed, err: ' + err);
} }
}) })
``` ```
## power.isScreenOn<sup>(deprecated)</sup>
## power.isScreenOn
isScreenOn(): Promise&lt;boolean&gt; isScreenOn(): Promise&lt;boolean&gt;
Checks the screen status of the current device. > This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
Checks the screen status of the current device. This API uses a promise to return the result.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------- | --------------------------------------- | | ---------------------- | -------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to obtain the return value. <br/>Return value: The value **true** indicates that the screen is on, and the value **false** indicates the opposite.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the screen is on, and the value **false** indicates the opposite.|
**Example** **Example**
```js ```js
power.isScreenOn() power.isScreenOn()
.then(screenOn => { .then(data => {
console.info('screenOn status is ' + screenOn); console.info('screen on status is ' + data);
}) })
.catch(error => { .catch(err => {
console.log('error: ' + error); console.error('check screen status failed, err: ' + err);
}) })
``` ```
## DevicePowerMode<sup>9+</sup>
Enumerates power modes.
**System capability:** SystemCapability.PowerManager.PowerManager.Core
| Name | Value | Description |
| ----------------------- | ---- | ---------------------- |
| MODE_NORMAL | 600 | Standard mode. It is the default value.|
| MODE_POWER_SAVE | 601 | Power saving mode. |
| MODE_PERFORMANCE | 602 | Performance mode. |
| MODE_EXTREME_POWER_SAVE | 603 | Ultra power saving mode. |
# Battery Level # Battery Info
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** This module allows you to query the charging status and remaining power of a device.
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.batteryInfo`](js-apis-battery-info.md) instead.
> > **NOTE**
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.batteryInfo`](js-apis-battery-info.md) instead.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -16,40 +17,46 @@ import battery from '@system.battery'; ...@@ -16,40 +17,46 @@ import battery from '@system.battery';
## battery.getStatus ## battery.getStatus
getStatus(Object): void getStatus(options?: GetStatusOptions): void;
Obtains the current charging state and battery level. Obtains the current charging state and battery level.
**System capability**: SystemCapability.PowerManager.BatteryManager.Core **System capability**: SystemCapability.PowerManager.BatteryManager.Core
**Parameter** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;check&nbsp;result&nbsp;is&nbsp;obtained | | options | [GetStatusOptions](#getstatusoptions) | No| Object that contains the API calling result.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;check&nbsp;result&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following value will be returned when the check result is obtained.
| Name | Type | Description |
| -------- | -------- | -------- |
| charging | boolean | Whether&nbsp;the&nbsp;battery&nbsp;is&nbsp;being&nbsp;charged |
| level | number | Current&nbsp;battery&nbsp;level,&nbsp;which&nbsp;ranges&nbsp;from&nbsp;0.00&nbsp;to&nbsp;1.00. |
**Example** **Example**
```js ```js
export default { battery.getStatus({
getStatus() { success: function(data) {
battery.getStatus({ console.log('success get battery level:' + data.level);
success: function(data) { },
console.log('success get battery level:' + data.level); fail: function(data, code) {
}, console.error('fail to get battery level code:' + code + ', data: ' + data);
fail: function(data, code) { }
console.log('fail to get battery level code:' + code + ', data: ' + data); });
}, ```
});
}, ## GetStatusOptions
}
``` Object that contains the API calling result.
\ No newline at end of file
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| success | (data: [BatteryResponse](#batteryresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BatteryResponse](#batteryresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## BatteryResponse
Defines a response that returns the charging status and remaining power of the device.
| Name| Type| Description|
| -------- | -------- | -------- |
| charging | boolean | Whether the battery is being charged.|
| level | number | Current battery level, which ranges from **0.00** to **1.00**.|
# Screen Brightness # Screen Brightness
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** This module provides APIs for querying and adjusting the screen brightness and mode.
> **NOTE**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead. > - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.brightness`](js-apis-brightness.md) instead.
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -16,7 +17,7 @@ import brightness from '@system.brightness'; ...@@ -16,7 +17,7 @@ import brightness from '@system.brightness';
## brightness.getValue ## brightness.getValue
getValue(Object): void getValue(options?: GetBrightnessOptions): void
Obtains the current screen brightness. Obtains the current screen brightness.
...@@ -24,39 +25,27 @@ Obtains the current screen brightness. ...@@ -24,39 +25,27 @@ Obtains the current screen brightness.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. | | options | [GetBrightnessOptions](#getbrightnessoptions) | No | Options for obtaining the screen brightness.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| value | number | Screen&nbsp;brightness,&nbsp;which&nbsp;ranges&nbsp;from&nbsp;1&nbsp;to&nbsp;255. |
**Example** **Example**
```js ```js
export default { brightness.getValue({
getValue() { success: function(data) {
brightness.getValue({ console.log('success get brightness value:' + data.value);
success: function(data){
console.log('success get brightness value:' + data.value);
},
fail: function(data, code) {
console.log('get brightness fail, code: ' + code + ', data: ' + data);
}, },
}); fail: function(data, code) {
}, console.error('get brightness fail, code: ' + code + ', data: ' + data);
} }
``` });
```
## brightness.setValue ## brightness.setValue
setValue(Object): void etValue(options?: SetBrightnessOptions): void
Sets the screen brightness. Sets the screen brightness.
...@@ -64,35 +53,28 @@ Sets the screen brightness. ...@@ -64,35 +53,28 @@ Sets the screen brightness.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | number | Yes | Screen&nbsp;brightness.&nbsp;The&nbsp;value&nbsp;is&nbsp;an&nbsp;integer&nbsp;ranging&nbsp;from&nbsp;1&nbsp;to&nbsp;255.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;less&nbsp;than&nbsp;or&nbsp;equal&nbsp;to&nbsp;**0**,&nbsp;value&nbsp;**1**&nbsp;will&nbsp;be&nbsp;used.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;greater&nbsp;than&nbsp;**255**,&nbsp;value&nbsp;**255**&nbsp;will&nbsp;be&nbsp;used.<br/>-&nbsp;If&nbsp;the&nbsp;value&nbsp;contains&nbsp;decimals,&nbsp;the&nbsp;integral&nbsp;part&nbsp;of&nbsp;the&nbsp;value&nbsp;will&nbsp;be&nbsp;used.&nbsp;For&nbsp;example,&nbsp;if&nbsp;value&nbsp;**8.1**&nbsp;is&nbsp;set,&nbsp;value&nbsp;**8**&nbsp;will&nbsp;be&nbsp;used. | | options | [SetBrightnessOptions](#setbrightnessoptions) | No | Options for setting the screen brightness.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example** **Example**
```js ```js
export default { brightness.setValue({
setValue() { value: 100,
brightness.setValue({ success: function() {
value: 100, console.log('handling set brightness success.');
success: function(){ },
console.log('handling set brightness success.'); fail: function(data, code) {
}, console.error('handling set brightness value fail, code:' + code + ', data: ' + data);
fail: function(data, code){ }
console.log('handling set brightness value fail, code:' + code + ', data: ' + data); });
}, ```
});
},
}
```
## brightness.getMode ## brightness.getMode
getMode(Object): void getMode(options?: GetBrightnessModeOptions: void
Obtains the screen brightness adjustment mode. Obtains the screen brightness adjustment mode.
...@@ -100,75 +82,57 @@ Obtains the screen brightness adjustment mode. ...@@ -100,75 +82,57 @@ Obtains the screen brightness adjustment mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. | | options | [GetBrightnessModeOptions](#getbrightnessmodeoptions) | No| Options for obtaining the screen brightness mode.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete |
The following values will be returned when the operation is successful.
| Name | Type | Description |
| -------- | -------- | -------- |
| mode | number | The&nbsp;value&nbsp;can&nbsp;be&nbsp;**0**&nbsp;or&nbsp;**1**.<br/>-&nbsp;**0**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;manually&nbsp;adjusted.<br/>-&nbsp;**1**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;automatically&nbsp;adjusted. |
**Example** **Example**
```js ```js
export default { brightness.getMode({
getMode() { success: function(data) {
brightness.getMode({ console.log('success get mode:' + data.mode);
success: function(data){
console.log('success get mode:' + data.mode);
},
fail: function(data, code){
console.log('handling get mode fail, code:' + code + ', data: ' + data);
}, },
}); fail: function(data, code){
}, console.error('handling get mode fail, code:' + code + ', data: ' + data);
} }
``` });
```
## brightness.setMode ## brightness.setMode
setMode(Object): void setMode(options?: SetBrightnessModeOptions): void
Sets the screen brightness adjustment mode. Sets the screen brightness adjustment mode.
**System capability**: SystemCapability.PowerManager.DisplayPowerManager **System capability**: SystemCapability.PowerManager.DisplayPowerManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description|
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| mode | number | Yes | The&nbsp;value&nbsp;can&nbsp;be&nbsp;**0**&nbsp;or&nbsp;**1**.<br/>-&nbsp;**0**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;manually&nbsp;adjusted.<br/>-&nbsp;**1**:&nbsp;The&nbsp;screen&nbsp;brightness&nbsp;is&nbsp;automatically&nbsp;adjusted. | | options | [SetBrightnessModeOptions](#setbrightnessmodeoptions) | No | Options for setting the screen brightness mode.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example** **Example**
```js ```js
export default { brightness.setMode({
setMode() { mode: 1,
brightness.setMode({ success: function() {
mode: 1, console.log('handling set mode success.');
success: function(){ },
console.log('handling set mode success.'); fail: function(data, code) {
}, console.error('handling set mode fail, code:' + code + ', data: ' + data);
fail: function(data, code){ }
console.log('handling set mode fail, code:' + code + ', data: ' + data); });
}, ```
});
},
}
```
## brightness.setKeepScreenOn ## brightness.setKeepScreenOn
setKeepScreenOn(Object): void setKeepScreenOn(options?: SetKeepScreenOnOptions): void
>This API is no longer maintained since API version 7. It is recommended that you use [window.setKeepScreenOn](js-apis-window.md#setkeepscreenon) instead.
Sets whether to always keep the screen on. Call this API in **onShow()**. Sets whether to always keep the screen on. Call this API in **onShow()**.
...@@ -176,27 +140,88 @@ Sets whether to always keep the screen on. Call this API in **onShow()**. ...@@ -176,27 +140,88 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| keepScreenOn | boolean | Yes | Whether&nbsp;to&nbsp;always&nbsp;keep&nbsp;the&nbsp;screen&nbsp;on | | options | [SetKeepScreenOnOptions](#setkeepscreenonoptions) | No| Options for setting the screen to be steady on.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. |
**Example** **Example**
```js ```js
export default { brightness.setKeepScreenOn({
setKeepScreenOn() { keepScreenOn: true,
brightness.setKeepScreenOn({ success: function () {
keepScreenOn: true, console.log('handling set keep screen on success.');
success: function () { },
console.log('handling set keep screen on success.') fail: function (data, code) {
}, console.error('handling set keep screen on fail, code:' + code + ', data: ' + data);
fail: function (data, code) { }
console.log('handling set keep screen on fail, code:' + code + ', data: ' + data); });
}, ```
}); ## GetBrightnessOptions
},
} Defines the options for obtaining the screen brightness.
```
\ No newline at end of file | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## SetBrightnessOptions
Defines the options for setting the screen brightness.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**.<br>-&nbsp;If the value is less than or equal to **0**, value **1** will be used.<br>-&nbsp;If the value is greater than **255**, value **255** will be used.<br>-&nbsp;If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used.|
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## BrightnessResponse
Defines a response that returns the screen brightness.
| Parameter| Type | Description|
| -------- | -------- | -------- |
| value | number | Screen brightness. The value ranges from 1 to 255.|
## GetBrightnessModeOptions
Defines the options for obtaining the screen brightness mode.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when API call is complete. |
## SetBrightnessModeOptions
Defines the options for setting the screen brightness mode.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------ |
| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when API call is complete. |
## BrightnessModeResponse
Defines a response that returns the screen brightness mode.
| Name| Type | Description|
| -------- | -------- | -------- |
| mode | number | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
## SetKeepScreenOnOptions
Defines the options for setting the screen to be steady on.
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------ | ---- | ------------------------------------------------------ |
| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. |
| success | () => void | No | Called when API call is successful. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
| complete | () => void | No | Called when API call is complete. |
# Thermal Manager # Thermal Manager
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides thermal level-related callback and query APIs to obtain the information required for thermal control. This module provides thermal level-related callback and query APIs to obtain the information required for thermal control.
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -13,78 +11,168 @@ This module provides thermal level-related callback and query APIs to obtain the ...@@ -13,78 +11,168 @@ This module provides thermal level-related callback and query APIs to obtain the
import thermal from '@ohos.thermal'; import thermal from '@ohos.thermal';
``` ```
## thermal.registerThermalLevelCallback<sup>9+</sup>
## ThermalLevel registerThermalLevelCallback(callback: Callback&lt;ThermalLevel&gt;): void
Represents the thermal level. Subscribes to thermal level changes.
**System capability:** SystemCapability.PowerManager.ThermalManager **System capability:** SystemCapability.PowerManager.ThermalManager
| Name | Default Value | Description | **Parameters**
| ---------- | ---- | ---------------------------------------- |
| COOL | 0 | The device is cool, and services are not restricted.| | Name | Type | Mandatory| Description |
| NORMAL | 1 | The device is operational but is not cool. You need to pay attention to its heating.| | -------- | ---------------------------- | ---- | ------------------------------ |
| WARM | 2 | The device is warm. You need to stop or delay some imperceptible services.| | callback | Callback&lt;ThermalLevel&gt; | Yes | Callback used to return the result.|
| HOT | 3 | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of other services.|
| OVERHEATED | 4 | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major services.| **Error codes**
| WARNING | 5 | The device is overheated and is about to enter the emergency state. You need to stop all imperceptible services and downgrade major services to the maximum extent.|
| EMERGENCY | 6 | The device has entered the emergency state. You need to stop all services except those for the emergency help purposes.| For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
| Code | Error Message |
|---------|---------|
| 4800101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
thermal.registerThermalLevelCallback(level => {
console.info('thermal level is: ' + level);
});
console.info('register thermal level callback success.');
} catch(err) {
console.error('register thermal level callback failed, err: ' + err);
}
```
## thermal.unregisterThermalLevelCallback<sup>9+</sup>
unregisterThermalLevelCallback(callback?: Callback\<void>): void
Unsubscribes from thermal level changes.
**System capability:** SystemCapability.PowerManager.ThermalManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------------------------- |
| callback | Callback&lt;void&gt; | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
| Code | Error Message |
|---------|---------|
| 4800101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
thermal.unregisterThermalLevelCallback(() => {
console.info('unsubscribe thermal level success.');
});
console.info('unregister thermal level callback success.');
} catch(err) {
console.error('unregister thermal level callback failed, err: ' + err);
}
```
## thermal.getLevel<sup>9+</sup>
getLevel(): ThermalLevel
Obtains the current thermal level.
**System capability:** SystemCapability.PowerManager.ThermalManager
**Return value**
## thermal.subscribeThermalLevel | Type | Description |
| ------------ | ------------ |
| ThermalLevel | Thermal level obtained.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
| Code | Error Message |
|---------|---------|
| 4800101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var level = thermal.getLevel();
console.info('thermal level is: ' + level);
} catch(err) {
console.error('get thermal level failed, err: ' + err);
}
```
## thermal.subscribeThermalLevel<sup>(deprecated)</sup>
subscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void subscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void
> This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9) instead.
Subscribes to thermal level changes. Subscribes to thermal level changes.
**System capability:** SystemCapability.PowerManager.ThermalManager **System capability:** SystemCapability.PowerManager.ThermalManager
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;ThermalLevel&gt; | Yes | Callback used to obtain the return value.<br>The return value contains only one parameter, that is, thermal level. If an alarm is generated, you can use `// @ts-ignore` to suppress the alarm.| | callback | AsyncCallback&lt;ThermalLevel&gt; | Yes | Callback used to return the result. The return value contains only one parameter, that is, thermal level. If an alarm is generated, you can use `// @ts-ignore` to suppress the alarm.|
**Example** **Example**
```js ```js
var lev = 0; thermal.subscribeThermalLevel((level) => {
thermal.subscribeThermalLevel((lev) => { console.info('thermal level is: ' + level);
console.info("Thermal level is: " + lev); });
})
``` ```
## thermal.unsubscribeThermalLevel ## thermal.unsubscribeThermalLevel<sup>(deprecated)</sup>
unsubscribeThermalLevel(callback?: AsyncCallback\<void>): void unsubscribeThermalLevel(callback?: AsyncCallback\<void>): void
> This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9) instead.
Unsubscribes from thermal level changes. Unsubscribes from thermal level changes.
**System capability:** SystemCapability.PowerManager.ThermalManager **System capability:** SystemCapability.PowerManager.ThermalManager
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | --------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | No | Callback without a return value.| | callback | AsyncCallback&lt;void&gt; | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.|
**Example** **Example**
```js ```js
thermal.unsubscribeThermalLevel(() => { thermal.unsubscribeThermalLevel(() => {
console.info("Unsubscribe completed."); console.info('unsubscribe thermal level success.');
}); });
``` ```
## thermal.getThermalLevel ## thermal.getThermalLevel<sup>(deprecated)</sup>
getThermalLevel(): ThermalLevel getThermalLevel(): ThermalLevel
> This API is deprecated since API version 9. You are advised to use [thermal.getLevel](#thermalgetlevel9) instead.
Obtains the current thermal level. Obtains the current thermal level.
**System capability:** SystemCapability.PowerManager.ThermalManager **System capability:** SystemCapability.PowerManager.ThermalManager
**Return value**: **Return value**
| Type | Description | | Type | Description |
| ------------ | ------ | | ------------ | ------ |
...@@ -93,6 +181,22 @@ Obtains the current thermal level. ...@@ -93,6 +181,22 @@ Obtains the current thermal level.
**Example** **Example**
```js ```js
var lev = thermal.getThermalLevel(); var level = thermal.getThermalLevel();
console.info("Thermal level is: " + lev); console.info('thermal level is: ' + level);
``` ```
## ThermalLevel
Represents the thermal level.
**System capability:** SystemCapability.PowerManager.ThermalManager
| Name | Value | Description |
| ---------- | ---- | ------------------------------------------------------------ |
| COOL | 0 | The device is cool, and services are not restricted. |
| NORMAL | 1 | The device is operational but is not cool. You need to pay attention to its heating.|
| WARM | 2 | The device is warm. You need to stop or delay some imperceptible services.|
| HOT | 3 | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of other services.|
| OVERHEATED | 4 | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major services.|
| WARNING | 5 | The device is overheated and is about to enter the emergency state. You need to stop all imperceptible services and downgrade major services to the maximum extent.|
| EMERGENCY | 6 | The device has entered the emergency state. You need to stop all services except those for the emergency help purposes.|
# Power Consumption Statistics Error Codes
## 4600101 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported for a service connection failure.
**Possible Causes**
1. The system service stops running.
2. The internal communication of system services is abnormal.
**Solution**
Check whether the system services are running properly.
1. Run the following command on the console to view the current system service list:
```bash
> hdc shell hidumper -ls
```
2. Check whether **BatteryStatisticsService** is included in the system service list.
# Brightness Error Codes
## 4700101 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported for a service connection failure.
**Possible Causes**
1. The system service stops running.
2. The internal communication of system services is abnormal.
**Solution**
Check whether the system services are running properly.
1. Run the following command on the console to view the current system service list:
```bash
> hdc shell hidumper -ls
```
2. Check whether **DisplayPowerManagerService** is included in the system service list.
# Power Manager Error Codes
## 4900101 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported for a service connection failure.
**Possible Causes**
1. The system service stops running.
2. The internal communication of system services is abnormal.
**Solution**
Check whether the system services are running properly.
1. Run the following command on the console to view the current system service list:
```bash
> hdc shell hidumper -ls
```
2. Check whether **PowerManagerService** is included in the system service list.
## 4900102 System Shuting Down
**Error Message**
Operation failed. System is shutting down.
**Description**
This error code is reported when an operation failed during system shutting down.
**Possible Causes**
The system is shutting down.
**Solution**
Make sure that the operation is performed when the system is running properly.
# Running Lock Error Codes
## 4900101 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported for a service connection failure.
**Possible Causes**
1. The system service stops running.
2. The internal communication of system services is abnormal.
**Solution**
Check whether the system services are running properly.
1. Run the following command on the console to view the current system service list:
```bash
> hdc shell hidumper -ls
```
2. Check whether **PowerManagerService** is included in the system service list.
# Thermal Manager Error Codes
## 4800101 Service Connection Failure
**Error Message**
Operation failed. Cannot connect to service.
**Description**
This error code is reported for a service connection failure.
**Possible Causes**
1. The system service stops running.
2. The internal communication of system services is abnormal.
**Solution**
Check whether the system services are running properly.
1. Run the following command on the console to view the current system service list:
```bash
> hdc shell hidumper -ls
```
2. Check whether **ThermalService** is included in the system service list.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册