• 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                                      | Permission Level    | Description              |
20| ------------------------------------------ | ------------ | ------------------ |
21| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.|
22| ohos.permission.INSTALL_BUNDLE             | system_core  | Permission to install or uninstall bundles.  |
23
24For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
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';
139let bundleName = 'com.example.myapplication';
140let moduleName = 'entry';
141let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
142try {
143    freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag).then(() => {
144        console.info('Operation succeed')
145    }).catch(err => {
146        console.error('Operation failed:' + JSON.stringify(err));
147    });
148} catch (err) {
149    console.error('Operation failed:' + JSON.stringify(err));
150}
151```
152
153## isHapModuleRemovable
154
155isHapModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback\<boolean>): void;
156
157Checks whether a module can be removed. This API uses an asynchronous callback to return the result.
158
159**System API**: This is a system API.
160
161**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
162
163**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
164
165**Parameters**
166
167| Name     | Type                  | Mandatory| Description                                         |
168| ---------- | ---------------------- | ---- | --------------------------------------------- |
169| bundleName | string                 | Yes  | Bundle name.                     |
170| moduleName | string                 | Yes  | Module name.                           |
171| callback   | AsyncCallback\<boolean> | Yes  | Callback used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
172
173**Error codes**
174
175For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
176
177| ID|    Error Message                           |
178|----------|----------------------------------------|
179| 17700001 | The specified bundle name is not found. |
180| 17700002 | The specified module name is not found. |
181
182**Example**
183
184```js
185import freeInstall from '@ohos.bundle.freeInstall';
186let bundleName = 'com.example.myapplication';
187let moduleName = 'entry';
188try {
189    freeInstall.isHapModuleRemovable(bundleName, moduleName, (err, data) => {
190        if (err) {
191            console.error('Operation failed:' + JSON.stringify(err));
192        } else {
193            console.info('Operation succeed:' + JSON.stringify(data));
194        }
195    });
196} catch (err) {
197    console.error('Operation failed:' + JSON.stringify(err));
198}
199```
200
201## isHapModuleRemovable
202
203isHapModuleRemovable(bundleName: string, moduleName: string): Promise\<boolean>;
204
205Checks whether a module can be removed. This API uses a promise to return the result.
206
207**System API**: This is a system API.
208
209**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
210
211**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
212
213**Parameters**
214
215| Name    | Type  | Mandatory| Description              |
216| ---------- | ------ | ---- | ------------------ |
217| bundleName | string | Yes  | Bundle name.  |
218| moduleName | string | Yes  | Module name.|
219
220**Return value**
221
222| Type            | Description                        |
223| ---------------- | ---------------------------- |
224| Promise\<boolean> | Promise used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
225
226**Error codes**
227
228For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
229
230| ID|    Error Message                           |
231|----------|----------------------------------------|
232| 17700001 | The specified bundle name is not found. |
233| 17700002 | The specified module name is not found. |
234
235**Example**
236
237```js
238import freeInstall from '@ohos.bundle.freeInstall';
239let bundleName = 'com.example.myapplication';
240let moduleName = 'entry';
241try {
242    freeInstall.isHapModuleRemovable(bundleName, moduleName).then(data => {
243        console.info('Operation succeed:' + JSON.stringify(data));
244    }).catch(err => {
245        console.error('Operation failed:' + JSON.stringify(err));
246    });
247} catch (err) {
248    console.error('Operation failed:' + JSON.stringify(err));
249}
250```
251
252## getBundlePackInfo
253
254getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag, callback: AsyncCallback\<BundlePackInfo>): void;
255
256Obtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses an asynchronous callback to return the result.
257
258**System API**: This is a system API.
259
260**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
261
262**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
263
264**Parameters**
265
266| Name        | Type                                                        | Mandatory| Description                                                        |
267| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
268| bundleName     | string                                                       | Yes  | Bundle name.                                            |
269| bundlePackFlag | [BundlePackFlag](#bundlepackflag)                            | Yes  | Flag of the bundle package.                                    |
270| 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.|
271
272**Error codes**
273
274For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
275
276| ID|    Error Message                           |
277|----------|----------------------------------------|
278| 17700001 | The specified bundle name is not found. |
279
280**Example**
281
282```js
283import freeInstall from '@ohos.bundle.freeInstall';
284let bundleName = 'com.example.myapplication';
285let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
286try {
287    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag, (err, data) => {
288        if (err) {
289            console.error('Operation failed:' + JSON.stringify(err));
290        } else {
291            console.info('Operation succeed:' + JSON.stringify(data));
292        }
293    });
294} catch (err) {
295    console.error('Operation failed:' + JSON.stringify(err));
296}
297```
298## getBundlePackInfo
299
300getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag): Promise\<BundlePackInfo>;
301
302Obtains **bundlePackInfo** based on **bundleName** and **bundleFlag**. This API uses a promise to return the result.
303
304**System API**: This is a system API.
305
306**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
307
308**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
309
310**Parameters**
311
312| Name        | Type                             | Mandatory| Description                  |
313| -------------- | --------------------------------- | ---- | ---------------------- |
314| bundleName     | string                            | Yes  | Bundle name.|
315| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes  | Flag of the bundle package.|
316
317**Return value**
318
319| Type                                                      | Description                               |
320| ---------------------------------------------------------- | ----------------------------------- |
321| Promise<[BundlePackInfo](js-apis-bundleManager-BundlePackInfo.md)> | Promise used to return the **BundlePackInfo** object obtained.|
322
323**Error codes**
324
325For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
326
327| ID|    Error Message                           |
328|----------|----------------------------------------|
329| 17700001 | The specified bundle name is not found. |
330
331**Example**
332
333```js
334import freeInstall from '@ohos.bundle.freeInstall';
335let bundleName = 'com.example.myapplication';
336let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
337try {
338    freeInstall.getBundlePackInfo(bundleName, bundlePackFlag).then(data => {
339        console.info('Operation succeed:' + JSON.stringify(data));
340    }).catch(err => {
341        console.error('Operation failed:' + JSON.stringify(err));
342    });
343} catch (err) {
344    console.error('Operation failed:' + JSON.stringify(err));
345}
346```
347
348## getDispatchInfo
349
350getDispatchInfo(callback: AsyncCallback\<DispatchInfo>): void;
351
352Obtains the dispatch information. This API uses an asynchronous callback to return the result.
353
354**System API**: This is a system API.
355
356**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
357
358**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
359
360**Parameters**
361
362| Name  | Type                                                        | Mandatory| Description                                                        |
363| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
364| 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.|
365
366**Example**
367
368```js
369import freeInstall from '@ohos.bundle.freeInstall';
370try {
371    freeInstall.getDispatchInfo((err, data) => {
372        if (err) {
373            console.error('Operation failed:' + JSON.stringify(err));
374        } else {
375            console.info('Operation succeed:' + JSON.stringify(data));
376        }
377    });
378} catch (err) {
379    console.error('Operation failed:' + JSON.stringify(err));
380}
381```
382
383## getDispatchInfo
384
385getDispatchInfo(): Promise\<DispatchInfo>;
386
387Obtains the dispatch information. This API uses a promise to return the result.
388
389**System API**: This is a system API.
390
391**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
392
393**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
394
395**Return value**
396
397| Type                                            | Description                                                        |
398| ------------------------------------------------ | ------------------------------------------------------------ |
399| Promise<[DispatchInfo](js-apis-bundleManager-dispatchInfo.md)> | Promise used to return the [DispatchInfo](js-apis-bundleManager-dispatchInfo.md) object obtained.|
400
401**Example**
402
403```js
404import freeInstall from '@ohos.bundle.freeInstall';
405try {
406    freeInstall.getDispatchInfo().then(data => {
407        console.info('Operation succeed:' + JSON.stringify(data));
408    }).catch(err => {
409        console.error('Operation failed:' + JSON.stringify(err));
410    });
411} catch (err) {
412    console.error('Operation failed:' + JSON.stringify(err));
413}
414```
415