• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
21import { AsyncCallback, BusinessError } from './@ohos.base';
22
23/**
24 * Provides interfaces to manage power.
25 *
26 * @namespace power
27 * @syscap SystemCapability.PowerManager.PowerManager.Core
28 * @since arkts {'1.1':'7', '1.2':'20'}
29 * @arkts 1.1&1.2
30 */
31declare namespace power {
32  /**
33   * Shuts down the system.
34   * <p>This method requires the ohos.permission.REBOOT permission.
35   *
36   * @permission ohos.permission.REBOOT
37   * @param { string } reason Indicates the shutdown reason.
38   * reason parameter must be of type string.
39   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
40   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
41   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
42   * @throws { BusinessError } 4900101 - Failed to connect to the service.
43   * @syscap SystemCapability.PowerManager.PowerManager.Core
44   * @systemapi
45   * @since arkts {'1.1':'7', '1.2':'20'}
46   * @arkts 1.1&1.2
47   */
48  function shutdown(reason: string): void;
49
50  /**
51   * Restarts the system.
52   * <p>This method requires the ohos.permission.REBOOT permission.
53   *
54   * @permission ohos.permission.REBOOT
55   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
56   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
57   * @syscap SystemCapability.PowerManager.PowerManager.Core
58   * @since 7
59   * @deprecated since 9
60   * @useinstead power#reboot
61   */
62  function rebootDevice(reason: string): void;
63
64  /**
65   * Restarts the system.
66   * <p>This method requires the ohos.permission.REBOOT permission.
67   *
68   * @permission ohos.permission.REBOOT
69   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
70   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
71   * reason parameter must be of type string.
72   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
73   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
74   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
75   * @throws { BusinessError } 4900101 - Failed to connect to the service.
76   * @syscap SystemCapability.PowerManager.PowerManager.Core
77   * @systemapi
78   * @since arkts {'1.1':'9', '1.2':'20'}
79   * @arkts 1.1&1.2
80   */
81  function reboot(reason: string): void;
82
83  /**
84   * Checks whether the screen of a device is on or off.
85   *
86   * @param { AsyncCallback<boolean> } callback Returns true if the screen is on; returns false otherwise.
87   * @syscap SystemCapability.PowerManager.PowerManager.Core
88   * @since 7
89   * @deprecated since 9
90   * @useinstead power#isActive
91   */
92  function isScreenOn(callback: AsyncCallback<boolean>): void;
93
94  /**
95   * Checks whether the screen of a device is on or off.
96   *
97   * @returns { Promise<boolean> } Returns true if the screen is on; returns false otherwise.
98   * @syscap SystemCapability.PowerManager.PowerManager.Core
99   * @since 7
100   * @deprecated since 9
101   * @useinstead power#isActive
102   */
103  function isScreenOn(): Promise<boolean>;
104
105  /**
106   * Checks whether the device is active.
107   * <p>
108   * The screen will be on if device is active, screen will be off otherwise.
109   *
110   * @returns { boolean } Returns true if the device is active; returns false otherwise.
111   * @syscap SystemCapability.PowerManager.PowerManager.Core
112   * @since arkts {'1.1':'9', '1.2':'20'}
113   * @arkts 1.1&1.2
114   */
115  function isActive(): boolean;
116
117  /**
118   * Wakes up the device to turn on the screen.
119   *
120   * @param { string } detail Indicates the detail information who request wakeup.
121   * detail parameter must be of type string.
122   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
123   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
124   * @throws { BusinessError } 4900101 - Failed to connect to the service.
125   * @syscap SystemCapability.PowerManager.PowerManager.Core
126   * @systemapi
127   * @since 9
128   */
129  /**
130   * Wakes up the device to turn on the screen with permission.
131   *
132   * @permission ohos.permission.POWER_MANAGER
133   * @param { string } detail Indicates the detail information who request wakeup.
134   * detail parameter must be of type string.
135   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
136   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
137   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
138   * @throws { BusinessError } 4900101 - Failed to connect to the service.
139   * @syscap SystemCapability.PowerManager.PowerManager.Core
140   * @systemapi
141   * @since arkts {'1.1':'19', '1.2':'20'}
142   * @arkts 1.1&1.2
143   */
144  function wakeup(detail: string): void;
145
146  /**
147   * Suspends the device to turn off the screen.
148   *
149   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
150   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
151   * @throws { BusinessError } 4900101 - Failed to connect to the service.
152   * @syscap SystemCapability.PowerManager.PowerManager.Core
153   * @systemapi
154   * @since 9
155   */
156  /**
157   * Suspends the device to turn off the screen.
158   *
159   * @param { boolean } isImmediate Indicates whether suspend the device immediately.
160   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
161   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
162   * @throws { BusinessError } 4900101 - Failed to connect to the service.
163   * @syscap SystemCapability.PowerManager.PowerManager.Core
164   * @systemapi
165   * @since 10
166   */
167  /**
168   * Suspends the device to turn off the screen with permission.
169   *
170   * @permission ohos.permission.POWER_MANAGER
171   * @param { boolean } isImmediate Indicates whether suspend the device immediately.
172   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
173   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
174   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
175   * @throws { BusinessError } 4900101 - Failed to connect to the service.
176   * @syscap SystemCapability.PowerManager.PowerManager.Core
177   * @systemapi
178   * @since arkts {'1.1':'19', '1.2':'20'}
179   * @arkts 1.1&1.2
180   */
181  function suspend(isImmediate?: boolean): void;
182
183  /**
184   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
185   *
186   * @returns { DevicePowerMode } The power mode {@link DevicePowerMode} of current device .
187   * @syscap SystemCapability.PowerManager.PowerManager.Core
188   * @since arkts {'1.1':'9', '1.2':'20'}
189   * @arkts 1.1&1.2
190   */
191  function getPowerMode(): DevicePowerMode;
192
193  /**
194   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
195   *
196   * @permission ohos.permission.POWER_OPTIMIZATION
197   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
198   * the DevicePowerMode type is an enumeration class.
199   * @param { AsyncCallback<void> } callback Indicates the callback of setting the power mode.
200   * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API.
201   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
202   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
203   * @syscap SystemCapability.PowerManager.PowerManager.Core
204   * @systemapi
205   * @since arkts {'1.1':'9', '1.2':'20'}
206   * @arkts 1.1&1.2
207   */
208  function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void;
209
210  /**
211   * Sets the power mode of current device. For details, see {@link DevicePowerMode}.
212   *
213   * @permission ohos.permission.POWER_OPTIMIZATION
214   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
215   * the DevicePowerMode type is an enumeration class.
216   * @returns { Promise<void> }
217   * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API.
218   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
219   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
220   * @syscap SystemCapability.PowerManager.PowerManager.Core
221   * @systemapi
222   * @since arkts {'1.1':'9', '1.2':'20'}
223   * @arkts 1.1&1.2
224   */
225  function setPowerMode(mode: DevicePowerMode): Promise<void>;
226
227  /**
228   * Returns true if the device is currently in idle mode.
229   *
230   * @returns { boolean } Returns true if the device is in idle mode; returns false otherwise.
231   * @throws { BusinessError } 4900101 - Failed to connect to the service.
232   * @syscap SystemCapability.PowerManager.PowerManager.Core
233   * @since arkts {'1.1':'10', '1.2':'20'}
234   * @arkts 1.1&1.2
235   */
236  function isStandby(): boolean;
237
238  /**
239   * hibernate the device.
240   *
241   * @param { boolean } clearMemory - Indicates whether to clear the memory before the device hibernates.
242   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
243   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
244   * @throws { BusinessError } 4900101 - Failed to connect to the service.
245   * @syscap SystemCapability.PowerManager.PowerManager.Core
246   * @systemapi
247   * @since 12
248   */
249  /**
250   * hibernate the device with permission.
251   *
252   * @permission ohos.permission.POWER_MANAGER
253   * @param { boolean } clearMemory - Indicates whether to clear the memory before the device hibernates.
254   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
255   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
256   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
257   * @throws { BusinessError } 4900101 - Failed to connect to the service.
258   * @syscap SystemCapability.PowerManager.PowerManager.Core
259   * @systemapi
260   * @since arkts {'1.1':'19', '1.2':'20'}
261   * @arkts 1.1&1.2
262   */
263  function hibernate(clearMemory: boolean): void;
264
265  /**
266   * Sets the timeout duration(ms) for turning off the screen.
267   *
268   * @param { number } timeout - Indicates duration(ms) for turning off the screen. The value -1 means restore the default value.
269   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
270   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
271   * @throws { BusinessError } 4900101 - Failed to connect to the service.
272   * @syscap SystemCapability.PowerManager.PowerManager.Core
273   * @systemapi
274   * @since 12
275   */
276  /**
277   * Sets the timeout duration(ms) for turning off the screen with permission.
278   *
279   * @permission ohos.permission.POWER_MANAGER
280   * @param { long } timeout - Indicates duration(ms) for turning off the screen. The value -1 means restore the default value.
281   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
282   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
283   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
284   * @throws { BusinessError } 4900101 - Failed to connect to the service.
285   * @syscap SystemCapability.PowerManager.PowerManager.Core
286   * @systemapi
287   * @since arkts {'1.1':'19', '1.2':'20'}
288   * @arkts 1.1&1.2
289   */
290  function setScreenOffTime(timeout: long): void;
291
292  /**
293   * Refresh the device activity (such as resetting the screen-off time, etc).
294   * Available only when the device is active, see {@link isActive}
295   *
296   * @permission ohos.permission.REFRESH_USER_ACTION
297   * @param { string } reason Indicates the reason of refreshing activity. The reason parameter must be of type string.
298   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission
299   *     required to call the API.
300   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
301   * @throws { BusinessError } 4900101 - Failed to connect to the service.
302   * @throws { BusinessError } 4900201 - The device activity is being refreshed too frequently; the minimum time
303   *     interval is 100 ms.
304   * @syscap SystemCapability.PowerManager.PowerManager.Core
305   * @systemapi
306   * @since 20
307   */
308  function refreshActivity(reason: string): void;
309
310  /**
311   * Power mode of a device.
312   *
313   * @enum { int }
314   * @syscap SystemCapability.PowerManager.PowerManager.Core
315   * @since arkts {'1.1':'9', '1.2':'20'}
316   * @arkts 1.1&1.2
317   */
318  export enum DevicePowerMode {
319    /**
320     * Normal power mode
321     *
322     * @syscap SystemCapability.PowerManager.PowerManager.Core
323     * @since arkts {'1.1':'9', '1.2':'20'}
324     * @arkts 1.1&1.2
325     */
326    MODE_NORMAL = 600,
327    /**
328     * Power save mode
329     * @syscap SystemCapability.PowerManager.PowerManager.Core
330     * @since arkts {'1.1':'9', '1.2':'20'}
331     * @arkts 1.1&1.2
332     *
333     */
334    MODE_POWER_SAVE,
335    /**
336     * Performance power mode
337     *
338     * @syscap SystemCapability.PowerManager.PowerManager.Core
339     * @since arkts {'1.1':'9', '1.2':'20'}
340     * @arkts 1.1&1.2
341     */
342    MODE_PERFORMANCE,
343    /**
344     * Extreme power save mode
345     *
346     * @syscap SystemCapability.PowerManager.PowerManager.Core
347     * @since arkts {'1.1':'9', '1.2':'20'}
348     * @arkts 1.1&1.2
349     */
350    MODE_EXTREME_POWER_SAVE,
351    /**
352     * Custom power save mode.
353     *
354     * @syscap SystemCapability.PowerManager.PowerManager.Core
355     * @since 20
356     */
357    MODE_CUSTOM_POWER_SAVE = 650
358  }
359}
360export default power;