• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Power Manager
2
3> **NOTE**<br>
4> 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.
5
6The Power Manager module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
7
8
9## Modules to Import
10
11```js
12import power from '@ohos.power';
13```
14
15## System Capability
16
17SystemCapability.PowerManager.PowerManager.Core
18
19
20## power.shutdownDevice
21
22shutdownDevice(reason: string): void
23
24Shuts down the system.
25
26This is a system API and cannot be called by third-party applications.
27
28**Required permission**: ohos.permission.REBOOT
29
30**Parameters**
31
32| Name   | Type    | Mandatory  | Description   |
33| ------ | ------ | ---- | ----- |
34| reason | string | Yes   | Reason for system shutdown.|
35
36**Example**
37
38```js
39power.shutdownDevice("shutdown_test");
40console.info('power_shutdown_device_test success')
41```
42
43
44## power.rebootDevice
45
46rebootDevice(reason: string): void
47
48Reboots the system.
49
50**Required permission**: ohos.permission.REBOOT (to reboot) or ohos.permission.REBOOT_RECOVERY (to reboot and enter the recovery or updater mode)
51
52**Parameters**
53
54| Name   | Type    | Mandatory  | Description   |
55| ------ | ------ | ---- | ----- |
56| reason | string | Yes   | Reason for system reboot.|
57
58**Example**
59
60```js
61power.rebootDevice("reboot_test");
62console.info('power_reboot_device_test success')
63```
64
65
66## power.isScreenOn
67
68isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
69
70Checks the screen status of the current device.
71
72**Parameters**
73
74| Name     | Type                          | Mandatory  | Description                                      |
75| -------- | ---------------------------- | ---- | ---------------------------------------- |
76| 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.|
77
78**Example**
79
80```js
81power.isScreenOn((error, screenOn) => {
82    if (typeof error === "undefined") {
83        console.info('screenOn status is ' + screenOn);
84    } else {
85        console.log('error: ' + error);
86    }
87})
88```
89
90
91## power.isScreenOn
92
93isScreenOn(): Promise&lt;boolean&gt;
94
95Checks the screen status of the current device.
96
97**Return value**
98| Type                    | Description                                     |
99| ---------------------- | --------------------------------------- |
100| 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.|
101
102**Example**
103
104```js
105power.isScreenOn()
106.then(screenOn => {
107    console.info('screenOn status is ' + screenOn);
108})
109.catch(error => {
110    console.log('error: ' + error);
111})
112```
113