• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 './basic';
17
18/**
19 * Provides interfaces to manage power.
20 *
21 * @syscap SystemCapability.PowerManager.PowerManager.Core
22 * @since 7
23 */
24declare namespace power {
25    /**
26     * Shuts down the system.
27     *
28     * <p>This method requires the ohos.permission.REBOOT permission.
29     *
30     * @param reason Indicates the shutdown reason.
31     * @permission ohos.permission.REBOOT
32     * @systemapi
33     * @since 7
34     */
35    function shutdownDevice(reason: string): void;
36
37    /**
38     * Shuts down the system.
39     *
40     * <p>This method requires the ohos.permission.REBOOT permission.
41     *
42     * @permission ohos.permission.REBOOT
43     * @param {string} reason Indicates the shutdown reason.
44     * @throws {BusinessError} If connecting to the service failed.
45     * @systemapi
46     * @since 7
47     */
48    function shutdown(reason: string): void;
49
50    /**
51     * Restarts the system.
52     *
53     * <p>This method requires the ohos.permission.REBOOT permission.
54     *
55     * @param 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     * @permission ohos.permission.REBOOT
58     * @since 7
59     * @deprecated since 9
60     */
61    function rebootDevice(reason: string): void;
62
63    /**
64     * Restarts the system.
65     *
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     * @throws {BusinessError} If connecting to the service failed.
72     * @systemapi
73     * @since 9
74     */
75    function reboot(reason: string): void;
76
77    /**
78     * Checks whether the screen of a device is on or off.
79     *
80     * @return Returns true if the screen is on; returns false otherwise.
81     * @since 7
82     * @deprecated since 9
83     * @useinstead {@link isScreenOn}
84     */
85    function isScreenOn(callback: AsyncCallback<boolean>): void;
86    function isScreenOn(): Promise<boolean>;
87
88    /**
89     * Checks whether the screen of a device is on or off.
90     *
91     * @return Returns true if the screen is on; returns false otherwise.
92     * @throws {BusinessError} If connecting to the service failed.
93     * @since 9
94     */
95    function isScreenOn(): boolean;
96
97    /**
98     * Wakes up the device to turn on the screen.
99     *
100     * @param {string} detail Indicates the detail information who request wakeup.
101     * @throws {BusinessError} If connecting to the service failed.
102     * @systemapi
103     * @since 9
104     */
105    function wakeup(detail: string): void;
106
107    /**
108     * Suspends the device to turn off the screen.
109     *
110     * @throws {BusinessError} If connecting to the service failed.
111     * @systemapi
112     * @since 9
113     */
114    function suspend(): void;
115
116    /**
117     * Get the power mode of the device.
118     *
119     * @return Returns the power mode {@link DevicePowerMode} of current device .
120     * @permission ohos.permission.POWER_OPTIMIZATION
121     * @since 9
122     */
123    function getPowerMode(callback: AsyncCallback<DevicePowerMode>): void;
124    function getPowerMode(): Promise<DevicePowerMode>;
125
126    /**
127     * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
128     *
129     * @permission ohos.permission.POWER_OPTIMIZATION
130     * @return The power mode {@link DevicePowerMode} of current device .
131     * @throws {BusinessError} If connecting to the service failed.
132     * @since 9
133     */
134    function getPowerMode(): DevicePowerMode;
135
136    /**
137     * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
138     *
139     * @permission ohos.permission.POWER_OPTIMIZATION
140     * @param {DevicePowerMode} mode Indicates power mode {@link DevicePowerMode} to set.
141     * @param {AsyncCallback<void>} callback Indicates the callback of setting the power mode.
142     * @throws {BusinessError} If mode or callback is not valid.
143     * @systemapi
144     * @since 9
145     */
146    function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void;
147
148    /**
149     * Sets the power mode of current device. For details, see {@link DevicePowerMode}.
150     *
151     * @permission ohos.permission.POWER_OPTIMIZATION
152     * @param {DevicePowerMode} mode Indicates power mode {@link DevicePowerMode} to set.
153     * @throws {BusinessError} If mode is not valid.
154     * @systemapi
155     * @since 9
156     */
157    function setPowerMode(mode: DevicePowerMode): Promise<void>;
158
159    /**
160     * Power mode of a device.
161     *
162     * @syscap SystemCapability.PowerManager.PowerManager.Core
163     * @since 9
164     */
165    export enum DevicePowerMode {
166        /**
167         * Normal power mode
168         * @since 9
169         */
170        MODE_NORMAL = 600,
171        /**
172         * Power save mode
173         * @since 9
174         */
175        MODE_POWER_SAVE,
176        /**
177         * Performance power mode
178         * @since 9
179         */
180        MODE_PERFORMANCE,
181        /**
182         * Extreme power save mode
183         * @since 9
184         */
185        MODE_EXTREME_POWER_SAVE
186    }
187}
188export default power;
189