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