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