2021-08-17 11:55:25 +00:00
|
|
|
|
/*
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
2021-08-17 11:55:25 +00:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-12-11 09:08:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* @file
|
2024-01-08 07:25:39 +00:00
|
|
|
|
* @kit BasicServicesKit
|
2023-12-11 09:08:03 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2023-04-04 02:17:06 +00:00
|
|
|
|
import { AsyncCallback, BusinessError } from './@ohos.base';
|
2021-08-17 11:55:25 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides interfaces to manage power.
|
|
|
|
|
*
|
2023-02-21 10:54:48 +00:00
|
|
|
|
* @namespace power
|
2022-03-02 07:44:27 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
2021-08-17 11:55:25 +00:00
|
|
|
|
* @since 7
|
|
|
|
|
*/
|
|
|
|
|
declare namespace power {
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Shuts down the system.
|
|
|
|
|
* <p>This method requires the ohos.permission.REBOOT permission.
|
|
|
|
|
*
|
|
|
|
|
* @permission ohos.permission.REBOOT
|
|
|
|
|
* @param { string } reason Indicates the shutdown reason.
|
|
|
|
|
* @throws { BusinessError } 201 - If the permission is denied.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 401 - If the reason is not valid.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 7
|
|
|
|
|
*/
|
|
|
|
|
function shutdown(reason: string): void;
|
2021-08-17 11:55:25 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Restarts the system.
|
|
|
|
|
* <p>This method requires the ohos.permission.REBOOT permission.
|
|
|
|
|
*
|
|
|
|
|
* @permission ohos.permission.REBOOT
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 7
|
|
|
|
|
* @deprecated since 9
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @useinstead power#reboot
|
2023-03-21 08:00:55 +00:00
|
|
|
|
*/
|
|
|
|
|
function rebootDevice(reason: string): void;
|
2021-08-17 11:55:25 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Restarts the system.
|
|
|
|
|
* <p>This method requires the ohos.permission.REBOOT permission.
|
|
|
|
|
*
|
|
|
|
|
* @permission ohos.permission.REBOOT
|
|
|
|
|
* @param { string } reason Indicates the restart reason. For example, "updater" indicates entering the updater mode
|
|
|
|
|
* after the restart. If the parameter is not specified, the system enters the normal mode after the restart.
|
|
|
|
|
* @throws { BusinessError } 201 - If the permission is denied.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 401 - If the reason is not valid.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function reboot(reason: string): void;
|
2022-04-01 09:34:55 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Checks whether the screen of a device is on or off.
|
|
|
|
|
*
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @param { AsyncCallback<boolean> } callback Returns true if the screen is on; returns false otherwise.
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 7
|
|
|
|
|
* @deprecated since 9
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @useinstead power#isActive
|
2023-03-21 08:00:55 +00:00
|
|
|
|
*/
|
|
|
|
|
function isScreenOn(callback: AsyncCallback<boolean>): void;
|
2022-04-01 09:34:55 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Checks whether the screen of a device is on or off.
|
|
|
|
|
*
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @returns { Promise<boolean> } Returns true if the screen is on; returns false otherwise.
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 7
|
|
|
|
|
* @deprecated since 9
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @useinstead power#isActive
|
2023-03-21 08:00:55 +00:00
|
|
|
|
*/
|
|
|
|
|
function isScreenOn(): Promise<boolean>;
|
2022-04-01 09:34:55 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Checks whether the device is active.
|
|
|
|
|
* <p>
|
|
|
|
|
* The screen will be on if device is active, screen will be off otherwise.
|
|
|
|
|
*
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @returns { boolean } Returns true if the device is active; returns false otherwise.
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function isActive(): boolean;
|
2022-04-01 09:34:55 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Wakes up the device to turn on the screen.
|
|
|
|
|
*
|
|
|
|
|
* @param { string } detail Indicates the detail information who request wakeup.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 401 - If the detail is not valid.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function wakeup(detail: string): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Suspends the device to turn off the screen.
|
|
|
|
|
*
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
2023-06-01 09:11:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Suspends the device to turn off the screen.
|
|
|
|
|
*
|
|
|
|
|
* @param { boolean } isImmediate Indicates whether suspend the device immediately.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 10
|
|
|
|
|
*/
|
|
|
|
|
function suspend(isImmediate?: boolean): void;
|
2023-03-21 08:00:55 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
|
|
|
|
|
*
|
2023-06-01 09:11:56 +00:00
|
|
|
|
* @returns { DevicePowerMode } The power mode {@link DevicePowerMode} of current device .
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function getPowerMode(): DevicePowerMode;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtains the power mode of the current device. For details, see {@link DevicePowerMode}.
|
|
|
|
|
*
|
|
|
|
|
* @permission ohos.permission.POWER_OPTIMIZATION
|
|
|
|
|
* @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
|
|
|
|
|
* @param { AsyncCallback<void> } callback Indicates the callback of setting the power mode.
|
|
|
|
|
* @throws { BusinessError } 201 – If the permission is denied.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 401 - If mode or callback is not valid.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function setPowerMode(mode: DevicePowerMode, callback: AsyncCallback<void>): void;
|
2022-04-01 09:34:55 +00:00
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the power mode of current device. For details, see {@link DevicePowerMode}.
|
|
|
|
|
*
|
|
|
|
|
* @permission ohos.permission.POWER_OPTIMIZATION
|
|
|
|
|
* @param { DevicePowerMode } mode Indicates power mode {@link DevicePowerMode} to set.
|
|
|
|
|
* @returns { Promise<void> }
|
|
|
|
|
* @throws { BusinessError } 201 – If the permission is denied.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 401 - If mode or callback is not valid.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
function setPowerMode(mode: DevicePowerMode): Promise<void>;
|
|
|
|
|
|
2023-06-26 11:25:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns true if the device is currently in idle mode.
|
|
|
|
|
*
|
|
|
|
|
* @returns { boolean } Returns true if the device is in idle mode; returns false otherwise.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 10
|
|
|
|
|
*/
|
|
|
|
|
function isStandby(): boolean;
|
|
|
|
|
|
2024-03-04 12:46:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* hibernate the device.
|
|
|
|
|
*
|
|
|
|
|
* @param { boolean } clearMemory indicates whether to clear the memory before the device hibernates.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 12
|
|
|
|
|
*/
|
|
|
|
|
function hibernate(clearMemory: boolean): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the timetout duration(ms) for turning off the screen.
|
|
|
|
|
*
|
|
|
|
|
* @param { number } timeout indicates duration(ms) for turning off the screen. The value -1 means restore the default value.
|
|
|
|
|
* @throws { BusinessError } 201 – If the permission is denied.
|
|
|
|
|
* @throws { BusinessError } 202 - If the system permission is denied.
|
|
|
|
|
* @throws { BusinessError } 4900101 - If connecting to the service failed.
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @systemapi
|
|
|
|
|
* @since 12
|
|
|
|
|
*/
|
|
|
|
|
function setScreenOffTime(timeout: number): void;
|
|
|
|
|
|
2023-03-21 08:00:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* Power mode of a device.
|
|
|
|
|
*
|
|
|
|
|
* @enum { number }
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
|
|
|
|
export enum DevicePowerMode {
|
2022-09-06 06:57:14 +00:00
|
|
|
|
/**
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* Normal power mode
|
2022-09-06 06:57:14 +00:00
|
|
|
|
*
|
2023-02-21 10:54:48 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
2022-09-06 06:57:14 +00:00
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
2023-03-21 08:00:55 +00:00
|
|
|
|
MODE_NORMAL = 600,
|
2022-09-06 06:57:14 +00:00
|
|
|
|
/**
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* Power save mode
|
2022-09-06 06:57:14 +00:00
|
|
|
|
*
|
2023-02-21 10:54:48 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
2022-09-06 06:57:14 +00:00
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
2023-03-21 08:00:55 +00:00
|
|
|
|
MODE_POWER_SAVE,
|
2022-09-06 06:57:14 +00:00
|
|
|
|
/**
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* Performance power mode
|
2022-09-06 06:57:14 +00:00
|
|
|
|
*
|
2023-02-21 10:54:48 +00:00
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
2022-09-06 06:57:14 +00:00
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
2023-03-21 08:00:55 +00:00
|
|
|
|
MODE_PERFORMANCE,
|
2022-09-06 06:57:14 +00:00
|
|
|
|
/**
|
2023-03-21 08:00:55 +00:00
|
|
|
|
* Extreme power save mode
|
2022-09-06 06:57:14 +00:00
|
|
|
|
*
|
|
|
|
|
* @syscap SystemCapability.PowerManager.PowerManager.Core
|
|
|
|
|
* @since 9
|
|
|
|
|
*/
|
2023-03-21 08:00:55 +00:00
|
|
|
|
MODE_EXTREME_POWER_SAVE
|
|
|
|
|
}
|
2021-08-17 11:55:25 +00:00
|
|
|
|
}
|
|
|
|
|
export default power;
|