• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle.freeInstall (freeInstall)
2
3The **Bundle.freeInstall** module provides APIs for setting and obtaining installation-free information and APIs for obtaining **BundlePackInfo** and **DispatchInfo**.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```js
14import freeInstall from '@ohos.bundle.freeInstall';
15```
16
17## Required Permissions
18
19| Permission                                      | APL    | Description              |
20| ------------------------------------------ | ------------ | ------------------ |
21| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications.|
22| ohos.permission.INSTALL_BUNDLE             | system_core  | Permission to install or uninstall other applications except enterprise applications, including enterprise InHouse, mobile device management (MDM), and Normal applications.  |
23
24For details, see [Permission APL](../../security/AccessToken/app-permission-mgmt-overview.md#permission-apl).
25## UpgradeFlag
26
27**System API**: This is a system API.
28
29**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
30
31| Name            | Value  | Description            |
32| ---------------- | ---- | ---------------- |
33| NOT_UPGRADE      | 0    | No module needs an upgrade.    |
34| SINGLE_UPGRADE   | 1    | A single module needs an upgrade.|
35| RELATION_UPGRADE | 2    | The module that has a relationship with the current one needs an upgrade.|
36
37## BundlePackFlag
38
39**System API**: This is a system API.
40
41**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
42
43| Name              | Value        | Description                              |
44| ------------------ | ---------- | ---------------------------------- |
45| GET_PACK_INFO_ALL  | 0x00000000 | All information in the **pack.info** file.   |
46| GET_PACKAGES       | 0x00000001 | Package information in the **pack.info** file.|
47| GET_BUNDLE_SUMMARY | 0x00000002 | Bundle summary information in the **pack.info** file. |
48| GET_MODULE_SUMMARY | 0x00000004 | Module summary information in the **pack.info** file. |
49
50## freeInstall.setHapModuleUpgradeFlag
51
52setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag, callback: AsyncCallback\<void>):void
53
54Sets an upgrade flag for a module. This API uses an asynchronous callback to return the result.
55
56**Required permissions**: ohos.permission.INSTALL_BUNDLE
57
58**System API**: This is a system API.
59
60**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
61
62**Parameters**
63
64| Name    | Type                       | Mandatory| Description                      |
65| ----------- | --------------------------- | ---- | ---------------------------- |
66| bundleName  | string                      | Yes  | Bundle name.    |
67| moduleName  | string                      | Yes  | Module name.          |
68| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes  | Upgrade flag, which is for internal use only.      |
69| callback    | AsyncCallback\<void>        | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
70
71**Error codes**
72
73For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
74
75| ID|    Error Message                           |
76|----------|---------------------------------------- |
77| 17700001 | The specified bundle name is not found. |
78| 17700002 | The specified module name is not found. |
79
80**Example**
81
82```js
83import freeInstall from '@ohos.bundle.freeInstall';
84let bundleName = 'com.example.myapplication';
85let moduleName = 'entry';
86let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
87try {
88    freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag, err => {
89        if (err) {
90            console.error('Operation failed:' + JSON.stringify(err));
91        } else {
92            console.info('Operation succeed');
93        }
94    });
95} catch (err) {
96    console.error('Operation failed:' + JSON.stringify(err));
97}
98```
99
100## setHapModuleUpgradeFlag
101
102setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag): Promise\<void>
103
104Sets an upgrade flag for a module. This API uses a promise to return the result.
105
106**System API**: This is a system API.
107
108**Required permissions**: ohos.permission.INSTALL_BUNDLE
109
110**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
111
112**Parameters**
113
114| Name     | Type                       | Mandatory| Description                  |
115| ----------- | --------------------------- | ---- | ---------------------- |
116| bundleName  | string                      | Yes  | Bundle name.|
117| moduleName  | string                      | Yes  | Module name.    |
118| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes  | Upgrade flag, which is for internal use only.|
119
120**Return value**
121
122| Type         | Description                                |
123| ------------- | ------------------------------------ |
124| Promise\<void> | Promise that returns no value.|
125
126**Error codes**
127
128For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
129
130| ID|    Error Message                           |
131|----------|----------------------------------------|
132| 17700001 | The specified bundle name is not found. |
133| 17700002 | The specified module name is not found. |
134
135**Example**
136
137```js
138import freeInstall from '@ohos.bundle.freeInstall';
139import { BusinessError } from '@ohos.base';
140let bundleName = 'com.example.myapplication';
141let moduleName = 'entry';
142let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
143try {
144    freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag).then(() => {
145        console.info('Operation succeed')
146    }).catch((err: BusinessError) => {
147        console.error('Operation failed:' + JSON.stringify(err));
148    });
149} catch (err) {
150    console.error('Operation failed:' + JSON.stringify(err));
151}
152```
153
154## isHapModuleRemovable
155
156isHapModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback\<boolean>): void
157
158Checks whether a module can be removed. This API uses an asynchronous callback to return the result.
159
160**System API**: This is a system API.
161
162**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
163
164**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
165
166**Parameters**
167
168| Name     | Type                  | Mandatory| Description                                         |
169| ---------- | ---------------------- | ---- | --------------------------------------------- |
170| bundleName | string                 | Yes  | Bundle name.                     |
171| moduleName | string                 | Yes  | Module name.                           |
172| callback   | AsyncCallback\<boolean> | Yes  | Callback used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
173
174**Error codes**
175
176For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
177
178| ID|    Error Message                           |
179|----------|----------------------------------------|
180| 17700001 | The specified bundle name is not found. |
181| 17700002 | The specified module name is not found. |
182
183**Example**
184
185```js
186import freeInstall from '@ohos.bundle.freeInstall';
187let bundleName = 'com.example.myapplication';
188let moduleName = 'entry';
189try {
190    freeInstall.isHapModuleRemovable(bundleName, moduleName, (err, data) => {
191        if (err) {
192            console.error('Operation failed:' + JSON.stringify(err));
193        } else {
194            console.info('Operation succeed:' + JSON.stringify(data));
195        }
196    });
197} catch (err) {
198    console.error('Operation failed:' + JSON.stringify(err));
199}
200```
201
202## isHapModuleRemovable
203
204isHapModuleRemovable(bundleName: string, moduleName: string): Promise\<boolean>
205
206Checks whether a module can be removed. This API uses a promise to return the result.
207
208**System API**: This is a system API.
209
210**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
211
212**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
213
214**Parameters**
215
216| Name    | Type  | Mandatory| Description              |
217| ---------- | ------ | ---- | ------------------ |
218| bundleName | string | Yes  | Bundle name.  |
219| moduleName | string | Yes  | Module name.|
220
221**Return value**
222
223| Type            | Description                        |
224| ---------------- | ---------------------------- |
225| Promise\<boolean> | Promise used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
226
227**Error codes**
228
229For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
230
231| ID|    Error Message                           |
232|----------|----------------------------------------|
233| 17700001 | The specified bundle name is not found. |
234| 17700002 | The specified module name is not found. |
235
236**Example**
237
238```js
239import freeInstall from '@ohos.bundle.freeInstall';
240import { BusinessError } from '@ohos.base';
241let bundleName = 'com.example.myapplication';
242let moduleName = 'entry';
243try {
244    freeInstall.isHapModuleRemovable(bundleName, moduleName).then(data => {
245        console.info('Operation succeed:' + JSON.stringify(data));
246    }).catch((err: BusinessError) => {
247        console.error('Operation failed:' + JSON.stringify(err));
248    });
249} catch (err) {
250    console.error('Operation failed:' + JSON.stringify(err));
251}
252```
253
254## getBundlePackInfo
255
256getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag, callback: AsyncCallback\<BundlePackInfo>): void
257
258Obtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses an asynchronous callback to return the result.
259
260**System API**: This is a system API.
261
262**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
263
264**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
265
266**Parameters**
267
268| Name        | Type                                                        | Mandatory| Description                                                        |
269| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
270| bundleName     | string                                                       | Yes  | Bundle name.                                            |
271| bundlePackFlag | [BundlePackFlag](#bundlepackflag)                            | Yes  | Flag of the bundle package.                                    |
272| callback       | AsyncCallback<[BundlePackInfo](js-apis-bundleManager-BundlePackInfo.md)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **BundlePackInfo** object obtained; otherwise, **err** is an error object.|
273
274**Error codes**
275
276For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
277
278| ID|    Error Message                           |
279|----------|----------------------------------------|
280| 17700001 | The specified bundle name is not found. |
281
282**Example**
283
284```js
285import freeInstall from '@ohos.bundle.freeInstall';
286let bundleName = 'com.example.myapplication';
287let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
288try {
289    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag, (err, data) => {
290        if (err) {
291            console.error('Operation failed:' + JSON.stringify(err));
292        } else {
293            console.info('Operation succeed:' + JSON.stringify(data));
294        }
295    });
296} catch (err) {
297    console.error('Operation failed:' + JSON.stringify(err));
298}
299```
300## getBundlePackInfo
301
302getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag): Promise\<BundlePackInfo>
303
304Obtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses a promise to return the result.
305
306**System API**: This is a system API.
307
308**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
309
310**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
311
312**Parameters**
313
314| Name        | Type                             | Mandatory| Description                  |
315| -------------- | --------------------------------- | ---- | ---------------------- |
316| bundleName     | string                            | Yes  | Bundle name.|
317| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes  | Flag of the bundle package.|
318
319**Return value**
320
321| Type                                                      | Description                               |
322| ---------------------------------------------------------- | ----------------------------------- |
323| Promise<[BundlePackInfo](js-apis-bundleManager-BundlePackInfo.md)> | Promise used to return the **BundlePackInfo** object obtained.|
324
325**Error codes**
326
327For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
328
329| ID|    Error Message                           |
330|----------|----------------------------------------|
331| 17700001 | The specified bundle name is not found. |
332
333**Example**
334
335```js
336import freeInstall from '@ohos.bundle.freeInstall';
337import { BusinessError } from '@ohos.base';
338let bundleName = 'com.example.myapplication';
339let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
340try {
341    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag).then(data => {
342        console.info('Operation succeed:' + JSON.stringify(data));
343    }).catch((err: BusinessError) => {
344        console.error('Operation failed:' + JSON.stringify(err));
345    });
346} catch (err) {
347    console.error('Operation failed:' + JSON.stringify(err));
348}
349```
350
351## getDispatchInfo
352
353getDispatchInfo(callback: AsyncCallback\<DispatchInfo>): void
354
355Obtains the dispatch information. This API uses an asynchronous callback to return the result.
356
357**System API**: This is a system API.
358
359**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
360
361**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
362
363**Parameters**
364
365| Name  | Type                                                        | Mandatory| Description                                                        |
366| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
367| callback | AsyncCallback<[DispatchInfo](js-apis-bundleManager-dispatchInfo.md)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**, and **data** is the [DispatchInfo](js-apis-bundleManager-dispatchInfo.md) object obtained. otherwise, **err** is an error object.|
368
369**Example**
370
371```js
372import freeInstall from '@ohos.bundle.freeInstall';
373try {
374    freeInstall.getDispatchInfo((err, data) => {
375        if (err) {
376            console.error('Operation failed:' + JSON.stringify(err));
377        } else {
378            console.info('Operation succeed:' + JSON.stringify(data));
379        }
380    });
381} catch (err) {
382    console.error('Operation failed:' + JSON.stringify(err));
383}
384```
385
386## getDispatchInfo
387
388getDispatchInfo(): Promise\<DispatchInfo>
389
390Obtains the dispatch information. This API uses a promise to return the result.
391
392**System API**: This is a system API.
393
394**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
395
396**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
397
398**Return value**
399
400| Type                                            | Description                                                        |
401| ------------------------------------------------ | ------------------------------------------------------------ |
402| Promise<[DispatchInfo](js-apis-bundleManager-dispatchInfo.md)> | Promise used to return the [DispatchInfo](js-apis-bundleManager-dispatchInfo.md) object obtained.|
403
404**Example**
405
406```js
407import freeInstall from '@ohos.bundle.freeInstall';
408import { BusinessError } from '@ohos.base';
409try {
410    freeInstall.getDispatchInfo().then(data => {
411        console.info('Operation succeed:' + JSON.stringify(data));
412    }).catch((err: BusinessError) => {
413        console.error('Operation failed:' + JSON.stringify(err));
414    });
415} catch (err) {
416    console.error('Operation failed:' + JSON.stringify(err));
417}
418```
419