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