1e41f4b71Sopenharmony_ci# @ohos.bundle.installer (installer) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **bundle.installer** 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 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 installer from '@ohos.bundle.installer';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Required Permissions
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci| Permission                          | APL   | Description            |
20e41f4b71Sopenharmony_ci| ------------------------------ | ----------- | ---------------- |
21e41f4b71Sopenharmony_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.|
22e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_BUNDLE | system_core | Permission to install enterprise InHouse applications.|
23e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE | system_core | Permission to install enterprise MDM applications.|
24e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE | system_core | Permission to install enterprise Normal applications.|
25e41f4b71Sopenharmony_ci| ohos.permission.UNINSTALL_BUNDLE | system_core | Allows an application to uninstall applications.|
26e41f4b71Sopenharmony_ci| ohos.permission.RECOVER_BUNDLE | system_core | Allows an application to restore pre-installed applications.|
27e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_SELF_BUNDLE | system_core | Allows automatic updates of the enterprise MDM applications on enterprise devices.|
28e41f4b71Sopenharmony_ci| ohos.permission.INSTALL_INTERNALTESTING_BUNDLE | system_core | Allows an application to install beta applications.|
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_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).
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstaller
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_cigetBundleInstaller(callback: AsyncCallback\<BundleInstaller>): void
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciObtains a **BundleInstaller** object. This API uses an asynchronous callback to return the result.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**System API**: This is a system API.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**Parameters**
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory| Description                                                        |
45e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
46e41f4b71Sopenharmony_ci| callback | AsyncCallback\<BundleInstaller> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **BundleInstaller** object obtained; otherwise, **err** is an error object.|
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**Error codes**
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciFor details about the error codes, see [Bundle Error Codes](errorcode-bundle.md).
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
53e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
54e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
55e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Incorrect parameter types.   |
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**Example**
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci```ts
60e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
61e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_citry {
64e41f4b71Sopenharmony_ci    installer.getBundleInstaller((err: BusinessError, data: installer.BundleInstaller) => {
65e41f4b71Sopenharmony_ci        if (err) {
66e41f4b71Sopenharmony_ci            console.error('getBundleInstaller failed:' + err.message);
67e41f4b71Sopenharmony_ci        } else {
68e41f4b71Sopenharmony_ci            console.info('getBundleInstaller successfully');
69e41f4b71Sopenharmony_ci        }
70e41f4b71Sopenharmony_ci    });
71e41f4b71Sopenharmony_ci} catch (error) {
72e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
73e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed:' + message);
74e41f4b71Sopenharmony_ci}
75e41f4b71Sopenharmony_ci```
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstaller
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_cigetBundleInstaller(): Promise\<BundleInstaller>
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ciObtains a **BundleInstaller** object. This API uses an asynchronous callback to return the result.
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**System API**: This is a system API.
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**Return value**
88e41f4b71Sopenharmony_ci| Type                                                        | Description                                |
89e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------ |
90e41f4b71Sopenharmony_ci| Promise\<BundleInstaller> | Promise used to return the **BundleInstaller** object obtained.|
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Error codes**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ciFor details about the error codes, see [Bundle Error Codes](errorcode-bundle.md).
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
97e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
98e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**Example**
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci```ts
103e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
104e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_citry {
107e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
108e41f4b71Sopenharmony_ci        console.info('getBundleInstaller successfully.');
109e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
110e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
111e41f4b71Sopenharmony_ci    });
112e41f4b71Sopenharmony_ci} catch (error) {
113e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
114e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
115e41f4b71Sopenharmony_ci}
116e41f4b71Sopenharmony_ci```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci## BundleInstaller.getBundleInstallerSync<sup>10+</sup>
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_cigetBundleInstallerSync(): BundleInstaller
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ciObtains a **BundleInstaller** object. This API is a synchronous API.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**System API**: This is a system API.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Return value**
129e41f4b71Sopenharmony_ci| Type                                                        | Description                                |
130e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------ |
131e41f4b71Sopenharmony_ci| BundleInstaller | **BundleInstaller** object.|
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**Error codes**
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ciFor details about the error codes, see [Bundle Error Codes](errorcode-bundle.md).
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
138e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
139e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**Example**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci```ts
144e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
145e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_citry {
148e41f4b71Sopenharmony_ci    installer.getBundleInstallerSync();
149e41f4b71Sopenharmony_ci    console.info('getBundleInstallerSync successfully.');
150e41f4b71Sopenharmony_ci} catch (error) {
151e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
152e41f4b71Sopenharmony_ci    console.error('getBundleInstallerSync failed. Cause: ' + message);
153e41f4b71Sopenharmony_ci}
154e41f4b71Sopenharmony_ci```
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci## BundleInstaller.install
157e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array&lt;string&gt;, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ciInstalls a bundle. This API uses an asynchronous callback to return the result.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**System API**: This is a system API.
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE, ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup>, ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup>, or ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup>
164e41f4b71Sopenharmony_ci> **NOTE**
165e41f4b71Sopenharmony_ci>
166e41f4b71Sopenharmony_ci> From API version 10, this API can be called with the permission **ohos.permission.INSTALL_ENTERPRISE_BUNDLE**, **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE**, or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE**.
167e41f4b71Sopenharmony_ci>
168e41f4b71Sopenharmony_ci> To install an enterprise application, you must have the **ohos.permission.INSTALL_ENTERPRISE_BUNDLE** permission.
169e41f4b71Sopenharmony_ci>
170e41f4b71Sopenharmony_ci> To install an enterprise Normal application, you must have the **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE** or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
171e41f4b71Sopenharmony_ci>
172e41f4b71Sopenharmony_ci> To install an enterprise MDM application, you must have the **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
173e41f4b71Sopenharmony_ci>
174e41f4b71Sopenharmony_ci> To install a common application, you must have the **ohos.permission.INSTALL_BUNDLE** permission.
175e41f4b71Sopenharmony_ci>
176e41f4b71Sopenharmony_ci> To install a beta application, you must have the **ohos.permission.INSTALL_INTERNALTESTING_BUNDLE** permission.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**Parameters**
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci| Name          | Type                                                | Mandatory| Description                                                        |
183e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
184e41f4b71Sopenharmony_ci| hapFilePaths | Array&lt;string&gt;                                  | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
185e41f4b71Sopenharmony_ci| installParam           | [InstallParam](#installparam)                        | Yes  | Parameters required for the installation.                                    |
186e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**Error codes**
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
193e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
194e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'.   |
195e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
196e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000.   |
197e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.                          |
198e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
199e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
200e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
201e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
202e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
203e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
204e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
205e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. |
206e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. |
207e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
208e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
209e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
210e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
211e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
212e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
213e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
214e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
215e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. |
216e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.|
217e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. |
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**Example**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci```ts
222e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
223e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
226e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
227e41f4b71Sopenharmony_ci    userId: 100,
228e41f4b71Sopenharmony_ci    isKeepData: false,
229e41f4b71Sopenharmony_ci    installFlag: 1,
230e41f4b71Sopenharmony_ci};
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_citry {
233e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
234e41f4b71Sopenharmony_ci        data.install(hapFilePaths, installParam, (err: BusinessError) => {
235e41f4b71Sopenharmony_ci            if (err) {
236e41f4b71Sopenharmony_ci                console.error('install failed:' + err.message);
237e41f4b71Sopenharmony_ci            } else {
238e41f4b71Sopenharmony_ci                console.info('install successfully.');
239e41f4b71Sopenharmony_ci            }
240e41f4b71Sopenharmony_ci        });
241e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
242e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
243e41f4b71Sopenharmony_ci    });
244e41f4b71Sopenharmony_ci} catch (error) {
245e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
246e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
247e41f4b71Sopenharmony_ci}
248e41f4b71Sopenharmony_ci```
249e41f4b71Sopenharmony_ci## BundleInstaller.install
250e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ciInstalls a bundle. This API uses an asynchronous callback to return the result.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**System API**: This is a system API.
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE, ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup>, ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup>, or ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup>
257e41f4b71Sopenharmony_ci> **NOTE**
258e41f4b71Sopenharmony_ci>
259e41f4b71Sopenharmony_ci> From API version 10, this API can be called with the permission **ohos.permission.INSTALL_ENTERPRISE_BUNDLE**, **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE**, or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE**.
260e41f4b71Sopenharmony_ci>
261e41f4b71Sopenharmony_ci> To install an enterprise application, you must have the **ohos.permission.INSTALL_ENTERPRISE_BUNDLE** permission.
262e41f4b71Sopenharmony_ci>
263e41f4b71Sopenharmony_ci> To install an enterprise Normal application, you must have the **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE** or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
264e41f4b71Sopenharmony_ci>
265e41f4b71Sopenharmony_ci> To install an enterprise MDM application, you must have the **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
266e41f4b71Sopenharmony_ci>
267e41f4b71Sopenharmony_ci> To install a common application, you must have the **ohos.permission.INSTALL_BUNDLE** permission.
268e41f4b71Sopenharmony_ci>
269e41f4b71Sopenharmony_ci> To install a beta application, you must have the **ohos.permission.INSTALL_INTERNALTESTING_BUNDLE** permission.
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci**Parameters**
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci| Name          | Type                                                | Mandatory| Description                                                        |
276e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
277e41f4b71Sopenharmony_ci| hapFilePaths | Array&lt;string&gt;                                  | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
278e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci**Error codes**
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
285e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
286e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'.   |
287e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
288e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
289e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
290e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
291e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
292e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
293e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
294e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
295e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
296e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. |
297e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. |
298e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
299e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
300e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
301e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
302e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
303e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
304e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
305e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
306e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. |
307e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.|
308e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. |
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**Example**
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci```ts
313e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
314e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_citry {
319e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
320e41f4b71Sopenharmony_ci        data.install(hapFilePaths, (err: BusinessError) => {
321e41f4b71Sopenharmony_ci            if (err) {
322e41f4b71Sopenharmony_ci                console.error('install failed:' + err.message);
323e41f4b71Sopenharmony_ci            } else {
324e41f4b71Sopenharmony_ci                console.info('install successfully.');
325e41f4b71Sopenharmony_ci            }
326e41f4b71Sopenharmony_ci        });
327e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
328e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
329e41f4b71Sopenharmony_ci    });
330e41f4b71Sopenharmony_ci} catch (error) {
331e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
332e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
333e41f4b71Sopenharmony_ci}
334e41f4b71Sopenharmony_ci```
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci## BundleInstaller.install
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_ciinstall(hapFilePaths: Array\<string\>, installParam?: InstallParam) : Promise\<void\>
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ciInstalls a bundle. This API uses a promise to return the result.
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci**System API**: This is a system API.
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE, ohos.permission.INSTALL_ENTERPRISE_BUNDLE<sup>10+</sup>, ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE<sup>10+</sup>, or ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE<sup>10+</sup>
345e41f4b71Sopenharmony_ci> **NOTE**
346e41f4b71Sopenharmony_ci>
347e41f4b71Sopenharmony_ci> From API version 10, this API can be called with the permission **ohos.permission.INSTALL_ENTERPRISE_BUNDLE**, **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE**, or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE**.
348e41f4b71Sopenharmony_ci>
349e41f4b71Sopenharmony_ci> To install an enterprise application, you must have the **ohos.permission.INSTALL_ENTERPRISE_BUNDLE** permission.
350e41f4b71Sopenharmony_ci>
351e41f4b71Sopenharmony_ci> To install an enterprise Normal application, you must have the **ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE** or **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
352e41f4b71Sopenharmony_ci>
353e41f4b71Sopenharmony_ci> To install an enterprise MDM application, you must have the **ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE** permission.
354e41f4b71Sopenharmony_ci>
355e41f4b71Sopenharmony_ci> To install a common application, you must have the **ohos.permission.INSTALL_BUNDLE** permission.
356e41f4b71Sopenharmony_ci>
357e41f4b71Sopenharmony_ci> To install a beta application, you must have the **ohos.permission.INSTALL_INTERNALTESTING_BUNDLE** permission.
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**Parameters**
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci| Name      | Type                         | Mandatory| Description                                                        |
364e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
365e41f4b71Sopenharmony_ci| hapFilePaths | Array\<string\>               | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
366e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | No  | Parameters required for the installation. For details about their default values, see [InstallParam](#installparam).                                    |
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci**Return value**
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci| Type           | Description                                  |
371e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
372e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci**Error codes**
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
379e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
380e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_MDM_BUNDLE' or 'ohos.permission.INSTALL_ENTERPRISE_NORMAL_BUNDLE'.   |
381e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
382e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000.   |
383e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.                          |
384e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
385e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
386e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
387e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
388e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
389e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
390e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
391e41f4b71Sopenharmony_ci| 17700031 | Failed to install the HAP because the overlay check of the HAP failed. |
392e41f4b71Sopenharmony_ci| 17700036 | Failed to install the HSP due to the lack of required permission. |
393e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
394e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
395e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
396e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
397e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
398e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
399e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
400e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
401e41f4b71Sopenharmony_ci| 17700052 | Failed to install the HAP because a debug bundle can be installed only in developer mode. |
402e41f4b71Sopenharmony_ci| 17700054 | Failed to install the HAP because the HAP requests wrong permissions.|
403e41f4b71Sopenharmony_ci| 17700066 | Failed to install the HAP because installing the native package failed. |
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci**Example**
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci```ts
408e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
409e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
412e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
413e41f4b71Sopenharmony_ci    userId: 100,
414e41f4b71Sopenharmony_ci    isKeepData: false,
415e41f4b71Sopenharmony_ci    installFlag: 1,
416e41f4b71Sopenharmony_ci};
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_citry {
419e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
420e41f4b71Sopenharmony_ci        data.install(hapFilePaths, installParam)
421e41f4b71Sopenharmony_ci            .then((data: void) => {
422e41f4b71Sopenharmony_ci                console.info('install successfully: ' + JSON.stringify(data));
423e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
424e41f4b71Sopenharmony_ci            console.error('install failed:' + error.message);
425e41f4b71Sopenharmony_ci        });
426e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
427e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
428e41f4b71Sopenharmony_ci    });
429e41f4b71Sopenharmony_ci} catch (error) {
430e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
431e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
432e41f4b71Sopenharmony_ci}
433e41f4b71Sopenharmony_ci```
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci## BundleInstaller.uninstall
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ciuninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ciUninstalls a bundle. This API uses an asynchronous callback to return the result.
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci**System API**: This is a system API.
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**Parameters**
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci| Name     | Type                                                | Mandatory| Description                                          |
450e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
451e41f4b71Sopenharmony_ci| bundleName | string                                               | Yes  | Name of the target bundle.                                          |
452e41f4b71Sopenharmony_ci| installParam      | [InstallParam](#installparam)                        | Yes  | Parameters required for the installation.                      |
453e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci**Error codes**
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
460e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
461e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
462e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
463e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
464e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
465e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
466e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
467e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. |
468e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. |
469e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. |
470e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. |
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci**Example**
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci```ts
475e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
476e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
479e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
480e41f4b71Sopenharmony_ci    userId: 100,
481e41f4b71Sopenharmony_ci    isKeepData: false,
482e41f4b71Sopenharmony_ci    installFlag: 1
483e41f4b71Sopenharmony_ci};
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_citry {
486e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
487e41f4b71Sopenharmony_ci        data.uninstall(bundleName, installParam, (err: BusinessError) => {
488e41f4b71Sopenharmony_ci            if (err) {
489e41f4b71Sopenharmony_ci                console.error('uninstall failed:' + err.message);
490e41f4b71Sopenharmony_ci            } else {
491e41f4b71Sopenharmony_ci                console.info('uninstall successfully.');
492e41f4b71Sopenharmony_ci            }
493e41f4b71Sopenharmony_ci        });
494e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
495e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
496e41f4b71Sopenharmony_ci    });
497e41f4b71Sopenharmony_ci} catch (error) {
498e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
499e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
500e41f4b71Sopenharmony_ci}
501e41f4b71Sopenharmony_ci```
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ci## BundleInstaller.uninstall
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ciuninstall(bundleName: string, callback: AsyncCallback&lt;void&gt;): void
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ciUninstalls a bundle. This API uses an asynchronous callback to return the result.
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci**System API**: This is a system API.
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ci**Parameters**
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ci| Name     | Type                                                | Mandatory| Description                                          |
518e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
519e41f4b71Sopenharmony_ci| bundleName | string                                               | Yes  | Name of the target bundle.                                          |
520e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci**Error codes**
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
527e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
528e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
529e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
530e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
531e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
532e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
533e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. |
534e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. |
535e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. |
536e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. |
537e41f4b71Sopenharmony_ci
538e41f4b71Sopenharmony_ci**Example**
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ci```ts
541e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
542e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_citry {
547e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
548e41f4b71Sopenharmony_ci        data.uninstall(bundleName, (err: BusinessError) => {
549e41f4b71Sopenharmony_ci            if (err) {
550e41f4b71Sopenharmony_ci                console.error('uninstall failed:' + err.message);
551e41f4b71Sopenharmony_ci            } else {
552e41f4b71Sopenharmony_ci                console.info('uninstall successfully.');
553e41f4b71Sopenharmony_ci            }
554e41f4b71Sopenharmony_ci        });
555e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
556e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
557e41f4b71Sopenharmony_ci    });
558e41f4b71Sopenharmony_ci} catch (error) {
559e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
560e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
561e41f4b71Sopenharmony_ci}
562e41f4b71Sopenharmony_ci```
563e41f4b71Sopenharmony_ci## BundleInstaller.uninstall
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ciuninstall(bundleName: string, installParam?: InstallParam) : Promise\<void\>
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ciUninstalls a bundle. This API uses a promise to return the result.
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ci**System API**: This is a system API.
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ci**Parameters**
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ci| Name      | Type                         | Mandatory| Description                                                        |
578e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
579e41f4b71Sopenharmony_ci| bundleName | string                          | Yes  | Name of the target bundle.                                          |
580e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | No  | Parameters required for the installation. For details about their default values, see [InstallParam](#installparam).                                    |
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci**Return value**
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ci| Type           | Description                                  |
585e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
586e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ci**Error codes**
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
593e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
594e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
595e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
596e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
597e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
598e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
599e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
600e41f4b71Sopenharmony_ci| 17700040 | The specified bundle is a shared bundle which cannot be uninstalled. |
601e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. |
602e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. |
603e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. |
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ci**Example**
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci```ts
608e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
609e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
612e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
613e41f4b71Sopenharmony_ci    userId: 100,
614e41f4b71Sopenharmony_ci    isKeepData: false,
615e41f4b71Sopenharmony_ci    installFlag: 1,
616e41f4b71Sopenharmony_ci};
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_citry {
619e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
620e41f4b71Sopenharmony_ci        data.uninstall(bundleName, installParam)
621e41f4b71Sopenharmony_ci            .then((data: void) => {
622e41f4b71Sopenharmony_ci                console.info('uninstall successfully: ' + JSON.stringify(data));
623e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
624e41f4b71Sopenharmony_ci            console.error('uninstall failed:' + error.message);
625e41f4b71Sopenharmony_ci        });
626e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
627e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
628e41f4b71Sopenharmony_ci    });
629e41f4b71Sopenharmony_ci} catch (error) {
630e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
631e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
632e41f4b71Sopenharmony_ci}
633e41f4b71Sopenharmony_ci```
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci## BundleInstaller.recover
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_cirecover(bundleName: string, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_ciRolls back a bundle to the initial installation state. This API uses an asynchronous callback to return the result.
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci**System API**: This is a system API.
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.RECOVER_BUNDLE
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
646e41f4b71Sopenharmony_ci
647e41f4b71Sopenharmony_ci**Parameters**
648e41f4b71Sopenharmony_ci
649e41f4b71Sopenharmony_ci| Name     | Type                                                | Mandatory| Description                                          |
650e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
651e41f4b71Sopenharmony_ci| bundleName | string                                               | Yes  | Name of the target bundle.                                          |
652e41f4b71Sopenharmony_ci| installParam      | [InstallParam](#installparam)                        | Yes  | Parameters required for the installation.                      |
653e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci**Error codes**
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ci| ID| Error Message                           |
660e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
661e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. |
662e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
663e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
664e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
665e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
666e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. |
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci**Example**
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_ci```ts
671e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
672e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
675e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
676e41f4b71Sopenharmony_ci    userId: 100,
677e41f4b71Sopenharmony_ci    isKeepData: false,
678e41f4b71Sopenharmony_ci    installFlag: 1
679e41f4b71Sopenharmony_ci};
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_citry {
682e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
683e41f4b71Sopenharmony_ci        data.recover(bundleName, installParam, (err: BusinessError) => {
684e41f4b71Sopenharmony_ci            if (err) {
685e41f4b71Sopenharmony_ci                console.error('recover failed:' + err.message);
686e41f4b71Sopenharmony_ci            } else {
687e41f4b71Sopenharmony_ci                console.info('recover successfully.');
688e41f4b71Sopenharmony_ci            }
689e41f4b71Sopenharmony_ci        });
690e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
691e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
692e41f4b71Sopenharmony_ci    });
693e41f4b71Sopenharmony_ci} catch (error) {
694e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
695e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
696e41f4b71Sopenharmony_ci}
697e41f4b71Sopenharmony_ci```
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci## BundleInstaller.recover
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_cirecover(bundleName: string, callback: AsyncCallback&lt;void&gt;): void
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ciRolls back a bundle to the initial installation state. This API uses an asynchronous callback to return the result.
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ci**System API**: This is a system API.
707e41f4b71Sopenharmony_ci
708e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.RECOVER_BUNDLE
709e41f4b71Sopenharmony_ci
710e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_ci**Parameters**
713e41f4b71Sopenharmony_ci
714e41f4b71Sopenharmony_ci| Name     | Type                                                | Mandatory| Description                                          |
715e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
716e41f4b71Sopenharmony_ci| bundleName | string                                               | Yes  | Name of the target bundle.                              |
717e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci**Error codes**
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci| ID| Error Message                           |
724e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
725e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. |
726e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
727e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
728e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
729e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. |
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci**Example**
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_ci```ts
734e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
735e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
736e41f4b71Sopenharmony_ci
737e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_citry {
740e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
741e41f4b71Sopenharmony_ci        data.recover(bundleName, (err: BusinessError) => {
742e41f4b71Sopenharmony_ci            if (err) {
743e41f4b71Sopenharmony_ci                console.error('recover failed:' + err.message);
744e41f4b71Sopenharmony_ci            } else {
745e41f4b71Sopenharmony_ci                console.info('recover successfully.');
746e41f4b71Sopenharmony_ci            }
747e41f4b71Sopenharmony_ci        });
748e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
749e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
750e41f4b71Sopenharmony_ci    });
751e41f4b71Sopenharmony_ci} catch (error) {
752e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
753e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
754e41f4b71Sopenharmony_ci}
755e41f4b71Sopenharmony_ci```
756e41f4b71Sopenharmony_ci
757e41f4b71Sopenharmony_ci## BundleInstaller.recover
758e41f4b71Sopenharmony_ci
759e41f4b71Sopenharmony_cirecover(bundleName: string, installParam?: InstallParam) : Promise\<void\>
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ciRolls back a bundle to the initial installation state. This API uses a promise to return the result.
762e41f4b71Sopenharmony_ci
763e41f4b71Sopenharmony_ci**System API**: This is a system API.
764e41f4b71Sopenharmony_ci
765e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.RECOVER_BUNDLE
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_ci**Parameters**
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ci| Name      | Type                         | Mandatory| Description                                                        |
772e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
773e41f4b71Sopenharmony_ci| bundleName | string                          | Yes  | Name of the target bundle.                                          |
774e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | No  | Parameters required for the installation. For details about their default values, see [InstallParam](#installparam).                                    |
775e41f4b71Sopenharmony_ci
776e41f4b71Sopenharmony_ci**Return value**
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci| Type           | Description                                  |
779e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
780e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci**Error codes**
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ci| ID| Error Message                           |
787e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
788e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.RECOVER_BUNDLE'. |
789e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
790e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
791e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
792e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found. |
793e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. |
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_ci**Example**
796e41f4b71Sopenharmony_ci```ts
797e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
798e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.demo';
801e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
802e41f4b71Sopenharmony_ci    userId: 100,
803e41f4b71Sopenharmony_ci    isKeepData: false,
804e41f4b71Sopenharmony_ci    installFlag: 1,
805e41f4b71Sopenharmony_ci};
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_citry {
808e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
809e41f4b71Sopenharmony_ci        data.recover(bundleName, installParam)
810e41f4b71Sopenharmony_ci            .then((data: void) => {
811e41f4b71Sopenharmony_ci                console.info('recover successfully: ' + JSON.stringify(data));
812e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
813e41f4b71Sopenharmony_ci            console.error('recover failed:' + error.message);
814e41f4b71Sopenharmony_ci        });
815e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
816e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
817e41f4b71Sopenharmony_ci    });
818e41f4b71Sopenharmony_ci} catch (error) {
819e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
820e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
821e41f4b71Sopenharmony_ci}
822e41f4b71Sopenharmony_ci```
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci## BundleInstaller.uninstall<sup>10+</sup>
825e41f4b71Sopenharmony_ci
826e41f4b71Sopenharmony_ciuninstall(uninstallParam: UninstallParam, callback : AsyncCallback\<void\>) : void
827e41f4b71Sopenharmony_ci
828e41f4b71Sopenharmony_ciUninstalls a shared bundle. This API uses an asynchronous callback to return the result.
829e41f4b71Sopenharmony_ci
830e41f4b71Sopenharmony_ci**System API**: This is a system API.
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci**Parameters**
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_ci| Name        | Type                               | Mandatory| Description                                                    |
839e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | -------------------------------------------------------- |
840e41f4b71Sopenharmony_ci| uninstallParam | [UninstallParam](#uninstallparam10) | Yes  | Parameters required for the uninstall.                            |
841e41f4b71Sopenharmony_ci| callback       | AsyncCallback&lt;void&gt;           | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ci**Error codes**
844e41f4b71Sopenharmony_ci
845e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
848e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
849e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
850e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
851e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
852e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
853e41f4b71Sopenharmony_ci| 17700037 | The version of the shared bundle is dependent on other applications. |
854e41f4b71Sopenharmony_ci| 17700038 | The specified shared bundle does not exist.                  |
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_ci**Example**
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci```ts
859e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
860e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_cilet uninstallParam: installer.UninstallParam = {
863e41f4b71Sopenharmony_ci    bundleName: "com.ohos.demo",
864e41f4b71Sopenharmony_ci};
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_citry {
867e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
868e41f4b71Sopenharmony_ci        data.uninstall(uninstallParam, (err: BusinessError) => {
869e41f4b71Sopenharmony_ci            if (err) {
870e41f4b71Sopenharmony_ci                console.error('uninstall failed:' + err.message);
871e41f4b71Sopenharmony_ci            } else {
872e41f4b71Sopenharmony_ci                console.info('uninstall successfully.');
873e41f4b71Sopenharmony_ci            }
874e41f4b71Sopenharmony_ci        });
875e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
876e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
877e41f4b71Sopenharmony_ci    });
878e41f4b71Sopenharmony_ci} catch (error) {
879e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
880e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
881e41f4b71Sopenharmony_ci}
882e41f4b71Sopenharmony_ci```
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_ci## BundleInstaller.uninstall<sup>10+</sup>
885e41f4b71Sopenharmony_ci
886e41f4b71Sopenharmony_ciuninstall(uninstallParam: UninstallParam) : Promise\<void>
887e41f4b71Sopenharmony_ci
888e41f4b71Sopenharmony_ciUninstalls a shared bundle. This API uses a promise to return the result.
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ci**System API**: This is a system API.
891e41f4b71Sopenharmony_ci
892e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
893e41f4b71Sopenharmony_ci
894e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci**Parameters**
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ci| Name        | Type                               | Mandatory| Description                        |
899e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- |
900e41f4b71Sopenharmony_ci| uninstallParam | [UninstallParam](#uninstallparam10) | Yes  | Parameters required for the uninstall.|
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci**Return value**
903e41f4b71Sopenharmony_ci
904e41f4b71Sopenharmony_ci| Type         | Description                                  |
905e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- |
906e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
907e41f4b71Sopenharmony_ci
908e41f4b71Sopenharmony_ci**Error codes**
909e41f4b71Sopenharmony_ci
910e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
911e41f4b71Sopenharmony_ci
912e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
913e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
914e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
915e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
916e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
917e41f4b71Sopenharmony_ci| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
918e41f4b71Sopenharmony_ci| 17700037 | The version of the shared bundle is dependent on other applications. |
919e41f4b71Sopenharmony_ci| 17700038 | The specified shared bundle does not exist.                  |
920e41f4b71Sopenharmony_ci
921e41f4b71Sopenharmony_ci**Example**
922e41f4b71Sopenharmony_ci
923e41f4b71Sopenharmony_ci```ts
924e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
925e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_cilet uninstallParam: installer.UninstallParam = {
928e41f4b71Sopenharmony_ci    bundleName: "com.ohos.demo",
929e41f4b71Sopenharmony_ci};
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_citry {
932e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
933e41f4b71Sopenharmony_ci        data.uninstall(uninstallParam, (err: BusinessError) => {
934e41f4b71Sopenharmony_ci            if (err) {
935e41f4b71Sopenharmony_ci                console.error('uninstall failed:' + err.message);
936e41f4b71Sopenharmony_ci            } else {
937e41f4b71Sopenharmony_ci                console.info('uninstall successfully.');
938e41f4b71Sopenharmony_ci            }
939e41f4b71Sopenharmony_ci        });
940e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
941e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
942e41f4b71Sopenharmony_ci    });
943e41f4b71Sopenharmony_ci} catch (error) {
944e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
945e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
946e41f4b71Sopenharmony_ci}
947e41f4b71Sopenharmony_ci```
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci## BundleInstaller.addExtResource<sup>12+</sup>
950e41f4b71Sopenharmony_ci
951e41f4b71Sopenharmony_ciaddExtResource(bundleName: string, filePaths: Array\<string>): Promise\<void>;
952e41f4b71Sopenharmony_ci
953e41f4b71Sopenharmony_ciAdds extended resources based on the specified bundle name and HSP file path. This API uses a promise to return the result.
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci**System API**: This is a system API.
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE
958e41f4b71Sopenharmony_ci
959e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
960e41f4b71Sopenharmony_ci
961e41f4b71Sopenharmony_ci**Parameters**
962e41f4b71Sopenharmony_ci
963e41f4b71Sopenharmony_ci| Name        | Type                               | Mandatory| Description                        |
964e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- |
965e41f4b71Sopenharmony_ci| bundleName | string | Yes  | Bundle name of the application to which extended resources are to be added.|
966e41f4b71Sopenharmony_ci| filePaths | Array\<string> | Yes  | Path of the extended resources to be added.|
967e41f4b71Sopenharmony_ci
968e41f4b71Sopenharmony_ci**Return value**
969e41f4b71Sopenharmony_ci
970e41f4b71Sopenharmony_ci| Type         | Description                                  |
971e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- |
972e41f4b71Sopenharmony_ci| Promise\<void> | that returns no value.|
973e41f4b71Sopenharmony_ci
974e41f4b71Sopenharmony_ci**Error codes**
975e41f4b71Sopenharmony_ci
976e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
977e41f4b71Sopenharmony_ci
978e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
979e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
980e41f4b71Sopenharmony_ci| 201 | Permission denied. |
981e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
982e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
983e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName is not found. |
984e41f4b71Sopenharmony_ci| 17700301 | Failed to add extended resources.                 |
985e41f4b71Sopenharmony_ci
986e41f4b71Sopenharmony_ci**Example**
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci```ts
989e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
990e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog';
991e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_cilet bundleName : string = 'com.ohos.demo';
994e41f4b71Sopenharmony_cilet filePaths : Array<string> = ['/data/storage/el2/base/a.hsp'];
995e41f4b71Sopenharmony_citry {
996e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
997e41f4b71Sopenharmony_ci        data.addExtResource(bundleName, filePaths).then((data) => {
998e41f4b71Sopenharmony_ci            hilog.info(0x0000, 'testTag', 'addExtResource successfully');
999e41f4b71Sopenharmony_ci        }).catch((err: BusinessError) => {
1000e41f4b71Sopenharmony_ci            hilog.error(0x0000, 'testTag', 'addExtResource failed. Cause: %{public}s', err.message);
1001e41f4b71Sopenharmony_ci        });
1002e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1003e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1004e41f4b71Sopenharmony_ci    });
1005e41f4b71Sopenharmony_ci} catch (error) {
1006e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1007e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1008e41f4b71Sopenharmony_ci}
1009e41f4b71Sopenharmony_ci```
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_ci## BundleInstaller.removeExtResource<sup>12+</sup>
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ciremoveExtResource(bundleName: string, moduleNames: Array\<string>): Promise\<void>;
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ciRemoves extended resources based on the specified bundle name and HSP file path. This API uses a promise to return the result.
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci**System API**: This is a system API.
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.UNINSTALL_BUNDLE
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1022e41f4b71Sopenharmony_ci
1023e41f4b71Sopenharmony_ci**Parameters**
1024e41f4b71Sopenharmony_ci
1025e41f4b71Sopenharmony_ci| Name        | Type                               | Mandatory| Description                        |
1026e41f4b71Sopenharmony_ci| -------------- | ----------------------------------- | ---- | ---------------------------- |
1027e41f4b71Sopenharmony_ci| bundleName | string | Yes  | Bundle name of the application for which extended resources are to be removed.|
1028e41f4b71Sopenharmony_ci| moduleNames | Array\<string> | Yes  | Names of the modules whose extended resources are to be removed.|
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_ci**Return value**
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_ci| Type         | Description                                  |
1033e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- |
1034e41f4b71Sopenharmony_ci| Promise\<void> | that returns no value.|
1035e41f4b71Sopenharmony_ci
1036e41f4b71Sopenharmony_ci**Error codes**
1037e41f4b71Sopenharmony_ci
1038e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
1041e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1042e41f4b71Sopenharmony_ci| 201 | Permission denied. |
1043e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1044e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1045e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName is not found. |
1046e41f4b71Sopenharmony_ci| 17700302 | Failed to remove extended resources.                  |
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**Example**
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci```ts
1051e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1052e41f4b71Sopenharmony_ciimport hilog from '@ohos.hilog';
1053e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1054e41f4b71Sopenharmony_ci
1055e41f4b71Sopenharmony_cilet bundleName : string = 'com.ohos.demo';
1056e41f4b71Sopenharmony_cilet moduleNames : Array<string> = ['moduleTest'];
1057e41f4b71Sopenharmony_citry {
1058e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1059e41f4b71Sopenharmony_ci        data.removeExtResource(bundleName, moduleNames).then((data) => {
1060e41f4b71Sopenharmony_ci            hilog.info(0x0000, 'testTag', 'removeExtResource successfully');
1061e41f4b71Sopenharmony_ci        }).catch((err: BusinessError) => {
1062e41f4b71Sopenharmony_ci            hilog.error(0x0000, 'testTag', 'removeExtResource failed. Cause: %{public}s', err.message);
1063e41f4b71Sopenharmony_ci        });
1064e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1065e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1066e41f4b71Sopenharmony_ci    });
1067e41f4b71Sopenharmony_ci} catch (error) {
1068e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1069e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1070e41f4b71Sopenharmony_ci}
1071e41f4b71Sopenharmony_ci```
1072e41f4b71Sopenharmony_ci
1073e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup>
1074e41f4b71Sopenharmony_ci
1075e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, installParam: InstallParam, callback: AsyncCallback\<void\>): void
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_ciUpdates the current bundle. This API uses an asynchronous callback to return the result. It can be called only by enterprise MDM applications on enterprise devices, and the HAPs in **hapFilePaths** must belong to the current application.
1078e41f4b71Sopenharmony_ci
1079e41f4b71Sopenharmony_ci**System API**: This is a system API.
1080e41f4b71Sopenharmony_ci
1081e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_SELF_BUNDLE
1082e41f4b71Sopenharmony_ci
1083e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1084e41f4b71Sopenharmony_ci
1085e41f4b71Sopenharmony_ci**Parameters**
1086e41f4b71Sopenharmony_ci
1087e41f4b71Sopenharmony_ci| Name          | Type                                                | Mandatory| Description                                                        |
1088e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
1089e41f4b71Sopenharmony_ci| hapFilePaths | Array&lt;string&gt;                                  | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
1090e41f4b71Sopenharmony_ci| installParam           | [InstallParam](#installparam)                        | Yes  | Parameters required for the installation.                                    |
1091e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
1092e41f4b71Sopenharmony_ci
1093e41f4b71Sopenharmony_ci**Error codes**
1094e41f4b71Sopenharmony_ci
1095e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1096e41f4b71Sopenharmony_ci
1097e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
1098e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1099e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. |
1100e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1101e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. |
1102e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.                          |
1103e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
1104e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
1105e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
1106e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
1107e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
1108e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
1109e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
1110e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
1111e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
1112e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
1113e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
1114e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
1115e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
1116e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
1117e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. |
1118e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
1119e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. |
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ci**Example**
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_ci```ts
1124e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1125e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
1128e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
1129e41f4b71Sopenharmony_ci    userId: 100,
1130e41f4b71Sopenharmony_ci    isKeepData: false,
1131e41f4b71Sopenharmony_ci    installFlag: 1,
1132e41f4b71Sopenharmony_ci};
1133e41f4b71Sopenharmony_ci
1134e41f4b71Sopenharmony_citry {
1135e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1136e41f4b71Sopenharmony_ci        data.updateBundleForSelf(hapFilePaths, installParam, (err: BusinessError) => {
1137e41f4b71Sopenharmony_ci            if (err) {
1138e41f4b71Sopenharmony_ci                console.error('updateBundleForSelf failed:' + err.message);
1139e41f4b71Sopenharmony_ci            } else {
1140e41f4b71Sopenharmony_ci                console.info('updateBundleForSelf successfully.');
1141e41f4b71Sopenharmony_ci            }
1142e41f4b71Sopenharmony_ci        });
1143e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1144e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1145e41f4b71Sopenharmony_ci    });
1146e41f4b71Sopenharmony_ci} catch (error) {
1147e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1148e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1149e41f4b71Sopenharmony_ci}
1150e41f4b71Sopenharmony_ci```
1151e41f4b71Sopenharmony_ci
1152e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup>
1153e41f4b71Sopenharmony_ci
1154e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, callback: AsyncCallback\<void\>): void
1155e41f4b71Sopenharmony_ci
1156e41f4b71Sopenharmony_ciUpdates the current bundle. This API uses an asynchronous callback to return the result. It can be called only by enterprise MDM applications on enterprise devices, and the HAPs in **hapFilePaths** must belong to the current application.
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci**System API**: This is a system API.
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_SELF_BUNDLE
1161e41f4b71Sopenharmony_ci
1162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**Parameters**
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci| Name          | Type                                                | Mandatory| Description                                                        |
1167e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
1168e41f4b71Sopenharmony_ci| hapFilePaths | Array&lt;string&gt;                                  | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
1169e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
1170e41f4b71Sopenharmony_ci
1171e41f4b71Sopenharmony_ci**Error codes**
1172e41f4b71Sopenharmony_ci
1173e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
1176e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1177e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. |
1178e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1179e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1180e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
1181e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
1182e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
1183e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
1184e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
1185e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
1186e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
1187e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
1188e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
1189e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
1190e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
1191e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
1192e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
1193e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
1194e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. |
1195e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
1196e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. |
1197e41f4b71Sopenharmony_ci
1198e41f4b71Sopenharmony_ci**Example**
1199e41f4b71Sopenharmony_ci
1200e41f4b71Sopenharmony_ci```ts
1201e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1202e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1203e41f4b71Sopenharmony_ci
1204e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
1205e41f4b71Sopenharmony_ci
1206e41f4b71Sopenharmony_citry {
1207e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1208e41f4b71Sopenharmony_ci        data.updateBundleForSelf(hapFilePaths, (err: BusinessError) => {
1209e41f4b71Sopenharmony_ci            if (err) {
1210e41f4b71Sopenharmony_ci                console.error('updateBundleForSelf failed:' + err.message);
1211e41f4b71Sopenharmony_ci            } else {
1212e41f4b71Sopenharmony_ci                console.info('updateBundleForSelf successfully.');
1213e41f4b71Sopenharmony_ci            }
1214e41f4b71Sopenharmony_ci        });
1215e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1216e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1217e41f4b71Sopenharmony_ci    });
1218e41f4b71Sopenharmony_ci} catch (error) {
1219e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1220e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1221e41f4b71Sopenharmony_ci}
1222e41f4b71Sopenharmony_ci```
1223e41f4b71Sopenharmony_ci
1224e41f4b71Sopenharmony_ci## BundleInstaller.updateBundleForSelf<sup>10+</sup>
1225e41f4b71Sopenharmony_ci
1226e41f4b71Sopenharmony_ciupdateBundleForSelf(hapFilePaths: Array\<string\>, installParam?: InstallParam): Promise\<void\>
1227e41f4b71Sopenharmony_ci
1228e41f4b71Sopenharmony_ciUpdates the current bundle. This API uses a promise to return the result. It can be called only by enterprise MDM applications on enterprise devices, and the HAPs in **hapFilePaths** must belong to the current application.
1229e41f4b71Sopenharmony_ci
1230e41f4b71Sopenharmony_ci**System API**: This is a system API.
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_SELF_BUNDLE
1233e41f4b71Sopenharmony_ci
1234e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1235e41f4b71Sopenharmony_ci
1236e41f4b71Sopenharmony_ci**Parameters**
1237e41f4b71Sopenharmony_ci
1238e41f4b71Sopenharmony_ci| Name          | Type                                                | Mandatory| Description                                                        |
1239e41f4b71Sopenharmony_ci| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
1240e41f4b71Sopenharmony_ci| hapFilePaths | Array&lt;string&gt;                                  | Yes  | Paths where the HAP files of the bundle are stored, which are the data directories. If only one directory is passed, the HAP files in the directory must belong to the same bundle and have the same signature.|
1241e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | No  | Parameters required for the installation. For details about their default values, see [InstallParam](#installparam).                                    |
1242e41f4b71Sopenharmony_ci
1243e41f4b71Sopenharmony_ci**Return value**
1244e41f4b71Sopenharmony_ci
1245e41f4b71Sopenharmony_ci| Type         | Description                                  |
1246e41f4b71Sopenharmony_ci| ------------- | -------------------------------------- |
1247e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
1248e41f4b71Sopenharmony_ci
1249e41f4b71Sopenharmony_ci**Error codes**
1250e41f4b71Sopenharmony_ci
1251e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1252e41f4b71Sopenharmony_ci
1253e41f4b71Sopenharmony_ci| ID| Error Message                                                    |
1254e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1255e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_SELF_BUNDLE'. |
1256e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1257e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter hapFiles is needed for code signature; 4. The size of specifiedDistributionType is greater than 128; 5. The size of additionalInfo is greater than 3000. |
1258e41f4b71Sopenharmony_ci| 17700004 | The specified user ID is not found.                          |
1259e41f4b71Sopenharmony_ci| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
1260e41f4b71Sopenharmony_ci| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
1261e41f4b71Sopenharmony_ci| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
1262e41f4b71Sopenharmony_ci| 17700015 | Failed to install the HAPs because they have different configuration information. |
1263e41f4b71Sopenharmony_ci| 17700016 | Failed to install the HAP because of insufficient system disk space. |
1264e41f4b71Sopenharmony_ci| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
1265e41f4b71Sopenharmony_ci| 17700018 | Failed to install the HAP or HSP because the dependent module does not exist. |
1266e41f4b71Sopenharmony_ci| 17700039 | Failed to install the HSP because installing a shared bundle specified by hapFilePaths is not allowed. |
1267e41f4b71Sopenharmony_ci| 17700041 | Failed to install the HAP because the installation is forbidden by enterprise device management. |
1268e41f4b71Sopenharmony_ci| 17700042 | Failed to install the HAP because of incorrect URI in the data proxy. |
1269e41f4b71Sopenharmony_ci| 17700043 | Failed to install the HAP because of low APL in the non-system data proxy (required APL: system_basic or system_core). |
1270e41f4b71Sopenharmony_ci| 17700044 | Failed to install the HAP because the isolationMode configured is not supported. |
1271e41f4b71Sopenharmony_ci| 17700047 | Failed to install the HAP because the VersionCode to be updated is not greater than the current VersionCode. |
1272e41f4b71Sopenharmony_ci| 17700048 | Failed to install the HAP because the code signature verification failed. |
1273e41f4b71Sopenharmony_ci| 17700049 | Failed to install the HAP because the bundleName is different from the bundleName of the caller application. |
1274e41f4b71Sopenharmony_ci| 17700050 | Failed to install the HAP because an enterprise normal/MDM bundle cannot be installed on non-enterprise devices. |
1275e41f4b71Sopenharmony_ci| 17700051 | Failed to install the HAP because the distribution type of the caller application is not enterprise_mdm. |
1276e41f4b71Sopenharmony_ci
1277e41f4b71Sopenharmony_ci**Example**
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ci```ts
1280e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1281e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1282e41f4b71Sopenharmony_ci
1283e41f4b71Sopenharmony_cilet hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
1284e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
1285e41f4b71Sopenharmony_ci    userId: 100,
1286e41f4b71Sopenharmony_ci    isKeepData: false,
1287e41f4b71Sopenharmony_ci    installFlag: 1,
1288e41f4b71Sopenharmony_ci};
1289e41f4b71Sopenharmony_ci
1290e41f4b71Sopenharmony_citry {
1291e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1292e41f4b71Sopenharmony_ci        data.updateBundleForSelf(hapFilePaths, installParam)
1293e41f4b71Sopenharmony_ci            .then((data: void) => {
1294e41f4b71Sopenharmony_ci                console.info('updateBundleForSelf successfully: ' + JSON.stringify(data));
1295e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
1296e41f4b71Sopenharmony_ci            console.error('updateBundleForSelf failed:' + error.message);
1297e41f4b71Sopenharmony_ci        });
1298e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1299e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1300e41f4b71Sopenharmony_ci    });
1301e41f4b71Sopenharmony_ci} catch (error) {
1302e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1303e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1304e41f4b71Sopenharmony_ci}
1305e41f4b71Sopenharmony_ci```
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ci## BundleInstaller.uninstallUpdates<sup>12+</sup>
1308e41f4b71Sopenharmony_ci
1309e41f4b71Sopenharmony_ciuninstallUpdates(bundleName: string, installParam?: InstallParam): Promise\<void\>;
1310e41f4b71Sopenharmony_ci
1311e41f4b71Sopenharmony_ciUninstalls and updates a pre-installed application and restores it to the initial installation status. This API uses a promise to return the result.
1312e41f4b71Sopenharmony_ci
1313e41f4b71Sopenharmony_ci**System API**: This is a system API.
1314e41f4b71Sopenharmony_ci
1315e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE or ohos.permission.RECOVER_BUNDLE
1316e41f4b71Sopenharmony_ci
1317e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1318e41f4b71Sopenharmony_ci
1319e41f4b71Sopenharmony_ci**Parameters**
1320e41f4b71Sopenharmony_ci
1321e41f4b71Sopenharmony_ci| Name       | Type                         | Mandatory| Description                                                        |
1322e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
1323e41f4b71Sopenharmony_ci| bundleName   | string                        | Yes  | Name of the target bundle.                                                 |
1324e41f4b71Sopenharmony_ci| installParam | [InstallParam](#installparam) | No  | Parameters required for the uninstall and update. For details about their default values, see [InstallParam](#installparam). The **userId** parameter cannot be specified. Calling this API will uninstall and update the application for all users.|
1325e41f4b71Sopenharmony_ci
1326e41f4b71Sopenharmony_ci**Return value**
1327e41f4b71Sopenharmony_ci
1328e41f4b71Sopenharmony_ci| Type           | Description                                  |
1329e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
1330e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
1331e41f4b71Sopenharmony_ci
1332e41f4b71Sopenharmony_ci**Error codes**
1333e41f4b71Sopenharmony_ci
1334e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1335e41f4b71Sopenharmony_ci
1336e41f4b71Sopenharmony_ci| ID| Error Message                           |
1337e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
1338e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE' or 'ohos.permission.UNINSTALL_BUNDLE'. |
1339e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1340e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1341e41f4b71Sopenharmony_ci| 17700001 | The specified bundle name is not found. |
1342e41f4b71Sopenharmony_ci| 17700045 | Failed to uninstall the HAP because the uninstall is forbidden by enterprise device management. |
1343e41f4b71Sopenharmony_ci| 17700057 | Failed to uninstall updates because the HAP is not pre-installed. |
1344e41f4b71Sopenharmony_ci| 17700060 | The specified application cannot be uninstalled. |
1345e41f4b71Sopenharmony_ci| 17700067 | Failed to uninstall the HAP because uninstalling the native package failed. |
1346e41f4b71Sopenharmony_ci
1347e41f4b71Sopenharmony_ci**Example**
1348e41f4b71Sopenharmony_ci
1349e41f4b71Sopenharmony_ci```ts
1350e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1351e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera';
1354e41f4b71Sopenharmony_cilet installParam: installer.InstallParam = {
1355e41f4b71Sopenharmony_ci    isKeepData: true,
1356e41f4b71Sopenharmony_ci    installFlag: 1,
1357e41f4b71Sopenharmony_ci};
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_citry {
1360e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1361e41f4b71Sopenharmony_ci        data.uninstallUpdates(bundleName, installParam)
1362e41f4b71Sopenharmony_ci            .then(() => {
1363e41f4b71Sopenharmony_ci                console.info('uninstallUpdates successfully.');
1364e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
1365e41f4b71Sopenharmony_ci            console.error('uninstallUpdates failed:' + error.message);
1366e41f4b71Sopenharmony_ci        });
1367e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1368e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1369e41f4b71Sopenharmony_ci    });
1370e41f4b71Sopenharmony_ci} catch (error) {
1371e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1372e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1373e41f4b71Sopenharmony_ci}
1374e41f4b71Sopenharmony_ci```
1375e41f4b71Sopenharmony_ci
1376e41f4b71Sopenharmony_ci## BundleInstaller.createAppClone<sup>12+</sup>
1377e41f4b71Sopenharmony_ci
1378e41f4b71Sopenharmony_cicreateAppClone(bundleName: string, createAppCloneParam?: CreateAppCloneParam): Promise\<number\>;
1379e41f4b71Sopenharmony_ci
1380e41f4b71Sopenharmony_ciCreates an application clone. This API uses a promise to return the result.
1381e41f4b71Sopenharmony_ci
1382e41f4b71Sopenharmony_ci**System API**: This is a system API.
1383e41f4b71Sopenharmony_ci
1384e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_CLONE_BUNDLE
1385e41f4b71Sopenharmony_ci
1386e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1387e41f4b71Sopenharmony_ci
1388e41f4b71Sopenharmony_ci**Parameters**
1389e41f4b71Sopenharmony_ci
1390e41f4b71Sopenharmony_ci| Name       | Type                         | Mandatory| Description                                                         |
1391e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
1392e41f4b71Sopenharmony_ci| bundleName   | string                        | Yes  | Bundle name of the application for which a clone is to be created.                                        |
1393e41f4b71Sopenharmony_ci| createAppCloneParam  | [createAppCloneParam](#createappcloneparam12)   | No  | Other parameters required for creating the clone. For details about the default values of these parameters, see [createAppCloneParam](#createappcloneparam12).  |
1394e41f4b71Sopenharmony_ci
1395e41f4b71Sopenharmony_ci**Return value**
1396e41f4b71Sopenharmony_ci
1397e41f4b71Sopenharmony_ci| Type           | Description                                  |
1398e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
1399e41f4b71Sopenharmony_ci| Promise\<number\> | Promise used to return the index of the application clone.|
1400e41f4b71Sopenharmony_ci
1401e41f4b71Sopenharmony_ci**Error codes**
1402e41f4b71Sopenharmony_ci
1403e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1404e41f4b71Sopenharmony_ci
1405e41f4b71Sopenharmony_ci| ID| Error Message                           |
1406e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
1407e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_CLONE_BUNDLE'. |
1408e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1409e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1410e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. |
1411e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. |
1412e41f4b71Sopenharmony_ci| 17700061 | The appIndex is not in valid range or already exists. |
1413e41f4b71Sopenharmony_ci| 17700069 | The app does not support the creation of an appClone instance. |
1414e41f4b71Sopenharmony_ci
1415e41f4b71Sopenharmony_ci**Example**
1416e41f4b71Sopenharmony_ci```ts
1417e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1418e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1419e41f4b71Sopenharmony_ci
1420e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera';
1421e41f4b71Sopenharmony_cilet createAppCloneParam: installer.CreateAppCloneParam = {
1422e41f4b71Sopenharmony_ci    userId: 100,
1423e41f4b71Sopenharmony_ci    appIndex: 1,
1424e41f4b71Sopenharmony_ci};
1425e41f4b71Sopenharmony_ci
1426e41f4b71Sopenharmony_citry {
1427e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1428e41f4b71Sopenharmony_ci        data.createAppClone(bundleName, createAppCloneParam)
1429e41f4b71Sopenharmony_ci            .then(() => {
1430e41f4b71Sopenharmony_ci                console.info('createAppClone successfully.');
1431e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
1432e41f4b71Sopenharmony_ci            console.error('createAppClone failed:' + error.message);
1433e41f4b71Sopenharmony_ci        });
1434e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1435e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1436e41f4b71Sopenharmony_ci    });
1437e41f4b71Sopenharmony_ci} catch (error) {
1438e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1439e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1440e41f4b71Sopenharmony_ci}
1441e41f4b71Sopenharmony_ci```
1442e41f4b71Sopenharmony_ci
1443e41f4b71Sopenharmony_ci## BundleInstaller.destroyAppClone<sup>12+</sup>
1444e41f4b71Sopenharmony_ci
1445e41f4b71Sopenharmony_cidestroyAppClone(bundleName: string, appIndex: number, userId?: number): Promise\<void\>;
1446e41f4b71Sopenharmony_ci
1447e41f4b71Sopenharmony_ciDestroys an application clone. This API uses a promise to return the result.
1448e41f4b71Sopenharmony_ci
1449e41f4b71Sopenharmony_ci**System API**: This is a system API.
1450e41f4b71Sopenharmony_ci
1451e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.UNINSTALL_CLONE_BUNDLE
1452e41f4b71Sopenharmony_ci
1453e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1454e41f4b71Sopenharmony_ci
1455e41f4b71Sopenharmony_ci**Parameters**
1456e41f4b71Sopenharmony_ci
1457e41f4b71Sopenharmony_ci| Name       | Type                         | Mandatory| Description                                                         |
1458e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
1459e41f4b71Sopenharmony_ci| bundleName   | string                        | Yes  | Bundle name of the application for which a clone is to be destroyed.                                        |
1460e41f4b71Sopenharmony_ci| appIndex     | number                        | Yes  | Index of the clone to destroy.                                        |
1461e41f4b71Sopenharmony_ci| userId       | number                        | No  | ID of the user to whom the clone to destroy belongs. The default value is the user ID of the caller.                |
1462e41f4b71Sopenharmony_ci
1463e41f4b71Sopenharmony_ci**Return value**
1464e41f4b71Sopenharmony_ci
1465e41f4b71Sopenharmony_ci| Type           | Description                                  |
1466e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
1467e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
1468e41f4b71Sopenharmony_ci
1469e41f4b71Sopenharmony_ci**Error codes**
1470e41f4b71Sopenharmony_ci
1471e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1472e41f4b71Sopenharmony_ci
1473e41f4b71Sopenharmony_ci| ID| Error Message                           |
1474e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
1475e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.UNINSTALL_CLONE_BUNDLE'. |
1476e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1477e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1478e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found or the bundle is not installed by the specified user. |
1479e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. |
1480e41f4b71Sopenharmony_ci| 17700061 | The appIndex is invalid. |
1481e41f4b71Sopenharmony_ci
1482e41f4b71Sopenharmony_ci**Example**
1483e41f4b71Sopenharmony_ci```ts
1484e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1485e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1486e41f4b71Sopenharmony_ci
1487e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera';
1488e41f4b71Sopenharmony_cilet index = 1;
1489e41f4b71Sopenharmony_cilet userId = 100;
1490e41f4b71Sopenharmony_ci
1491e41f4b71Sopenharmony_citry {
1492e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1493e41f4b71Sopenharmony_ci        data.destroyAppClone(bundleName, index, userId)
1494e41f4b71Sopenharmony_ci            .then(() => {
1495e41f4b71Sopenharmony_ci                console.info('destroyAppClone successfully.');
1496e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
1497e41f4b71Sopenharmony_ci            console.error('destroyAppClone failed:' + error.message);
1498e41f4b71Sopenharmony_ci        });
1499e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1500e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1501e41f4b71Sopenharmony_ci    });
1502e41f4b71Sopenharmony_ci} catch (error) {
1503e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1504e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1505e41f4b71Sopenharmony_ci}
1506e41f4b71Sopenharmony_ci```
1507e41f4b71Sopenharmony_ci
1508e41f4b71Sopenharmony_ci## BundleInstaller.installPreexistingApp<sup>12+</sup>
1509e41f4b71Sopenharmony_ci
1510e41f4b71Sopenharmony_ciinstallPreexistingApp(bundleName: string, userId?: number): Promise\<void\>;
1511e41f4b71Sopenharmony_ci
1512e41f4b71Sopenharmony_ciInstalls a bundle. This API uses a promise to return the result.
1513e41f4b71Sopenharmony_ci
1514e41f4b71Sopenharmony_ci**System API**: This is a system API.
1515e41f4b71Sopenharmony_ci
1516e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.INSTALL_BUNDLE
1517e41f4b71Sopenharmony_ci
1518e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1519e41f4b71Sopenharmony_ci
1520e41f4b71Sopenharmony_ci**Parameters**
1521e41f4b71Sopenharmony_ci
1522e41f4b71Sopenharmony_ci| Name       | Type                         | Mandatory| Description                                                         |
1523e41f4b71Sopenharmony_ci| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
1524e41f4b71Sopenharmony_ci| bundleName   | string                        | Yes  | Bundle name of the application to install.                                          |
1525e41f4b71Sopenharmony_ci| userId       | number                        | No  | ID of the user for whom the application is to be installed. The value must be greater than 0. The default value is the user ID of the caller.   |
1526e41f4b71Sopenharmony_ci
1527e41f4b71Sopenharmony_ci**Return value**
1528e41f4b71Sopenharmony_ci
1529e41f4b71Sopenharmony_ci| Type           | Description                                  |
1530e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- |
1531e41f4b71Sopenharmony_ci| Promise\<void\> | Promise that returns no value.|
1532e41f4b71Sopenharmony_ci
1533e41f4b71Sopenharmony_ci**Error codes**
1534e41f4b71Sopenharmony_ci
1535e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bundle Error Codes](errorcode-bundle.md).
1536e41f4b71Sopenharmony_ci
1537e41f4b71Sopenharmony_ci| ID| Error Message                           |
1538e41f4b71Sopenharmony_ci| -------- | ----------------------------------- |
1539e41f4b71Sopenharmony_ci| 201 | Calling interface without permission 'ohos.permission.INSTALL_BUNDLE'. |
1540e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
1541e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types.|
1542e41f4b71Sopenharmony_ci| 17700001 | The specified bundleName cannot be found. |
1543e41f4b71Sopenharmony_ci| 17700004 | The userId is invalid. |
1544e41f4b71Sopenharmony_ci| 17700071 | It is not allowed to install the enterprise bundle. |
1545e41f4b71Sopenharmony_ci| 17700058 | Failed to install the HAP because this application is prohibited from being installed on this device or by specified users. |
1546e41f4b71Sopenharmony_ci
1547e41f4b71Sopenharmony_ci**Example**
1548e41f4b71Sopenharmony_ci```ts
1549e41f4b71Sopenharmony_ciimport installer from '@ohos.bundle.installer';
1550e41f4b71Sopenharmony_ciimport { BusinessError } from '@ohos.base';
1551e41f4b71Sopenharmony_ci
1552e41f4b71Sopenharmony_cilet bundleName = 'com.ohos.camera';
1553e41f4b71Sopenharmony_cilet userId = 100;
1554e41f4b71Sopenharmony_ci
1555e41f4b71Sopenharmony_citry {
1556e41f4b71Sopenharmony_ci    installer.getBundleInstaller().then((data: installer.BundleInstaller) => {
1557e41f4b71Sopenharmony_ci        data.installPreexistingApp(bundleName, userId)
1558e41f4b71Sopenharmony_ci            .then(() => {
1559e41f4b71Sopenharmony_ci                console.info('installPreexistingApp successfully.');
1560e41f4b71Sopenharmony_ci        }).catch((error: BusinessError) => {
1561e41f4b71Sopenharmony_ci            console.error('installPreexistingApp failed:' + error.message);
1562e41f4b71Sopenharmony_ci        });
1563e41f4b71Sopenharmony_ci    }).catch((error: BusinessError) => {
1564e41f4b71Sopenharmony_ci        console.error('getBundleInstaller failed. Cause: ' + error.message);
1565e41f4b71Sopenharmony_ci    });
1566e41f4b71Sopenharmony_ci} catch (error) {
1567e41f4b71Sopenharmony_ci    let message = (error as BusinessError).message;
1568e41f4b71Sopenharmony_ci    console.error('getBundleInstaller failed. Cause: ' + message);
1569e41f4b71Sopenharmony_ci}
1570e41f4b71Sopenharmony_ci```
1571e41f4b71Sopenharmony_ci
1572e41f4b71Sopenharmony_ci## HashParam
1573e41f4b71Sopenharmony_ci
1574e41f4b71Sopenharmony_ciDefines the hash parameters for bundle installation and uninstall.
1575e41f4b71Sopenharmony_ci
1576e41f4b71Sopenharmony_ci **System capability**: SystemCapability.BundleManager.BundleFramework.Core
1577e41f4b71Sopenharmony_ci
1578e41f4b71Sopenharmony_ci **System API**: This is a system API.
1579e41f4b71Sopenharmony_ci
1580e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description            |
1581e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- |
1582e41f4b71Sopenharmony_ci| moduleName | string | Yes| Module name of the bundle.|
1583e41f4b71Sopenharmony_ci| hashValue  | string | Yes| Hash value.          |
1584e41f4b71Sopenharmony_ci
1585e41f4b71Sopenharmony_ci## InstallParam
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_ciDefines the parameters that need to be specified for bundle installation, uninstall, or recovering.
1588e41f4b71Sopenharmony_ci
1589e41f4b71Sopenharmony_ci **System capability**: SystemCapability.BundleManager.BundleFramework.Core
1590e41f4b71Sopenharmony_ci
1591e41f4b71Sopenharmony_ci **System API**: This is a system API.
1592e41f4b71Sopenharmony_ci
1593e41f4b71Sopenharmony_ci| Name                       | Type                          | Mandatory                        | Description              |
1594e41f4b71Sopenharmony_ci| ------------------------------ | ------------------------------ | ------------------ | ------------------ |
1595e41f4b71Sopenharmony_ci| userId                         | number                         | No                       | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. You can call [queryOsAccountLocalIdFromProcess](../apis-basic-services-kit/js-apis-osAccount.md#getosaccountlocalid9) to obtain the user ID of the current process. When a driver application is installed, uninstalled, or restored, this parameter is ignored and the operation is executed for all users.|
1596e41f4b71Sopenharmony_ci| installFlag                    | number                         | No                       | Installation flag. The value **0x00** means initial installation, **0x01** means overwrite installation, and **0x10** means installation-free. The default value is **0x00**.|
1597e41f4b71Sopenharmony_ci| isKeepData                     | boolean                        | No                      | Whether to retain the data directory during bundle uninstall. The default value is **false**.|
1598e41f4b71Sopenharmony_ci| hashParams        | Array<[HashParam](#hashparam)> | No| Hash parameters. By default, no value is passed.        |
1599e41f4b71Sopenharmony_ci| crowdtestDeadline| number                         | No                       | End date of crowdtesting. The default value is **-1**, indicating that no end date is specified for crowdtesting.|
1600e41f4b71Sopenharmony_ci| sharedBundleDirPaths<sup>10+</sup> | Array\<String> | No|Paths of the shared bundle files. By default, no value is passed.|
1601e41f4b71Sopenharmony_ci| specifiedDistributionType<sup>10+</sup> | string | No|Distribution type specified during application installation. By default, no value is passed. The maximum length is 128 bytes. This field is usually specified by the application market of the operating system operator.|
1602e41f4b71Sopenharmony_ci| additionalInfo<sup>10+</sup> | string | No|Additional information during application installation (usually an enterprise application). By default, no value is passed. The maximum length is 3,000 bytes. This field is usually specified by the application market of the operating system operator.|
1603e41f4b71Sopenharmony_ci| verifyCodeParams<sup>deprecated<sup> | Array<[VerifyCodeParam](#verifycodeparamdeprecated)> | No| Information about the code signature file. The default value is null.        |
1604e41f4b71Sopenharmony_ci| pgoParams<sup>11+</sup> | Array<[PGOParam](#pgoparam11)> | No| Parameters of the Profile-guided Optimization (PGO) configuration file. The default value is null.        |
1605e41f4b71Sopenharmony_ci
1606e41f4b71Sopenharmony_ci## UninstallParam<sup>10+</sup>
1607e41f4b71Sopenharmony_ci
1608e41f4b71Sopenharmony_ciDefines the parameters required for the uninstall of a shared bundle.
1609e41f4b71Sopenharmony_ci
1610e41f4b71Sopenharmony_ci **System capability**: SystemCapability.BundleManager.BundleFramework.Core
1611e41f4b71Sopenharmony_ci
1612e41f4b71Sopenharmony_ci **System API**: This is a system API.
1613e41f4b71Sopenharmony_ci
1614e41f4b71Sopenharmony_ci| Name       | Type  | Mandatory| Description                                                        |
1615e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------------------------------------------------ |
1616e41f4b71Sopenharmony_ci| bundleName  | string | Yes  | Name of the shared bundle.                                                |
1617e41f4b71Sopenharmony_ci| versionCode | number | No  | Version number of the shared bundle. By default, no value is passed, and all shared bundles of the specified name are uninstalled.|
1618e41f4b71Sopenharmony_ci
1619e41f4b71Sopenharmony_ci## VerifyCodeParam<sup>deprecated<sup>
1620e41f4b71Sopenharmony_ci
1621e41f4b71Sopenharmony_ci> Since API version 11, the code signature file of an application is integrated into the installation package, rather than being specified by using this field.
1622e41f4b71Sopenharmony_ci
1623e41f4b71Sopenharmony_ciDefines the information about the code signature file.
1624e41f4b71Sopenharmony_ci
1625e41f4b71Sopenharmony_ci **System capability**: SystemCapability.BundleManager.BundleFramework.Core
1626e41f4b71Sopenharmony_ci
1627e41f4b71Sopenharmony_ci **System API**: This is a system API.
1628e41f4b71Sopenharmony_ci
1629e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description            |
1630e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- |
1631e41f4b71Sopenharmony_ci| moduleName | string | Yes| Module name of the bundle.|
1632e41f4b71Sopenharmony_ci| signatureFilePath  | string | Yes| Path of the code signature file.          |
1633e41f4b71Sopenharmony_ci
1634e41f4b71Sopenharmony_ci## PGOParam<sup>11+</sup>
1635e41f4b71Sopenharmony_ci
1636e41f4b71Sopenharmony_ciDefines the parameters of the PGO configuration file.
1637e41f4b71Sopenharmony_ci
1638e41f4b71Sopenharmony_ci **System capability**: SystemCapability.BundleManager.BundleFramework.Core
1639e41f4b71Sopenharmony_ci
1640e41f4b71Sopenharmony_ci **System API**: This is a system API.
1641e41f4b71Sopenharmony_ci
1642e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory| Description            |
1643e41f4b71Sopenharmony_ci| ---------- | ------ | ---------------- | ---------------- |
1644e41f4b71Sopenharmony_ci| moduleName | string | Yes| Module name of the bundle.|
1645e41f4b71Sopenharmony_ci| pgoFilePath  | string | Yes| Path of the PGO configuration file.          |
1646e41f4b71Sopenharmony_ci
1647e41f4b71Sopenharmony_ci## CreateAppCloneParam<sup>12+</sup>
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ciDescribes the parameters used for creating an application clone.
1650e41f4b71Sopenharmony_ci
1651e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BundleManager.BundleFramework.Core
1652e41f4b71Sopenharmony_ci
1653e41f4b71Sopenharmony_ci**System API**: This is a system API.
1654e41f4b71Sopenharmony_ci
1655e41f4b71Sopenharmony_ci| Name       | Type  | Mandatory| Description                                                         |
1656e41f4b71Sopenharmony_ci| ----------- | ------ | ---- | ------------------------------------------------------------ |
1657e41f4b71Sopenharmony_ci| userId      | number | No  | ID of the user for whom the clone is created. The default value is the user ID of the caller.            |
1658e41f4b71Sopenharmony_ci| appIndex    | number | No  | Index of the clone. The default value is the currently available minimum index.          |
1659