diff --git a/en/application-dev/reference/apis/js-apis-power.md b/en/application-dev/reference/apis/js-apis-power.md index ad6e437f09767e362b2787f5ee78dd58d1a65165..8c0ef244a3d5b1d42ccbc48613fa542826a9df80 100644 --- a/en/application-dev/reference/apis/js-apis-power.md +++ b/en/application-dev/reference/apis/js-apis-power.md @@ -1,10 +1,10 @@ # 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. +> **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 @@ -12,10 +12,6 @@ The Power Manager module provides APIs for rebooting and shutting down the syste import power from '@ohos.power'; ``` -## System Capability - -SystemCapability.PowerManager.PowerManager.Core - ## power.shutdownDevice @@ -27,6 +23,8 @@ This is a system API and cannot be called by third-party applications. **Required permission**: ohos.permission.REBOOT +**System capability:** SystemCapability.PowerManager.PowerManager.Core + **Parameters** | Name | Type | Mandatory | Description | @@ -47,7 +45,9 @@ rebootDevice(reason: string): void 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** @@ -69,6 +69,8 @@ isScreenOn(callback: AsyncCallback<boolean>): void Checks the screen status of the current device. +**System capability:** SystemCapability.PowerManager.PowerManager.Core + **Parameters** | Name | Type | Mandatory | Description | @@ -94,6 +96,8 @@ isScreenOn(): Promise<boolean> Checks the screen status of the current device. +**System capability:** SystemCapability.PowerManager.PowerManager.Core + **Return value** | Type | Description | | ---------------------- | --------------------------------------- | @@ -110,3 +114,182 @@ power.isScreenOn() console.log('error: ' + error); }) ``` + +## power.wakeupDevice9+ + +wakeupDevice(detail: string): void + +Wakes up a device. + +This is a system API and cannot be called by third-party applications. + +**System capability:** SystemCapability.PowerManager.PowerManager.Core + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ---------- | +| detail | string | Yes | Reason for wakeup.| + +**Example** + +```js +power.wakeupDevice("application"); +console.info('power_wakeup_device_test success') +``` + +## power.suspendDevice9+ + +suspendDevice(): void + +Hibernates a device. + +This is a system API and cannot be called by third-party applications. + +**System capability:** SystemCapability.PowerManager.PowerManager.Core + +**Example** + +```js +power.suspendDevice(); +console.info('power_suspend_device_test success') +``` + +## power.getPowerMode9+ + +getPowerMode(callback: AsyncCallback<DevicePowerMode>): void + +Obtains the power mode of this device. + +**Required permission**: ohos.permission.POWER_OPTIMIZATION + +**System capability:** SystemCapability.PowerManager.PowerManager.Core + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<DevicePowerMode> | Yes | Callback used to obtain the return value.
Return value: [DevicePowerMode](#devicepowermode9)| + +**Example** + +```js +power.getPowerMode((error, mode) => { + if (typeof error === "undefined") { + console.info('power mode is ' + mode); + } else { + console.log('error: ' + error); + } +}) +``` + + +## power.getPowerMode9+ + +getPowerMode(): Promise<DevicePowerMode> + +Obtains the power mode of this device. + +**Required permission**: ohos.permission.POWER_OPTIMIZATION + +**System capability:** SystemCapability.PowerManager.PowerManager.Core + +**Return value** + +| Type | Description | +| ------------------------------ | ------------------------------------------------------------ | +| Promise<DevicePowerMode> | Promise used to obtain the return value.
Return value: [DevicePowerMode](#devicepowermode9)| + +**Example** + +```js +power.getPowerMode() +.then(mode => { + console.info('power mode is ' + mode); +}) +.catch(error => { + console.log('error: ' + error); +}) +``` + +## power.setPowerMode9+ + +setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void + +Sets the power mode of this device. + +This is a system API and cannot be called by third-party applications. + +**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<void> | Yes | Callback used to return the result.| + +**Example** + +```js +power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE, error => { + if (typeof error === "undefined") { + console.info('set power mode to MODE_PERFORMANCE'); + } else { + console.log('error: ' + error); + } +}) +``` + + +## power.setPowerMode9+ + +setPowerMode(mode: DevicePowerMode): Promise<void> + +Sets the power mode of this device. + +This is a system API and cannot be called by third-party applications. + +**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<void> | Promise used to return the result.| + +**Example** + +```js +power.setPowerMode(power.DevicePowerMode.MODE_PERFORMANCE) +.then(() => { + console.info('set power mode to MODE_PERFORMANCE'); +}) +.catch(error => { + console.log('error: ' + error); +}) +``` + +## DevicePowerMode9+ + +Enumerates power modes. + +**System capability:** SystemCapability.PowerManager.PowerManager.Core + + +| Name | Default 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. |