1# BundleInstaller 2 3The **BundleInstaller** module provides APIs for you to install, uninstall, and recover bundles on devices. 4 5> **NOTE** 6> 7> 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. 8 9## BundleInstaller.install<sup>(deprecated)<sup> 10 11> This API is deprecated since API version 9. You are advised to use [@ohos.bundle.installer.install](js-apis-installer.md) instead. 12 13install(bundleFilePaths: Array<string>, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 14 15Installs a bundle. Multiple HAP files can be installed. This API uses an asynchronous callback to return the result. 16 17**Required permissions** 18 19ohos.permission.INSTALL_BUNDLE 20 21**System capability** 22 23SystemCapability.BundleManager.BundleFramework 24 25**System API**: This is a system API. 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 31| 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).| 32| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle installation. | 33| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the installation status. | 34 35**Example** 36 37```ts 38import bundleInstall from '@ohos.bundle.installer'; 39import { BusinessError } from '@ohos.base'; 40 41let hapFilePaths: Array<string> = ['/data/storage/el2/base/haps/entry/files/']; 42let installParam: bundleInstall.InstallParam = { 43 userId: 100, 44 isKeepData: false, 45 installFlag: 1, 46}; 47 48bundleInstall.getBundleInstaller().then(installer => { 49 installer.install(hapFilePaths, installParam, err => { 50 if (err) { 51 console.error('install failed:' + JSON.stringify(err)); 52 } else { 53 console.info('install successfully.'); 54 } 55 }); 56}).catch((error: BusinessError)=> { 57 let message = (error as BusinessError).message; 58 console.error('getBundleInstaller failed. Cause: ' + message); 59}); 60``` 61 62## BundleInstaller.uninstall<sup>(deprecated)<sup> 63 64> This API is deprecated since API version 9. You are advised to use [uninstall](js-apis-installer.md) instead. 65 66uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 67 68Uninstalls a bundle. This API uses an asynchronous callback to return the result. 69 70**Required permissions** 71 72ohos.permission.INSTALL_BUNDLE 73 74**System capability** 75 76SystemCapability.BundleManager.BundleFramework 77 78**System API**: This is a system API. 79 80**Parameters** 81 82| Name | Type | Mandatory| Description | 83| ---------- | ------------------------------------------------------------ | ---- | ---------------------------------------------- | 84| bundleName | string | Yes | Bundle name. | 85| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle uninstall. | 86| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the installation status.| 87 88**Example** 89 90```ts 91import bundleInstall from '@ohos.bundle.installer'; 92import { BusinessError } from '@ohos.base'; 93 94let bundleName: string = 'com.example.myapplication'; 95let installParam: bundleInstall.InstallParam = { 96 userId: 100, 97 isKeepData: false, 98 installFlag: 1, 99}; 100 101bundleInstall.getBundleInstaller().then(installer => { 102 installer.uninstall(bundleName, installParam, err => { 103 if (err) { 104 console.error('uninstall failed:' + JSON.stringify(err)); 105 } else { 106 console.info('uninstall successfully.'); 107 } 108 }); 109}).catch((error: BusinessError) => { 110 let message = (error as BusinessError).message; 111 console.error('getBundleInstaller failed. Cause: ' + message); 112}); 113``` 114## BundleInstaller.recover<sup>(deprecated)<sup> 115 116> This API is deprecated since API version 9. You are advised to use [recover](js-apis-installer.md) instead. 117 118recover(bundleName: string, param: InstallParam, callback: AsyncCallback<InstallStatus>): void; 119 120Recovers 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. 121 122**Required permissions** 123 124ohos.permission.INSTALL_BUNDLE 125 126**System capability** 127 128SystemCapability.BundleManager.BundleFramework 129 130**System API**: This is a system API. 131 132**Parameters** 133 134| Name | Type | Mandatory| Description | 135| ---------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- | 136| bundleName | string | Yes | Bundle name. | 137| param | [InstallParam](#installparamdeprecated) | Yes | Parameters required for bundle recovery. | 138| callback | AsyncCallback<[InstallStatus](#installstatusdeprecated)> | Yes | Callback used to return the recovery status.| 139 140**Example** 141 142```ts 143import bundleInstall from '@ohos.bundle.installer'; 144import { BusinessError } from '@ohos.base'; 145 146let bundleName: string = 'com.example.myapplication'; 147let installParam: bundleInstall.InstallParam = { 148 userId: 100, 149 isKeepData: false, 150 installFlag: 1, 151}; 152 153bundleInstall.getBundleInstaller().then(installer => { 154 installer.uninstall(bundleName, installParam, err => { 155 if (err) { 156 console.error('uninstall failed:' + JSON.stringify(err)); 157 } else { 158 console.info('uninstall successfully.'); 159 } 160 }); 161}).catch((error: BusinessError) => { 162 let message = (error as BusinessError).message; 163 console.error('getBundleInstaller failed. Cause: ' + message); 164}); 165``` 166 167## InstallParam<sup>(deprecated)<sup> 168 169Describes the parameters required for bundle installation, recovery, or uninstall. 170 171**System capability**: SystemCapability.BundleManager.BundleFramework 172 173**System API**: This is a system API. 174 175| Name | Type | Readable| Writable| Description | 176| ----------- | ------- | ---- | ---- | ------------------ | 177| userId | number | Yes | Yes | User ID. The default value is the user ID of the caller.| 178| installFlag | number | Yes | Yes | Installation flag.<br>**1** (default): overwrite installation.<br>**16**: installation-free.| 179| isKeepData | boolean | Yes | Yes | Whether data is kept. The default value is **false**.| 180 181## InstallStatus<sup>(deprecated)<sup> 182 183Describes the bundle installation or uninstall status. 184 185**System capability**: SystemCapability.BundleManager.BundleFramework 186 187**System API**: This is a system API. 188 189| Name | Type | Readable| Writable| Description | 190| ------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------ | 191| status | bundle.[InstallErrorCode](js-apis-Bundle.md#installerrorcode) | Yes | No | Installation or uninstall error code. The value must be defined in [InstallErrorCode](js-apis-Bundle.md#installerrorcode).| 192| statusMessage | string | Yes | 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.| 193 194## Obtaining the Sandbox Path 195For 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 attribute in [Context](js-apis-inner-application-uiAbilityContext.md#abilitycontext). The following describes how to obtain the sandbox path. 196 197**Example** 198``` ts 199// Stage model 200import UIAbility from '@ohos.app.ability.UIAbility'; 201export default class EntryAbility extends UIAbility { 202 onWindowStageCreate(windowStage) { 203 let context = this.context; 204 let pathDir = context.filesDir; 205 console.info('sandbox path is ' + pathDir); 206 } 207} 208 209// FA model 210import featureAbility from '@ohos.ability.featureAbility'; 211let context = featureAbility.getContext(); 212context.getFilesDir().then((data) => { 213 let pathDir = data; 214 console.info('sandbox path is ' + pathDir); 215}); 216``` 217