1e41f4b71Sopenharmony_ci# BundleInstaller (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **BundleInstaller** module provides APIs for you to install, uninstall, and recover bundles on devices. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 7. 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## BundleInstaller.install<sup>(deprecated)<sup> 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [@ohos.bundle.installer.install](js-apis-installer-sys.md) instead. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciinstall(bundleFilePaths: Array<string>, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciInstalls a bundle. Multiple HAP files can be installed. This API uses an asynchronous callback to return the result. 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**Required permissions** 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciohos.permission.INSTALL_BUNDLE 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**System capability** 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciSystemCapability.BundleManager.BundleFramework 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**System API**: This is a system API. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Parameters** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 32e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 33e41f4b71Sopenharmony_ci| bundleFilePaths | Array<string> | Yes | Sandbox path where the HAP files of the bundle are stored. For details about how to obtain the sandbox path, see [Obtaining the Sandbox Path](#obtaining-the-sandbox-path).| 34e41f4b71Sopenharmony_ci| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle installation. | 35e41f4b71Sopenharmony_ci| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the installation status. | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**Example** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci```ts 40e41f4b71Sopenharmony_ciimport bundleInstall from '@ohos.bundle.installer'; 41e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_cilet hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/files/']; 44e41f4b71Sopenharmony_cilet installParam: bundleInstall.InstallParam = { 45e41f4b71Sopenharmony_ci userId: 100, 46e41f4b71Sopenharmony_ci isKeepData: false, 47e41f4b71Sopenharmony_ci installFlag: 1, 48e41f4b71Sopenharmony_ci}; 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_cibundleInstall.getBundleInstaller().then(installer => { 51e41f4b71Sopenharmony_ci installer.install(hapFilePaths, installParam, err => { 52e41f4b71Sopenharmony_ci if (err) { 53e41f4b71Sopenharmony_ci console.error('install failed:' + JSON.stringify(err)); 54e41f4b71Sopenharmony_ci } else { 55e41f4b71Sopenharmony_ci console.info('install successfully.'); 56e41f4b71Sopenharmony_ci } 57e41f4b71Sopenharmony_ci }); 58e41f4b71Sopenharmony_ci}).catch((error: BusinessError)=> { 59e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 60e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 61e41f4b71Sopenharmony_ci}); 62e41f4b71Sopenharmony_ci``` 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci## BundleInstaller.uninstall<sup>(deprecated)<sup> 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [uninstall](js-apis-installer-sys.md) instead. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciuninstall(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciUninstalls a bundle. This API uses an asynchronous callback to return the result. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Required permissions** 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciohos.permission.INSTALL_BUNDLE 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciSystemCapability.BundleManager.BundleFramework 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**System API**: This is a system API. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Parameters** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 85e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ---------------------------------------------- | 86e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 87e41f4b71Sopenharmony_ci| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle uninstall. | 88e41f4b71Sopenharmony_ci| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the installation status.| 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**Example** 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci```ts 93e41f4b71Sopenharmony_ciimport bundleInstall from '@ohos.bundle.installer'; 94e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_cilet bundleName: string = 'com.example.myapplication'; 97e41f4b71Sopenharmony_cilet installParam: bundleInstall.InstallParam = { 98e41f4b71Sopenharmony_ci userId: 100, 99e41f4b71Sopenharmony_ci isKeepData: false, 100e41f4b71Sopenharmony_ci installFlag: 1, 101e41f4b71Sopenharmony_ci}; 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_cibundleInstall.getBundleInstaller().then(installer => { 104e41f4b71Sopenharmony_ci installer.uninstall(bundleName, installParam, err => { 105e41f4b71Sopenharmony_ci if (err) { 106e41f4b71Sopenharmony_ci console.error('uninstall failed:' + JSON.stringify(err)); 107e41f4b71Sopenharmony_ci } else { 108e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci }); 111e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 112e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 113e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 114e41f4b71Sopenharmony_ci}); 115e41f4b71Sopenharmony_ci``` 116e41f4b71Sopenharmony_ci## BundleInstaller.recover<sup>(deprecated)<sup> 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [recover](js-apis-installer-sys.md) instead. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_cirecover(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ciRecovers a bundle. This API uses an asynchronous callback to return the result. After a pre-installed bundle is uninstalled, you can call this API to recover it. 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**Required permissions** 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ciohos.permission.INSTALL_BUNDLE 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**System capability** 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ciSystemCapability.BundleManager.BundleFramework 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**System API**: This is a system API. 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**Parameters** 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 137e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | 138e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name. | 139e41f4b71Sopenharmony_ci| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle recovery. | 140e41f4b71Sopenharmony_ci| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the recovery status.| 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Example** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci```ts 145e41f4b71Sopenharmony_ciimport bundleInstall from '@ohos.bundle.installer'; 146e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base'; 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_cilet bundleName: string = 'com.example.myapplication'; 149e41f4b71Sopenharmony_cilet installParam: bundleInstall.InstallParam = { 150e41f4b71Sopenharmony_ci userId: 100, 151e41f4b71Sopenharmony_ci isKeepData: false, 152e41f4b71Sopenharmony_ci installFlag: 1, 153e41f4b71Sopenharmony_ci}; 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_cibundleInstall.getBundleInstaller().then(installer => { 156e41f4b71Sopenharmony_ci installer.uninstall(bundleName, installParam, err => { 157e41f4b71Sopenharmony_ci if (err) { 158e41f4b71Sopenharmony_ci console.error('uninstall failed:' + JSON.stringify(err)); 159e41f4b71Sopenharmony_ci } else { 160e41f4b71Sopenharmony_ci console.info('uninstall successfully.'); 161e41f4b71Sopenharmony_ci } 162e41f4b71Sopenharmony_ci }); 163e41f4b71Sopenharmony_ci}).catch((error: BusinessError) => { 164e41f4b71Sopenharmony_ci let message = (error as BusinessError).message; 165e41f4b71Sopenharmony_ci console.error('getBundleInstaller failed. Cause: ' + message); 166e41f4b71Sopenharmony_ci}); 167e41f4b71Sopenharmony_ci``` 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci## InstallParam<sup>(deprecated)<sup> 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciDescribes the parameters required for bundle installation, recovery, or uninstall. 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**System API**: This is a system API. 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci| Name | Type | Read-Only| Optional| Description | 178e41f4b71Sopenharmony_ci| ----------- | ------- | ---- | ---- | ------------------ | 179e41f4b71Sopenharmony_ci| userId | number | No | No | User ID. The default value is the user ID of the caller.| 180e41f4b71Sopenharmony_ci| installFlag | number | No | No | Installation flag.<br>**1** (default): overwrite installation.<br>**16**: installation-free.| 181e41f4b71Sopenharmony_ci| isKeepData | boolean | No | No | Whether data is kept. The default value is **false**.| 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci## InstallStatus<sup>(deprecated)<sup> 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ciDescribes the bundle installation or uninstall status. 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**System API**: This is a system API. 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci| Name | Type | Read-Only| Optional| Description | 192e41f4b71Sopenharmony_ci| ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 193e41f4b71Sopenharmony_ci| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | No | No | Installation or uninstall error code. The value must be defined in [InstallErrorCode](js-apis-Bundle.md#installerrorcode).| 194e41f4b71Sopenharmony_ci| statusMessage | string | No | No | Installation or uninstall status message. <br>**SUCCESS**: install_succeed<br>**STATUS_INSTALL_FAILURE**: Installation failed (no installation file exists).<br>**STATUS_INSTALL_FAILURE_ABORTED**: Installation aborted.<br>**STATUS_INSTALL_FAILURE_INVALID**: Invalid installation parameter.<br>**STATUS_INSTALL_FAILURE_CONFLICT**: Installation conflict. (The basic information of the application to update is inconsistent with that of the existing application.)<br>**STATUS_INSTALL_FAILURE_STORAGE**: Failed to store the bundle information.<br>**STATUS_INSTALL_FAILURE_INCOMPATIBLE**: Installation incompatibility. (A downgrade occurs or the signature information is incorrect.)<br>**STATUS_UNINSTALL_FAILURE**: Uninstall failed. (The application to be uninstalled is not found.)<br>**STATUS_UNINSTALL_FAILURE_ABORTED**: Uninstall aborted. (This error code is not in use.)<br>**STATUS_UNINSTALL_FAILURE_ABORTED**: Uninstall conflict. (Failed to uninstall a system application or end the application process.)<br>**STATUS_INSTALL_FAILURE_DOWNLOAD_TIMEOUT**: Installation failed. (Download timed out.)<br>**STATUS_INSTALL_FAILURE_DOWNLOAD_FAILED**: Installation failed. (Download failed.)<br>**STATUS_RECOVER_FAILURE_INVALID**: Failed to restore the pre-installed application.<br>**STATUS_ABILITY_NOT_FOUND**: Ability not found.<br>**STATUS_BMS_SERVICE_ERROR**: BMS service error.<br>**STATUS_FAILED_NO_SPACE_LEFT**: Insufficient device space.<br>**STATUS_GRANT_REQUEST_PERMISSIONS_FAILED**: Application authorization failed.<br>**STATUS_INSTALL_PERMISSION_DENIED**: No installation permission.<br>**STATUS_UNINSTALL_PERMISSION_DENIED**: No uninstall permission. | 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci## Obtaining the Sandbox Path 197e41f4b71Sopenharmony_ciFor the FA model, the sandbox path of a bundle can be obtained using the APIs in [Context](js-apis-inner-app-context.md). For the stage model, the sandbox path can be obtained using the property in [Context](js-apis-inner-application-uiAbilityContext-sys.md#abilitycontext). The following describes how to obtain the sandbox path. 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**Example** 200e41f4b71Sopenharmony_ci``` ts 201e41f4b71Sopenharmony_ci// Stage model 202e41f4b71Sopenharmony_ciimport UIAbility from '@ohos.app.ability.UIAbility'; 203e41f4b71Sopenharmony_ciimport window from '@ohos.window'; 204e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility { 205e41f4b71Sopenharmony_ci onWindowStageCreate(windowStage: window.WindowStage) { 206e41f4b71Sopenharmony_ci let context = this.context; 207e41f4b71Sopenharmony_ci let pathDir = context.filesDir; 208e41f4b71Sopenharmony_ci console.info('sandbox path is ' + pathDir); 209e41f4b71Sopenharmony_ci } 210e41f4b71Sopenharmony_ci} 211e41f4b71Sopenharmony_ci``` 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci<!--code_no_check_fa--> 214e41f4b71Sopenharmony_ci``` ts 215e41f4b71Sopenharmony_ci// FA model 216e41f4b71Sopenharmony_ciimport featureAbility from '@ohos.ability.featureAbility'; 217e41f4b71Sopenharmony_cilet context = featureAbility.getContext(); 218e41f4b71Sopenharmony_cicontext.getFilesDir().then((data: string) => { 219e41f4b71Sopenharmony_ci let pathDir = data; 220e41f4b71Sopenharmony_ci console.info('sandbox path is ' + pathDir); 221e41f4b71Sopenharmony_ci}); 222e41f4b71Sopenharmony_ci``` 223