• 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 7
29 */
30declare namespace power {
31  /**
32   * Shuts down the system.
33   * <p>This method requires the ohos.permission.REBOOT permission.
34   *
35   * @permission ohos.permission.REBOOT
36   * @param { string } reason Indicates the shutdown reason.
37   * reason parameter must be of type string.
38   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
39   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
40   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
41   * @throws { BusinessError } 4900101 - Failed to connect to the service.
42   * @syscap SystemCapability.PowerManager.PowerManager.Core
43   * @systemapi
44   * @since 7
45   */
46  function shutdown(reason: string): void;
47
48  /**
49   * Restarts the system.
50   * <p>This method requires the ohos.permission.REBOOT permission.
51   *
52   * @permission ohos.permission.REBOOT
53   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
54   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
55   * @syscap SystemCapability.PowerManager.PowerManager.Core
56   * @since 7
57   * @deprecated since 9
58   * @useinstead power#reboot
59   */
60  function rebootDevice(reason: string): void;
61
62  /**
63   * Restarts the system.
64   * <p>This method requires the ohos.permission.REBOOT permission.
65   *
66   * @permission ohos.permission.REBOOT
67   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
68   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
69   * reason parameter must be of type string.
70   * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API.
71   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
72   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
73   * @throws { BusinessError } 4900101 - Failed to connect to the service.
74   * @syscap SystemCapability.PowerManager.PowerManager.Core
75   * @systemapi
76   * @since 9
77   */
78  function reboot(reason: string): void;
79
80  /**
81   * Checks whether the screen of a device is on or off.
82   *
83   * @param { AsyncCallback<boolean> } callback Returns true if the screen is on; returns false otherwise.
84   * @syscap SystemCapability.PowerManager.PowerManager.Core
85   * @since 7
86   * @deprecated since 9
87   * @useinstead power#isActive
88   */
89  function isScreenOn(callback: AsyncCallback<boolean>): void;
90
91  /**
92   * Checks whether the screen of a device is on or off.
93   *
94   * @returns { Promise<boolean> } Returns true if the screen is on; returns false otherwise.
95   * @syscap SystemCapability.PowerManager.PowerManager.Core
96   * @since 7
97   * @deprecated since 9
98   * @useinstead power#isActive
99   */
100  function isScreenOn(): Promise<boolean>;
101
102  /**
103   * Checks whether the device is active.
104   * <p>
105   * The screen will be on if device is active, screen will be off otherwise.
106   *
107   * @returns { boolean } Returns true if the device is active; returns false otherwise.
108   * @throws { BusinessError } 4900101 - Failed to connect to the service.
109   * @syscap SystemCapability.PowerManager.PowerManager.Core
110   * @since 9
111   */
112  function isActive(): boolean;
113
114  /**
115   * Wakes up the device to turn on the screen.
116   *
117   * @param { string } detail Indicates the detail information who request wakeup.
118   * detail parameter must be of type string.
119   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
120   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types;
121   * @throws { BusinessError } 4900101 - Failed to connect to the service.
122   * @syscap SystemCapability.PowerManager.PowerManager.Core
123   * @systemapi
124   * @since 9
125   */
126  function wakeup(detail: string): void;
127
128  /**
129   * Suspends the device to turn off the screen.
130   *
131   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
132   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
133   * @throws { BusinessError } 4900101 - Failed to connect to the service.
134   * @syscap SystemCapability.PowerManager.PowerManager.Core
135   * @systemapi
136   * @since 9
137   */
138  /**
139   * Suspends the device to turn off the screen.
140   *
141   * @param { boolean } isImmediate Indicates whether suspend the device immediately.
142   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
143   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
144   * @throws { BusinessError } 4900101 - Failed to connect to the service.
145   * @syscap SystemCapability.PowerManager.PowerManager.Core
146   * @systemapi
147   * @since 10
148   */
149  function suspend(isImmediate?: boolean): void;
150
151  /**
152   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
153   *
154   * @returns { DevicePowerMode } The power mode {@link DevicePowerMode} of current device .
155   * @throws { BusinessError } 4900101 - Failed to connect to the service.
156   * @syscap SystemCapability.PowerManager.PowerManager.Core
157   * @since 9
158   */
159  function getPowerMode(): DevicePowerMode;
160
161  /**
162   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
163   *
164   * @permission ohos.permission.POWER_OPTIMIZATION
165   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
166   * the DevicePowerMode type is an enumeration class.
167   * @param { AsyncCallback<void> } callback Indicates the callback of setting the power mode.
168   * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API.
169   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
170   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
171   * @throws { BusinessError } 4900101 - Failed to connect to the service.
172   * @syscap SystemCapability.PowerManager.PowerManager.Core
173   * @systemapi
174   * @since 9
175   */
176  function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void;
177
178  /**
179   * Sets the power mode of current device. For details, see {@link DevicePowerMode}.
180   *
181   * @permission ohos.permission.POWER_OPTIMIZATION
182   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
183   * the DevicePowerMode type is an enumeration class.
184   * @returns { Promise<void> }
185   * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API.
186   * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
187   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
188   * @throws { BusinessError } 4900101 - Failed to connect to the service.
189   * @syscap SystemCapability.PowerManager.PowerManager.Core
190   * @systemapi
191   * @since 9
192   */
193  function setPowerMode(mode: DevicePowerMode): Promise<void>;
194
195  /**
196   * Returns true if the device is currently in idle mode.
197   *
198   * @returns { boolean } Returns true if the device is in idle mode; returns false otherwise.
199   * @throws { BusinessError } 4900101 - Failed to connect to the service.
200   * @syscap SystemCapability.PowerManager.PowerManager.Core
201   * @since 10
202   */
203  function isStandby(): boolean;
204
205  /**
206  * hibernate the device.
207  *
208  * @param { boolean } clearMemory - Indicates whether to clear the memory before the device hibernates.
209  * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
210  * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
211  * @throws { BusinessError } 4900101 - Failed to connect to the service.
212  * @syscap SystemCapability.PowerManager.PowerManager.Core
213  * @systemapi
214  * @since 12
215  */
216  function hibernate(clearMemory: boolean): void;
217
218  /**
219  * Sets the timeout duration(ms) for turning off the screen.
220  *
221  * @param { number } timeout - Indicates duration(ms) for turning off the screen. The value -1 means restore the default value.
222  * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
223  * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed.
224  * @throws { BusinessError } 4900101 - Failed to connect to the service.
225  * @syscap SystemCapability.PowerManager.PowerManager.Core
226  * @systemapi
227  * @since 12
228  */
229  function setScreenOffTime(timeout: number): void;
230
231  /**
232   * Power mode of a device.
233   *
234   * @enum { number }
235   * @syscap SystemCapability.PowerManager.PowerManager.Core
236   * @since 9
237   */
238  export enum DevicePowerMode {
239    /**
240     * Normal power mode
241     *
242     * @syscap SystemCapability.PowerManager.PowerManager.Core
243     * @since 9
244     */
245    MODE_NORMAL = 600,
246    /**
247     * Power save mode
248     *
249     * @syscap SystemCapability.PowerManager.PowerManager.Core
250     * @since 9
251     */
252    MODE_POWER_SAVE,
253    /**
254     * Performance power mode
255     *
256     * @syscap SystemCapability.PowerManager.PowerManager.Core
257     * @since 9
258     */
259    MODE_PERFORMANCE,
260    /**
261     * Extreme power save mode
262     *
263     * @syscap SystemCapability.PowerManager.PowerManager.Core
264     * @since 9
265     */
266    MODE_EXTREME_POWER_SAVE
267  }
268}
269export default power;
270