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