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