1# @ohos.power (Power Management)
2
3The **power** module provides APIs for rebooting and shutting down the system, as well as querying the screen status.
4
5> **NOTE**
6>
7> 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.
8
9## Modules to Import
10
11```js
12import {power} from '@kit.BasicServicesKit';
13```
14
15## power.isActive<sup>9+</sup>
16
17isActive(): boolean
18
19Checks whether the current device is active. In the active state, the screen is on if the device has a screen and the device is not in sleep state if the device does not have a screen.
20
21**System capability:** SystemCapability.PowerManager.PowerManager.Core
22
23**Error codes**
24
25For details about the error codes, see [Power Manager Error Codes](errorcode-power.md).
26
27| ID  | Error Message   |
28|---------|---------|
29| 4900101 | Failed to connect to the service. |
30
31**Example**
32
33```js
34try {
35    let isActive = power.isActive();
36    console.info('power is active: ' + isActive);
37} catch(err) {
38    console.error('check active status failed, err: ' + err);
39}
40```
41
42## power.rebootDevice<sup>(deprecated)</sup>
43
44rebootDevice(reason: string): void
45
46> **NOTE**<br>This API is supported since API version 7 and is deprecated since API version 9. The substitute API is available only for system applications.
47
48Reboots a device.
49
50**Required permissions**: ohos.permission.REBOOT (available only for system applications)
51
52**System capability:** SystemCapability.PowerManager.PowerManager.Core
53
54
55**Parameters**
56
57| Name   | Type    | Mandatory  | Description   |
58| ------ | ------ | ---- | ----- |
59| reason | string | Yes   | Reason for system reboot.|
60
61**Example**
62
63```js
64power.rebootDevice('reboot_test');
65```
66
67## power.getPowerMode<sup>9+</sup>
68
69getPowerMode(): DevicePowerMode
70
71Obtains the power mode of this device.
72
73**System capability:** SystemCapability.PowerManager.PowerManager.Core
74
75**Return value**
76
77| Type                                | Description      |
78| ------------------------------------ | ---------- |
79| [DevicePowerMode](#devicepowermode9) | Power mode.|
80
81**Error codes**
82
83For details about the error codes, see [Power Manager Error Codes](errorcode-power.md).
84
85| ID  | Error Message   |
86|---------|---------|
87| 4900101 | Failed to connect to the service. |
88
89**Example**
90
91```js
92try {
93    let mode = power.getPowerMode();
94    console.info('power mode: ' + mode);
95} catch(err) {
96    console.error('get power mode failed, err: ' + err);
97}
98```
99
100## power.isStandby<sup>10+</sup>
101
102isStandby(): boolean
103
104Checks whether the device is in standby mode.
105
106**System capability:** SystemCapability.PowerManager.PowerManager.Core
107
108**Return value**
109
110| Type               | Description                                  |
111| ------------------- | -------------------------------------- |
112| boolean | The value **true** indicates that the device is in standby mode, and the value **false** indicates the opposite.|
113
114**Error codes**
115
116For details about the error codes, see [Power Manager Error Codes](errorcode-power.md).
117
118| ID  | Error Message   |
119|---------|---------|
120| 4900101 | Failed to connect to the service. |
121
122**Example**
123
124```js
125try {
126    let isStandby = power.isStandby();
127    console.info('device is in standby: ' + isStandby);
128} catch(err) {
129    console.error('check isStandby failed, err: ' + err);
130}
131```
132
133## power.isScreenOn<sup>(deprecated)</sup>
134
135isScreenOn(callback: AsyncCallback&lt;boolean&gt;): void
136
137> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
138
139Checks the screen status of the current device. This API uses an asynchronous callback to return the result.
140
141**System capability:** SystemCapability.PowerManager.PowerManager.Core
142
143**Parameters**
144
145| Name  | Type                        | Mandatory| Description                                                        |
146| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
147| 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 off. Otherwise, **err** is an error object.|
148
149**Example**
150
151```js
152power.isScreenOn((err: Error, data: boolean) => {
153    if (typeof err === 'undefined') {
154        console.info('screen on status is ' + data);
155    } else {
156        console.error('check screen status failed, err: ' + err);
157    }
158})
159```
160
161## power.isScreenOn<sup>(deprecated)</sup>
162
163isScreenOn(): Promise&lt;boolean&gt;
164
165> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [power.isActive](#powerisactive9) instead.
166
167Checks the screen status of the current device. This API uses a promise to return the result.
168
169**System capability:** SystemCapability.PowerManager.PowerManager.Core
170
171**Return value**
172| Type                  | Description                                              |
173| ---------------------- | -------------------------------------------------- |
174| 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.|
175
176**Example**
177
178```js
179power.isScreenOn()
180.then((data: boolean) => {
181    console.info('screen on status is ' + data);
182})
183.catch((err: Error) => {
184    console.error('check screen status failed, err: ' + err);
185})
186```
187
188## DevicePowerMode<sup>9+</sup>
189
190Enumerates power modes.
191
192**System capability:** SystemCapability.PowerManager.PowerManager.Core
193
194| Name                   | Value  | Description                  |
195| ----------------------- | ---- | ---------------------- |
196| MODE_NORMAL             | 600  | Standard mode. It is the default value.|
197| MODE_POWER_SAVE         | 601  | Power saving mode.        |
198| MODE_PERFORMANCE        | 602  | Performance mode.        |
199| MODE_EXTREME_POWER_SAVE | 603  | Ultra power saving mode.    |
200