1/* 2 * Copyright (c) 2025 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 BackgroundTasksKit 19 */ 20 21/** 22 * Declares the BackgroundProcessManager interfaces. 23 * 24 * @namespace backgroundProcessManager 25 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 26 * @since 17 27 */ 28declare namespace backgroundProcessManager { 29 /** 30 * Describes the level of BackgroundProcessManager priority. 31 * 32 * @enum { number } 33 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 34 * @since 17 35 */ 36 export enum ProcessPriority { 37 /** 38 * Means the process has stopped working and in the background 39 * 40 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 41 * @since 17 42 */ 43 PROCESS_BACKGROUND = 1, 44 45 /** 46 * Means the process is working in the background 47 * 48 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 49 * @since 17 50 */ 51 PROCESS_INACTIVE = 2, 52 } 53 54 /** 55 * Describes the status of the power saving mode. 56 * 57 * @enum { number } 58 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 59 * @since 20 60 */ 61 export enum PowerSaveMode { 62 /** 63 * Means the process request not to entry power saving mode 64 * This setting may be overridden by settings in Task Manager 65 * 66 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 67 * @since 20 68 */ 69 EFFICIENCY_MODE = 1, 70 71 /** 72 * Means the process operating mode follows the system and may entry power saving mode 73 * 74 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 75 * @since 20 76 */ 77 DEFAULT_MODE = 2, 78 } 79 80 /** 81 * Set the priority of process. 82 * 83 * @param { number } pid - Indicates the pid of the process to be set. 84 * @param { ProcessPriority } priority - Indicates the priority to set. Specific priority can be referenced ProcessPriority 85 * @returns { Promise<void> } The promise returned by the function. 86 * @throws { BusinessError } 401 - Parameter error. Possible causes: priority is out of range. 87 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 88 * @since 17 89 */ 90 function setProcessPriority(pid: number, priority: ProcessPriority): Promise<void>; 91 92 /** 93 * Reset the priority of process. 94 * 95 * @param { number } pid - Indicates the pid of the process to be reset. 96 * @returns { Promise<void> } The promise returned by the function. 97 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 98 * @since 17 99 */ 100 function resetProcessPriority(pid: number): Promise<void>; 101 102 /** 103 * Set the power saving mode of process. The setting may fail due to user setting reasons or 104 * <br> system scheduling reasons. 105 * 106 * @permission ohos.permission.BACKGROUND_MANAGER_POWER_SAVE_MODE 107 * @param { number } pid - Indicates the pid of the power saving mode to be set. 108 * @param { PowerSaveMode } powerSaveMode - Indicates the power saving mode that needs to be set. 109 * <br> For details, please refer to PowerSaveModeStatus. 110 * @returns { Promise<void> } The promise returned by the function. 111 * @throws { BusinessError } 201 - Permission denied. 112 * @throws { BusinessError } 31800002 - Parameter error. Possible causes: 113 * <br> 1. Mandatory parameters are left unspecified; 114 * <br> 2. Incorrect parameter types; 3. PowerSaveMode status is out of range. 115 * @throws { BusinessError } 31800003 - Setup error, This setting is overridden by setting in Task Manager. 116 * @throws { BusinessError } 31800004 - The setting failed due to system scheduling reasons. 117 * @throws { BusinessError } 801 - Capability not supported. 118 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 119 * @since 20 120 */ 121 function setPowerSaveMode(pid: number, powerSaveMode: PowerSaveMode): Promise<void>; 122 123 /** 124 * Check if the process is in power saving mode. 125 * 126 * @permission ohos.permission.BACKGROUND_MANAGER_POWER_SAVE_MODE 127 * @param { number } pid - Indicates the process to be checked is the pid of the power saving mode. 128 * @returns { Promise<boolean> } The promise returns whether it is in power saving mode. 129 * @throws { BusinessError } 201 - Permission denied. 130 * @throws { BusinessError } 31800002 - Parameter error. Possible causes: 131 * <br> 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 132 * @throws { BusinessError } 801 - Capability not supported. 133 * @syscap SystemCapability.Resourceschedule.BackgroundProcessManager 134 * @since 20 135 */ 136 function isPowerSaveMode(pid: number): Promise<boolean>; 137} 138 139export default backgroundProcessManager; 140