1# @ohos.enterprise.bundleManager (Bundle Management) 2 3The **bundleManager** module provides APIs for bundle management, including adding, obtaining, and removing a list of bundles that are allowed to install. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 12. 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 that is enabled. For details, see [MDM Kit Development](../../mdm/mdm-kit-guide.md). 12 13## Modules to Import 14 15```ts 16import { bundleManager } from '@kit.MDMKit'; 17``` 18 19## bundleManager.addAllowedInstallBundlesSync 20 21addAllowedInstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 22 23Adds the applications that can be installed by the current or specified user. 24 25**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 26 27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 28 29 30**Parameters** 31 32| Name | Type | Mandatory| Description | 33| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 34| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 35| appIds | Array<string> | Yes | IDs of the applications to add. | 36| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 37 38**Error codes** 39 40For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 41 42| ID| Error Message | 43| -------- | ------------------------------------------------------------ | 44| 9200001 | The application is not an administrator application of the device. | 45| 9200002 | The administrator application does not have permission to manage the device. | 46| 201 | Permission verification failed. The application does not have the permission required to call the API. | 47| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 48 49**Example** 50 51```ts 52import { Want } from '@kit.AbilityKit'; 53import { BusinessError } from '@kit.BasicServicesKit'; 54 55let wantTemp: Want = { 56 bundleName: 'com.example.myapplication', 57 abilityName: 'EntryAbility', 58}; 59let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 60 61try { 62 bundleManager.addAllowedInstallBundlesSync(wantTemp, appIds, 100); 63 console.info('Succeeded in adding allowed install bundles.'); 64} catch (err) { 65 console.error(`Failed to add allowed install bundles. Code is ${err.code}, message is ${err.message}`); 66} 67``` 68 69## bundleManager.removeAllowedInstallBundlesSync 70 71removeAllowedInstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 72 73Removes the applications that can be installed by the current or specified user. 74 75**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 76 77**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 78 79 80**Parameters** 81 82| Name | Type | Mandatory| Description | 83| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 84| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 85| appIds | Array<string> | Yes | IDs of the applications to add. | 86| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 87 88**Error codes** 89 90For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 91 92| ID| Error Message | 93| -------- | ------------------------------------------------------------ | 94| 9200001 | The application is not an administrator application of the device. | 95| 9200002 | The administrator application does not have permission to manage the device. | 96| 201 | Permission verification failed. The application does not have the permission required to call the API. | 97| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 98 99**Example** 100 101```ts 102import { Want } from '@kit.AbilityKit'; 103import { BusinessError } from '@kit.BasicServicesKit'; 104 105let wantTemp: Want = { 106 bundleName: 'com.example.myapplication', 107 abilityName: 'EntryAbility', 108}; 109let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 110 111try { 112 bundleManager.removeAllowedInstallBundlesSync(wantTemp, appIds, 100); 113 console.info('Succeeded in removing allowed install bundles.'); 114} catch (err) { 115 console.error(`Failed to remove allowed install bundles. Code is ${err.code}, message is ${err.message}`); 116} 117``` 118 119## bundleManager.getAllowedInstallBundlesSync 120 121getAllowedInstallBundlesSync(admin: Want, accountId?: number): Array<string> 122 123Obtains the applications that can be installed by the current or specified user. 124 125**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 126 127**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 128 129 130**Parameters** 131 132| Name | Type | Mandatory| Description | 133| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 134| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 135| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 136 137**Return value** 138 139| Type | Description | 140| ------------------- | ------------------------------ | 141| Array<string> | Applications that can be installed.| 142 143**Error codes** 144 145For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 146 147| ID| Error Message | 148| -------- | ------------------------------------------------------------ | 149| 9200001 | The application is not an administrator application of the device. | 150| 9200002 | The administrator application does not have permission to manage the device. | 151| 201 | Permission verification failed. The application does not have the permission required to call the API. | 152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 153 154**Example** 155 156```ts 157import { Want } from '@kit.AbilityKit'; 158 159let wantTemp: Want = { 160 bundleName: 'com.example.myapplication', 161 abilityName: 'EntryAbility', 162}; 163 164try { 165 let result: Array<string> = bundleManager.getAllowedInstallBundlesSync(wantTemp, 100); 166 console.info(`Succeeded in getting allowed install bundles, result : ${JSON.stringify(result)}`); 167} catch (err) { 168 console.error(`Failed to get allowed install bundles. Code is ${err.code}, message is ${err.message}`); 169} 170``` 171 172## bundleManager.addDisallowedInstallBundlesSync 173 174addDisallowedInstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 175 176Adds the applications that cannot be installed by the current or specified user. 177 178**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 179 180**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 181 182**Parameters** 183 184| Name | Type | Mandatory| Description | 185| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 186| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 187| appIds | Array<string> | Yes | IDs of the applications to add. | 188| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 189 190**Error codes** 191 192For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 193 194| ID| Error Message | 195| -------- | ------------------------------------------------------------ | 196| 9200001 | The application is not an administrator application of the device. | 197| 9200002 | The administrator application does not have permission to manage the device. | 198| 201 | Permission verification failed. The application does not have the permission required to call the API. | 199| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 200 201**Example** 202 203```ts 204import { Want } from '@kit.AbilityKit'; 205import { BusinessError } from '@kit.BasicServicesKit'; 206 207let wantTemp: Want = { 208 bundleName: 'com.example.myapplication', 209 abilityName: 'EntryAbility', 210}; 211let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 212 213try { 214 bundleManager.addDisallowedInstallBundlesSync(wantTemp, appIds, 100); 215 console.info('Succeeded in adding disallowed install bundles.'); 216} catch (err) { 217 console.error(`Failed to add disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 218} 219``` 220 221## bundleManager.removeDisallowedInstallBundlesSync 222 223removeDisallowedInstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 224 225Removes the applications that cannot be installed by the current or specified user. 226 227**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 228 229**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 230 231**Parameters** 232 233| Name | Type | Mandatory| Description | 234| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 235| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 236| appIds | Array<string> | Yes | IDs of the applications to add. | 237| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 238 239**Error codes** 240 241For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 242 243| ID| Error Message | 244| -------- | ------------------------------------------------------------ | 245| 9200001 | The application is not an administrator application of the device. | 246| 9200002 | The administrator application does not have permission to manage the device. | 247| 201 | Permission verification failed. The application does not have the permission required to call the API. | 248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 249 250**Example** 251 252```ts 253import { Want } from '@kit.AbilityKit'; 254import { BusinessError } from '@kit.BasicServicesKit'; 255 256let wantTemp: Want = { 257 bundleName: 'com.example.myapplication', 258 abilityName: 'EntryAbility', 259}; 260let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 261 262try { 263 bundleManager.removeDisallowedInstallBundlesSync(wantTemp, appIds, 100) 264 console.info('Succeeded in removing disallowed install bundles.'); 265} catch (err) { 266 console.error(`Failed to remove disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 267} 268``` 269 270## bundleManager.getDisallowedInstallBundlesSync 271 272getDisallowedInstallBundlesSync(admin: Want, accountId?: number): Array<string> 273 274Obtains the applications that cannot be installed by the current or specified user. 275 276**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 277 278**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 279 280 281**Parameters** 282 283| Name | Type | Mandatory| Description | 284| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 285| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 286| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 287 288**Return value** 289 290| Type | Description | 291| ------------------- | ------------------------------ | 292| Array<string> | Applications that cannot be installed.| 293 294**Error codes** 295 296For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 297 298| ID| Error Message | 299| -------- | ------------------------------------------------------------ | 300| 9200001 | The application is not an administrator application of the device. | 301| 9200002 | The administrator application does not have permission to manage the device. | 302| 201 | Permission verification failed. The application does not have the permission required to call the API. | 303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 304 305**Example** 306 307```ts 308import { Want } from '@kit.AbilityKit'; 309 310let wantTemp: Want = { 311 bundleName: 'com.example.myapplication', 312 abilityName: 'EntryAbility', 313}; 314 315try { 316 let result: Array<string> = bundleManager.getDisallowedInstallBundlesSync(wantTemp, 100); 317 console.info(`Succeeded in getting disallowed install bundles, result : ${JSON.stringify(result)}`); 318} catch (err) { 319 console.error(`Failed to get disallowed install bundles. Code is ${err.code}, message is ${err.message}`); 320} 321``` 322 323## bundleManager.addDisallowedUninstallBundlesSync 324 325addDisallowedUninstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 326 327Adds the applications that cannot be uninstalled by the current or specified user. 328 329**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 330 331**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 332 333 334**Parameters** 335 336| Name | Type | Mandatory| Description | 337| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 338| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 339| appIds | Array<string> | Yes | IDs of the applications to add. | 340| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 341 342**Error codes** 343 344For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 345 346| ID| Error Message | 347| -------- | ------------------------------------------------------------ | 348| 9200001 | The application is not an administrator application of the device. | 349| 9200002 | The administrator application does not have permission to manage the device. | 350| 201 | Permission verification failed. The application does not have the permission required to call the API. | 351| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 352 353**Example** 354 355```ts 356import { Want } from '@kit.AbilityKit'; 357 358let wantTemp: Want = { 359 bundleName: 'com.example.myapplication', 360 abilityName: 'EntryAbility', 361}; 362let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 363 364try { 365 bundleManager.addDisallowedUninstallBundlesSync(wantTemp, appIds, 100); 366 console.info('Succeeded in adding disallowed uninstall bundles.'); 367} catch (err) { 368 console.error(`Failed to add disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 369} 370``` 371 372## bundleManager.removeDisallowedUninstallBundlesSync 373 374removeDisallowedUninstallBundlesSync(admin: Want, appIds: Array<string>, accountId?: number): void 375 376Removes the applications that cannot be uninstalled by the current or specified user through the specified device administrator application. 377 378**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 379 380**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 381 382 383**Parameters** 384 385| Name | Type | Mandatory| Description | 386| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 387| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 388| appIds | Array<string> | Yes | IDs of the applications to add. | 389| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 390 391**Error codes** 392 393For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 394 395| ID| Error Message | 396| -------- | ------------------------------------------------------------ | 397| 9200001 | The application is not an administrator application of the device. | 398| 9200002 | The administrator application does not have permission to manage the device. | 399| 201 | Permission verification failed. The application does not have the permission required to call the API. | 400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 401 402**Example** 403 404```ts 405import { Want } from '@kit.AbilityKit'; 406 407let wantTemp: Want = { 408 bundleName: 'com.example.myapplication', 409 abilityName: 'EntryAbility', 410}; 411let appIds: Array<string> = ['com.example.******_******/******5t5CoBM=']; 412 413try { 414 bundleManager.removeDisallowedUninstallBundlesSync(wantTemp, appIds, 100); 415 console.info('Succeeded in removing disallowed uninstall bundles.'); 416} catch (err) { 417 console.error(`Failed to remove disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 418} 419``` 420 421## bundleManager.getDisallowedUninstallBundlesSync 422 423getDisallowedUninstallBundlesSync(admin: Want, accountId?: number): Array<string> 424 425Obtains the applications that cannot be uninstalled by the current or specified user. 426 427**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 428 429**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 430 431 432**Parameters** 433 434| Name | Type | Mandatory| Description | 435| --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 436| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 437| accountId | number | No | User ID, which must be greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of **@ohos.account.osAccount** to obtain the user ID.<br> - If **accountId** is passed in, this API applies to the specified user.<br> - If **accountId** is not passed in, this API applies to the current user.| 438 439**Return value** 440 441| Type | Description | 442| ------------------- | ------------------------------ | 443| Array<string> | Applications that cannot be uninstalled by the user.| 444 445**Error codes** 446 447For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 448 449| ID| Error Message | 450| -------- | ------------------------------------------------------------ | 451| 9200001 | The application is not an administrator application of the device. | 452| 9200002 | The administrator application does not have permission to manage the device. | 453| 201 | Permission verification failed. The application does not have the permission required to call the API. | 454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 455 456**Example** 457 458```ts 459import { Want } from '@kit.AbilityKit'; 460 461let wantTemp: Want = { 462 bundleName: 'com.example.myapplication', 463 abilityName: 'EntryAbility', 464}; 465 466try { 467 let result: Array<String> = bundleManager.getDisallowedUninstallBundlesSync(wantTemp, 100); 468 console.info(`Succeeded in getting disallowed uninstall bundles, result : ${JSON.stringify(result)}`); 469} catch (err) { 470 console.error(`Failed to get disallowed uninstall bundles. Code is ${err.code}, message is ${err.message}`); 471} 472``` 473 474## bundleManager.uninstall 475 476uninstall(admin: Want, bundleName: string, userId?: number, isKeepData?: boolean): Promise<void> 477 478Uninstalls an application of the current or specified user. The **isKeepData** parameter specifies whether to retain the bundle data. This API uses a promise to return the result. 479 480**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE 481 482**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 483 484 485**Parameters** 486 487| Name | Type | Mandatory| Description | 488| ---------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 489| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 490| bundleName | string | Yes | Name of the bundle to uninstall. | 491| userId | number | No | User ID, which must be greater than or equal to 0.<br> - If **userId** is passed in, this API applies to the specified user.<br> - If **userId** is not passed in, this API applies to the current user.| 492| isKeepData | boolean | No | Whether to retain the bundle data. The value **true** means to retain the bundle data; the value **false** means the opposite. | 493 494**Return value** 495 496| Type | Description | 497| ------------------- | ----------------------------------------------------- | 498| Promise<void> | Promise that returns no value. An error object will be thrown if the application fails to be uninstalled.| 499 500**Error codes** 501 502For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 503 504| ID| Error Message | 505| -------- | ------------------------------------------------------------ | 506| 9200001 | The application is not an administrator application of the device. | 507| 9200002 | The administrator application does not have permission to manage the device. | 508| 201 | Permission verification failed. The application does not have the permission required to call the API. | 509| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 510 511**Example** 512 513```ts 514import { Want } from '@kit.AbilityKit'; 515import { BusinessError } from '@kit.BasicServicesKit'; 516 517let wantTemp: Want = { 518 bundleName: 'com.example.myapplication', 519 abilityName: 'EntryAbility', 520}; 521 522bundleManager.uninstall(wantTemp, 'bundleName', 100, true).then(() => { 523 console.info('Succeeded in uninstalling bundles.'); 524}).catch((err: BusinessError) => { 525 console.error(`Failed to uninstall bundles. Code is ${err.code}, message is ${err.message}`); 526}); 527``` 528 529## bundleManager.install 530 531install(admin: Want, hapFilePaths: Array\<string>, installParam?: InstallParam): Promise\<void> 532 533Installs specified applications. This API uses a promise to return the result.<br>The distribution type of the application can only be **enterprise_mdm** or **enterprise_normal**. 534 535**Required permissions**: ohos.permission.ENTERPRISE_INSTALL_BUNDLE 536 537**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 538 539**Parameters** 540 541| Name | Type | Mandatory| Description | 542| ------------ | ------------------------------------------------------- | ---- | ---------------------- | 543| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 544| hapFilePaths | Array\<string> | Yes | Applications to install.| 545| installParam | [InstallParam](#installparam) | No | Application installation parameters. | 546 547**Return value** 548 549| Type | Description | 550| ------------------- | ------------------------------------------------------- | 551| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.| 552 553**Error codes** 554 555For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 556 557| ID| Error Message | 558| -------- | ------------------------------------------------------------ | 559| 9200001 | The application is not an administrator application of the device. | 560| 9200002 | The administrator application does not have permission to manage the device. | 561| 9201002 | Failed to install the application. | 562| 201 | Permission verification failed. The application does not have the permission required to call the API. | 563| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 564 565**Example** 566 567```ts 568import { Want } from '@kit.AbilityKit'; 569import { BusinessError } from '@kit.BasicServicesKit'; 570 571// Install the application for the current user. 572let wantTemp: Want = { 573 bundleName: 'com.example.myapplication', 574 abilityName: 'EntryAbility', 575}; 576let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']; 577 578bundleManager.install(wantTemp, hapFilePaths).then(() => { 579 console.info('Succeeded in installing bundles.'); 580}).catch((err: BusinessError) => { 581 console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`); 582}); 583``` 584 585```ts 586import { Want } from '@kit.AbilityKit'; 587import { BusinessError } from '@kit.BasicServicesKit'; 588 589// Install the application for all users. 590let wantTemp: Want = { 591 bundleName: 'com.example.myapplication', 592 abilityName: 'EntryAbility', 593}; 594let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/testinstall/ExtensionTest.hap']; 595const params: Record<string, string> = { 596 'ohos.bms.param.enterpriseForAllUser': 'true' 597}; 598let installParam: bundleManager.InstallParam = { 599 userId: 100, 600 installFlag: 0, 601 parameters: params 602}; 603bundleManager.install(wantTemp, hapFilePaths, installParam).then(() => { 604 console.info('Succeeded in installing bundles.'); 605}).catch((err: BusinessError) => { 606 console.error(`Failed to install bundles. Code is ${err.code}, message is ${err.message}`); 607}); 608``` 609 610## bundleManager.getInstalledBundleList<sup>20+</sup> 611 612getInstalledBundleList(admin: Want, accountId: number): Promise\<Array\<BundleInfo>> 613 614Obtains the applications installed by a specified user on a device. This API uses a promise to return the result. 615 616**Required permissions**: ohos.permission.ENTERPRISE_GET_ALL_BUNDLE_INFO 617 618**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 619 620**Parameters** 621 622| Name | Type | Mandatory| Description | 623| ------------ | ------------------------------------------------------- | ---- | ---------------------- | 624| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 625| accountId | number | Yes | User ID. The value is a positive integer greater than or equal to 0.<br> You can call [getOsAccountLocalId](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9-1) of @ohos.account.osAccount to obtain the user ID.| 626 627**Return value** 628 629| Type | Description | 630| ------------------- | ------------------------------------------------------- | 631| Promise<Array<[BundleInfo](#bundleinfo20)>> | Promise used to return the bundle information of the installed application.| 632 633**Error codes** 634 635For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 636 637| ID| Error Message | 638| -------- | ------------------------------------------------------------ | 639| 9200001 | The application is not an administrator application of the device. | 640| 9200002 | The administrator application does not have permission to manage the device. | | 641| 201 | Permission verification failed. The application does not have the permission required to call the API. | 642 643**Example** 644 645```ts 646import { Want } from '@kit.AbilityKit'; 647import { BusinessError } from '@kit.BasicServicesKit'; 648import { bundleManager } from '@kit.MDMKit'; 649 650let wantTemp: Want = { 651 bundleName: 'com.example.myapplication', 652 abilityName: 'EntryAbility', 653}; 654let accountId: number = 100; 655bundleManager.getInstalledBundleList(wantTemp, accountId).then((result) => { 656 console.info('Succeeded in getting installed bundle list.'); 657}).catch((err: BusinessError) => { 658 console.error(`Failed to get installed bundle list. Code is ${err.code}, message is ${err.message}`); 659}); 660``` 661 662## InstallParam 663 664Defines the parameters for application installation. 665 666**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 667 668| Name | Type | Read-Only| Optional| Description | 669| ------------------------ | ---------------------- | ---- | ---- | ------------------------------------------------------------ | 670| userId | number | No | Yes| User ID, which must be greater than or equal to 0. The default value is the user ID of the caller. | 671| installFlag | number | No | Yes|Installation flag.<br> - **0**: initial installation.<br>- **1**: overwrite installation.<br>- **2**: installation-free.<br>Default value: **0**| 672| parameters<sup>19+</sup> | Record<string, string> | No | Yes| Extended parameters. The default value is null. The key value can be **ohos.bms.param.enterpriseForAllUser**. If the value is **true**, the application is installed for all users.| 673 674## bundleManager.addInstallationAllowedAppDistributionTypes<sup>20+</sup> 675 676addInstallationAllowedAppDistributionTypes(admin: Want, appDistributionTypes: Array<AppDistributionType>): void 677 678Adds the distribution type of the application that can be installed. Only applications of the distribution type that is added to [AppDistributionType](#appdistributiontype20) can be installed on the current device.<br> 679For details about the distribution type of the application signing certificate, refer to the **appDistributionType** attribute in [ApplicationInfo](../apis-ability-kit/js-apis-bundleManager-applicationInfo.md#applicationinfo-1). 680 681**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 682 683**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 684 685**Parameters** 686 687| Name | Type | Mandatory| Description | 688| ------------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 689| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 690| appDistributionTypes | Array<[AppDistributionType](#appdistributiontype20)> | Yes | Distribution types of the application signing certificate.| 691 692**Error codes** 693 694For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 695 696| ID| Error Message | 697| -------- | ------------------------------------------------------------ | 698| 9200001 | The application is not an administrator application of the device. | 699| 9200002 | The administrator application does not have permission to manage the device. | | 700| 201 | Permission verification failed. The application does not have the permission required to call the API. | 701 702**Example** 703 704```ts 705import { Want } from '@kit.AbilityKit'; 706import { BusinessError } from '@kit.BasicServicesKit'; 707import { bundleManager } from '@kit.MDMKit'; 708 709let wantTemp: Want = { 710 // Replace it as required. 711 bundleName: 'com.example.myapplication', 712 abilityName: 'EntryAbility' 713}; 714try { 715 let appDistributionTypes: Array<bundleManager.AppDistributionType> = [bundleManager.AppDistributionType.APP_GALLERY]; 716 bundleManager.addInstallationAllowedAppDistributionTypes(wantTemp, appDistributionTypes); 717 console.info('Succeeded in adding allowed appDistributionTypes.'); 718} catch (err) { 719 console.error(`Failed to add allowed appDistributionTypes. Code: ${err.code}, message: ${err.message}`); 720} 721``` 722 723## bundleManager.removeInstallationAllowedAppDistributionTypes<sup>20+</sup> 724 725removeInstallationAllowedAppDistributionTypes(admin: Want, appDistributionTypes: Array<AppDistributionType>): void 726 727Removes the distribution type of an application. If only some distribution types in the array are removed, the current device can install applications of the remaining distribution types in the array, but cannot install applications of the distribution types not included in [AppDistributionType](#appdistributiontype20).<br> 728For details about the distribution type of the application signing certificate, refer to the **appDistributionType** attribute in [ApplicationInfo](../apis-ability-kit/js-apis-bundleManager-applicationInfo.md#applicationinfo-1). 729 730**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 731 732**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 733 734**Parameters** 735 736| Name | Type | Mandatory| Description | 737| ------------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 738| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 739| appDistributionTypes | Array<[AppDistributionType](#appdistributiontype20)> | Yes| Distribution types of the application signing certificate.| 740 741**Error codes** 742 743For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 744 745| ID| Error Message | 746| -------- | ------------------------------------------------------------ | 747| 9200001 | The application is not an administrator application of the device. | 748| 9200002 | The administrator application does not have permission to manage the device. | | 749| 201 | Permission verification failed. The application does not have the permission required to call the API. | 750 751**Example** 752 753```ts 754import { Want } from '@kit.AbilityKit'; 755import { BusinessError } from '@kit.BasicServicesKit'; 756import { bundleManager } from '@kit.MDMKit'; 757 758let wantTemp: Want = { 759 // Replace it as required. 760 bundleName: 'com.example.myapplication', 761 abilityName: 'EntryAbility' 762}; 763try { 764 let appDistributionTypes: Array<bundleManager.AppDistributionType> = [bundleManager.AppDistributionType.APP_GALLERY]; 765 bundleManager.removeInstallationAllowedAppDistributionTypes(wantTemp, appDistributionTypes); 766 console.info('Succeeded in removing allowed appDistributionTypes.'); 767} catch (err) { 768 console.error(`Failed to remove allowed appDistributionTypes. Code: ${err.code}, message: ${err.message}`); 769} 770``` 771 772## bundleManager.getInstallationAllowedAppDistributionTypes<sup>20+</sup> 773 774getInstallationAllowedAppDistributionTypes(admin: Want): Array<AppDistributionType> 775 776Obtains the distribution type of the signing certificate used by applications that can be installed. 777 778**Required permissions**: ohos.permission.ENTERPRISE_SET_BUNDLE_INSTALL_POLICY 779 780**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 781 782**Parameters** 783 784| Name | Type | Mandatory| Description | 785| ------------ | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 786| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | EnterpriseAdminExtensionAbility. | 787 788**Return value** 789 790| Type | Description | 791| ---------------------------------- | ------------------------- | 792| Array<[AppDistributionType](#appdistributiontype20)> | Distribution types of the application signing certificate.| 793 794**Error codes** 795 796For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). 797 798| ID| Error Message | 799| -------- | ------------------------------------------------------------ | 800| 9200001 | The application is not an administrator application of the device. | 801| 9200002 | The administrator application does not have permission to manage the device. | | 802| 201 | Permission verification failed. The application does not have the permission required to call the API. | 803 804**Example** 805 806```ts 807import { Want } from '@kit.AbilityKit'; 808import { BusinessError } from '@kit.BasicServicesKit'; 809import { bundleManager } from '@kit.MDMKit'; 810 811let wantTemp: Want = { 812 // Replace it as required. 813 bundleName: 'com.example.edmtest', 814 abilityName: 'com.example.edmtest.EnterpriseAdminAbility' 815}; 816try { 817 let result: Array<bundleManager.AppDistributionType> = bundleManager.getInstallationAllowedAppDistributionTypes(wantTemp); 818 console.info(`Succeeded in getting allowed appDistributionTypes. Result: ${JSON.stringify(result)}`); 819} catch (err) { 820 console.error(`Failed to get allowed appDistributionTypes. Code: ${err.code}, message: ${err.message}`); 821} 822``` 823 824## AppDistributionType<sup>20+</sup> 825 826Defines the distribution type of the application signing certificate. For details, please refer to the **appDistributionType** attribute of [ApplicationInfo](../apis-ability-kit/js-apis-bundleManager-applicationInfo.md#applicationinfo-1). 827 828**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 829 830| Name | Value| Description | 831| ----------- | -------- | ------------------------------- | 832| APP_GALLERY | 1 | Application installed from AppGallery.| 833| ENTERPRISE | 2 | Enterprise application.| 834| ENTERPRISE_NORMAL | 3 | Common enterprise application.| 835| ENTERPRISE_MDM | 4 | Enterprise MDM application.| 836| INTERNALTESTING | 5 | Application under internal testing of AppGallery.| 837| CROWDTESTING | 6 | Crowdtesting application.| 838 839## BundleInfo<sup>20+</sup> 840 841Describes the application bundle information. 842 843**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 844 845| Name | Type | Read-Only| Optional| Description | 846| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 847| name | string | Yes | No | Name of the application bundle. It corresponds to the **bundleName** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 848| vendor | string | Yes | No | Vendor of the application bundle. It corresponds to the **vendor** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 849| versionCode | number | Yes | No | Version code of the application bundle. It corresponds to the **versionCode** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 850| versionName | string | Yes | No | Version description of the application bundle. It corresponds to the **versionName** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 851| minCompatibleVersionCode | number | Yes | No | Minimum compatible version of the application bundle in the distributed scenario. It corresponds to the **minCompatibleVersionCode** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 852| targetVersion | number | Yes | No | Target version of the application. It corresponds to the **targetAPIVersion** field in the [app.json5](../../quick-start/app-configuration-file.md) file.| 853| appInfo | [ApplicationInfo](#applicationinfo20) | Yes | No | Application information, including the application name and installation directory.| 854| signatureInfo | [SignatureInfo](#signatureinfo20) | Yes | No | Signature information of the bundle.| 855| installTime | number | Yes | No | Timestamp for the installation of the application bundle. It measures the milliseconds elapsed since the Unix epoch (January 1, 1970, 08:00:00 UTC+8).| 856| updateTime | number | Yes | No | Timestamp for the last update of the application bundle. It measures the milliseconds elapsed since the Unix epoch (January 1, 1970, 08:00:00 UTC+8).| 857| appIndex | number | Yes | No | Index of an application clone. It takes effect only for application clones.| 858| firstInstallTime | number | Yes | Yes | Timestamp for the initial installation of the application bundle. It measures the milliseconds elapsed since the Unix epoch (January 1, 1970, 08:00:00 UTC+8). For preinstalled applications, the initial installation timestamp is 1533657660000.| 859 860 861## SignatureInfo<sup>20+</sup> 862 863Describes the signature information of the bundle. 864 865**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 866 867| Name | Type | Read-Only| Optional| Description | 868| --------- | -------------- | ---- | ---- | --------------------------- | 869| appId | string | Yes | No | Application ID. | 870|fingerprint| string | Yes | No | Fingerprint information of the bundle. This field changes when the used signing certificate changes. | 871|appIdentifier| string | Yes | No | Unique ID of the application. It is the [app ID](https://developer.huawei.com/consumer/en/doc/app/agc-help-createharmonyapp-0000001945392297), which is a random string, allocated by AppGallery Connect during the creation of the application. This ID does not change along the application lifecycle, including version updates, certificate changes, public and private key changes, and application transfers. | 872|certificate| string | Yes | Yes | Public key of the application certificate. | 873 874 875## ApplicationInfo<sup>20+</sup> 876 877Defines the application information. 878 879**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 880 881| Name | Type | Read-Only| Optional| Description | 882| -------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 883| name | string | Yes | No | Bundle name of the application. | 884| description | string | Yes | No | Application description, for example, `"description": $string: mainability_description"`. For details, see the description of the **descriptionResource** field below.| 885| descriptionId | number | Yes | No | ID of the application description.| 886| enabled | boolean | Yes | No | Whether the application is enabled. The value **true** means that the application is enabled, and **false** means the opposite.| 887| label | string | Yes | No | Application label, for example, `"label": "$string: mainability_description"`. For details, see the description of the **labelResource** field below.| 888| labelId | number | Yes | No | ID of the application label.| 889| icon | string | Yes | No | Application icon, for example, `"icon": "$media:icon"`. For details, see the description of the **iconResource** field below.| 890| iconId | number | Yes | No | ID of the application icon.| 891| process | string | Yes | No | Process name.| 892| codePath | string | Yes | No | Installation directory of the application.| 893| removable | boolean | Yes | No | Whether the application is removable. The value **true** means that the application is removable, and **false** means the opposite.| 894| accessTokenId | number | Yes | No | Access token ID of the application.| 895| uid | number | Yes | No | UID of the application.| 896| iconResource | [Resource](#resource20) | Yes| No| Resource information of the application icon, including the bundle name, module name, and ID of the resource.| 897| labelResource | [Resource](#resource20) | Yes| No| Resource information of the application label, including the bundle name, module name, and ID of the resource.| 898| descriptionResource | [Resource](#resource20) | Yes| No| Resource information of the application description, including the bundle name, module name, and ID of the resource.| 899| appDistributionType | string | Yes | No | Distribution type of the application signing certificate. The options are:<br> - **app_gallery**: application distributed by AppGallery.<br> - **enterprise**: enterprise application that can be installed on personal devices.<br> - **enterprise_mdm**: enterprise MDM application, which can be installed only on enterprise devices. The applications of this type must have device management privileges, such as remote locking devices and installing common enterprise applications on devices.<br> - **enterprise_normal**: common enterprise application, which can be installed on enterprise devices only through an enterprise MDM application. The applications of this type do not require device management privileges.<br> - **os_integration**: preset application in the system.<br> - **crowdtesting**: Crowdtesting application.<br> - **internaltesting**: application under internal testing of AppGallery.<br> - **none**: others.| 900| appProvisionType | string | Yes | No | Type of the application signing certificate file. The options are:<br> - **debug**: debug type.<br> - **release**: release type.| 901| systemApp | boolean | Yes | No | Whether the application is a system application. The value **true** means that the application is a system application, and **false** means the opposite.| 902| debug | boolean | Yes | No | Whether the application is running in debug mode. The value **true** means that the application is running in debug mode, and **false** means the opposite.| 903| dataUnclearable | boolean | Yes | No | Whether the application data is unclearable. The value **true** means that the application data is unclearable, and **false** means the opposite.| 904| nativeLibraryPath | string | Yes | No | Local library file path of the application. | 905| appIndex | number | Yes | No | Index of an application clone. It takes effect only for application clones.| 906| installSource | string | Yes | No | Installation source of the application. The options are as follows:<br> - **pre-installed**: The application is a preset application installed at initial device startup.<br> - **ota**: The application is a preset application added during system upgrade.<br> - **recovery**: The preset application is uninstalled and then restored.<br> - **bundleName**: The application corresponding to the bundle name is installed.<br> - **unknown**: The installation source is unknown.| 907| releaseType | string | Yes | No | Release type of the SDK used for application packing. Currently, the SDK release types include Canary, Beta, and Release. Each of the Canary and Beta releases can be distinguished by a sequential number, such as Canary1, Canary2, Beta1, and Beta2. You can compare the SDK release type on which application packaging depends and the OS release type (specified by [deviceInfo.distributionOSReleaseType](../apis-basic-services-kit/js-apis-device-info.md)) to determine the compatibility.| 908 909 910## Resource<sup>20+</sup> 911 912Describes application resource information, including the bundle name, module name, and resource ID. 913 914**System capability**: SystemCapability.Customization.EnterpriseDeviceManager 915 916| Name | Type | Read-Only | Optional |Description | 917| ---------- | ------ | ----- | ---- | ---------------| 918| bundleName | string | No | No| Bundle name of the application.| 919| moduleName | string | No | No| Module name of the application.| 920| id | number | No | No| Resource ID. | 921