161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit BasicServicesKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport { AsyncCallback, BusinessError } from './@ohos.base'; 2261847f8eSopenharmony_ci 2361847f8eSopenharmony_ci/** 2461847f8eSopenharmony_ci * Provides interfaces to manage power. 2561847f8eSopenharmony_ci * 2661847f8eSopenharmony_ci * @namespace power 2761847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 2861847f8eSopenharmony_ci * @since 7 2961847f8eSopenharmony_ci */ 3061847f8eSopenharmony_cideclare namespace power { 3161847f8eSopenharmony_ci /** 3261847f8eSopenharmony_ci * Shuts down the system. 3361847f8eSopenharmony_ci * <p>This method requires the ohos.permission.REBOOT permission. 3461847f8eSopenharmony_ci * 3561847f8eSopenharmony_ci * @permission ohos.permission.REBOOT 3661847f8eSopenharmony_ci * @param { string } reason Indicates the shutdown reason. 3761847f8eSopenharmony_ci * reason parameter must be of type string. 3861847f8eSopenharmony_ci * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 3961847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 4061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types; 4161847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 4261847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 4361847f8eSopenharmony_ci * @systemapi 4461847f8eSopenharmony_ci * @since 7 4561847f8eSopenharmony_ci */ 4661847f8eSopenharmony_ci function shutdown(reason: string): void; 4761847f8eSopenharmony_ci 4861847f8eSopenharmony_ci /** 4961847f8eSopenharmony_ci * Restarts the system. 5061847f8eSopenharmony_ci * <p>This method requires the ohos.permission.REBOOT permission. 5161847f8eSopenharmony_ci * 5261847f8eSopenharmony_ci * @permission ohos.permission.REBOOT 5361847f8eSopenharmony_ci * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode 5461847f8eSopenharmony_ci * after the restart. If the parameter is not specified, the system enters the normal mode after the restart. 5561847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 5661847f8eSopenharmony_ci * @since 7 5761847f8eSopenharmony_ci * @deprecated since 9 5861847f8eSopenharmony_ci * @useinstead power#reboot 5961847f8eSopenharmony_ci */ 6061847f8eSopenharmony_ci function rebootDevice(reason: string): void; 6161847f8eSopenharmony_ci 6261847f8eSopenharmony_ci /** 6361847f8eSopenharmony_ci * Restarts the system. 6461847f8eSopenharmony_ci * <p>This method requires the ohos.permission.REBOOT permission. 6561847f8eSopenharmony_ci * 6661847f8eSopenharmony_ci * @permission ohos.permission.REBOOT 6761847f8eSopenharmony_ci * @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode 6861847f8eSopenharmony_ci * after the restart. If the parameter is not specified, the system enters the normal mode after the restart. 6961847f8eSopenharmony_ci * reason parameter must be of type string. 7061847f8eSopenharmony_ci * @throws { BusinessError } 201 - Permission verification failed. The application does not have the permission required to call the API. 7161847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 7261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types; 7361847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 7461847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 7561847f8eSopenharmony_ci * @systemapi 7661847f8eSopenharmony_ci * @since 9 7761847f8eSopenharmony_ci */ 7861847f8eSopenharmony_ci function reboot(reason: string): void; 7961847f8eSopenharmony_ci 8061847f8eSopenharmony_ci /** 8161847f8eSopenharmony_ci * Checks whether the screen of a device is on or off. 8261847f8eSopenharmony_ci * 8361847f8eSopenharmony_ci * @param { AsyncCallback<boolean> } callback Returns true if the screen is on; returns false otherwise. 8461847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 8561847f8eSopenharmony_ci * @since 7 8661847f8eSopenharmony_ci * @deprecated since 9 8761847f8eSopenharmony_ci * @useinstead power#isActive 8861847f8eSopenharmony_ci */ 8961847f8eSopenharmony_ci function isScreenOn(callback: AsyncCallback<boolean>): void; 9061847f8eSopenharmony_ci 9161847f8eSopenharmony_ci /** 9261847f8eSopenharmony_ci * Checks whether the screen of a device is on or off. 9361847f8eSopenharmony_ci * 9461847f8eSopenharmony_ci * @returns { Promise<boolean> } Returns true if the screen is on; returns false otherwise. 9561847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 9661847f8eSopenharmony_ci * @since 7 9761847f8eSopenharmony_ci * @deprecated since 9 9861847f8eSopenharmony_ci * @useinstead power#isActive 9961847f8eSopenharmony_ci */ 10061847f8eSopenharmony_ci function isScreenOn(): Promise<boolean>; 10161847f8eSopenharmony_ci 10261847f8eSopenharmony_ci /** 10361847f8eSopenharmony_ci * Checks whether the device is active. 10461847f8eSopenharmony_ci * <p> 10561847f8eSopenharmony_ci * The screen will be on if device is active, screen will be off otherwise. 10661847f8eSopenharmony_ci * 10761847f8eSopenharmony_ci * @returns { boolean } Returns true if the device is active; returns false otherwise. 10861847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 10961847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 11061847f8eSopenharmony_ci * @since 9 11161847f8eSopenharmony_ci */ 11261847f8eSopenharmony_ci function isActive(): boolean; 11361847f8eSopenharmony_ci 11461847f8eSopenharmony_ci /** 11561847f8eSopenharmony_ci * Wakes up the device to turn on the screen. 11661847f8eSopenharmony_ci * 11761847f8eSopenharmony_ci * @param { string } detail Indicates the detail information who request wakeup. 11861847f8eSopenharmony_ci * detail parameter must be of type string. 11961847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 12061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Incorrect parameter types; 12161847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 12261847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 12361847f8eSopenharmony_ci * @systemapi 12461847f8eSopenharmony_ci * @since 9 12561847f8eSopenharmony_ci */ 12661847f8eSopenharmony_ci function wakeup(detail: string): void; 12761847f8eSopenharmony_ci 12861847f8eSopenharmony_ci /** 12961847f8eSopenharmony_ci * Suspends the device to turn off the screen. 13061847f8eSopenharmony_ci * 13161847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 13261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 13361847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 13461847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 13561847f8eSopenharmony_ci * @systemapi 13661847f8eSopenharmony_ci * @since 9 13761847f8eSopenharmony_ci */ 13861847f8eSopenharmony_ci /** 13961847f8eSopenharmony_ci * Suspends the device to turn off the screen. 14061847f8eSopenharmony_ci * 14161847f8eSopenharmony_ci * @param { boolean } isImmediate Indicates whether suspend the device immediately. 14261847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 14361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 14461847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 14561847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 14661847f8eSopenharmony_ci * @systemapi 14761847f8eSopenharmony_ci * @since 10 14861847f8eSopenharmony_ci */ 14961847f8eSopenharmony_ci function suspend(isImmediate?: boolean): void; 15061847f8eSopenharmony_ci 15161847f8eSopenharmony_ci /** 15261847f8eSopenharmony_ci * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}. 15361847f8eSopenharmony_ci * 15461847f8eSopenharmony_ci * @returns { DevicePowerMode } The power mode {@link DevicePowerMode} of current device . 15561847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 15661847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 15761847f8eSopenharmony_ci * @since 9 15861847f8eSopenharmony_ci */ 15961847f8eSopenharmony_ci function getPowerMode(): DevicePowerMode; 16061847f8eSopenharmony_ci 16161847f8eSopenharmony_ci /** 16261847f8eSopenharmony_ci * Obtains the power mode of the current device. For details, see {@link DevicePowerMode}. 16361847f8eSopenharmony_ci * 16461847f8eSopenharmony_ci * @permission ohos.permission.POWER_OPTIMIZATION 16561847f8eSopenharmony_ci * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set. 16661847f8eSopenharmony_ci * the DevicePowerMode type is an enumeration class. 16761847f8eSopenharmony_ci * @param { AsyncCallback<void> } callback Indicates the callback of setting the power mode. 16861847f8eSopenharmony_ci * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API. 16961847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 17061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 17161847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 17261847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 17361847f8eSopenharmony_ci * @systemapi 17461847f8eSopenharmony_ci * @since 9 17561847f8eSopenharmony_ci */ 17661847f8eSopenharmony_ci function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void; 17761847f8eSopenharmony_ci 17861847f8eSopenharmony_ci /** 17961847f8eSopenharmony_ci * Sets the power mode of current device. For details, see {@link DevicePowerMode}. 18061847f8eSopenharmony_ci * 18161847f8eSopenharmony_ci * @permission ohos.permission.POWER_OPTIMIZATION 18261847f8eSopenharmony_ci * @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set. 18361847f8eSopenharmony_ci * the DevicePowerMode type is an enumeration class. 18461847f8eSopenharmony_ci * @returns { Promise<void> } 18561847f8eSopenharmony_ci * @throws { BusinessError } 201 – Permission verification failed. The application does not have the permission required to call the API. 18661847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 18761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 18861847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 18961847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 19061847f8eSopenharmony_ci * @systemapi 19161847f8eSopenharmony_ci * @since 9 19261847f8eSopenharmony_ci */ 19361847f8eSopenharmony_ci function setPowerMode(mode: DevicePowerMode): Promise<void>; 19461847f8eSopenharmony_ci 19561847f8eSopenharmony_ci /** 19661847f8eSopenharmony_ci * Returns true if the device is currently in idle mode. 19761847f8eSopenharmony_ci * 19861847f8eSopenharmony_ci * @returns { boolean } Returns true if the device is in idle mode; returns false otherwise. 19961847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 20061847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 20161847f8eSopenharmony_ci * @since 10 20261847f8eSopenharmony_ci */ 20361847f8eSopenharmony_ci function isStandby(): boolean; 20461847f8eSopenharmony_ci 20561847f8eSopenharmony_ci /** 20661847f8eSopenharmony_ci * hibernate the device. 20761847f8eSopenharmony_ci * 20861847f8eSopenharmony_ci * @param { boolean } clearMemory - Indicates whether to clear the memory before the device hibernates. 20961847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 21061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 21161847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 21261847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 21361847f8eSopenharmony_ci * @systemapi 21461847f8eSopenharmony_ci * @since 12 21561847f8eSopenharmony_ci */ 21661847f8eSopenharmony_ci function hibernate(clearMemory: boolean): void; 21761847f8eSopenharmony_ci 21861847f8eSopenharmony_ci /** 21961847f8eSopenharmony_ci * Sets the timeout duration(ms) for turning off the screen. 22061847f8eSopenharmony_ci * 22161847f8eSopenharmony_ci * @param { number } timeout - Indicates duration(ms) for turning off the screen. The value -1 means restore the default value. 22261847f8eSopenharmony_ci * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 22361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Parameter verification failed. 22461847f8eSopenharmony_ci * @throws { BusinessError } 4900101 - Failed to connect to the service. 22561847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 22661847f8eSopenharmony_ci * @systemapi 22761847f8eSopenharmony_ci * @since 12 22861847f8eSopenharmony_ci */ 22961847f8eSopenharmony_ci function setScreenOffTime(timeout: number): void; 23061847f8eSopenharmony_ci 23161847f8eSopenharmony_ci /** 23261847f8eSopenharmony_ci * Power mode of a device. 23361847f8eSopenharmony_ci * 23461847f8eSopenharmony_ci * @enum { number } 23561847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 23661847f8eSopenharmony_ci * @since 9 23761847f8eSopenharmony_ci */ 23861847f8eSopenharmony_ci export enum DevicePowerMode { 23961847f8eSopenharmony_ci /** 24061847f8eSopenharmony_ci * Normal power mode 24161847f8eSopenharmony_ci * 24261847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 24361847f8eSopenharmony_ci * @since 9 24461847f8eSopenharmony_ci */ 24561847f8eSopenharmony_ci MODE_NORMAL = 600, 24661847f8eSopenharmony_ci /** 24761847f8eSopenharmony_ci * Power save mode 24861847f8eSopenharmony_ci * 24961847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 25061847f8eSopenharmony_ci * @since 9 25161847f8eSopenharmony_ci */ 25261847f8eSopenharmony_ci MODE_POWER_SAVE, 25361847f8eSopenharmony_ci /** 25461847f8eSopenharmony_ci * Performance power mode 25561847f8eSopenharmony_ci * 25661847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 25761847f8eSopenharmony_ci * @since 9 25861847f8eSopenharmony_ci */ 25961847f8eSopenharmony_ci MODE_PERFORMANCE, 26061847f8eSopenharmony_ci /** 26161847f8eSopenharmony_ci * Extreme power save mode 26261847f8eSopenharmony_ci * 26361847f8eSopenharmony_ci * @syscap SystemCapability.PowerManager.PowerManager.Core 26461847f8eSopenharmony_ci * @since 9 26561847f8eSopenharmony_ci */ 26661847f8eSopenharmony_ci MODE_EXTREME_POWER_SAVE 26761847f8eSopenharmony_ci } 26861847f8eSopenharmony_ci} 26961847f8eSopenharmony_ciexport default power; 270