1# @ohos.enterprise.applicationManager (Application Management) (System API) 2 3The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module can be used only in the stage model. 10> 11> - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is [enabled](js-apis-enterprise-adminManager-sys.md#adminmanagerenableadmin-2). 12> 13> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.enterprise.applicationManager](js-apis-enterprise-applicationManager.md). 14 15## Modules to Import 16 17```ts 18import { applicationManager } from '@kit.MDMKit'; 19``` 20 21## applicationManager.addDisallowedRunningBundles 22 23addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 24 25Adds an application that is not allowed to run under the current user. This API uses an asynchronous callback to return the result. 26 27**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 28 29**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 30 31 32 33**Parameters** 34 35| Name | Type | Mandatory | Description | 36| -------- | ---------------------------------------- | ---- | ------------------------------- | 37| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 38| appIds | Array<string> | Yes | Application IDs. | 39| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 40 41**Error codes** 42 43For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 44 45| ID| Error Message | 46| ------- | ---------------------------------------------------------------------------- | 47| 9200001 | The application is not an administrator application of the device. | 48| 9200002 | The administrator application does not have permission to manage the device. | 49| 201 | Permission verification failed. The application does not have the permission required to call the API. | 50| 202 | Permission verification failed. A non-system application calls a system API. | 51| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 52 53 54**Example** 55 56```ts 57import { Want } from '@kit.AbilityKit'; 58 59let wantTemp: Want = { 60 bundleName: 'com.example.myapplication', 61 abilityName: 'EntryAbility', 62}; 63let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 64 65applicationManager.addDisallowedRunningBundles(wantTemp, appIds, (err) => { 66 if (err) { 67 console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 68 return; 69 } 70 console.info('Succeeded in adding disallowed running bundles'); 71}); 72``` 73 74## applicationManager.addDisallowedRunningBundles 75 76addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 77 78Adds an application that is not allowed to run under the current user (specified by userId). This API uses an asynchronous callback to return the result. 79 80**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 81 82**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 83 84 85 86**Parameters** 87 88| Name | Type | Mandatory | Description | 89| ----- | ----------------------------------- | ---- | ------- | 90| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 91| appIds | Array<string> | Yes | Application IDs. | 92| userId | number | Yes | User ID, which must be greater than or equal to 0.| 93| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 94 95**Error codes** 96 97For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 98 99| ID| Error Message | 100| ------- | ---------------------------------------------------------------------------- | 101| 9200001 | The application is not an administrator application of the device. | 102| 9200002 | The administrator application does not have permission to manage the device. | 103| 201 | Permission verification failed. The application does not have the permission required to call the API. | 104| 202 | Permission verification failed. A non-system application calls a system API. | 105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 106 107**Example** 108 109```ts 110import { Want } from '@kit.AbilityKit'; 111 112let wantTemp: Want = { 113 bundleName: 'com.example.myapplication', 114 abilityName: 'EntryAbility', 115}; 116let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 117 118applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100, (err) => { 119 if (err) { 120 console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 121 return; 122 } 123 console.info('Succeeded in adding disallowed running bundles'); 124}); 125``` 126 127## applicationManager.addDisallowedRunningBundles 128 129addDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 130 131Adds the applications that are not allowed to run by the current or specified user. This API uses a promise to return the result. 132 133**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 134 135**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 136 137 138 139**Parameters** 140 141| Name | Type | Mandatory | Description | 142| ----- | ----------------------------------- | ---- | ------- | 143| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 144| appIds | Array<string> | Yes | Application IDs. | 145| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.| 146 147**Return value** 148 149| Type | Description | 150| --------------------- | ------------------------- | 151| Promise<void> | Promise that returns no value. An error object is thrown when an application that is not allowed to run fails to be added. | 152 153**Error codes** 154 155For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 156 157| ID| Error Message | 158| ------- | ---------------------------------------------------------------------------- | 159| 9200001 | The application is not an administrator application of the device. | 160| 9200002 | The administrator application does not have permission to manage the device. | 161| 201 | Permission verification failed. The application does not have the permission required to call the API. | 162| 202 | Permission verification failed. A non-system application calls a system API. | 163| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 164 165**Example** 166 167```ts 168import { Want } from '@kit.AbilityKit'; 169import { BusinessError } from '@kit.BasicServicesKit'; 170 171let wantTemp: Want = { 172 bundleName: 'com.example.myapplication', 173 abilityName: 'EntryAbility', 174}; 175let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 176 177applicationManager.addDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { 178 console.info('Succeeded in adding disallowed running bundles'); 179}).catch((err: BusinessError) => { 180 console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 181}); 182``` 183 184## applicationManager.removeDisallowedRunningBundles 185 186removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, callback: AsyncCallback<void>): void 187 188Removes an application from the applications that are not allowed to run under the current user. This API uses an asynchronous callback to return the result. 189 190**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 191 192**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 193 194 195 196**Parameters** 197 198| Name | Type | Mandatory | Description | 199| -------- | ---------------------------------------- | ---- | ------------------------------- | 200| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 201| appIds | Array<string> | Yes | Application IDs. | 202| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 203 204**Error codes** 205 206For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 207 208| ID| Error Message | 209| ------- | ---------------------------------------------------------------------------- | 210| 9200001 | The application is not an administrator application of the device. | 211| 9200002 | The administrator application does not have permission to manage the device. | 212| 201 | Permission verification failed. The application does not have the permission required to call the API. | 213| 202 | Permission verification failed. A non-system application calls a system API. | 214| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 215 216**Example** 217 218```ts 219import { Want } from '@kit.AbilityKit'; 220 221let wantTemp: Want = { 222 bundleName: 'com.example.myapplication', 223 abilityName: 'EntryAbility', 224}; 225let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 226 227applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, (err) => { 228 if (err) { 229 console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 230 return; 231 } 232 console.info('Succeeded in removing disallowed running bundles'); 233}); 234``` 235 236## applicationManager.removeDisallowedRunningBundles 237 238removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId: number, callback: AsyncCallback<void>): void 239 240Removes an application from the applications that are not allowed to run under the current user. (specified by userId). This API uses an asynchronous callback to return the result. 241 242**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 243 244**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 245 246 247 248**Parameters** 249 250| Name | Type | Mandatory | Description | 251| ----- | ----------------------------------- | ---- | ------- | 252| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 253| appIds | Array<string> | Yes | Application IDs. | 254| userId | number | Yes | User ID, which must be greater than or equal to 0.| 255| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.| 256 257**Error codes** 258 259For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 260 261| ID| Error Message | 262| ------- | ---------------------------------------------------------------------------- | 263| 9200001 | The application is not an administrator application of the device. | 264| 9200002 | The administrator application does not have permission to manage the device. | 265| 201 | Permission verification failed. The application does not have the permission required to call the API. | 266| 202 | Permission verification failed. A non-system application calls a system API. | 267| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 268 269**Example** 270 271```ts 272import { Want } from '@kit.AbilityKit'; 273 274let wantTemp: Want = { 275 bundleName: 'com.example.myapplication', 276 abilityName: 'EntryAbility', 277}; 278let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 279 280applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100, (err) => { 281 if (err) { 282 console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 283 return; 284 } 285 console.info('Succeeded in removing disallowed running bundles'); 286}); 287``` 288 289## applicationManager.removeDisallowedRunningBundles 290 291removeDisallowedRunningBundles(admin: Want, appIds: Array\<string>, userId?: number): Promise<void> 292 293Removes an application from the applications that are not allowed to run under the current or specified user. This API uses a promise to return the result. 294 295**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 296 297**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 298 299 300 301**Parameters** 302 303| Name | Type | Mandatory | Description | 304| ----- | ----------------------------------- | ---- | ------- | 305| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 306| appIds | Array<string> | Yes | Application IDs. | 307| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.| 308 309**Return value** 310 311| Type | Description | 312| --------------------- | ------------------------- | 313| Promise<void> | Promise that returns no value. An error object is thrown when an application that is not allowed to run fails to be removed. | 314 315**Error codes** 316 317For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 318 319| ID| Error Message | 320| ------- | ---------------------------------------------------------------------------- | 321| 9200001 | The application is not an administrator application of the device. | 322| 9200002 | The administrator application does not have permission to manage the device. | 323| 201 | Permission verification failed. The application does not have the permission required to call the API. | 324| 202 | Permission verification failed. A non-system application calls a system API. | 325| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 326 327**Example** 328 329```ts 330import { Want } from '@kit.AbilityKit'; 331import { BusinessError } from '@kit.BasicServicesKit'; 332 333let wantTemp: Want = { 334 bundleName: 'com.example.myapplication', 335 abilityName: 'EntryAbility', 336}; 337let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 338 339applicationManager.removeDisallowedRunningBundles(wantTemp, appIds, 100).then(() => { 340 console.info('Succeeded in removing disallowed running bundles'); 341}).catch((err: BusinessError) => { 342 console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 343}); 344``` 345 346## applicationManager.getDisallowedRunningBundles 347 348getDisallowedRunningBundles(admin: Want, callback: AsyncCallback<Array<string>>): void 349 350Obtains the applications that are not allowed to run by the current user. This API uses an asynchronous callback to return the result. 351 352**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 353 354**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 355 356 357 358**Parameters** 359 360| Name | Type | Mandatory | Description | 361| -------- | ---------------------------------------- | ---- | ------------------------------- | 362| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 363| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 364 365**Error codes** 366 367For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 368 369| ID| Error Message | 370| ------- | ---------------------------------------------------------------------------- | 371| 9200001 | The application is not an administrator application of the device. | 372| 9200002 | The administrator application does not have permission to manage the device. | 373| 201 | Permission verification failed. The application does not have the permission required to call the API. | 374| 202 | Permission verification failed. A non-system application calls a system API. | 375| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 376 377**Example** 378 379```ts 380import { Want } from '@kit.AbilityKit'; 381 382let wantTemp: Want = { 383 bundleName: 'com.example.myapplication', 384 abilityName: 'EntryAbility', 385}; 386 387applicationManager.getDisallowedRunningBundles(wantTemp, (err, result) => { 388 if (err) { 389 console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 390 return; 391 } 392 console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`); 393}); 394``` 395 396## applicationManager.getDisallowedRunningBundles 397 398getDisallowedRunningBundles(admin: Want, userId: number, callback: AsyncCallback<Array<string>>): void 399 400Obtains an application from the applications that are not allowed to run by the current user (specified by userId). This API uses an asynchronous callback to return the result. 401 402**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 403 404**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 405 406 407 408**Parameters** 409 410| Name | Type | Mandatory | Description | 411| -------- | ---------------------------------------- | ---- | ------------------------------- | 412| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 413| userId | number | Yes | User ID, which must be greater than or equal to 0.| 414| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object. | 415 416**Error codes** 417 418For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 419 420| ID| Error Message | 421| ------- | ---------------------------------------------------------------------------- | 422| 9200001 | The application is not an administrator application of the device. | 423| 9200002 | The administrator application does not have permission to manage the device. | 424| 201 | Permission verification failed. The application does not have the permission required to call the API. | 425| 202 | Permission verification failed. A non-system application calls a system API. | 426| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 427 428**Example** 429 430```ts 431import { Want } from '@kit.AbilityKit'; 432 433let wantTemp: Want = { 434 bundleName: 'com.example.myapplication', 435 abilityName: 'EntryAbility', 436}; 437 438applicationManager.getDisallowedRunningBundles(wantTemp, 100, (err, result) => { 439 if (err) { 440 console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 441 return; 442 } 443 console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`); 444}); 445``` 446 447## applicationManager.getDisallowedRunningBundles 448 449getDisallowedRunningBundles(admin: Want, userId?: number): Promise<Array<string>> 450 451Obtains applications that are not allowed to run by the current user or a specified user. This API uses a promise to return the result. 452 453**Required permissions**: ohos.permission.ENTERPRISE_MANAGE_SET_APP_RUNNING_POLICY 454 455**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 456 457 458 459**Parameters** 460 461| Name | Type | Mandatory | Description | 462| ----- | ----------------------------------- | ---- | ------- | 463| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility.| 464| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, the applications cannot be run by the specified user.<br> - If **userId** is not passed in, the applications cannot be run by the current user.| 465 466**Return value** 467 468| Type | Description | 469| --------------------- | ------------------------- | 470| Promise<Array<string>> | Promise used to return the applications that are not allowed to run by the current user or a specified user.| 471 472**Error codes** 473 474For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 475 476| ID| Error Message | 477| ------- | ---------------------------------------------------------------------------- | 478| 9200001 | The application is not an administrator application of the device. | 479| 9200002 | The administrator application does not have permission to manage the device. | 480| 201 | Permission verification failed. The application does not have the permission required to call the API. | 481| 202 | Permission verification failed. A non-system application calls a system API. | 482| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 483 484**Example** 485 486```ts 487import { Want } from '@kit.AbilityKit'; 488import { BusinessError } from '@kit.BasicServicesKit'; 489 490let wantTemp: Want = { 491 bundleName: 'com.example.myapplication', 492 abilityName: 'EntryAbility', 493}; 494 495applicationManager.getDisallowedRunningBundles(wantTemp, 100).then((result) => { 496 console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`); 497}).catch((err: BusinessError) => { 498 console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`); 499}); 500``` 501