1/* 2 * Copyright (c) 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 } from './basic'; 17import * as _ApplicationStateObserver from './application/ApplicationStateObserver'; 18import * as _AbilityStateData from './application/AbilityStateData'; 19import * as _AppStateData from './application/AppStateData'; 20import { ProcessInformation as _ProcessInformation } from './application/ProcessInformation'; 21 22/** 23 * This module provides the function of app manager service. 24 * @namespace appManager 25 * @syscap SystemCapability.Ability.AbilityRuntime.Core 26 * @since 9 27 * 28 */ 29declare namespace appManager { 30 /** 31 * Enum for the application state 32 * @enum { number } 33 * @syscap SystemCapability.Ability.AbilityRuntime.Core 34 * @systemapi 35 * @since 9 36 */ 37 export enum ApplicationState { 38 STATE_CREATE, 39 STATE_FOREGROUND, 40 STATE_ACTIVE, 41 STATE_BACKGROUND, 42 STATE_DESTROY 43 } 44 45 /** 46 * Enum for the process state 47 * @enum { number } 48 * @syscap SystemCapability.Ability.AbilityRuntime.Core 49 * @systemapi 50 * @since 9 51 */ 52 export enum ProcessState { 53 STATE_CREATE, 54 STATE_FOREGROUND, 55 STATE_ACTIVE, 56 STATE_BACKGROUND, 57 STATE_DESTROY 58 } 59 60 /** 61 * Register application state observer. 62 * @permission ohos.permission.RUNNING_STATE_OBSERVER 63 * @param { string } type - applicationState. 64 * @param { ApplicationStateObserver } observer - The application state observer. 65 * @returns { number } Returns the number code of the observer. 66 * @throws { BusinessError } 201 - Permission denied. 67 * @throws { BusinessError } 202 - Not system application. 68 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 69 * @throws { BusinessError } 16000050 - Internal error. 70 * @syscap SystemCapability.Ability.AbilityRuntime.Core 71 * @systemapi 72 * @since 9 73 */ 74 function on(type: "applicationState", observer: ApplicationStateObserver): number; 75 76 /** 77 * Register application state observer. 78 * @permission ohos.permission.RUNNING_STATE_OBSERVER 79 * @param { string } type - applicationState. 80 * @param { ApplicationStateObserver } observer - The application state observer. 81 * @param { Array<string> } bundleNameList - The list of bundleName. The max length is 128. 82 * @returns { number } Returns the number code of the observer. 83 * @throws { BusinessError } 201 - Permission denied. 84 * @throws { BusinessError } 202 - Not system application. 85 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 86 * @throws { BusinessError } 16000050 - Internal error. 87 * @syscap SystemCapability.Ability.AbilityRuntime.Core 88 * @systemapi 89 * @since 9 90 */ 91 function on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList: Array<string>): number; 92 93 /** 94 * Unregister application state observer. 95 * @permission ohos.permission.RUNNING_STATE_OBSERVER 96 * @param { string } type - applicationState. 97 * @param { number } observerId - Indicates the number code of the observer. 98 * @param { AsyncCallback<void> } callback - The callback of off. 99 * @throws { BusinessError } 201 - Permission denied. 100 * @throws { BusinessError } 202 - Not system application. 101 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 102 * @throws { BusinessError } 16000050 - Internal error. 103 * @syscap SystemCapability.Ability.AbilityRuntime.Core 104 * @systemapi 105 * @since 9 106 */ 107 function off(type: "applicationState", observerId: number, callback: AsyncCallback<void>): void; 108 109 /** 110 * Unregister application state observer. 111 * @permission ohos.permission.RUNNING_STATE_OBSERVER 112 * @param { string } type - applicationState. 113 * @param { number } observerId - Indicates the number code of the observer. 114 * @returns { Promise<void> } The promise returned by the function. 115 * @throws { BusinessError } 201 - Permission denied. 116 * @throws { BusinessError } 202 - Not system application. 117 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 118 * @throws { BusinessError } 16000050 - Internal error. 119 * @syscap SystemCapability.Ability.AbilityRuntime.Core 120 * @systemapi 121 * @since 9 122 */ 123 function off(type: "applicationState", observerId: number): Promise<void>; 124 125 /** 126 * getForegroundApplications. 127 * @permission ohos.permission.GET_RUNNING_INFO 128 * @param { AsyncCallback<Array<AppStateData>> } callback - The callback is used to return the list of AppStateData. 129 * @throws { BusinessError } 201 - Permission denied. 130 * @throws { BusinessError } 202 - Not system application. 131 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 132 * @throws { BusinessError } 16000050 - Internal error. 133 * @syscap SystemCapability.Ability.AbilityRuntime.Core 134 * @systemapi 135 * @since 9 136 */ 137 function getForegroundApplications(callback: AsyncCallback<Array<AppStateData>>): void; 138 139 /** 140 * getForegroundApplications. 141 * @permission ohos.permission.GET_RUNNING_INFO 142 * @returns { Promise<Array<AppStateData>> } Returns the list of AppStateData. 143 * @throws { BusinessError } 201 - Permission denied. 144 * @throws { BusinessError } 202 - Not system application. 145 * @throws { BusinessError } 16000050 - Internal error. 146 * @syscap SystemCapability.Ability.AbilityRuntime.Core 147 * @systemapi 148 * @since 9 149 */ 150 function getForegroundApplications(): Promise<Array<AppStateData>>; 151 152 /** 153 * Kill process with account. 154 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 155 * @param { string } bundleName - The process bundle name. 156 * @param { number } accountId - The account id. 157 * @returns { Promise<void> } The promise returned by the function. 158 * @throws { BusinessError } 201 - Permission denied. 159 * @throws { BusinessError } 202 - Not system application. 160 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 161 * @throws { BusinessError } 16000050 - Internal error. 162 * @syscap SystemCapability.Ability.AbilityRuntime.Core 163 * @systemapi 164 * @since 9 165 */ 166 function killProcessWithAccount(bundleName: string, accountId: number): Promise<void>; 167 168 /** 169 * Kill process with account. 170 * @permission ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS and ohos.permission.CLEAN_BACKGROUND_PROCESSES 171 * @param { string } bundleName - The process bundle name. 172 * @param { number } accountId - The account id. 173 * @param { AsyncCallback<void> } callback - The callback of killProcessWithAccount. 174 * @throws { BusinessError } 201 - Permission denied. 175 * @throws { BusinessError } 202 - Not system application. 176 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 177 * @throws { BusinessError } 16000050 - Internal error. 178 * @syscap SystemCapability.Ability.AbilityRuntime.Core 179 * @systemapi 180 * @since 9 181 */ 182 function killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCallback<void>): void; 183 184 /** 185 * Is user running in stability test. 186 * @param { AsyncCallback<boolean> } callback - The callback is used to return true if user is running stability test. 187 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 188 * @throws { BusinessError } 16000050 - Internal error. 189 * @syscap SystemCapability.Ability.AbilityRuntime.Core 190 * @since 9 191 */ 192 function isRunningInStabilityTest(callback: AsyncCallback<boolean>): void; 193 194 /** 195 * Is user running in stability test. 196 * @returns { Promise<boolean> } Returns true if user is running stability test. 197 * @throws { BusinessError } 16000050 - Internal error. 198 * @syscap SystemCapability.Ability.AbilityRuntime.Core 199 * @since 9 200 */ 201 function isRunningInStabilityTest(): Promise<boolean>; 202 203 /** 204 * Kill processes by bundle name 205 * @permission ohos.permission.CLEAN_BACKGROUND_PROCESSES 206 * @param { string } bundleName - bundle name. 207 * @returns { Promise<void> } The promise returned by the function. 208 * @throws { BusinessError } 201 - Permission denied. 209 * @throws { BusinessError } 202 - Not system application. 210 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 211 * @throws { BusinessError } 16000050 - Internal error. 212 * @syscap SystemCapability.Ability.AbilityRuntime.Core 213 * @systemapi 214 * @since 9 215 */ 216 function killProcessesByBundleName(bundleName: string): Promise<void>; 217 218 /** 219 * Kill processes by bundle name 220 * @permission ohos.permission.CLEAN_BACKGROUND_PROCESSES 221 * @param { string } bundleName - bundle name. 222 * @param { AsyncCallback<void> } callback - The callback of killProcessesByBundleName. 223 * @throws { BusinessError } 201 - Permission denied. 224 * @throws { BusinessError } 202 - Not system application. 225 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 226 * @throws { BusinessError } 16000050 - Internal error. 227 * @syscap SystemCapability.Ability.AbilityRuntime.Core 228 * @systemapi 229 * @since 9 230 */ 231 function killProcessesByBundleName(bundleName: string, callback: AsyncCallback<void>); 232 233 /** 234 * Clear up application data by bundle name 235 * @permission ohos.permission.CLEAN_APPLICATION_DATA 236 * @param { string } bundleName - bundle name. 237 * @returns { Promise<void> } The promise returned by the function. 238 * @throws { BusinessError } 201 - Permission denied. 239 * @throws { BusinessError } 202 - Not system application. 240 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 241 * @throws { BusinessError } 16000050 - Internal error. 242 * @syscap SystemCapability.Ability.AbilityRuntime.Core 243 * @systemapi 244 * @since 9 245 */ 246 function clearUpApplicationData(bundleName: string): Promise<void>; 247 248 /** 249 * Clear up application data by bundle name 250 * @permission ohos.permission.CLEAN_APPLICATION_DATA 251 * @param { string } bundleName - bundle name. 252 * @param { AsyncCallback<void> } callback - The callback of clearUpApplicationData. 253 * @throws { BusinessError } 201 - Permission denied. 254 * @throws { BusinessError } 202 - Not system application. 255 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 256 * @throws { BusinessError } 16000050 - Internal error. 257 * @syscap SystemCapability.Ability.AbilityRuntime.Core 258 * @systemapi 259 * @since 9 260 */ 261 function clearUpApplicationData(bundleName: string, callback: AsyncCallback<void>); 262 263 /** 264 * Is it a ram-constrained device 265 * @returns { Promise<boolean> } Returns true if the device is ram-constrained. 266 * @throws { BusinessError } 16000050 - Internal error. 267 * @syscap SystemCapability.Ability.AbilityRuntime.Core 268 * @since 9 269 */ 270 function isRamConstrainedDevice(): Promise<boolean>; 271 272 /** 273 * Is it a ram-constrained device 274 * @param { AsyncCallback<boolean> } callback - The callback is used to return true if the device is ram-constrained. 275 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 276 * @throws { BusinessError } 16000050 - Internal error. 277 * @syscap SystemCapability.Ability.AbilityRuntime.Core 278 * @since 9 279 */ 280 function isRamConstrainedDevice(callback: AsyncCallback<boolean>): void; 281 282 /** 283 * Get the memory size of the application 284 * @returns { Promise<number> } Returns the application memory size. 285 * @throws { BusinessError } 16000050 - Internal error. 286 * @syscap SystemCapability.Ability.AbilityRuntime.Core 287 * @since 9 288 */ 289 function getAppMemorySize(): Promise<number>; 290 291 /** 292 * Get the memory size of the application 293 * @param { AsyncCallback<number> } callback - The callback is used to return the application memory size. 294 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 295 * @throws { BusinessError } 16000050 - Internal error. 296 * @syscap SystemCapability.Ability.AbilityRuntime.Core 297 * @since 9 298 */ 299 function getAppMemorySize(callback: AsyncCallback<number>): void; 300 301 /** 302 * If you apply for permission, you can obtain information about all running processes. If you do not apply, you can only obtain information about the current process. 303 * @permission ohos.permission.GET_RUNNING_INFO 304 * @returns { Promise<Array<ProcessInformation>> } Returns the array of {@link ProcessInformation}. 305 * @throws { BusinessError } 16000050 - Internal error. 306 * @syscap SystemCapability.Ability.AbilityRuntime.Core 307 * @since 9 308 */ 309 function getRunningProcessInformation(): Promise<Array<ProcessInformation>>; 310 311 /** 312 * If you apply for permission, you can obtain information about all running processes. If you do not apply, you can only obtain information about the current process. 313 * @permission ohos.permission.GET_RUNNING_INFO 314 * @param { AsyncCallback<Array<ProcessInformation>> } callback - The callback is used to return the array of {@link ProcessInformation}. 315 * @throws { BusinessError } 401 - If the input parameter is not valid parameter. 316 * @throws { BusinessError } 16000050 - Internal error. 317 * @syscap SystemCapability.Ability.AbilityRuntime.Core 318 * @since 9 319 */ 320 function getRunningProcessInformation(callback: AsyncCallback<Array<ProcessInformation>>): void; 321 322 /** 323 * The ability or extension state data. 324 * @syscap SystemCapability.Ability.AbilityRuntime.Core 325 * @systemapi 326 * @since 9 327 */ 328 export type AbilityStateData = _AbilityStateData.default 329 330 /** 331 * The application state data. 332 * @syscap SystemCapability.Ability.AbilityRuntime.Core 333 * @systemapi 334 * @since 9 335 */ 336 export type AppStateData = _AppStateData.default 337 338 /** 339 * The application state observer. 340 * @syscap SystemCapability.Ability.AbilityRuntime.Core 341 * @systemapi 342 * @since 9 343 */ 344 export type ApplicationStateObserver = _ApplicationStateObserver.default 345 346 /** 347 * The class of a process information. 348 * @syscap SystemCapability.Ability.AbilityRuntime.Core 349 * @since 9 350 */ 351 export type ProcessInformation = _ProcessInformation 352} 353 354export default appManager; 355