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 * @permission ohos.permission.REBOOT 31 * @param {string} reason Indicates the shutdown reason. 32 * @throws {BusinessError} 201 - If the permission is denied. 33 * @throws {BusinessError} 401 - If the reason is not valid. 34 * @throws {BusinessError} 4900101 - If connecting to the service failed. 35 * @systemapi 36 * @since 7 37 */ 38 function shutdown(reason: string): void; 39 40 /** 41 * Restarts the system. 42 * 43 * <p>This method requires the ohos.permission.REBOOT permission. 44 * 45 * @param reason Indicates the restart reason. For example, "updater" indicates entering the updater mode 46 * after the restart. If the parameter is not specified, the system enters the normal mode after the restart. 47 * @permission ohos.permission.REBOOT 48 * @since 7 49 * @deprecated since 9 50 * @useinstead {@link power#reboot} 51 */ 52 function rebootDevice(reason: string): void; 53 54 /** 55 * Restarts the system. 56 * 57 * <p>This method requires the ohos.permission.REBOOT permission. 58 * 59 * @permission ohos.permission.REBOOT 60 * @param {string} reason Indicates the restart reason. For example, "updater" indicates entering the updater mode 61 * after the restart. If the parameter is not specified, the system enters the normal mode after the restart. 62 * @throws {BusinessError} 201 - If the permission is denied. 63 * @throws {BusinessError} 401 - If the reason is not valid. 64 * @throws {BusinessError} 4900101 - If connecting to the service failed. 65 * @systemapi 66 * @since 9 67 */ 68 function reboot(reason: string): void; 69 70 /** 71 * Checks whether the screen of a device is on or off. 72 * 73 * @returns Returns true if the screen is on; returns false otherwise. 74 * @since 7 75 * @deprecated since 9 76 * @useinstead {@link power#isActive} 77 */ 78 function isScreenOn(callback: AsyncCallback<boolean>): void; 79 function isScreenOn(): Promise<boolean>; 80 81 /** 82 * Checks whether the device is active. 83 * <p> 84 * The screen will be on if device is active, screen will be off otherwise. 85 * 86 * @returns Returns true if the device is active; returns false otherwise. 87 * @throws {BusinessError} 4900101 - If connecting to the service failed. 88 * @since 9 89 */ 90 function isActive(): boolean; 91 92 /** 93 * Wakes up the device to turn on the screen. 94 * 95 * @param {string} detail Indicates the detail information who request wakeup. 96 * @throws {BusinessError} 401 - If the detail is not valid. 97 * @throws {BusinessError} 4900101 - If connecting to the service failed. 98 * @systemapi 99 * @since 9 100 */ 101 function wakeup(detail: string): void; 102 103 /** 104 * Suspends the device to turn off the screen. 105 * 106 * @throws {BusinessError} 4900101 - If connecting to the service failed. 107 * @systemapi 108 * @since 9 109 */ 110 function suspend(): void; 111 112 /** 113 * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}. 114 * 115 * @returns The power mode {@link DevicePowerMode} of current device . 116 * @throws {BusinessError} 4900101 - If connecting to the service failed. 117 * @since 9 118 */ 119 function getPowerMode(): DevicePowerMode; 120 121 /** 122 * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}. 123 * 124 * @permission ohos.permission.POWER_OPTIMIZATION 125 * @param {DevicePowerMode} mode Indicates power mode {@link DevicePowerMode} to set. 126 * @param {AsyncCallback<void>} callback Indicates the callback of setting the power mode. 127 * @throws {BusinessError} 201 – If the permission is denied. 128 * @throws {BusinessError} 401 - If mode or callback is not valid. 129 * @systemapi 130 * @since 9 131 */ 132 function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void; 133 134 /** 135 * Sets the power mode of current device. For details, see {@link DevicePowerMode}. 136 * 137 * @permission ohos.permission.POWER_OPTIMIZATION 138 * @param {DevicePowerMode} mode Indicates power mode {@link DevicePowerMode} to set. 139 * @throws {BusinessError} 201 – If the permission is denied. 140 * @throws {BusinessError} 401 - If mode or callback is not valid. 141 * @systemapi 142 * @since 9 143 */ 144 function setPowerMode(mode: DevicePowerMode): Promise<void>; 145 146 /** 147 * Power mode of a device. 148 * 149 * @syscap SystemCapability.PowerManager.PowerManager.Core 150 * @since 9 151 */ 152 export enum DevicePowerMode { 153 /** 154 * Normal power mode 155 * @since 9 156 */ 157 MODE_NORMAL = 600, 158 /** 159 * Power save mode 160 * @since 9 161 */ 162 MODE_POWER_SAVE, 163 /** 164 * Performance power mode 165 * @since 9 166 */ 167 MODE_PERFORMANCE, 168 /** 169 * Extreme power save mode 170 * @since 9 171 */ 172 MODE_EXTREME_POWER_SAVE 173 } 174} 175export default power; 176