• 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
16import { AsyncCallback, BusinessError } from './@ohos.base';
17
18/**
19 * Provides interfaces to manage power.
20 *
21 * @namespace power
22 * @syscap SystemCapability.PowerManager.PowerManager.Core
23 * @since 7
24 */
25declare namespace power {
26  /**
27   * Shuts down the system.
28   * <p>This method requires the ohos.permission.REBOOT permission.
29   *
30   * @permission ohos.permission.REBOOT
31   * @param { string } reason Indicates the shutdown reason.
32   * @throws { BusinessError } 201 - If the permission is denied.
33   * @throws { BusinessError } 202 - If the system permission is denied.
34   * @throws { BusinessError } 401 - If the reason is not valid.
35   * @throws { BusinessError } 4900101 - If connecting to the service failed.
36   * @syscap SystemCapability.PowerManager.PowerManager.Core
37   * @systemapi
38   * @since 7
39   */
40  function shutdown(reason: string): void;
41
42  /**
43   * Restarts the system.
44   * <p>This method requires the ohos.permission.REBOOT permission.
45   *
46   * @permission ohos.permission.REBOOT
47   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
48   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
49   * @syscap SystemCapability.PowerManager.PowerManager.Core
50   * @since 7
51   * @deprecated since 9
52   * @useinstead power#reboot
53   */
54  function rebootDevice(reason: string): void;
55
56  /**
57   * Restarts the system.
58   * <p>This method requires the ohos.permission.REBOOT permission.
59   *
60   * @permission ohos.permission.REBOOT
61   * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
62   * after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
63   * @throws { BusinessError } 201 - If the permission is denied.
64   * @throws { BusinessError } 202 - If the system permission is denied.
65   * @throws { BusinessError } 401 - If the reason is not valid.
66   * @throws { BusinessError } 4900101 - If connecting to the service failed.
67   * @syscap SystemCapability.PowerManager.PowerManager.Core
68   * @systemapi
69   * @since 9
70   */
71  function reboot(reason: string): void;
72
73  /**
74   * Checks whether the screen of a device is on or off.
75   *
76   * @param { AsyncCallback<boolean> } callback Returns true if the screen is on; returns false otherwise.
77   * @syscap SystemCapability.PowerManager.PowerManager.Core
78   * @since 7
79   * @deprecated since 9
80   * @useinstead power#isActive
81   */
82  function isScreenOn(callback: AsyncCallback<boolean>): void;
83
84  /**
85   * Checks whether the screen of a device is on or off.
86   *
87   * @returns { Promise<boolean> } Returns true if the screen is on; returns false otherwise.
88   * @syscap SystemCapability.PowerManager.PowerManager.Core
89   * @since 7
90   * @deprecated since 9
91   * @useinstead power#isActive
92   */
93  function isScreenOn(): Promise<boolean>;
94
95  /**
96   * Checks whether the device is active.
97   * <p>
98   * The screen will be on if device is active, screen will be off otherwise.
99   *
100   * @returns { boolean } Returns true if the device is active; returns false otherwise.
101   * @throws { BusinessError } 4900101 - If connecting to the service failed.
102   * @syscap SystemCapability.PowerManager.PowerManager.Core
103   * @since 9
104   */
105  function isActive(): boolean;
106
107  /**
108   * Wakes up the device to turn on the screen.
109   *
110   * @param { string } detail Indicates the detail information who request wakeup.
111   * @throws { BusinessError } 202 - If the system permission is denied.
112   * @throws { BusinessError } 401 - If the detail is not valid.
113   * @throws { BusinessError } 4900101 - If connecting to the service failed.
114   * @syscap SystemCapability.PowerManager.PowerManager.Core
115   * @systemapi
116   * @since 9
117   */
118  function wakeup(detail: string): void;
119
120  /**
121   * Suspends the device to turn off the screen.
122   *
123   * @throws { BusinessError } 202 - If the system permission is denied.
124   * @throws { BusinessError } 4900101 - If connecting to the service failed.
125   * @syscap SystemCapability.PowerManager.PowerManager.Core
126   * @systemapi
127   * @since 9
128   */
129  /**
130   * Suspends the device to turn off the screen.
131   *
132   * @param { boolean } isImmediate Indicates whether suspend the device immediately.
133   * @throws { BusinessError } 202 - If the system permission is denied.
134   * @throws { BusinessError } 4900101 - If connecting to the service failed.
135   * @syscap SystemCapability.PowerManager.PowerManager.Core
136   * @systemapi
137   * @since 10
138   */
139  function suspend(isImmediate?: boolean): void;
140
141  /**
142   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
143   *
144   * @returns { DevicePowerMode } The power mode {@link DevicePowerMode} of current device .
145   * @throws { BusinessError } 4900101 - If connecting to the service failed.
146   * @syscap SystemCapability.PowerManager.PowerManager.Core
147   * @since 9
148   */
149  function getPowerMode(): DevicePowerMode;
150
151  /**
152   * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
153   *
154   * @permission ohos.permission.POWER_OPTIMIZATION
155   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
156   * @param { AsyncCallback<void> } callback Indicates the callback of setting the power mode.
157   * @throws { BusinessError } 201 – If the permission is denied.
158   * @throws { BusinessError } 202 - If the system permission is denied.
159   * @throws { BusinessError } 401 - If mode or callback is not valid.
160   * @throws { BusinessError } 4900101 - If connecting to the service failed.
161   * @syscap SystemCapability.PowerManager.PowerManager.Core
162   * @systemapi
163   * @since 9
164   */
165  function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void;
166
167  /**
168   * Sets the power mode of current device. For details, see {@link DevicePowerMode}.
169   *
170   * @permission ohos.permission.POWER_OPTIMIZATION
171   * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
172   * @returns { Promise<void> }
173   * @throws { BusinessError } 201 – If the permission is denied.
174   * @throws { BusinessError } 202 - If the system permission is denied.
175   * @throws { BusinessError } 401 - If mode or callback is not valid.
176   * @throws { BusinessError } 4900101 - If connecting to the service failed.
177   * @syscap SystemCapability.PowerManager.PowerManager.Core
178   * @systemapi
179   * @since 9
180   */
181  function setPowerMode(mode: DevicePowerMode): Promise<void>;
182
183  /**
184   * Returns true if the device is currently in idle mode.
185   *
186   * @returns { boolean } Returns true if the device is in idle mode; returns false otherwise.
187   * @throws { BusinessError } 4900101 - If connecting to the service failed.
188   * @syscap SystemCapability.PowerManager.PowerManager.Core
189   * @since 10
190   */
191  function isStandby(): boolean;
192
193  /**
194   * Power mode of a device.
195   *
196   * @enum { number }
197   * @syscap SystemCapability.PowerManager.PowerManager.Core
198   * @since 9
199   */
200  export enum DevicePowerMode {
201    /**
202     * Normal power mode
203     *
204     * @syscap SystemCapability.PowerManager.PowerManager.Core
205     * @since 9
206     */
207    MODE_NORMAL = 600,
208    /**
209     * Power save mode
210     *
211     * @syscap SystemCapability.PowerManager.PowerManager.Core
212     * @since 9
213     */
214    MODE_POWER_SAVE,
215    /**
216     * Performance power mode
217     *
218     * @syscap SystemCapability.PowerManager.PowerManager.Core
219     * @since 9
220     */
221    MODE_PERFORMANCE,
222    /**
223     * Extreme power save mode
224     *
225     * @syscap SystemCapability.PowerManager.PowerManager.Core
226     * @since 9
227     */
228    MODE_EXTREME_POWER_SAVE
229  }
230}
231export default power;
232