• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.bundle (Bundle) (System API)
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9The module provides APIs for obtaining information about an application, including [bundle information](js-apis-bundle-BundleInfo.md), [application information](js-apis-bundle-ApplicationInfo.md), and [ability information](js-apis-bundle-AbilityInfo.md). It also provides APIs to obtain and set the application disabling state.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14>
15> The APIs of this module are deprecated since API version 9. You are advised to use [@ohos.bundle.bundleManager](js-apis-bundleManager-sys.md) instead.
16>
17> This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.bundle](js-apis-Bundle.md).
18
19## Modules to Import
20
21```ts
22import bundle from '@ohos.bundle';
23```
24
25## Required Permissions
26
27| Permission                                        | APL        | Description           |
28|--------------------------------------------|--------------|---------------|
29| ohos.permission.CHANGE_ABILITY_ENABLED_STATE | system_basic | Permission to enable or disable an application or ability.|
30| ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about a specified bundle.|
31| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all bundles.    |
32| ohos.permission.INSTALL_BUNDLE             | system_core  | Permission to install or uninstall bundles.     |
33| ohos.permission.REMOVE_CACHE_FILES | system_basic | Permission to clear cache files of a bundle.|
34
35For details about the APL, see [Basic Concepts in the Permission Mechanism](../../security/AccessToken/app-permission-mgmt-overview.md#basic-concepts-in-the-permission-mechanism).
36
37## bundle.getBundleInstaller<sup>deprecated<sup>
38
39> This API is deprecated since API version 9. You are advised to use [installer.getBundleInstaller](js-apis-installer-sys.md#bundleinstallergetbundleinstaller) instead.
40
41getBundleInstaller(): Promise&lt;BundleInstaller&gt;
42
43Obtains the installation package. This API uses a promise to return the result.
44
45**Required permissions**
46
47ohos.permission.INSTALL_BUNDLE
48
49**System capability**
50
51SystemCapability.BundleManager.BundleFramework
52
53**System API**
54
55This is a system API.
56
57**Return value**
58
59| Type                                                        | Description                                        |
60| ------------------------------------------------------------ | -------------------------------------------- |
61| Promise<[BundleInstaller](js-apis-bundle-BundleInstaller-sys.md)> | Promise used to return the installation package.|
62
63**Example**
64
65```ts
66import bundle from '@ohos.bundle';
67import { BusinessError } from '@ohos.base';
68
69bundle.getBundleInstaller().then((data) => {
70  console.info('getBundleInstaller successfully.');
71}).catch((error: BusinessError) => {
72  console.error('getBundleInstaller failed.');
73});
74```
75
76## bundle.getBundleInstaller<sup>deprecated<sup>
77
78> This API is deprecated since API version 9. You are advised to use [installer.getBundleInstaller](js-apis-installer-sys.md#bundleinstallergetbundleinstaller) instead.
79
80getBundleInstaller(callback: AsyncCallback&lt;BundleInstaller&gt;): void
81
82Obtains the installation package. This API uses an asynchronous callback to return the result.
83
84**Required permissions**
85
86ohos.permission.INSTALL_BUNDLE
87
88**System capability**
89
90SystemCapability.BundleManager.BundleFramework
91
92**System API**
93
94This is a system API.
95
96**Parameters**
97
98| Name  | Type                                                        | Mandatory| Description            |
99| -------- | ------------------------------------------------------------ | ---- | ---------------- |
100| callback | AsyncCallback<[BundleInstaller](js-apis-bundle-BundleInstaller-sys.md)> | Yes  | Callback used to return the installation package.|
101
102**Example**
103
104```ts
105import bundle from '@ohos.bundle';
106
107bundle.getBundleInstaller((err, data) => {
108  if (err.code == 0) {
109    console.error('getBundleInstaller successfully.');
110  } else {
111    console.info('getBundleInstaller failed.');
112  }
113});
114```
115## bundle.cleanBundleCacheFiles<sup>8+</sup> <sup>deprecated<sup>
116
117> This API is deprecated since API version 9. You are advised to use [bundleManager.cleanBundleCacheFiles](js-apis-bundleManager-sys.md#bundlemanagercleanbundlecachefiles) instead.
118
119cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback&lt;void&gt;): void
120
121Clears the cache data of an application. This API uses an asynchronous callback to return the result.
122
123**Required permissions**
124
125ohos.permission.REMOVE_CACHE_FILES
126
127**System capability**
128
129SystemCapability.BundleManager.BundleFramework
130
131**System API**
132
133This is a system API.
134
135**Parameters**
136
137| Name     | Type               | Mandatory| Description                                 |
138| ---------- | ------------------- | ---- | ------------------------------------- |
139| bundleName | string              | Yes  | Bundle name.|
140| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result.         |
141
142**Example**
143
144```ts
145import bundle from '@ohos.bundle';
146
147let bundleName: string = "com.example.myapplication";
148
149bundle.cleanBundleCacheFiles(bundleName, err => {
150  if (err) {
151    console.error('cleanBundleCacheFiles failed.');
152  } else {
153    console.info('cleanBundleCacheFiles successfully.');
154  }
155});
156```
157
158## bundle.cleanBundleCacheFiles<sup>8+</sup> <sup>deprecated<sup>
159
160> This API is deprecated since API version 9. You are advised to use [bundleManager.cleanBundleCacheFiles](js-apis-bundleManager-sys.md#bundlemanagercleanbundlecachefiles) instead.
161
162cleanBundleCacheFiles(bundleName: string): Promise&lt;void&gt;
163
164Clears the cache data of an application. This API uses a promise to return the result.
165
166**Required permissions**
167
168ohos.permission.REMOVE_CACHE_FILES
169
170**System capability**
171
172SystemCapability.BundleManager.BundleFramework
173
174**System API**
175
176This is a system API.
177
178**Parameters**
179
180| Name    | Type  | Mandatory| Description                                 |
181| ---------- | ------ | ---- | ------------------------------------- |
182| bundleName | string | Yes  | Bundle name.|
183
184**Return value**
185
186| Type         | Description                                |
187| ------------- | ------------------------------------ |
188| Promise\<void> | Promise that returns no value.|
189
190**Example**
191
192```ts
193import bundle from '@ohos.bundle';
194import { BusinessError } from '@ohos.base';
195
196let bundleName: string = "com.example.myapplication";
197
198bundle.cleanBundleCacheFiles(bundleName).then(() => {
199  console.info('cleanBundleCacheFiles successfully.');
200}).catch((error: BusinessError) => {
201  console.error('cleanBundleCacheFiles failed.');
202});
203```
204
205## bundle.setApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
206
207> This API is deprecated since API version 9. You are advised to use [bundleManager.setApplicationEnabled](js-apis-bundleManager-sys.md#bundlemanagersetapplicationenabled) instead.
208
209setApplicationEnabled(bundleName: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
210
211Sets whether to enable an application. This API uses an asynchronous callback to return the result.
212
213**Required permissions**
214
215ohos.permission.CHANGE_ABILITY_ENABLED_STATE
216
217**System capability**
218
219SystemCapability.BundleManager.BundleFramework
220
221**System API**
222
223This is a system API.
224
225**Parameters**
226
227| Name     | Type               | Mandatory| Description                            |
228| ---------- | ------------------- | ---- |--------------------------------|
229| bundleName | string              | Yes  | Bundle name.         |
230| isEnable   | boolean             | Yes  | Whether to enable the application. **true** to enable, **false** otherwise.|
231| callback   | AsyncCallback\<void> | Yes  | Callback used to return the result.                         |
232
233**Example**
234
235```ts
236import bundle from '@ohos.bundle';
237
238let bundleName: string = "com.example.myapplication";
239
240bundle.setApplicationEnabled(bundleName, false, err => {
241  if (err) {
242    console.error('setApplicationEnabled failed.');
243  } else {
244    console.info('setApplicationEnabled successfully.');
245  }
246});
247```
248
249## bundle.setApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
250
251> This API is deprecated since API version 9. You are advised to use [bundleManager.setApplicationEnabled](js-apis-bundleManager-sys.md#bundlemanagersetapplicationenabled) instead.
252
253setApplicationEnabled(bundleName: string, isEnable: boolean): Promise&lt;void&gt;
254
255Sets whether to enable an application. This API uses a promise to return the result.
256
257**Required permissions**
258
259ohos.permission.CHANGE_ABILITY_ENABLED_STATE
260
261**System capability**
262
263SystemCapability.BundleManager.BundleFramework
264
265**System API**
266
267This is a system API.
268
269**Parameters**
270
271| Name    | Type   | Mandatory| Description                                           |
272| ---------- | ------- | ---- | ----------------------------------------------- |
273| bundleName | string  | Yes  | Bundle name.           |
274| isEnable   | boolean | Yes  | Whether to enable the application. **true** to enable, **false** otherwise.|
275
276**Return value**
277
278| Type         | Description                                |
279| ------------- | ------------------------------------ |
280| Promise\<void> | Promise that returns no value.|
281
282**Example**
283
284```ts
285import bundle from '@ohos.bundle';
286import { BusinessError } from '@ohos.base';
287
288let bundleName: string = "com.example.myapplication";
289
290bundle.setApplicationEnabled(bundleName, false).then(() => {
291  console.info('setApplicationEnabled successfully.');
292}).catch((error: BusinessError) => {
293  console.error('setApplicationEnabled failed.');
294});
295```
296
297## bundle.setAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
298
299> This API is deprecated since API version 9. You are advised to use [bundleManager.setAbilityEnabled](js-apis-bundleManager-sys.md#bundlemanagersetabilityenabled) instead.
300
301setAbilityEnabled(info: AbilityInfo, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void
302
303Sets whether to enable an ability. This API uses an asynchronous callback to return the result.
304
305**Required permissions**
306
307ohos.permission.CHANGE_ABILITY_ENABLED_STATE
308
309**System capability**
310
311SystemCapability.BundleManager.BundleFramework
312
313**System API**
314
315This is a system API.
316
317**Parameters**
318
319| Name  | Type                                        | Mandatory| Description                                           |
320| -------- | -------------------------------------------- | ---- | ----------------------------------------------- |
321| info     | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes  | Ability information.                                  |
322| isEnable | boolean                                      | Yes  | Whether to enable the ability. **true** to enable, **false** otherwise.|
323| callback | AsyncCallback\<void>                         | Yes  | Callback used to return the result.                   |
324
325## bundle.setAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
326
327> This API is deprecated since API version 9. You are advised to use [bundleManager.setAbilityEnabled](js-apis-bundleManager-sys.md#bundlemanagersetabilityenabled) instead.
328
329setAbilityEnabled(info: AbilityInfo, isEnable: boolean): Promise&lt;void&gt;
330
331Sets whether to enable an ability. This API uses a promise to return the result.
332
333**Required permissions**
334
335ohos.permission.CHANGE_ABILITY_ENABLED_STATE
336
337**System capability**
338
339SystemCapability.BundleManager.BundleFramework
340
341**System API**
342
343This is a system API.
344
345**Parameters**
346
347| Name  | Type                                        | Mandatory| Description                                           |
348| -------- | -------------------------------------------- | ---- | ----------------------------------------------- |
349| info     | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes  | Ability information.                                  |
350| isEnable | boolean                                      | Yes  | Whether to enable the ability. **true** to enable, **false** otherwise.|
351
352**Return value**
353
354| Type         | Description                                |
355| ------------- | ------------------------------------ |
356| Promise\<void> | Promise that returns no value.|
357
358**Example**
359
360```ts
361import bundle from '@ohos.bundle';
362import { BusinessError } from '@ohos.base';
363
364let bundleName: string = "com.example.myapplication";
365let abilityName: string = "EntryAbility";
366
367bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo) => {
368  console.info('getAbilityInfo successfully. Data: ' + JSON.stringify(abilityInfo));
369
370  bundle.setAbilityEnabled(abilityInfo, false).then(data => {
371    console.info('setAbilityEnabled successfully.');
372  }).catch((error: BusinessError) => {
373    console.error('setAbilityEnabled failed:' + JSON.stringify(error));
374  })
375}).catch((error: BusinessError) => {
376  console.error('getAbilityInfo failed. Cause: ' + JSON.stringify(error));
377});
378```
379## bundle.getPermissionDef<sup>8+</sup> <sup>deprecated<sup>
380
381> This API is deprecated since API version 9. You are advised to use [bundleManager.getPermissionDef](js-apis-bundleManager-sys.md#bundlemanagergetpermissiondef) instead.
382
383getPermissionDef(permissionName: string, callback: AsyncCallback&lt;PermissionDef&gt;): void
384
385Obtains the permission details by permission name. This API uses an asynchronous callback to return the result.
386
387**Required permissions**
388
389ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
390
391**System capability**
392
393SystemCapability.BundleManager.BundleFramework
394
395**System API**
396
397This is a system API.
398
399**Parameters**
400
401| Name        | Type                                                        | Mandatory| Description                                            |
402| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
403| permissionName | string                                                       | Yes  | Name of the permission.                                |
404| callback       | AsyncCallback<[PermissionDef](js-apis-bundle-PermissionDef-sys.md)> | Yes  | Callback used to return the permission details.|
405
406**Example**
407
408```ts
409import bundle from '@ohos.bundle';
410
411let permission: string = "ohos.permission.GET_BUNDLE_INFO";
412bundle.getPermissionDef(permission, (err, data) => {
413  if (err) {
414    console.error('getPermissionDef failed:' + err.message);
415  } else {
416    console.info('getPermissionDef successfully:' + JSON.stringify(data));
417  }
418});
419```
420
421## bundle.getPermissionDef<sup>8+</sup> <sup>deprecated<sup>
422
423> This API is deprecated since API version 9. You are advised to use [bundleManager.getPermissionDef](js-apis-bundleManager-sys.md#bundlemanagergetpermissiondef) instead.
424
425getPermissionDef(permissionName: string): Promise&lt;PermissionDef&gt;
426
427Obtains the permission details by permission name. This API uses a promise to return the result.
428
429**Required permissions**
430
431ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
432
433**System capability**
434
435SystemCapability.BundleManager.BundleFramework
436
437**System API**
438
439This is a system API.
440
441**Parameters**
442
443| Name        | Type  | Mandatory| Description            |
444| -------------- | ------ | ---- | ---------------- |
445| permissionName | string | Yes  | Name of the permission.|
446
447**Return value**
448
449| Type                                                  | Description                                                  |
450| ------------------------------------------------------ | ------------------------------------------------------ |
451| Promise<[PermissionDef](js-apis-bundle-PermissionDef-sys.md)> | Promise used to return the permission details.|
452
453**Example**
454
455```ts
456import bundle from '@ohos.bundle';
457import { BusinessError } from '@ohos.base';
458
459let permissionName: string = "ohos.permission.GET_BUNDLE_INFO";
460bundle.getPermissionDef(permissionName).then((data) => {
461  console.info('getPermissionDef successfully. Data: ' + JSON.stringify(data));
462}).catch((error: BusinessError) => {
463  console.error('getPermissionDef failed. Cause: ' + error.message);
464});
465```
466