1e41f4b71Sopenharmony_ci# @ohos.bundle.freeInstall (freeInstall) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **Bundle.freeInstall** module provides APIs for setting and obtaining installation-free information and APIs for obtaining **BundlePackInfo** and **DispatchInfo**. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Modules to Import 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci```js 14e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## Required Permissions 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci| Permission | APL | Description | 20e41f4b71Sopenharmony_ci| ------------------------------------------ | ------------ | ------------------ | 21e41f4b71Sopenharmony_ci| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications. | 22e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall other applications except enterprise applications, including enterprise InHouse, mobile device management (MDM), and Normal applications. | 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciFor details about the APL, see [Basic Concepts in the Permission Mechanism](../../security/AccessToken/app-permission-mgmt-overview.md#basic-concepts-in-the-permission-mechanism). 25e41f4b71Sopenharmony_ci## UpgradeFlag 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System API**: This is a system API. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name | Value | Description | 32e41f4b71Sopenharmony_ci| ---------------- | ---- | ---------------- | 33e41f4b71Sopenharmony_ci| NOT_UPGRADE | 0 | No module needs an upgrade. | 34e41f4b71Sopenharmony_ci| SINGLE_UPGRADE | 1 | A single module needs an upgrade. | 35e41f4b71Sopenharmony_ci| RELATION_UPGRADE | 2 | The module that has a relationship with the current one needs an upgrade. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## BundlePackFlag 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**System API**: This is a system API. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name | Value | Description | 44e41f4b71Sopenharmony_ci| ------------------ | ---------- | ---------------------------------- | 45e41f4b71Sopenharmony_ci| GET_PACK_INFO_ALL | 0x00000000 | All information in the **pack.info** file. | 46e41f4b71Sopenharmony_ci| GET_PACKAGES | 0x00000001 | Package information in the **pack.info** file. | 47e41f4b71Sopenharmony_ci| GET_BUNDLE_SUMMARY | 0x00000002 | Bundle summary information in the **pack.info** file. | 48e41f4b71Sopenharmony_ci| GET_MODULE_SUMMARY | 0x00000004 | Module summary information in the **pack.info** file. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## freeInstall.setHapModuleUpgradeFlag 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_cisetHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag, callback: AsyncCallback\<void>):void 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciSets an upgrade flag for a module. This API uses an asynchronous callback to return the result. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**System API**: This is a system API. 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**Parameters** 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 65e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ---------------------------- | 66e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 67e41f4b71Sopenharmony_ci| moduleName | string | Yes | Module name. | 68e41f4b71Sopenharmony_ci| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is for internal use only. | 69e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object. | 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**Error codes** 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci| ID | Error Message | 76e41f4b71Sopenharmony_ci|----------|---------------------------------------- | 77e41f4b71Sopenharmony_ci| 201 | Permission denied. | 78e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 79e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 80e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 81e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 82e41f4b71Sopenharmony_ci| 17700002 | The specified module name is not found. | 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Example** 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci```js 87e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 88e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 89e41f4b71Sopenharmony_cilet moduleName = 'entry'; 90e41f4b71Sopenharmony_cilet upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE; 91e41f4b71Sopenharmony_citry { 92e41f4b71Sopenharmony_ci freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag, err => { 93e41f4b71Sopenharmony_ci if (err) { 94e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 95e41f4b71Sopenharmony_ci } else { 96e41f4b71Sopenharmony_ci console.info('Operation succeed'); 97e41f4b71Sopenharmony_ci } 98e41f4b71Sopenharmony_ci }); 99e41f4b71Sopenharmony_ci} catch (err) { 100e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 101e41f4b71Sopenharmony_ci} 102e41f4b71Sopenharmony_ci``` 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci## setHapModuleUpgradeFlag 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_cisetHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag): Promise\<void> 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ciSets an upgrade flag for a module. This API uses a promise to return the result. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci**System API**: This is a system API. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**Parameters** 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 119e41f4b71Sopenharmony_ci| ----------- | --------------------------- | ---- | ---------------------- | 120e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 121e41f4b71Sopenharmony_ci| moduleName | string | Yes | Module name. | 122e41f4b71Sopenharmony_ci| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is for internal use only.| 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**Return value** 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci| Type | Description | 127e41f4b71Sopenharmony_ci| ------------- | ------------------------------------ | 128e41f4b71Sopenharmony_ci| Promise\<void> | Promise that returns no value. | 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**Error codes** 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| ID | Error Message | 135e41f4b71Sopenharmony_ci|----------|----------------------------------------| 136e41f4b71Sopenharmony_ci| 201 | Permission denied. | 137e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 138e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 139e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 140e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 141e41f4b71Sopenharmony_ci| 17700002 | The specified module name is not found. | 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Example** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci```js 146e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 147e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 148e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 149e41f4b71Sopenharmony_cilet moduleName = 'entry'; 150e41f4b71Sopenharmony_cilet upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE; 151e41f4b71Sopenharmony_citry { 152e41f4b71Sopenharmony_ci freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag).then(() => { 153e41f4b71Sopenharmony_ci console.info('Operation succeed') 154e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 155e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 156e41f4b71Sopenharmony_ci }); 157e41f4b71Sopenharmony_ci} catch (err) { 158e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 159e41f4b71Sopenharmony_ci} 160e41f4b71Sopenharmony_ci``` 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci## isHapModuleRemovable 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ciisHapModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback\<boolean>): void 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ciChecks whether a module can be removed. This API uses an asynchronous callback to return the result. 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**System API**: This is a system API. 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**Parameters** 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 177e41f4b71Sopenharmony_ci| ---------- | ---------------------- | ---- | --------------------------------------------- | 178e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 179e41f4b71Sopenharmony_ci| moduleName | string | Yes | Module name. | 180e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned. | 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**Error codes** 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| ID | Error Message | 187e41f4b71Sopenharmony_ci|----------|----------------------------------------| 188e41f4b71Sopenharmony_ci| 201 | Permission denied. | 189e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 190e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 191e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 192e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 193e41f4b71Sopenharmony_ci| 17700002 | The specified module name is not found. | 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci**Example** 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci```js 198e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 199e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 200e41f4b71Sopenharmony_cilet moduleName = 'entry'; 201e41f4b71Sopenharmony_citry { 202e41f4b71Sopenharmony_ci freeInstall.isHapModuleRemovable(bundleName, moduleName, (err, data) => { 203e41f4b71Sopenharmony_ci if (err) { 204e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 205e41f4b71Sopenharmony_ci } else { 206e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 207e41f4b71Sopenharmony_ci } 208e41f4b71Sopenharmony_ci }); 209e41f4b71Sopenharmony_ci} catch (err) { 210e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 211e41f4b71Sopenharmony_ci} 212e41f4b71Sopenharmony_ci``` 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci## isHapModuleRemovable 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ciisHapModuleRemovable(bundleName: string, moduleName: string): Promise\<boolean> 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ciChecks whether a module can be removed. This API uses a promise to return the result. 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**System API**: This is a system API. 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**Parameters** 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 229e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ------------------ | 230e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 231e41f4b71Sopenharmony_ci| moduleName | string | Yes | Module name. | 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**Return value** 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci| Type | Description | 236e41f4b71Sopenharmony_ci| ---------------- | ---------------------------- | 237e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned. | 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**Error codes** 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci| ID | Error Message | 244e41f4b71Sopenharmony_ci|----------|----------------------------------------| 245e41f4b71Sopenharmony_ci| 201 | Permission denied. | 246e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 247e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 248e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 249e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 250e41f4b71Sopenharmony_ci| 17700002 | The specified module name is not found. | 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**Example** 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci```js 255e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 256e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 257e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 258e41f4b71Sopenharmony_cilet moduleName = 'entry'; 259e41f4b71Sopenharmony_citry { 260e41f4b71Sopenharmony_ci freeInstall.isHapModuleRemovable(bundleName, moduleName).then(data => { 261e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 262e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 263e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 264e41f4b71Sopenharmony_ci }); 265e41f4b71Sopenharmony_ci} catch (err) { 266e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 267e41f4b71Sopenharmony_ci} 268e41f4b71Sopenharmony_ci``` 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci## getBundlePackInfo 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_cigetBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag, callback: AsyncCallback\<BundlePackInfo>): void 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ciObtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses an asynchronous callback to return the result. 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci**System API**: This is a system API. 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**Parameters** 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 285e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 286e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 287e41f4b71Sopenharmony_ci| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes | Flag of the bundle package. | 288e41f4b71Sopenharmony_ci| callback | AsyncCallback<[BundlePackInfo](js-apis-bundleManager-BundlePackInfo-sys.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **BundlePackInfo** object obtained; otherwise, **err** is an error object. | 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci**Error codes** 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci| ID | Error Message | 295e41f4b71Sopenharmony_ci|----------|----------------------------------------| 296e41f4b71Sopenharmony_ci| 201 | Permission denied. | 297e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 298e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 299e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 300e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci**Example** 303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci```js 305e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 306e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 307e41f4b71Sopenharmony_cilet bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL; 308e41f4b71Sopenharmony_citry { 309e41f4b71Sopenharmony_ci freeInstall.getBundlePackInfo(bundleName, bundlePackFlag, (err, data) => { 310e41f4b71Sopenharmony_ci if (err) { 311e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 312e41f4b71Sopenharmony_ci } else { 313e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 314e41f4b71Sopenharmony_ci } 315e41f4b71Sopenharmony_ci }); 316e41f4b71Sopenharmony_ci} catch (err) { 317e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 318e41f4b71Sopenharmony_ci} 319e41f4b71Sopenharmony_ci``` 320e41f4b71Sopenharmony_ci## getBundlePackInfo 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cigetBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag): Promise\<BundlePackInfo> 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ciObtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses a promise to return the result. 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**System API**: This is a system API. 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**Parameters** 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 335e41f4b71Sopenharmony_ci| -------------- | --------------------------------- | ---- | ---------------------- | 336e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 337e41f4b71Sopenharmony_ci| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes | Flag of the bundle package.| 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**Return value** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci| Type | Description | 342e41f4b71Sopenharmony_ci| ---------------------------------------------------------- | ----------------------------------- | 343e41f4b71Sopenharmony_ci| Promise<[BundlePackInfo](js-apis-bundleManager-BundlePackInfo-sys.md)> | Promise used to return the **BundlePackInfo** object obtained. | 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**Error codes** 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md). 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci| ID | Error Message | 350e41f4b71Sopenharmony_ci|----------|----------------------------------------| 351e41f4b71Sopenharmony_ci| 201 | Permission denied. | 352e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 353e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.| 354e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 355e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. | 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**Example** 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci```js 360e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 361e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 362e41f4b71Sopenharmony_cilet bundleName = 'com.example.myapplication'; 363e41f4b71Sopenharmony_cilet bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL; 364e41f4b71Sopenharmony_citry { 365e41f4b71Sopenharmony_ci freeInstall.getBundlePackInfo(bundleName, bundlePackFlag).then(data => { 366e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 367e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 368e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 369e41f4b71Sopenharmony_ci }); 370e41f4b71Sopenharmony_ci} catch (err) { 371e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 372e41f4b71Sopenharmony_ci} 373e41f4b71Sopenharmony_ci``` 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci## getDispatchInfo 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_cigetDispatchInfo(callback: AsyncCallback\<DispatchInfo>): void 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciObtains the dispatch information. This API uses an asynchronous callback to return the result. 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**System API**: This is a system API. 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**Parameters** 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 390e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 391e41f4b71Sopenharmony_ci| callback | AsyncCallback<[DispatchInfo](js-apis-bundleManager-dispatchInfo-sys.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**, and **data** is the [DispatchInfo](js-apis-bundleManager-dispatchInfo-sys.md) object obtained. otherwise, **err** is an error object. | 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**Error codes** 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| ID | Error Message | 398e41f4b71Sopenharmony_ci|----------|----------------------------------------| 399e41f4b71Sopenharmony_ci| 201 | Permission denied. | 400e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 401e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**Example** 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci```js 406e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 407e41f4b71Sopenharmony_citry { 408e41f4b71Sopenharmony_ci freeInstall.getDispatchInfo((err, data) => { 409e41f4b71Sopenharmony_ci if (err) { 410e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 411e41f4b71Sopenharmony_ci } else { 412e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 413e41f4b71Sopenharmony_ci } 414e41f4b71Sopenharmony_ci }); 415e41f4b71Sopenharmony_ci} catch (err) { 416e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 417e41f4b71Sopenharmony_ci} 418e41f4b71Sopenharmony_ci``` 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci## getDispatchInfo 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_cigetDispatchInfo(): Promise\<DispatchInfo> 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ciObtains the dispatch information. This API uses a promise to return the result. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**System API**: This is a system API. 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci**Return value** 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci| Type | Description | 435e41f4b71Sopenharmony_ci| ------------------------------------------------ | ------------------------------------------------------------ | 436e41f4b71Sopenharmony_ci| Promise<[DispatchInfo](js-apis-bundleManager-dispatchInfo-sys.md)> | Promise used to return the [DispatchInfo](js-apis-bundleManager-dispatchInfo-sys.md) object obtained. | 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci**Error codes** 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci| ID | Error Message | 443e41f4b71Sopenharmony_ci|----------|----------------------------------------| 444e41f4b71Sopenharmony_ci| 201 | Permission denied. | 445e41f4b71Sopenharmony_ci| 202 | Permission denied, non-system app called system api. | 446e41f4b71Sopenharmony_ci| 801 | Capability not supported. | 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**Example** 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci```js 451e41f4b71Sopenharmony_ciimport freeInstall from '@ohos.bundle.freeInstall'; 452e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 453e41f4b71Sopenharmony_citry { 454e41f4b71Sopenharmony_ci freeInstall.getDispatchInfo().then(data => { 455e41f4b71Sopenharmony_ci console.info('Operation succeed:' + JSON.stringify(data)); 456e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 457e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 458e41f4b71Sopenharmony_ci }); 459e41f4b71Sopenharmony_ci} catch (err) { 460e41f4b71Sopenharmony_ci console.error('Operation failed:' + JSON.stringify(err)); 461e41f4b71Sopenharmony_ci} 462e41f4b71Sopenharmony_ci``` 463