提交 34ed2be9 编写于 作者: G Gloria

Update docs against 11278+11480+11618+11384+11654+11518+10458+11718+11642+11687+11639

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 a6f3eb34
......@@ -60,13 +60,34 @@
- [@ohos.notification](js-apis-notification.md)
- application/[EventHub](js-apis-eventhub.md)
- Bundle Management
- [@ohos.bundle.appControl](js-apis-appControl.md)
- [@ohos.bundle.bundleManager](js-apis-bundleManager.md)
- [@ohos.bundle.bundleMonitor](js-apis-bundleMonitor.md)
- [@ohos.bundle.defaultAppManager](js-apis-defaultAppManager.md)
- [@ohos.bundle.distributedBundle](js-apis-distributedBundle.md)
- [@ohos.bundle.freeInstall](js-apis-freeInstall.md)
- [@ohos.bundle.installer](js-apis-installer.md)
- [@ohos.bundle.launcherBundleManager](js-apis-launcherBundleManager.md)
- [@ohos.zlib](js-apis-zlib.md)
- bundleManager/[abilityInfo](js-apis-bundleManager-abilityInfo.md)
- bundleManager/[applicationInfo](js-apis-bundleManager-applicationInfo.md)
- bundleManager/[bundleInfo](js-apis-bundleManager-bundleInfo.md)
- bundleManager/[dispatchInfo](js-apis-bundleManager-dispatchInfo.md)
- bundleManager/[elementName](js-apis-bundleManager-elementName.md)
- bundleManager/[extensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)
- bundleManager/[hapModuleInfo](js-apis-bundleManager-hapModuleInfo.md)
- bundleManager/[launcherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)
- bundleManager/[metadata](js-apis-bundleManager-metadata.md)
- bundleManager/[packInfo](js-apis-bundleManager-packInfo.md)
- bundleManager/[permissionDef](js-apis-bundleManager-permissionDef.md)
- bundleManager/[remoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)
- bundleManager/[shortcutInfo](js-apis-bundleManager-shortcutInfo.md)
- UI Page
- [@ohos.animator](js-apis-animator.md)
- [@ohos.mediaquery](js-apis-mediaquery.md)
- [@ohos.promptAction](js-apis-promptAction.md)
- [@ohos.router](js-apis-router.md)
- Graphics
- Graphics
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.display ](js-apis-display.md)
- [@ohos.effectKit](js-apis-effectKit.md)
......@@ -86,7 +107,6 @@
- [@ohos.intl](js-apis-intl.md)
- [@ohos.resourceManager](js-apis-resource-manager.md)
- Resource Scheduling
- [@ohos.backgroundTaskManager](js-apis-backgroundTaskManager.md)
- [@ohos.distributedMissionManager](js-apis-distributedMissionManager.md)
- [@ohos.reminderAgentManager](js-apis-reminderAgentManager.md)
- [@ohos.resourceschedule.backgroundTaskManager](js-apis-resourceschedule-backgroundTaskManager.md)
......@@ -96,8 +116,7 @@
- Security
- [@ohos.abilityAccessCtrl](js-apis-abilityAccessCtrl.md)
- [@ohos.privacyManager](js-apis-privacyManager.md)
- [@ohos.security.cert](js-apis-cert.md)
- [@ohos.security.cryptoFramework]js-apis-cryptoFramework.md)
- [@ohos.security.cryptoFramework](js-apis-cryptoFramework.md)
- [@ohos.security.huks ](js-apis-huks.md)
- [@ohos.userIAM.faceAuth](js-apis-useriam-faceauth.md)
- [@ohos.userIAM.userAuth ](js-apis-useriam-userauth.md)
......@@ -136,11 +155,8 @@
- [@ohos.net.connection](js-apis-net-connection.md)
- [@ohos.net.ethernet](js-apis-net-ethernet.md)
- [@ohos.net.http](js-apis-http.md)
- [@ohos.net.policy](js-apis-net-policy.md)
- [@ohos.net.sharing](js-apis-net-sharing.md)
- [@ohos.net.socket](js-apis-socket.md)
- [@ohos.net.statistics](js-apis-net-statistics.md)
- [@ohos.net.tlsSocket](js-apis-tlsSocket.md)
- [@ohos.net.webSocket](js-apis-webSocket.md)
- [@ohos.request](js-apis-request.md)
- Connectivity
......@@ -197,6 +213,7 @@
- [@ohos.runningLock](js-apis-runninglock.md)
- [@ohos.sensor](js-apis-sensor.md)
- [@ohos.settings](js-apis-settings.md)
- [@ohos.systemParameterV9](js-apis-system-parameterV9.md)
- [@ohos.thermal](js-apis-thermal.md)
- [@ohos.update](js-apis-update.md)
- [@ohos.usb](js-apis-usb.md)
......@@ -206,10 +223,8 @@
- [@ohos.account.distributedAccount](js-apis-distributed-account.md)
- [@ohos.account.osAccount](js-apis-osAccount.md)
- Custom Management
- [@ohos.configPolicy](js-apis-config-policy.md)
- [@ohos.configPolicy](js-apis-configPolicy.md)
- [@ohos.EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md)
- [@ohos.enterpriseDeviceManager](js-apis-enterprise-device-manager.md)
- enterpriseDeviceManager/[DeviceSettingsManager](js-apis-enterpriseDeviceManager-DeviceSettingsManager.md)
- Language Base Class Library
- [@ohos.buffer](js-apis-buffer.md)
- [@ohos.convertxml](js-apis-convertxml.md)
......@@ -252,6 +267,7 @@
- [@ohos.prompt](js-apis-prompt.md)
- [@ohos.reminderAgent](js-apis-reminderAgent.md)
- [@ohos.systemParameter](js-apis-system-parameter.md)
- [@ohos.workScheduler](js-apis-workScheduler.md)
- [@system.app](js-apis-system-app.md)
- [@system.battery](js-apis-system-battery.md)
- [@system.bluetooth](js-apis-system-bluetooth.md)
......@@ -277,6 +293,7 @@
- bundle/[bundleInfo](js-apis-bundle-BundleInfo.md)
- bundle/[bundleInstaller](js-apis-bundle-BundleInstaller.md)
- bundle/[bundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md)
- bundle/[customizeData](js-apis-bundle-CustomizeData.md)
- bundle/[elementName](js-apis-bundle-ElementName.md)
- bundle/[hapModuleInfo](js-apis-bundle-HapModuleInfo.md)
- bundle/[launcherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)
......
......@@ -4,16 +4,18 @@ The **BundleStatusCallback** module provides bundle callback information, which
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This module is deprecated since API version 9. You are advised to use [bundleMonitor](js-apis-bundleMonitor.md) instead.
## BundleStatusCallback
## BundleStatusCallback<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [bundleMonitor](js-apis-bundleMonitor.md) instead.
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| Type | Callback | Description |
| ------ | --------------------------------------------- | -------------------------------------- |
| add | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is added.|
| update | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is updated.|
| remove | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is removed.|
| add | (bundleName : string, userId: number) => void | Used to obtain information when a bundle is installed.|
| update | (bundleName : string, userId: number) => void | Used to obtain information when a bundle is updated.|
| remove | (bundleName : string, userId: number) => void | Used to obtain information when a bundle is uninstalled.|
# innerBundleManager
# innerBundleManager<sup>(deprecated)</sup>
The **innerBundleManager** module manages internal bundles.
The **innerBundleManager** module provides APIs for the **Home Screen** application.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This module is deprecated since API version 9. You are advised to use [launcherBundleManager](js-apis-launcherBundleManager.md) and [bundleMonitor](js-apis-bundleMonitor.md) instead.
## Modules to Import
```
```typescript
import innerBundleManager from '@ohos.bundle.innerBundleManager';
```
......@@ -16,20 +16,13 @@ import innerBundleManager from '@ohos.bundle.innerBundleManager';
SystemCapability.BundleManager.BundleFramework
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ---------------------------- |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications. |
| ohos.permission.LISTEN_BUNDLE_CHANGE | system_grant | Permission to listen for application changes.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## innerBundleManager.getLauncherAbilityInfos
## innerBundleManager.getLauncherAbilityInfos<sup>(deprecated)</sup>
getLauncherAbilityInfos(bundleName: string, userId: number, callback: AsyncCallback&lt;Array&lt;LauncherAbilityInfo&gt;&gt;) : void;
Obtains the launcher ability information based on a given bundle name. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......@@ -52,12 +45,12 @@ This is a system API and cannot be called by third-party applications.
| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Yes | Callback used to return an array of the launcher ability information. |
## innerBundleManager.getLauncherAbilityInfos
## innerBundleManager.getLauncherAbilityInfos<sup>(deprecated)</sup>
getLauncherAbilityInfos(bundleName: string, userId: number) : Promise&lt;Array&lt;LauncherAbilityInfo&gt;&gt;
Obtains the launcher ability information based on a given bundle name. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......@@ -84,11 +77,12 @@ This is a system API and cannot be called by third-party applications.
| ------------------------------------------------------------ | ------------------------- |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Promise used to return an array of the launcher ability information.|
## innerBundleManager.on
## innerBundleManager.on<sup>(deprecated)</sup>
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback, callback: AsyncCallback&lt;string&gt;) : void;
Registers a callback to receive bundle status changes. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleMonitor#on](js-apis-bundleMonitor.md) instead.
**Required permissions**
......@@ -110,11 +104,12 @@ This is a system API and cannot be called by third-party applications.
| bundleStatusCallback | [BundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md) | Yes | Callback to register. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.on
## innerBundleManager.on<sup>(deprecated)</sup>
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback): Promise&lt;string&gt;
on(type:"BundleStatusChange", bundleStatusCallback : BundleStatusCallback) : Promise&lt;string&gt;
Registers a callback to receive bundle status changes. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleMonitor#on](js-apis-bundleMonitor.md) instead.
**Required permissions**
......@@ -141,11 +136,12 @@ This is a system API and cannot be called by third-party applications.
| --------------- | ----------------------------------- |
| Promise\<string> | Promise used to return a successful result or error information.|
## innerBundleManager.off
## innerBundleManager.off<sup>(deprecated)</sup>
off(type:"BundleStatusChange", callback: AsyncCallback&lt;string&gt;) : void;
Deregisters the callback that receives bundle status changes. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleMonitor#off](js-apis-bundleMonitor.md) instead.
**Required permissions**
......@@ -166,11 +162,12 @@ This is a system API and cannot be called by third-party applications.
| type | string | Yes | Event type. Only **BundleStatusChange** is supported. |
| callback | AsyncCallback\<string> | Yes | Callback used to return a successful result or error information.|
## innerBundleManager.off
## innerBundleManager.off<sup>(deprecated)</sup>
off(type:"BundleStatusChange"): Promise&lt;string&gt;
off(type:"BundleStatusChange") : Promise&lt;string&gt;
Deregisters the callback that receives bundle status changes. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleMonitor#off](js-apis-bundleMonitor.md) instead.
**Required permissions**
......@@ -187,7 +184,7 @@ This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------------------------------ |
| ------ | ------ | ---- | ------------------------------------------ |
| type | string | Yes | Event type. Only **BundleStatusChange** is supported.|
**Return value**
......@@ -196,11 +193,12 @@ This is a system API and cannot be called by third-party applications.
| --------------- | ----------------------------------- |
| Promise\<string> | Promise used to return a successful result or error information.|
## innerBundleManager.getAllLauncherAbilityInfos
## innerBundleManager.getAllLauncherAbilityInfos<sup>(deprecated)</sup>
getAllLauncherAbilityInfos(userId: number, callback: AsyncCallback&lt;Array&lt;LauncherAbilityInfo&gt;&gt;) : void;
Obtains the information about all launcher abilities. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......@@ -221,11 +219,12 @@ This is a system API and cannot be called by third-party applications.
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Yes | Callback used to return an array of the launcher ability information. |
## innerBundleManager.getAllLauncherAbilityInfos
## innerBundleManager.getAllLauncherAbilityInfos<sup>(deprecated)</sup>
getAllLauncherAbilityInfos(userId: number) : Promise&lt;Array&lt;LauncherAbilityInfo&gt;&gt;
Obtains the information about all launcher abilities. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getAllLauncherAbilityInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......@@ -241,7 +240,7 @@ This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ----------------------------------------------------- |
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
......@@ -251,11 +250,12 @@ This is a system API and cannot be called by third-party applications.
| ------------------------------------------------------------ | ------------------------- |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)>> | Promise used to return an array of the launcher ability information.|
## innerBundleManager.getShortcutInfos
## innerBundleManager.getShortcutInfos<sup>(deprecated)</sup>
getShortcutInfos(bundleName :string, callback: AsyncCallback&lt;Array&lt;ShortcutInfo&gt;&gt;) : void;
Obtains the shortcut information based on a given bundle name. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getShortcutInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......@@ -276,11 +276,12 @@ This is a system API and cannot be called by third-party applications.
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<Array<[ShortcutInfo](js-apis-bundle-ShortcutInfo.md)>> | Yes | Callback used to return an array of the shortcut information.|
## innerBundleManager.getShortcutInfos
## innerBundleManager.getShortcutInfos<sup>(deprecated)</sup>
getShortcutInfos(bundleName : string) : Promise&lt;Array&lt;ShortcutInfo&gt;&gt;
Obtains the shortcut information based on a given bundle name. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [launcherBundleManager#getShortcutInfo](js-apis-launcherBundleManager.md) instead.
**Required permissions**
......
......@@ -5,7 +5,6 @@ The **Bundle** module provides APIs for querying the information about bundles,
> **NOTE**
>
> 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.
> API version 9 is a canary version for trial use. The APIs of this version may be unstable.
## Modules to Import
```js
......@@ -21,9 +20,11 @@ import bundle from '@ohos.bundle';
| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall applications. |
| ohos.permission.MANAGE_DISPOSED_APP_STATUS | system_core | Permission to set and query the application disposal status. |
For details, see "Permission Levels" in [Access Control Overview](../../security/accesstoken-overview.md).
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## bundle.getApplicationInfo
## bundle.getApplicationInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getApplicationInfo](js-apis-bundleManager.md#bundlemanagergetapplicationinfo) instead.
getApplicationInfo(bundleName: string, bundleFlags: number, userId?: number): Promise\<ApplicationInfo>
......@@ -65,7 +66,9 @@ bundle.getApplicationInfo(bundleName, bundleFlags, userId)
})
```
## bundle.getApplicationInfo
## bundle.getApplicationInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getApplicationInfo](js-apis-bundleManager.md#bundlemanagergetapplicationinfo) instead.
getApplicationInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<ApplicationInfo>): void
......@@ -103,7 +106,10 @@ bundle.getApplicationInfo(bundleName, bundleFlags, userId, (err, data) => {
})
```
## bundle.getApplicationInfo
## bundle.getApplicationInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getApplicationInfo](js-apis-bundleManager.md#bundlemanagergetapplicationinfo) instead.
getApplicationInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<ApplicationInfo>): void
......@@ -139,81 +145,10 @@ bundle.getApplicationInfo(bundleName, bundleFlags, (err, data) => {
})
```
## bundle.getApplicationInfoSync<sup>9+</sup>
getApplicationInfoSync(bundleName: string, bundleFlags: number, userId: number): ApplicationInfo;
Obtains the application information of the specified user based on a given bundle name. This API returns the result synchronously.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| ---------------------------------------------------- | ------------------- |
| [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | **ApplicationInfo** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
let bundleFlags = 0;
let userId = 100;
var applicationInfo = bundle.getApplicationInfoSync(bundleName, bundleFlags, userId);
console.info('Operation successful. Name:' + applicationInfo.name);
```
## bundle.getApplicationInfoSync<sup>9+</sup>
getApplicationInfoSync(bundleName: string, bundleFlags: number) : ApplicationInfo;
Obtains the application information based on a given bundle name. This API returns the result synchronously.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
**Return value**
| Type | Description |
| ---------------------------------------------------- | ------------------- |
| [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | **ApplicationInfo** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
let bundleFlags = 0;
var applicationInfo = bundle.getApplicationInfoSync(bundleName, bundleFlags);
console.info('Operation successful. Name:' + applicationInfo.name);
```
## bundle.getAllBundleInfo<sup>deprecated<sup>
## bundle.getAllBundleInfo
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllBundleInfo](js-apis-bundleManager.md#bundlemanagergetallbundleinfo) instead.
getAllBundleInfo(bundleFlag: BundleFlag, userId?: number): Promise<Array\<BundleInfo>>
......@@ -253,7 +188,10 @@ bundle.getAllBundleInfo(bundleFlag, userId)
})
```
## bundle.getAllBundleInfo
## bundle.getAllBundleInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllBundleInfo](js-apis-bundleManager.md#bundlemanagergetallbundleinfo) instead.
getAllBundleInfo(bundleFlag: BundleFlag, callback: AsyncCallback<Array\<BundleInfo>>): void
......@@ -287,7 +225,10 @@ bundle.getAllBundleInfo(bundleFlag, (err, data) => {
})
```
## bundle.getAllBundleInfo
## bundle.getAllBundleInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllBundleInfo](js-apis-bundleManager.md#bundlemanagergetallbundleinfo) instead.
getAllBundleInfo(bundleFlag: BundleFlag, userId: number, callback: AsyncCallback<Array\<BundleInfo>>): void
......@@ -323,7 +264,10 @@ bundle.getAllBundleInfo(bundleFlag, userId, (err, data) => {
})
```
## bundle.getBundleInfo
## bundle.getBundleInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo) instead.
getBundleInfo(bundleName: string, bundleFlags: number, options?: BundleOptions): Promise\<BundleInfo>
......@@ -367,7 +311,9 @@ bundle.getBundleInfo(bundleName, bundleFlags, options)
})
```
## bundle.getBundleInfo
## bundle.getBundleInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo) instead.
getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void
......@@ -404,7 +350,9 @@ bundle.getBundleInfo(bundleName, bundleFlags, (err, data) => {
```
## bundle.getBundleInfo
## bundle.getBundleInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo) instead.
getBundleInfo(bundleName: string, bundleFlags: number, options: BundleOptions, callback: AsyncCallback\<BundleInfo>): void
......@@ -444,83 +392,11 @@ bundle.getBundleInfo(bundleName, bundleFlags, options, (err, data) => {
})
```
## bundle.getBundleInfoSync<sup>9+</sup>
getBundleInfoSync(bundleName: string, bundleFlags: number, options: BundleOptions): BundleInfo;
Obtains the bundle information based on a given bundle name and bundle options. This API returns the result synchronously.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
| options | [BundleOptions](#bundleoptions) | Yes | Options of the bundle. |
**Return value**
| Type | Description |
| ------------------------------------------ | -------------- |
| [BundleInfo](js-apis-bundle-BundleInfo.md) | **BundleInfo** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
let options = {
"userId" : 100
};
var bundleInfo = bundle.getBundleInfoSync(bundleName, bundleFlags, options);
console.info('Operation successful. Name:' + bundleInfo.name);
```
## bundle.getBundleInfoSync<sup>9+</sup>
getBundleInfoSync(bundleName: string, bundleFlags: number): BundleInfo;
Obtains the bundle information based on a given bundle name. This API returns the result synchronously.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the bundle information flags in [BundleFlag](#bundleflag).|
**Return value**
| Type | Description |
| ------------------------------------------ | -------------- |
| [BundleInfo](js-apis-bundle-BundleInfo.md) | **BundleInfo** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
let bundleFlags = 1;
var bundleInfo = bundle.getBundleInfoSync(bundleName, bundleFlags);
console.info('Operation successful. Name:' + bundleInfo.name);
```
## bundle.getBundleInstaller<sup>deprecated<sup>
## bundle.getBundleInstaller
> This API is deprecated since API version 9. You are advised to use [installer.getBundleInstaller](js-apis-installer.md#bundleinstallergetbundleinstaller) instead.
getBundleInstaller(): Promise&lt;BundleInstaller&gt;;
......@@ -544,7 +420,9 @@ This is a system API and cannot be called by third-party applications.
| ------------------------------------------------------------ | -------------------------------------------- |
| Promise<[BundleInstaller](js-apis-bundle-BundleInstaller.md)> | Promise used to return the installation package information.|
## bundle.getBundleInstaller
## bundle.getBundleInstaller<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [installer.getBundleInstaller](js-apis-installer.md#bundleinstallergetbundleinstaller) instead.
getBundleInstaller(callback: AsyncCallback&lt;BundleInstaller&gt;): void;
......@@ -568,7 +446,9 @@ This is a system API and cannot be called by third-party applications.
| -------- | ------------------------------------------------------------ | ---- | ---------------- |
| callback | AsyncCallback<[BundleInstaller](js-apis-bundle-BundleInstaller.md)> | Yes | Callback used to return the installation package information.|
## bundle.cleanBundleCacheFiles<sup>8+</sup>
## bundle.cleanBundleCacheFiles<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.cleanBundleCacheFiles](js-apis-bundleManager.md#bundlemanagercleanbundlecachefiles) instead.
cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback&lt;void&gt;): void;
......@@ -593,7 +473,9 @@ This is a system API and cannot be called by third-party applications.
| bundleName | string | Yes | Bundle name of an application.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
## bundle.cleanBundleCacheFiles<sup>8+</sup>
## bundle.cleanBundleCacheFiles<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.cleanBundleCacheFiles](js-apis-bundleManager.md#bundlemanagercleanbundlecachefiles) instead.
cleanBundleCacheFiles(bundleName: string): Promise&lt;void&gt;
......@@ -623,7 +505,9 @@ This is a system API and cannot be called by third-party applications.
| ------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
## bundle.setApplicationEnabled<sup>8+</sup>
## bundle.setApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.setApplicationEnabled](js-apis-bundleManager.md#bundlemanagersetapplicationenabled) instead.
setApplicationEnabled(bundleName: string, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void;
......@@ -649,7 +533,9 @@ This is a system API and cannot be called by third-party applications.
| isEnable | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
## bundle.setApplicationEnabled<sup>8+</sup>
## bundle.setApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.setApplicationEnabled](js-apis-bundleManager.md#bundlemanagersetapplicationenabled) instead.
setApplicationEnabled(bundleName: string, isEnable: boolean): Promise&lt;void&gt;
......@@ -680,7 +566,9 @@ This is a system API and cannot be called by third-party applications.
| ------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
## bundle.setAbilityEnabled<sup>8+</sup>
## bundle.setAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.setAbilityEnabled](js-apis-bundleManager.md#bundlemanagersetabilityenabled) instead.
setAbilityEnabled(info: AbilityInfo, isEnable: boolean, callback: AsyncCallback&lt;void&gt;): void;
......@@ -703,10 +591,12 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ----------------------------------------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information. |
| isEnable | boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means the opposite.|
| isEnable | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means the opposite.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
## bundle.setAbilityEnabled<sup>8+</sup>
## bundle.setAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.setAbilityEnabled](js-apis-bundleManager.md#bundlemanagersetabilityenabled) instead.
setAbilityEnabled(info: AbilityInfo, isEnable: boolean): Promise&lt;void&gt;
......@@ -729,7 +619,7 @@ This is a system API and cannot be called by third-party applications.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ----------------------------------------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information. |
| isEnable | boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means the opposite.|
| isEnable | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means the opposite.|
**Return value**
......@@ -737,7 +627,9 @@ This is a system API and cannot be called by third-party applications.
| ------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
## bundle.getPermissionDef<sup>8+</sup>
## bundle.getPermissionDef<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getPermissionDef](js-apis-bundleManager.md#bundlemanagergetpermissiondef) instead.
getPermissionDef(permissionName: string, callback: AsyncCallback&lt;PermissionDef&gt;): void;
......@@ -762,7 +654,9 @@ This is a system API and cannot be called by third-party applications.
| permissionName | string | Yes | Name of the permission. |
| callback | AsyncCallback<[PermissionDef](js-apis-bundle-PermissionDef)> | Yes | Callback used to return the permission details.|
## bundle.getPermissionDef<sup>8+</sup>
## bundle.getPermissionDef<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getPermissionDef](js-apis-bundleManager.md#bundlemanagergetpermissiondef) instead.
getPermissionDef(permissionName: string): Promise&lt;PermissionDef&gt;
......@@ -792,313 +686,131 @@ This is a system API and cannot be called by third-party applications.
| ------------------------------------------------------ | ------------------------------------------------------ |
| Promise<[PermissionDef](js-apis-bundle-PermissionDef)> | Promise used to return the permission details.|
## bundle.setModuleUpgradeFlag<sup>9+</sup>
setModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag, callback: AsyncCallback&lt;void&gt;):void;
Sets whether the module needs an upgrade. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
## bundle.getAllApplicationInfo<sup>deprecated<sup>
**Parameters**
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllApplicationInfo](js-apis-bundleManager.md#bundlemanagergetallapplicationinfo) instead.
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is used only by the internal system. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
getAllApplicationInfo(bundleFlags: number, userId?: number): Promise<Array\<ApplicationInfo>>
## bundle.setModuleUpgradeFlag<sup>9+</sup>
Obtains the information about all applications of the specified user. This API uses a promise to return the result.
setModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag): Promise&lt;void&gt;
**Required permissions**
Sets whether the module needs an upgrade. This API uses a promise to return the result.
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ---------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is for internal use only.|
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| ------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
## bundle.isModuleRemovable<sup>9+</sup>
isModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback&lt;boolean&gt;): void;
Checks whether a module is removable. This API uses an asynchronous callback to return the result.
**System capability**
| -------------------------------- | ------------------------------- |
| Promise<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Promise used to return the application information.|
SystemCapability.BundleManager.BundleFramework
**Example**
**System API**
```js
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
This is a system API and cannot be called by third-party applications.
## bundle.getAllApplicationInfo<sup>deprecated<sup>
**Parameters**
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllApplicationInfo](js-apis-bundleManager.md#bundlemanagergetallapplicationinfo) instead.
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | --------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the module is removable, **true** is returned. Otherwise, **false** is returned.|
getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array\<ApplicationInfo>>): void
## bundle.isModuleRemovable<sup>9+</sup>
Obtains the information about all applications of the specified user. This API uses an asynchronous callback to return the result.
isModuleRemovable(bundleName: string, moduleName: string): Promise&lt;boolean&gt;
**Required permissions**
Checks whether a module is removable. This API uses a promise to return the result.
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application.|
**Return value**
| Type | Description |
| ---------------- | ---------------------------- |
| Promise\<boolean> | Promise used to return the result. If the module is removable, **true** is returned. Otherwise, **false** is returned.|
## bundle.getBundlePackInfo<sup>9+</sup>
getBundlePackInfo(bundleName: string, bundlePackFlag : pack.BundlePackFlag, callback: AsyncCallback&lt;pack.BundlePackInfo&gt;): void;
Obtains the bundle package information based on a given bundle name and bundle flags. This API uses an asynchronous callback to return the result.
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes | Callback used to return the application information. |
**System capability**
**Example**
SystemCapability.BundleManager.BundleFramework
```js
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
**System API**
This is a system API and cannot be called by third-party applications.
## bundle.getAllApplicationInfo<sup>deprecated<sup>
**Parameters**
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAllApplicationInfo](js-apis-bundleManager.md#bundlemanagergetallapplicationinfo) instead.
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ---------------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| bundlePackFlag | pack.BundlePackFlag | Yes | Flags of the bundle package. |
| callback | AsyncCallback<pack.BundlePackInfo> | Yes | Callback used to return the bundle package information.|
getAllApplicationInfo(bundleFlags: number, callback: AsyncCallback<Array\<ApplicationInfo>>) : void;
## bundle.getBundlePackInfo<sup>9+</sup>
Obtains the information about all applications. This API uses an asynchronous callback to return the result.
getBundlePackInfo(bundleName: string, bundlePackFlag : pack.BundlePackFlag): Promise&lt;pack.BundlePackInfo&gt;;
**Required permissions**
Obtains the bundle package information based on a given bundle name and bundle flags. This API uses a promise to return the result.
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------- | ---- | ---------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| bundlePackFlag | pack.BundlePackFlag | Yes | Flags of the bundle package.|
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes | Callback used to return the application information. |
**Return value**
**Example**
| Type | Description |
| ---------------------------- | ------------------------------------------------------ |
| Promise<pack.BundlePackInfo> | Promise used to return the bundle package information. |
```js
let bundleFlags = 8;
bundle.getAllApplicationInfo(bundleFlags, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getDispatcherVersion<sup>9+</sup>
## bundle.getBundleArchiveInfo<sup>deprecated<sup>
getDispatcherVersion(callback: AsyncCallback&lt;DispatchInfo&gt;): void;
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleArchiveInfo](js-apis-bundleManager.md#bundlemanagergetbundlearchiveinfo) instead.
Obtains the dispatcher version. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback<[DispatchInfo](js-apis-dispatchInfo.md)> | Yes | Callback used to return the [DispatchInfo](js-apis-dispatchInfo.md).|
## bundle.getDispatcherVersion<sup>9+</sup>
getDispatcherVersion(): Promise&lt;DispatchInfo&gt;;
Obtains the dispatcher version. This API uses a promise to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**System API**
This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ------------------------------------------------ | ------------------------------------------------------------ |
| Promise<[DispatchInfo](js-apis-dispatchInfo.md)> | Promise used to return the [DispatchInfo](js-apis-dispatchInfo.md).|
## bundle.getAllApplicationInfo
getAllApplicationInfo(bundleFlags: number, userId?: number): Promise<Array\<ApplicationInfo>>
Obtains the information about all applications of the specified user. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| -------------------------------- | ------------------------------- |
| Promise<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Promise used to return the application information.|
**Example**
```js
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getAllApplicationInfo
getAllApplicationInfo(bundleFlags: number, userId: number, callback: AsyncCallback<Array\<ApplicationInfo>>): void
Obtains the information about all applications of the specified user. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes | Callback used to return the application information. |
**Example**
```js
let bundleFlags = 8;
let userId = 100;
bundle.getAllApplicationInfo(bundleFlags, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getAllApplicationInfo
getAllApplicationInfo(bundleFlags: number, callback: AsyncCallback<Array\<ApplicationInfo>>) : void;
Obtains the information about all applications. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleFlags | number | Yes | Type of information that will be returned. The default value is **0**. For details on the available enumerated values, see the application information flags in [BundleFlag](#bundleflag).|
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)>> | Yes | Callback used to return the application information. |
**Example**
```js
let bundleFlags = 8;
bundle.getAllApplicationInfo(bundleFlags, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getBundleArchiveInfo
getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) : Promise\<BundleInfo>
Obtains information about the bundles contained in a HAP file. This API uses a promise to return the result.
getBundleArchiveInfo(hapFilePath: string, bundleFlags: number) : Promise\<BundleInfo>
Obtains information about the bundles contained in a HAP file. This API uses a promise to return the result.
**System capability**
......@@ -1129,7 +841,9 @@ bundle.getBundleArchiveInfo(hapFilePath, bundleFlags)
})
```
## bundle.getBundleArchiveInfo
## bundle.getBundleArchiveInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleArchiveInfo](js-apis-bundleManager.md#bundlemanagergetbundlearchiveinfo) instead.
getBundleArchiveInfo(hapFilePath: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>) : void
......@@ -1162,7 +876,9 @@ bundle.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
```
## bundle.getAbilityInfo
## bundle.getAbilityInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
getAbilityInfo(bundleName: string, abilityName: string): Promise\<AbilityInfo>
......@@ -1202,7 +918,9 @@ bundle.getAbilityInfo(bundleName, abilityName)
})
```
## bundle.getAbilityInfo
## bundle.getAbilityInfo<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
getAbilityInfo(bundleName: string, abilityName: string, callback: AsyncCallback\<AbilityInfo>): void;
......@@ -1237,87 +955,10 @@ bundle.getAbilityInfo(bundleName, abilityName, (err, data) => {
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getAbilityInfo<sup>9+</sup>
getAbilityInfo(bundleName: string, moduleName: string, abilityName: string): Promise\<AbilityInfo>
Obtains the ability information based on a given bundle name, module name, and ability name. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ---------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| abilityName | string | Yes | Ability name.|
**Return value**
| Type | Description |
| --------------------- | --------------------- |
| Promise\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Promise used to return the ability information.|
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, moduleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getAbilityInfo<sup>9+</sup>
getAbilityInfo(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<AbilityInfo>): void;
Obtains the ability information based on a given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------------ | ---- | ---------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| abilityName | string | Yes | Ability name.|
| callback | AsyncCallback\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)> | Yes | Callback used to return the ability information.|
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, moduleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getAbilityLabel<sup>8+</sup> <sup>deprecated<sup>
## bundle.getAbilityLabel<sup>8+</sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAbilityLabel](js-apis-bundleManager.md#bundlemanagergetabilitylabel) instead.
getAbilityLabel(bundleName: string, abilityName: string): Promise\<string>
......@@ -1357,7 +998,9 @@ bundle.getAbilityLabel(bundleName, abilityName)
})
```
## bundle.getAbilityLabel<sup>8+</sup>
## bundle.getAbilityLabel<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAbilityLabel](js-apis-bundleManager.md#bundlemanagergetabilitylabel) instead.
getAbilityLabel(bundleName: string, abilityName: string, callback : AsyncCallback\<string>): void
......@@ -1392,15 +1035,14 @@ bundle.getAbilityLabel(bundleName, abilityName, (err, data) => {
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getAbilityLabel<sup>9+</sup>
getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string>
## bundle.isAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
Obtains the application name based on a given bundle name, module name, and ability name. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleManager.isAbilityEnabled](js-apis-bundleManager.md#bundlemanagerisabilityenabled) instead.
**Required permissions**
isAbilityEnabled(info: AbilityInfo): Promise\<boolean>
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses a promise to return the result.
**System capability**
......@@ -1408,552 +1050,72 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ---------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| abilityName | string | Yes | Ability name.|
| Name| Type | Mandatory| Description |
| ------ | -------------------------------------------- | ---- | ----------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information.|
**Return value**
| Type | Description |
| ---------------- | ------------------ |
| Promise\<string> | Promise used to return the application name.|
| ----------------- | ------------------------- |
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityLabel(bundleName, moduleName, abilityName)
.then((data) => {
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo).then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
})
```
## bundle.getAbilityLabel<sup>9+</sup>
## bundle.isAbilityEnabled<sup>8+</sup> <sup>deprecated<sup>
getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback : AsyncCallback\<string>): void
> This API is deprecated since API version 9. You are advised to use [bundleManager.isAbilityEnabled](js-apis-bundleManager.md#bundlemanagerisabilityenabled) instead.
Obtains the application name based on a given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.
**Required permissions**
isAbilityEnabled(info : AbilityInfo, callback : AsyncCallback\<boolean>): void
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------- | ---- | ---------------- |
| bundleName | string | Yes | Bundle name of an application. |
| moduleName | string | Yes | Module name of the application. |
| abilityName | string | Yes | Ability name.|
| callback | AsyncCallback\<string> | Yes | Callback used to return the application name. |
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.isAbilityEnabled<sup>8+</sup>
isAbilityEnabled(info: AbilityInfo): Promise\<boolean>
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses a promise to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ----------- | ---- | ------------ |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information.|
**Return value**
| Type | Description |
| ----------------- | ------------------------- |
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo).then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
})
```
## bundle.isAbilityEnabled<sup>8+</sup>
isAbilityEnabled(info : AbilityInfo, callback : AsyncCallback\<boolean>): void
Checks whether the ability that matches a given **AbilityInfo** object is enabled. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------- | ---- | --------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
})
```
## bundle.isApplicationEnabled<sup>8+</sup>
isApplicationEnabled(bundleName: string): Promise\<boolean>
Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------ |
| bundleName | string | Yes | Bundle name of an application.|
**Return value**
| Type | Description |
| ----------------- | ------------------------- |
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
bundle.isApplicationEnabled(bundleName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.isApplicationEnabled<sup>8+</sup>
isApplicationEnabled(bundleName: string, callback : AsyncCallback\<boolean>): void
Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ----------------------- | ---- | --------------- |
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
bundle.isApplicationEnabled(bundleName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.queryAbilityByWant
queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise<Array\<AbilityInfo>>
Obtains the ability information based on a given want. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | ------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| ---------------------------- | --------------------- |
| Promise<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Promise used to return the ability information.|
**Example**
```js
let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.queryAbilityByWant
queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array\<AbilityInfo>>): void
Obtains the ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
**Example**
```js
let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.queryAbilityByWant
queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Array\<AbilityInfo>>): void;
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
**Example**
```js
let bundleFlags = 0;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryAbilityByWant(want, bundleFlags, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getLaunchWantForBundle
getLaunchWantForBundle(bundleName: string): Promise\<Want>
Obtains the **Want** object that launches the specified application. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------ |
| bundleName | string | Yes | Bundle name of an application.|
**Return value**
| Type | Description |
| -------------- | -------------------------------------- |
| Promise\<[Want](js-apis-application-Want.md)> | Promise used to return the **Want** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getLaunchWantForBundle
getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void;
Obtains the **Want** object that launches the specified application. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | -------------------- | ---- | ------------------------------ |
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<[Want](js-apis-application-Want.md)> | Yes | Callback used to return the **Want** object.|
**Example**
```js
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getNameForUid<sup>8+</sup>
getNameForUid(uid: number): Promise\<string>
Obtains the bundle name based on a UID. This API uses a promise to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | -------- |
| uid | number | Yes | UID based on which the bundle name is to obtain.|
**Return value**
| Type | Description |
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the bundle name.|
**Example**
```js
let uid = 20010005;
bundle.getNameForUid(uid)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getNameForUid<sup>8+</sup>
getNameForUid(uid: number, callback: AsyncCallback\<string>) : void
Obtains the bundle name based on a UID. This API uses an asynchronous callback to return the result.
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ------------------------- |
| uid | number | Yes | UID based on which the bundle name is to obtain. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
```js
let uid = 20010005;
bundle.getNameForUid(uid, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getAbilityIcon<sup>8+</sup>
getAbilityIcon(bundleName: string, abilityName: string): Promise\<image.PixelMap>;
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses a promise to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain. |
**Return value**
| Type | Description |
| --------------------- | ------------------------------------------------------------ |
| Promise\<image.PixelMap> | Promise used to return the [pixel map](js-apis-image.md).|
**Example**
```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getAbilityIcon<sup>8+</sup>
getAbilityIcon(bundleName: string, abilityName: string, callback: AsyncCallback\<image.PixelMap>): void;
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses an asynchronous callback to return the result.
**Required permissions**
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain. |
| callback | AsyncCallback\<image.PixelMap> | Yes | Callback used to return the [pixel map](js-apis-image.md).|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ----------------------- |
| info | [AbilityInfo](js-apis-bundle-AbilityInfo.md) | Yes | Ability information. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
bundle.getAbilityInfo(bundleName, abilityName).then((abilityInfo)=>{
bundle.isAbilityEnabled(abilityInfo, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
})
```
## bundle.getAbilityIcon<sup>9+</sup>
getAbilityIcon(bundleName: string, moduleName: string, abilityName: string): Promise\<image.PixelMap>;
## bundle.isApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name, module name, and ability name. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleManager.isApplicationEnabled](js-apis-bundleManager.md#bundlemanagerisapplicationenabled) instead.
**Required permissions**
isApplicationEnabled(bundleName: string): Promise\<boolean>
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
Checks whether an application is enabled based on a given bundle name. This API uses a promise to return the result.
**System capability**
......@@ -1961,24 +1123,21 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| moduleName | string | Yes | Module name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain. |
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
| bundleName | string | Yes | Bundle name of an application.|
**Return value**
| Type | Description |
| --------------------- | ------------------------------------------------------------ |
| Promise\<image.PixelMap> | Promise used to return the [pixel map](js-apis-image.md).|
| ----------------- | ------------------------- |
| Promise\<boolean> | Promise used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned.|
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, moduleName, abilityName)
bundle.isApplicationEnabled(bundleName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
......@@ -1986,15 +1145,13 @@ bundle.getAbilityIcon(bundleName, moduleName, abilityName)
})
```
## bundle.getAbilityIcon<sup>9+</sup>
getAbilityIcon(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<image.PixelMap>): void;
## bundle.isApplicationEnabled<sup>8+</sup> <sup>deprecated<sup>
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [bundleManager.isApplicationEnabled](js-apis-bundleManager.md#bundlemanagerisapplicationenabled) instead.
**Required permissions**
isApplicationEnabled(bundleName: string, callback : AsyncCallback\<boolean>): void
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
Checks whether an application is enabled based on a given bundle name. This API uses an asynchronous callback to return the result.
**System capability**
......@@ -2002,20 +1159,16 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| moduleName | string | Yes | Module name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain. |
| callback | AsyncCallback\<image.PixelMap> | Yes | Callback used to return the [pixel map](js-apis-image.md).|
| Name | Type | Mandatory| Description |
| ---------- | ----------------------- | ---- | ------------------------ |
| bundleName | string | Yes | Bundle name of an application.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return whether the ability is enabled. If the ability is enabled, **true** will be returned; otherwise, **false** will be returned. |
**Example**
```js
let bundleName = "com.example.myapplication";
let moduleName = "entry";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, moduleName, abilityName, (err, data) => {
bundle.isApplicationEnabled(bundleName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -2024,11 +1177,13 @@ bundle.getAbilityIcon(bundleName, moduleName, abilityName, (err, data) => {
})
```
## bundle.queryExtensionAbilityInfos<sup>9+</sup>
## bundle.queryAbilityByWant<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
queryExtensionAbilityInfos(want: Want, extensionType: number, extensionFlags: number, userId?: number): Promise<Array\<ExtensionAbilityInfo>>
queryAbilityByWant(want: Want, bundleFlags: number, userId?: number): Promise<Array\<AbilityInfo>>
Obtains the Extension ability information based on a given want. This API uses a promise to return the result.
Obtains the ability information based on a given want. This API uses a promise to return the result.
**Required permissions**
......@@ -2041,29 +1196,27 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ------ | ---- | ---------------------------------------- |
| ----------- | ------ | ---- | ------------------------------------- |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionType | number | Yes | Type of the Extension ability information to obtain. The default value is **0**. For details on the available enumerated values, see [ExtensionAbilityType](#extensionabilitytype9).|
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#extensionflag9).|
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| userId | number | No | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------ |
| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Promise used to return the Extension ability information.|
| ---------------------------- | --------------------- |
| Promise<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Promise used to return the ability information.|
**Example**
```js
let extensionType = 0;
let extensionFlags = 0;
let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
bundle.queryExtensionAbilityInfos(want, extensionType, extensionFlags, userId)
bundle.queryAbilityByWant(want, bundleFlags, userId)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
......@@ -2073,11 +1226,13 @@ bundle.queryExtensionAbilityInfos(want, extensionType, extensionFlags, userId)
## bundle.queryExtensionAbilityInfos<sup>9+</sup>
## bundle.queryAbilityByWant<sup>deprecated<sup>
queryExtensionAbilityInfos(want: Want, extensionType: number, extensionFlags: number, userId: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
queryAbilityByWant(want: Want, bundleFlags: number, userId: number, callback: AsyncCallback<Array\<AbilityInfo>>): void
Obtains the Extension ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
Obtains the ability information of the specified user based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
......@@ -2090,37 +1245,37 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionType | number | Yes | Type of the Extension ability information to obtain. The default value is **0**. For details on the available enumerated values, see [ExtensionAbilityType](#extensionabilitytype9).|
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#extensionflag9).|
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| userId | number | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0. |
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
**Example**
```js
let extensionType = 0;
let extensionFlags = 0;
let bundleFlags = 0;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
const receiver = function onReceive(err, data) {
var errValue = JSON.stringify(err)
var dataValue = JSON.stringify(data)
console.error('Operation failed. Cause: ' + errValue);
console.error('Operation failed. Cause: ' + dataValue);
}
bundle.queryExtensionAbilityInfos(want, extensionType, extensionFlags, userId, receiver)
bundle.queryAbilityByWant(want, bundleFlags, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.queryExtensionAbilityInfos<sup>9+</sup>
## bundle.queryAbilityByWant<sup>deprecated<sup>
queryExtensionAbilityInfos(want: Want, extensionType: number, extensionFlags: number, callback: AsyncCallback<Array\<ExtensionAbilityInfo>>): void;
> This API is deprecated since API version 9. You are advised to use [bundleManager.queryAbilityInfo](js-apis-bundleManager.md#bundlemanagerqueryabilityinfo) instead.
Obtains the Extension ability information based on a given want. This API uses an asynchronous callback to return the result.
queryAbilityByWant(want: Want, bundleFlags: number, callback: AsyncCallback<Array\<AbilityInfo>>): void;
Obtains the ability information based on a given want. This API uses an asynchronous callback to return the result.
**Required permissions**
......@@ -2132,312 +1287,268 @@ SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ---------------------------------------- | ---- | ---------------------------------------- |
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-Want.md) | Yes | Want that contains the bundle name. |
| extensionType | number | Yes | Type of the Extension ability information to obtain. The default value is **0**. For details on the available enumerated values, see [ExtensionAbilityType](#extensionabilitytype9).|
| extensionFlags | number | Yes | Extension ability information to be returned. The default value is **0**. For details on the available enumerated values, see [ExtensionFlags](#extensionflag9).|
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)>> | Yes | Callback used to return the Extension ability information. |
| bundleFlags | number | Yes | Ability information to be returned. The default value is **0**. For details on the available enumerated values, see the ability information flags in [BundleFlag](#bundleflag).|
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundle-AbilityInfo.md)>> | Yes | Callback used to return the ability information. |
**Example**
```js
let extensionType = 0;
let extensionFlags = 0;
let bundleFlags = 0;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
const receiver = function onReceive(err, data) {
var errValue = JSON.stringify(err)
var dataValue = JSON.stringify(data)
console.error('Operation failed. Cause: ' + errValue);
console.error('Operation failed. Cause: ' + dataValue);
}
bundle.queryExtensionAbilityInfos(want, extensionType, extensionFlags, receiver)
bundle.queryAbilityByWant(want, bundleFlags, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getProfileByAbility<sup>9+</sup>
getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string>>): void;
Obtains the JSON string array of the current application's configuration file in the [metadata](js-apis-bundle-Metadata.md) based on a given module name, ability name, and metadata name. This API uses an asynchronous callback to return the result. This API cannot be used to obtain the JSON string array of another application.
## bundle.getLaunchWantForBundle<sup>deprecated<sup>
**System capability**: SystemCapability.BundleManager.BundleFramework
> This API is deprecated since API version 9. You are advised to use [bundleManager.getLaunchWantForBundle](js-apis-bundleManager.md#bundlemanagergetlaunchwantforbundle) instead.
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| moduleName | string | Yes | Module to which the configuration file to be obtained belongs. |
| abilityName | string | Yes | Ability to which the configuration file to be obtained belongs. |
| metadataName | string | Yes | Metadata to which the configuration file to be obtained belongs. |
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the JSON string array of the configuration file. |
**Example**
getLaunchWantForBundle(bundleName: string): Promise\<Want>
```js
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'ohos.ability.shortcuts';
const caller = function callback(err, data) {
console.error('Operation errcode is: ' + err);
console.error('Operation result is: ' + data);
}
bundle.getProfileByAbility(moduleName, abilityName, metadataName, caller)
```
Obtains the **Want** object that launches the specified application. This API uses a promise to return the result.
## bundle.getProfileByAbility<sup>9+</sup>
**Required permissions**
getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise\<Array\<string>>;
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
Obtains the JSON string array of the current application's configuration file in the [metadata](js-apis-bundle-Metadata.md) based on a given module name, ability name, and metadata name. This API uses a promise to return the result. This API cannot be used to obtain the JSON string array of another application.
**System capability**
**System capability**: SystemCapability.BundleManager.BundleFramework
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| moduleName | string | Yes | Module to which the configuration file to be obtained belongs. |
| abilityName | string | Yes | Ability to which the configuration file to be obtained belongs. |
| metadataName | string | No | Metadata to which the configuration file to be obtained belongs. |
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------ |
| bundleName | string | Yes | Bundle name of an application.|
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------ |
| Promise\<Array\<string>> | Promise used to return the JSON string array of the configuration file.|
| -------------- | -------------------------------------- |
| Promise\<[Want](js-apis-application-Want.md)> | Promise used to return the **Want** object.|
**Example**
```js
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'ohos.ability.shortcuts';
bundle.getProfileByAbility(moduleName, abilityName, metadataName).then(data=>{
console.error('Operation result is: ' + data);
}).catch(err=>{
console.error('Operation errcode is: ' + err);
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getProfileByExtensionAbility<sup>9+</sup>
## bundle.getLaunchWantForBundle<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getLaunchWantForBundle](js-apis-bundleManager.md#bundlemanagergetlaunchwantforbundle) instead.
getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void;
Obtains the **Want** object that launches the specified application. This API uses an asynchronous callback to return the result.
**Required permissions**
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback\<Array\<string>>): void;
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
Obtains the JSON string array of the current application's configuration file in the [metadata](js-apis-bundle-Metadata.md) based on a given module name, Extension ability name, and metadata name. This API uses an asynchronous callback to return the result. This API cannot be used to obtain the JSON string array of another application.
**System capability**
**System capability**: SystemCapability.BundleManager.BundleFramework
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| moduleName | string | Yes | Module to which the configuration file to be obtained belongs. |
| extensionAbilityName | string | Yes | Extension ability to which the configuration file to be obtained belongs. |
| metadataName | string | Yes | Metadata to which the configuration file to be obtained belongs. |
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the JSON string array of the configuration file. |
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------------------- | ---- | -------------------------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<[Want](js-apis-application-Want.md)> | Yes | Callback used to return the **Want** object.|
**Example**
```js
let moduleName = 'entry';
let extensionAbilityName = 'Form';
let metadataName = 'ohos.extension.form';
const caller = function callback(err, data) {
console.error('Operation errcode is: ' + err);
console.error('Operation result is: ' + data);
}
bundle.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, caller)
let bundleName = "com.example.myapplication";
bundle.getLaunchWantForBundle(bundleName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.getProfileByExtensionAbility<sup>9+</sup>
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise\<Array\<string>>;
## bundle.getNameForUid<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleNameByUid](js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) instead.
Obtains the JSON string array of the current application's configuration file in the [metadata](js-apis-bundle-Metadata.md) based on a given module name, Extension ability name, and metadata name. This API uses a promise to return the result. This API cannot be used to obtain the JSON string array of another application.
getNameForUid(uid: number): Promise\<string>
Obtains the bundle name based on a UID. This API uses a promise to return the result.
**System capability**
**System capability**: SystemCapability.BundleManager.BundleFramework
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| moduleName | string | Yes | Module to which the configuration file to be obtained belongs. |
| extensionAbilityName | string | Yes | Extension ability to which the configuration file to be obtained belongs. |
| metadataName | string | No | Metadata to which the configuration file to be obtained belongs. |
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------- |
| uid | number | Yes | UID based on which the bundle name is to obtain.|
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------ |
| Promise\<Array\<string>> | Promise used to return the JSON string array of the configuration file.|
| ---------------- | --------------------------------- |
| Promise\<string> | Promise used to return the bundle name.|
**Example**
```js
let moduleName = 'entry';
let extensionAbilityName = 'Form';
let metadataName = 'ohos.extension.form';
bundle.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then(data=>{
console.error('Operation result is: ' + data);
}).catch(err=>{
console.error('Operation errcode is: ' + err);
let uid = 20010005;
bundle.getNameForUid(uid)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.setDisposedStatus<sup>9+</sup>
## bundle.getNameForUid<sup>8+</sup> <sup>deprecated<sup>
setDisposedStatus(bundleName: string, status: number, callback: AsyncCallback\<void>): void;
> This API is deprecated since API version 9. You are advised to use [bundleManager.getBundleNameByUid](js-apis-bundleManager.md#bundlemanagergetbundlenamebyuid) instead.
Sets the disposal status for an application based on a given bundle name. This API uses an asynchronous callback to return the result.
getNameForUid(uid: number, callback: AsyncCallback\<string>) : void
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
Obtains the bundle name based on a UID. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**
**System API**: This is a system API and cannot be called by third-party applications.
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| status | number | Yes | Disposal status to set. This parameter is reserved for the application market. The default value is **0**, indicating that no disposal is performed. |
| callback | AsyncCallback\<void> | Yes | Callback that returns no value. |
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ----------------------------------------------- |
| uid | number | Yes | UID based on which the bundle name is to obtain. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the bundle name.|
**Example**
```js
let bundleName = 'com.ohos.camera';
let status = 1;
const caller = function callback(err, data) {
console.error('Operation err is: ' + err);
console.error('Operation result is: ' + data);
}
bundle.setDisposedStatus(bundleName, status, caller)
let uid = 20010005;
bundle.getNameForUid(uid, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## bundle.setDisposedStatus<sup>9+</sup>
setDisposedStatus(bundleName: string, status: number): Promise\<void>;
## bundle.getAbilityIcon<sup>8+</sup> <sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAbilityIcon](js-apis-bundleManager.md#bundlemanagergetabilityicon) instead.
getAbilityIcon(bundleName: string, abilityName: string): Promise\<image.PixelMap>;
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses a promise to return the result.
Sets the disposal status for an application based on a given bundle name. This API uses a promise to return the result.
**Required permissions**
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**
**System API**: This is a system API and cannot be called by third-party applications.
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| status | number | Yes | Disposal status to set. This parameter is reserved for the application market. The default value is **0**, indicating that no disposal is performed. |
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | --------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain.|
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------ |
| Promise\<void> | Promise that returns no value.|
| --------------------- | ------------------------------------------------------------ |
| Promise\<image.PixelMap> | Promise used to return the [pixel map](js-apis-image.md).|
**Example**
```js
let bundleName = 'com.ohos.camera';
let status = 1;
bundle.setDisposedStatus(bundleName, status).then(data=>{
console.error('Operation result is: ' + data);
}).catch(err=>{
console.error('Operation err is: ' + err);
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName)
.then((data) => {
console.info('Operation successful. Data: ' + JSON.stringify(data));
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
})
```
## bundle.getDisposedStatus<sup>9+</sup>
getDisposedStatus(bundleName: string, callback: AsyncCallback\<number>): void;
Obtains the disposal status of an application based on a given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework
**System API**: This is a system API and cannot be called by third-party applications.
## bundle.getAbilityIcon<sup>8+</sup> <sup>deprecated<sup>
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the disposal status. |
**Example**
```js
let bundleName = 'com.ohos.camera';
const caller = function callback(err, data) {
console.error('Operation err is: ' + err);
console.error('Operation result is: ' + data);
}
bundle.getDisposedStatus(bundleName, caller)
```
> This API is deprecated since API version 9. You are advised to use [bundleManager.getAbilityIcon](js-apis-bundleManager.md#bundlemanagergetabilityicon) instead.
## bundle.getDisposedStatus<sup>9+</sup>
getAbilityIcon(bundleName: string, abilityName: string, callback: AsyncCallback\<image.PixelMap>): void;
getDisposedStatus(bundleName: string): Promise\<number>;
Obtains the [pixel map](js-apis-image.md) of the icon corresponding to a given bundle name and ability name. This API uses an asynchronous callback to return the result.
Obtains the disposal status of an application based on a given bundle name. This API uses a promise to return the result.
**Required permissions**
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**
**System API**: This is a system API and cannot be called by third-party applications.
SystemCapability.BundleManager.BundleFramework
**Parameters**
| Name | Type | Mandatory | Description |
| ---------------- | ---------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name of an application. |
**Return value**
| Type | Description |
| ------------------------------------- | ------------------------------ |
| Promise\<number> | Promise used to return the disposal status.|
| ----------- | ---------------------------------------- | ---- | ---------------------------------------- |
| bundleName | string | Yes | Bundle name based on which the pixel map is to obtain. |
| abilityName | string | Yes | Ability name based on which the pixel map is to obtain. |
| callback | AsyncCallback\<image.PixelMap> | Yes | Callback used to return the [pixel map](js-apis-image.md).|
**Example**
```js
let bundleName = 'com.ohos.camera';
bundle.getDisposedStatus(bundleName).then(data=>{
console.error('Operation result is: ' + data);
}).catch(err=>{
console.error('Operation err is: ' + err);
let bundleName = "com.example.myapplication";
let abilityName = "com.example.myapplication.MainAbility";
bundle.getAbilityIcon(bundleName, abilityName, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
}
console.info('Operation successful. Data:' + JSON.stringify(data));
})
```
## InstallErrorCode
## InstallErrorCode<sup>deprecated<sup>
> This API is deprecated since API version 9. You are not advised to use it anymore.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Default Value | Description |
| ---------------------------------------- | ---- | ------------------------- |
| Name | Value | Description |
| ---------------------------------------------------- | ---- | ------------------------------------------------ |
| SUCCESS | 0 | Installation succeeded. |
| STATUS_INSTALL_FAILURE | 1 | Installation failed. (The application to be installed is not found.) |
| STATUS_INSTALL_FAILURE_ABORTED | 2 | Installation aborted. |
| STATUS_INSTALL_FAILURE_INVALID | 3 | Invalid installation parameter. |
| STATUS_INSTALL_FAILURE_CONFLICT | 4 | Installation conflict. (The basic information of the application to update is inconsistent with that of the existing application.) |
| STATUS_INSTALL_FAILURE_STORAGE | 5 | Failed to store the bundle information. |
| STATUS_INSTALL_FAILURE_INCOMPATIBLE | 6 | Installation incompatibility. (A downgrade occurs or the signature information is incorrect.) |
| STATUS_INSTALL_FAILURE_INCOMPATIBLE | 6 | Installation incompatibility. (A downgrade occurs or the signature information is incorrect.)|
| STATUS_UNINSTALL_FAILURE | 7 | Uninstallation failed. (The application to be uninstalled is not found.) |
| STATUS_UNINSTALL_FAILURE_BLOCKED | 8 | Uninstallation aborted. (This error code is not in use.) |
| STATUS_UNINSTALL_FAILURE_ABORTED | 9 | Uninstallation aborted. (Invalid parameters.) |
......@@ -2449,17 +1560,19 @@ bundle.getDisposedStatus(bundleName).then(data=>{
| STATUS_BMS_SERVICE_ERROR | 0x41 | BMS service error. |
| STATUS_FAILED_NO_SPACE_LEFT<sup>8+</sup> | 0x42 | Insufficient device space. |
| STATUS_GRANT_REQUEST_PERMISSIONS_FAILED<sup>8+</sup> | 0x43 | Application authorization failed. |
| STATUS_INSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x44 | Installation permission denied. |
| STATUS_UNINSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x45 | Uninstallation permission denied. |
| STATUS_INSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x44 | No installation permission. |
| STATUS_UNINSTALL_PERMISSION_DENIED<sup>8+</sup> | 0x45 | No uninstallation permission. |
## BundleFlag
## BundleFlag<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.BundleFlag](js-apis-bundleManager.md#bundleflag) instead.
Enumerates bundle flags.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Default Value | Description |
| ---------------------------------------- | ---------- | ------------------- |
| Name | Value | Description |
| ----------------------------------------------- | ---------- | ------------------------------- |
| GET_BUNDLE_DEFAULT | 0x00000000 | Obtains the default application information. |
| GET_BUNDLE_WITH_ABILITIES | 0x00000001 | Obtains the bundle information with the ability information. |
| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000002 | Obtains the ability information with the permission information. |
......@@ -2467,164 +1580,100 @@ Enumerates bundle flags.
| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000008 | Obtains the application information with the permission information. |
| GET_BUNDLE_WITH_REQUESTED_PERMISSION | 0x00000010 | Obtains the bundle information with the information about the required permissions. |
| GET_ABILITY_INFO_WITH_METADATA<sup>8+</sup> | 0x00000020 | Obtains the ability metadata information. |
| GET_BUNDLE_WITH_EXTENSION_ABILITY<sup>9+</sup> | 0x00000020 | Obtains the bundle information with the Extension ability information.|
| GET_APPLICATION_INFO_WITH_METADATA<sup>8+</sup> | 0x00000040 | Obtains the application metadata information. |
| GET_ABILITY_INFO_SYSTEMAPP_ONLY<sup>8+</sup> | 0x00000080 | Obtains the ability information of system applications.|
| GET_ABILITY_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000100 | Obtains information about disabled abilities. |
| GET_APPLICATION_INFO_WITH_DISABLE<sup>8+</sup> | 0x00000200 | Obtains information about disabled applications. |
| GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT <sup>9+</sup> | 0x00000400 | Obtains the signing certificate fingerprint of the application. |
| GET_ALL_APPLICATION_INFO | 0xFFFF0000 | Obtains all application information. |
| GET_BUNDLE_WITH_HASH_VALUE<sup>9+</sup> | 0x00000030 | Obtains information about the bundle that contains a hash value. |
## BundleOptions
## BundleOptions<sup>deprecated<sup>
> This API is deprecated since API version 9. You are not advised to use it anymore.
Describes the bundle options.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable | Writable | Description |
| ------ | ------ | ---- | ---- | ---------------------------- |
| Name | Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | ----------------------------------------------------- |
| userId | number | Yes | Yes | User ID. The default value is the user ID of the caller. The value must be greater than or equal to 0.|
## AbilityType
## AbilityType<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.AbilityType](js-apis-bundleManager.md#abilitytype) instead.
Enumerates ability types.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------- | ---- | ----------------- |
| Name| Value| Description |
| ------- | ---- | --------------------------- |
| UNKNOWN | None | Unknown ability type. |
| PAGE | None | Ability that has a UI. |
| SERVICE | None | Ability that does not have a UI. |
| DATA | None | Ability that is used to provide data access services.|
| PAGE | None | FA developed using the Page template to provide the capability of interacting with users. |
| SERVICE | None | PA developed using the Service template to provide the capability of running tasks in the background. |
| DATA | None | PA developed using the Data template to provide unified data access for external systems.|
## DisplayOrientation<sup>deprecated<sup>
## DisplayOrientation
> This API is deprecated since API version 9. You are advised to use [bundleManager.DisplayOrientation](js-apis-bundleManager.md#displayorientation) instead.
Enumerates display orientations.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------------- | ---- | ------------- |
| Name | Value | Description |
| ------------- | ---- | ------------------------ |
| UNSPECIFIED | None | Unspecified display orientation. |
| LANDSCAPE | None | Landscape orientation. |
| PORTRAIT | None | Portrait orientation. |
| FOLLOW_RECENT | None | Orientation same as that of the nearest ability in the stack.|
| LANDSCAPE_INVERTED<sup>9+</sup> |None | Reverse landscape orientation. |
| PORTRAIT_INVERTED<sup>9+</sup> |None | Reverse portrait orientation. |
| AUTO_ROTATION<sup>9+</sup> |None | Orientation determined by the sensor. |
| AUTO_ROTATION_LANDSCAPE<sup>9+</sup> |None | Orientation determined by the sensor in the horizontal direction, including landscape and reverse landscape. |
| AUTO_ROTATION_PORTRAIT<sup>9+</sup> |None | Orientation determined by the sensor in the vertical direction, including portrait and reverse portrait. |
| AUTO_ROTATION_RESTRICTED<sup>9+</sup> |None | Orientation determined by the sensor when the sensor switch is enabled. |
| AUTO_ROTATION_LANDSCAPE_RESTRICTED<sup>9+</sup> |None | Orientation determined by the sensor in the horizontal direction, including landscape and reverse landscape, when the sensor switch is enabled. |
| AUTO_ROTATION_PORTRAIT_RESTRICTED<sup>9+</sup> |None | Orientation determined by the sensor in the vertical direction, including portrait and reverse portrait, when the sensor switch is enabled. |
| LOCKED<sup>9+</sup> |None | Auto rotate disabled. |
## LaunchMode
## LaunchMode<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.LaunchType](js-apis-bundleManager.md#launchtype) instead.
Enumerates launch modes.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| --------- | ---- | ------------- |
| Name | Value | Description |
| --------- | ---- | ------------------- |
| SINGLETON | 0 | The ability has only one instance.|
| STANDARD | 1 | The ability can have multiple instances. |
## AbilitySubType
## AbilitySubType<sup>deprecated<sup>
> This API is deprecated since API version 9. You are not advised to use it anymore.
Enumerates ability subtypes.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ----------- | ---- | -------------------- |
| Name | Value | Description |
| ----------- | ---- | ----------------------------- |
| UNSPECIFIED | 0 | Undefined ability subtype. |
| CA | 1 | Ability that has a UI.|
## ExtensionAbilityType<sup>9+</sup>
Enumerates Extension ability types.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------------------------------ | ---- | ------------------------- |
| FORM<sup>9+</sup> | 0 | Form (widget) included. |
| WORK_SCHEDULER<sup>9+</sup> | 1 | Work scheduler included.|
| INPUT_METHOD<sup>9+</sup> | 2 | Input method included. |
| SERVICE<sup>9+</sup> | 3 | Service included. |
| ACCESSIBILITY<sup>9+</sup> | 4 | Accessibility included. |
| DATA_SHARE<sup>9+</sup> | 5 | Data sharing included.|
| FILE_SHARE<sup>9+</sup> | 6 | File sharing included.|
| STATIC_SUBSCRIBER<sup>9+</sup> | 7 | Subscribers included. |
| WALLPAPER<sup>9+</sup> | 8 | Wallpaper included. |
| BACKUP<sup>9+</sup> | 9 | Data backup and restore included.|
| WINDOW<sup>9+</sup> | 10 | Window type extension information included.|
| ENTERPRISE_ADMIN<sup>9+</sup> | 11 | Enterprise administrators included. |
| THUMBNAIL<sup>9+</sup> | 13 | Thumbnails included.|
| PREVIEW<sup>9+</sup> | 14 | Preview included.|
| UNSPECIFIED<sup>9+</sup> | 255 | Unspecified type. |
## ExtensionFlag<sup>9+</sup>
Enumerates Extension flags.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Default Value | Description |
| ---------------------------------------- | ---------- | ------------------------------ |
| GET_EXTENSION_INFO_DEFAULT<sup>9+</sup> | 0x00000000 | Obtains the default Extension ability information. |
| GET_EXTENSION_INFO_WITH_PERMISSION<sup>9+</sup> | 0x00000002 | Obtains the Extension ability information that carries permission information. |
| GET_EXTENSION_INFO_WITH_APPLICATION<sup>9+</sup> | 0x00000004 | Obtains the Extension ability information that carries application information. |
| GET_EXTENSION_INFO_WITH_METADATA<sup>9+</sup> | 0x00000020 | Obtains the Extension ability information that carries metadata information.|
## ColorMode
## ColorMode<sup>deprecated<sup>
> This API is deprecated since API version 9. You are not advised to use it anymore.
Enumerates color modes.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ---------- | ---- | ---- |
| Name | Value | Description |
| ---------- | ---- | -------- |
| AUTO_MODE | -1 | Automatic mode.|
| DARK_MODE | 0 | Dark mode.|
| LIGHT_MODE | 1 | Light mode.|
## GrantStatus
## GrantStatus<sup>deprecated<sup>
> This API is deprecated since API version 9. You are advised to use [bundleManager.PermissionGrantState](js-apis-bundleManager.md#permissiongrantstate) instead.
Enumerates permission grant states.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------------------ | ---- | ---- |
| Name | Value | Description |
| ------------------ | ---- | ------------ |
| PERMISSION_DENIED | -1 | Permission denied.|
| PERMISSION_GRANTED | 0 | Permission granted. |
## SupportWindowMode
Enumerates window modes.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------------------ | ---- | ---- |
| FULL_SCREEN<sup>9+</sup> | 0 | Full screen.|
| SPLIT<sup>9+</sup> | 1 | Split-screen. |
| FLOATING<sup>9+</sup> | 2 | Floating. |
## UpgradeFlag
Enumerates the upgrade flags, which are for internal use only.
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Value | Description |
| ----------------------------- | ---- | ---------------- |
| NOT_UPGRADE<sup>9+</sup> | 0 | No module needs an upgrade. |
| SINGLE_UPGRADE<sup>9+</sup> | 1 | A single module needs an upgrade.|
| RELATION_UPGRADE<sup>9+</sup> | 2 | The module that has a relationship with the current one needs an upgrade.|
# appControl
The **appControl** module provides APIs for setting, obtaining, and deleting the disposed status of an application. An application in the disposed state is forbidden to run. When a user clicks the application icon on the home screen, the corresponding page is displayed based on the disposal intent.
> **NOTE**
>
> 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.
>
> The APIs provided by this module are system APIs.
## Modules to Import
``` ts
import appControl from '@ohos.bundle.appControl'
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want): Promise\<void>
Sets the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| disposedWant | Want | Yes| Disposal intent of the application.|
**Return value**
| Type | Description |
| ------------------------- | ------------------ |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
var want = {bundleName: 'com.example.myapplication'};
try {
appControl.setDisposedStatus(appId, want)
.then(() => {
console.info('setDisposedStatus success');
}).catch((error) => {
console.error('setDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('setDisposedStatus failed ' + error.message);
}
```
## appControl.setDisposedStatus
setDisposedStatus(appId: string, disposedWant: Want, callback: AsyncCallback\<void>): void;
Sets the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------------------------------- | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| disposedWant | Want | Yes| Disposal intent of the application.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
var want = {bundleName: 'com.example.myapplication'};
try {
appControl.setDisposedStatus(appId, want, (error, data) => {
if (error) {
console.error('setDisposedStatus failed ' + error.message);
return;
}
console.info('setDisposedStatus success');
});
} catch (error) {
console.error('setDisposedStatus failed ' + error.message);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string): Promise\<Want>;
Obtains the disposed status of an application. This API uses a promise to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
**Return value**
| Type | Description |
| ------------------------- | ------------------ |
| Promise\<Want> | Promise used to return the disposed status.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
try {
appControl.getDisposedStatus(appId)
.then((data) => {
console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
}).catch((error) => {
console.error('getDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('getDisposedStatus failed ' + error.message);
}
```
## appControl.getDisposedStatus
getDisposedStatus(appId: string, callback: AsyncCallback\<Want>): void;
Obtains the disposed status of an application. This API uses an asynchronous callback to return the result. If the operation is successful, the disposed status of the application is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the disposed status obtained; otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
try {
appControl.getDisposedStatus(appId, (error, data) => {
if (error) {
console.error('getDisposedStatus failed ' + error.message);
return;
}
console.info('getDisposedStatus success. DisposedStatus: ' + JSON.stringify(data));
});
} catch (error) {
console.error('getDisposedStatus failed ' + error.message);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string): Promise\<void>
Deletes the disposed status for an application. This API uses a promise to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
**Return value**
| Type | Description |
| ------------------------- | ------------------ |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
try {
appControl.deleteDisposedStatus(appId)
.then(() => {
console.info('deleteDisposedStatus success');
}).catch((error) => {
console.error('deleteDisposedStatus failed ' + error.message);
});
} catch (error) {
console.error('deleteDisposedStatus failed ' + error.message);
}
```
## appControl.deleteDisposedStatus
deleteDisposedStatus(appId: string, callback: AsyncCallback\<void>) : void
Deletes the disposed status for an application. This API uses an asynchronous callback to return the result. If the operation is successful, **null** is returned. If the operation fails, an error message is returned.
**Required permissions**: ohos.permission.MANAGE_DISPOSED_APP_STATUS
**System capability**: SystemCapability.BundleManager.BundleFramework.AppControl
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| ----------- | ------ | ---- | --------------------------------------- |
| appId | string | Yes | ID of the target application.<br> **appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. For details about how to obtain **appId**, see [Obtaining appId of an Application](#obtaining-appid-of-an-application). |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| ------ | -------------------------------------- |
| 17700005 | The specified appId was not found. |
**Example**
```ts
var appId = "com.example.myapplication_xxxxx";
try {
appControl.deleteDisposedStatus(appId, (error, data) => {
if (error) {
console.error('deleteDisposedStatus failed ' + error.message);
return;
}
console.info('deleteDisposedStatus success');
});
} catch (error) {
console.error('deleteDisposedStatus failed ' + error.message);
}
```
## Obtaining appId of an Application
**appId** is the unique identifier of an application and is determined by the bundle name and signature information of the application. It can be obtained by calling [getBundleInfo](js-apis-bundleManager.md#bundlemanagergetbundleinfo).
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager';
var bundleName = 'com.example.myapplication';
var appId;
try {
bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)
.then((data) => {
appId = data.signatureInfo.appId;
console.info("appId is " + appId);
}).catch((error) => {
console.error("getBundleInfo failed " + error.message);
});
} catch (error) {
console.error("getBundleInfo failed " + error.message);
}
```
......@@ -3,11 +3,14 @@
Unless otherwise specified, ability information is obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> 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.
## AbilityInfo
## AbilityInfo<sup>(deprecated)<sup>
**System capability**: SystemCapability.BundleManager.BundleFramework
> This API is deprecated since API version 9. You are advised to use [AbilityInfo](js-apis-bundleManager-abilityInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------------------------------------------- | ---- | ---- | ----------------------------------------- |
......@@ -36,13 +39,5 @@ Unless otherwise specified, ability information is obtained through **GET_BUNDLE
| uri | string | Yes | No | URI of the ability.<br>This attribute can be used only in the FA model.|
| labelId | number | Yes | No | Ability label ID. |
| subType | AbilitySubType | Yes | No | Subtype of the template that can be used by the ability.<br>This attribute can be used only in the FA model.|
| metaData<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Custom metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| metadata<sup>8+</sup> | Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)> | Yes | No | Metadata of the ability.<br>The value is obtained by passing **GET_ABILITY_INFO_WITH_METADATA**.|
| enabled<sup>8+</sup> | boolean | Yes | No | Whether the ability is enabled. |
| supportWindowMode<sup>9+</sup> | Array\<[SupportWindowMode](js-apis-Bundle.md)> | Yes | No | Window modes supported by the ability. |
| maxWindowRatio<sup>9+</sup> | number | Yes | No | Maximum window ratio supported by the ability. |
| minWindowRatio<sup>9+</sup> | number | Yes | No | Minimum window ratio supported by ability. |
| maxWindowWidth<sup>9+</sup> | number | Yes | No | Maximum window width supported by the ability. |
| minWindowWidth<sup>9+</sup> | number | Yes | No | Minimum window width supported by the ability. |
| maxWindowHeight<sup>9+</sup> | number | Yes | No | Maximum window height supported by the ability. |
| minWindowHeight<sup>9+</sup> | number | Yes | No | Minimum window height supported by the ability. |
......@@ -6,7 +6,9 @@ The **ApplicationInfo** module provides application information. Unless otherwis
>
> 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.
## ApplicationInfo
## ApplicationInfo<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
......@@ -18,11 +20,9 @@ The **ApplicationInfo** module provides application information. Unless otherwis
| systemApp | boolean | Yes | No | Whether the application is a system application. The default value is **false**. |
| enabled | boolean | Yes | No | Whether the application is enabled. The default value is **true**. |
| label | string | Yes | No | Application label. |
| labelId<sup>(deprecated)</sup> | string | Yes | No | Application label ID.<br>\- **NOTE**: This attribute is deprecated from API version 9. Use **labelIndex** instead. |
| labelIndex<sup>9+</sup> | number | Yes | No | Index of the application label.|
| labelId<sup>(deprecated)</sup> | string | Yes | No | Application label ID.<br>\- **NOTE**: This attribute is deprecated from API version 9. Use **labelIndex** instead.|
| icon | string | Yes | No | Application icon. |
| iconId<sup>(deprecated)</sup> | string | Yes | No | Application icon ID.<br>\- **NOTE**: This attribute is deprecated from API version 9. Use **iconIndex** instead. |
| iconIndex<sup>9+</sup> | number | Yes | No | Index of the application icon.|
| iconId<sup>(deprecated)</sup> | string | Yes | No | Application icon ID.<br>\- **NOTE**: This attribute is deprecated from API version 9. Use **iconIndex** instead.|
| process | string | Yes | No | Process in which the application runs. If this parameter is not set, the bundle name is used. |
| supportedModes | number | Yes | No | Running modes supported by the application. |
| moduleSourceDirs | Array\<string> | Yes | No | Relative paths for storing application resources. |
......@@ -31,14 +31,7 @@ The **ApplicationInfo** module provides application information. Unless otherwis
| entryDir | string | Yes | No | Path for storing application files. |
| codePath<sup>8+</sup> | string | Yes | No | Installation directory of the application. |
| metaData<sup>8+</sup> | Map\<string, Array\<[CustomizeData](js-apis-bundle-CustomizeData.md)>> | Yes | No | Custom metadata of the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_METADATA**.|
| metadata<sup>9+</sup> | Map\<string, Array\<[Metadata](js-apis-bundle-Metadata.md)>> | Yes | No | Metadata of the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_METADATA**.|
| removable<sup>8+</sup> | boolean | Yes | No | Whether the application is removable. |
| accessTokenId<sup>8+</sup> | number | Yes | No | Access token ID of the application. |
| uid<sup>8+</sup> | number | Yes | No | UID of the application. |
| entityType<sup>8+</sup> | string | Yes | No | Entity type of the application. |
| fingerprint<sup>9+</sup> | string | Yes | No | Signing certificate fingerprint of the application, that is, the SHA-256 checksum of the signing certificate that you request for the application.<br>The value is obtained by passing **GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT**.|
| iconResource<sup>9+</sup> | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Icon resource of the application.|
| labelResource<sup>9+</sup> | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Label resource of the application.|
| descriptionResource<sup>9+</sup> | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Description resource of the application.|
| appDistributionType<sup>9+</sup> | string | Yes | No | Distribution type of the application signing certificate. The options are **app_gallery**, **enterprise**, **os_integration**, and **crowdtesting**. |
| appProvisionType<sup>9+</sup> | string | Yes | No | Type of the application signing certificate file. The options are **debug** and **release**.|
......@@ -6,7 +6,11 @@ The **BundleInfo** module provides bundle information. Unless otherwise specifie
>
> 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.
## BundleInfo
## BundleInfo<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [BundleInfo](js-apis-bundleManager-bundleInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
......@@ -35,11 +39,12 @@ The **BundleInfo** module provides bundle information. Unless otherwise specifie
| minCompatibleVersionCode | number | Yes | No | Earliest version compatible with the bundle in the distributed scenario. |
| entryInstallationFree | boolean | Yes | No | Whether installation-free is supported for the entry module. |
| reqPermissionStates<sup>8+</sup> | Array\<number> | Yes | No | Permission grant state. |
| extensionAbilityInfo<sup>9+</sup> | Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)> | Yes | No | Extension ability information.<br>The value is obtained by passing **GET_BUNDLE_WITH_EXTENSION_ABILITY**.|
## ReqPermissionDetail
## ReqPermissionDetail<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [ReqPermissionDetail](js-apis-bundleManager-bundleInfo.md) instead.
Provides the detailed information of the permissions to request from the system.
......@@ -49,12 +54,13 @@ Provides the detailed information of the permissions to request from the system.
| --------------------- | ----------------------- | ---- | ---- | ---------------------- |
| name | string | Yes | Yes | Name of the permission to request. |
| reason | string | Yes | Yes | Reason for requesting the permission. |
| reasonId<sup>9+</sup> | number | Yes | Yes | ID of the reason for requesting the permission.|
| usedScene | [UsedScene](#usedscene) | Yes | Yes | Application scenario and timing for using the permission.|
## UsedScene
## UsedScene<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [UsedScene](js-apis-bundleManager-bundleInfo.md) instead.
Describes the application scenario and timing for using the permission.
......
# BundleInstaller
The **BundleInstaller** module provides APIs for installing, updating, and deleting bundles on devices.
The **BundleInstaller** module provides APIs for you to install, uninstall, and recover bundles on devices.
> **NOTE**
>
> 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.
## BundleInstaller.install
## BundleInstaller.install<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [install](js-apis-installer.md) instead.
install(bundleFilePaths: Array&lt;string&gt;, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
Installs bundles. This API uses an asynchronous callback to return the result.
Installs a bundle. This API uses an asynchronous callback to return the result.
**Required permissions**
......@@ -25,11 +28,13 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| bundleFilePaths | Array&lt;string&gt; | Yes | Paths where the bundles are stored. Each path should point to a relative directory of the current application's data directory.|
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| bundleFilePaths | Array&lt;string&gt; | Yes | Paths where the HAP files of the bundle are stored. Each path should point to a relative directory of the current bundle's data directory.|
| param | [InstallParam](#installparam) | Yes | Parameters required for bundle installation. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status. |
## BundleInstaller.uninstall
## BundleInstaller.uninstall<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [uninstall](js-apis-installer.md) instead.
uninstall(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
......@@ -50,10 +55,12 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| param | [InstallParam](#installparam) | Yes | Parameters required for bundle uninstall. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status.|
## BundleInstaller.recover<sup>8+</sup>
## BundleInstaller.recover<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [recover](js-apis-installer.md) instead.
recover(bundleName: string, param: InstallParam, callback: AsyncCallback&lt;InstallStatus&gt;): void;
......@@ -74,23 +81,10 @@ SystemCapability.BundleManager.BundleFramework
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| param | [InstallParam](#installparam) | Yes | Parameters required for the installation or uninstall. |
| param | [InstallParam](#installparam) | Yes | Parameters required for bundle recovering. |
| callback | AsyncCallback&lt;[InstallStatus](#installstatus)&gt; | Yes | Callback used to return the installation status.|
## HashParam<sup>9+</sup>
Describes the parameters required for bundle installation or uninstall.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Description |
| ---------- | ------ | ---------------- |
| moduleName | string | Module name of the application.|
| hashValue | string | Hash value. |
## InstallParam
## InstallParam<sup>(deprecated)<sup>
Describes the parameters required for bundle installation or uninstall.
......@@ -98,15 +92,13 @@ Describes the parameters required for bundle installation or uninstall.
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Description |
| ------------------------------ | ------------------------------ | ------------------ |
| userId | number | User ID. |
| installFlag | number | Installation flag. |
| isKeepData | boolean | Whether data is kept.|
| hashParams<sup>9+</sup> | Array<[HashParam](#hashparam)> | Hash parameters. |
| crowdtestDeadline<sup>9+</sup> | number | Time when the test package is killed.|
| Name | Type | Readable| Writable| Description |
| ----------- | ------- | ---- | ---- | ------------------ |
| userId | number | Yes | No | User ID. |
| installFlag | number | Yes | No | Installation flag. |
| isKeepData | boolean | Yes | No | Whether data is kept.|
## InstallStatus
## InstallStatus<sup>(deprecated)<sup>
Describes the bundle installation status.
......
# CustomizeData
The **CustomizeData** module provides custom metadata.
> **NOTE**
>
> 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.
## CustomizeData<sup>(deprecated)</sup>
Provides custom metadata.
## CustomizeData
> This API is deprecated since API version 9. You are advised to use [Metadata](js-apis-bundleManager-metadata.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ------------------ | ------ | ---- | ---- | ---------------- |
| name | string | Yes | Yes | Custom metadata name.|
......
......@@ -6,11 +6,11 @@ The **ElementName** module provides the element name information, which can be o
>
> 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.
## ElementName<sup>(deprecated)<sup>
## ElementName<sup>(deprecated)</sup>
> This API is deprecated since API version 9. You are advised to use [ElementName](js-apis-bundleManager-elementName.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| ----------------------- | ---------| ---- | ---- | ------------------------- |
......@@ -19,6 +19,3 @@ The **ElementName** module provides the element name information, which can be o
| abilityName | string | Yes | Yes | Name of the ability. |
| uri | string | Yes | Yes | Resource ID. |
| shortName | string | Yes | Yes | Short name of the ability. |
| moduleName<sup>9+</sup> | string | Yes | Yes | Name of the HAP file to which the ability belongs. |
<!--no_check-->
\ No newline at end of file
# HapModuleInfo
The **HapModuleInfo** module provides module information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
> **NOTE**
>
> 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.
The **HapModuleInfo** module provides module information. Unless otherwise specified, all attributes are obtained through **GET_BUNDLE_DEFAULT**.
## HapModuleInfo<sup>(deprecated)<sup>
## HapModuleInfo
> This API is deprecated since API version 9. You are advised to use [HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
......@@ -29,7 +29,3 @@ The **HapModuleInfo** module provides module information. Unless otherwise speci
| moduleName | string | Yes | No | Module name. |
| mainAbilityName | string | Yes | No | Name of the main ability. |
| installationFree | boolean | Yes | No | Whether installation-free is supported. |
| mainElementName<sup>9+</sup> | string | Yes | No | Information about the main ability. |
| extensionAbilityInfo<sup>9+</sup> | Array\<[ExtensionAbilityInfo](js-apis-bundle-ExtensionAbilityInfo.md)> | Yes | No | Information about the Extension ability.|
| metadata<sup>9+</sup> | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the ability. |
| hashValue<sup>9+</sup> | string | Yes | No | Hash value of the module.<br>The value is obtained by passing **GET_BUNDLE_WITH_HASH_VALUE**.|
......@@ -6,7 +6,9 @@ The **LauncherAbilityInfo** module provides information about the launcher abili
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## LauncherAbilityInfo
## LauncherAbilityInfo<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
......
# ModuleInfo
The **ModuleInfo** module provides module information of an application.
> **NOTE**
>
> 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.
Provides the module information of the application.
## ModuleInfo
## ModuleInfo<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| --------------- | ------ | ---- | ---- | -------- |
| moduleName | string | Yes | No | Module name.|
......
......@@ -6,7 +6,9 @@ The **PermissionDef** module provides permission details defined in the configur
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## **PermissionDef**
## **PermissionDef**<sup>(deprecated)<sup>
> This API is deprecated since API version 9. You are advised to use [PermissionDef](js-apis-bundleManager-permissionDef.md) instead.
**System capability**: SystemCapability.BundleManager.BundleFramework
......
# AbilityInfo
The **AbilityInfo** module provides information about an ability. Unless otherwise specified, the information is obtained through [GET_ABILITY_INFO_DEFAULT](js-apis-bundleManager.md).
> **NOTE**
>
> 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.
## AbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------------------- | -------------------------------------------------------- | ---- | ---- | ----------------------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| moduleName | string | Yes | No | Name of the HAP file to which the ability belongs. |
| name | string | Yes | No | Ability name. |
| label | string | Yes | No | Ability name visible to users. |
| labelId | number | Yes | No | ID of the ability label. |
| description | string | Yes | No | Ability description. |
| descriptionId | number | Yes | No | ID of the ability description. |
| icon | string | Yes | No | Index of the ability icon resource file. |
| iconId | number | Yes | No | ID of the ability icon. |
| process | string | Yes | No | Process in which the ability runs. If this parameter is not set, the bundle name is used.|
| isVisible | boolean | Yes | No | Whether the ability can be called by other bundles. |
| type | [AbilityType](js-apis-bundleManager.md#abilitytype) | Yes | No | Ability type.<br>This attribute can be used only in the FA model. |
| orientation | [DisplayOrientation](js-apis-bundleManager.md#displayorientation) | Yes | No | Ability display orientation. |
| launchType | [LaunchType](js-apis-bundleManager.md#launchtype) | Yes | No | Ability launch mode. |
| permissions | Array\<string> | Yes | No | Permissions required for other bundles to call the ability. The information is obtained by using **GET_ABILITY_INFO_WITH_PERMISSION**.|
| readPermission | string | Yes | No | Permission required for reading the ability data.<br>This attribute can be used only in the FA model.|
| writePermission | string | Yes | No | Permission required for writing data to the ability.<br>This attribute can be used only in the FA model.|
| uri | string | Yes | No | URI of the ability.<br>This attribute can be used only in the FA model.|
| deviceTypes | Array\<string> | Yes | No | Device types supported by the ability. |
| applicationInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information. The information is obtained by using **GET_ABILITY_INFO_WITH_APPLICATION**.|
| metadata | Array\<[Metadata](js-apis-bundleManager-metadata.md)> | Yes | No | Metadata of the ability. The information is obtained by using **GET_ABILITY_INFO_WITH_METADATA**.|
| enabled | boolean | Yes | No | Whether the ability is enabled. |
| supportWindowModes | Array\<[SupportWindowMode](js-apis-bundleManager.md#supportwindowmode)> | Yes | No | Window modes supported by the ability. |
| windowSize|[WindowSize](#windowsize) | Yes | No | Window size.|
## WindowSize
Describes the window size.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| -------------------| ------- | ---- | ---- | ---------------------------------- |
| maxWindowRatio | number | Yes | No | Maximum aspect ratio of the window in free window mode. The value ranges from 0 to 1.|
| minWindowRatio | number | Yes | No | Minimum aspect ratio of the window in free window mode. The value ranges from 0 to 1.|
| maxWindowWidth | number | Yes | No | Maximum width of the window in free window mode. The unit is vp.|
| minWindowWidth | number | Yes | No | Minimum width of the window in free window mode. The unit is vp.|
| maxWindowHeight | number | Yes | No | Maximum height of the window in free window mode. The unit is vp.|
| minWindowHeight | number | Yes | No | Maximum height of the window in free window mode. The unit is vp.|
# ApplicationInfo
The **ApplicationInfo** module provides information about an application. Unless otherwise specified, the information is obtained through [GET_APPLICATION_INFO_DEFAULT](js-apis-bundleManager.md).
> **NOTE**
>
> 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.
## ApplicationInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| -------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Application name. |
| description | string | Yes | No | Application description. |
| descriptionId | number | Yes | No | ID of the application description. |
| enabled | boolean | Yes | No | Whether the application is enabled. The default value is **true**. |
| label | string | Yes | No | Application label. |
| labelId | number | Yes | No | ID of the application label. |
| icon | string | Yes | No | Application icon. |
| iconId | number | Yes | No | ID of the application icon. |
| process | string | Yes | No | Process in which the application runs. If this parameter is not set, the bundle name is used. |
| permissions | Array\<string> | Yes | No | Permissions required for accessing the application. The information is obtained by using **GET_APPLICATION_INFO_WITH_PERMISSION**.|
| entryDir | string | Yes | No | Path for storing application files. |
| codePath | string | Yes | No | Installation directory of the application. |
| metadata | Map\<string, Array\<[Metadata](js-apis-bundleManager-metadata.md)>> | Yes | No | Metadata of the application. The information is obtained by using **GET_APPLICATION_INFO_WITH_METADATA**.|
| removable | boolean | Yes | No | Whether the application is removable. |
| accessTokenId | number | Yes | No | Access token ID of the application. |
| uid | number | Yes | No | UID of the application. |
| iconResource | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Icon resource of the application. |
| labelResource | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Label resource of the application. |
| descriptionResource | [Resource](js-apis-resource-manager.md#resource9) | Yes| No| Description resource of the application. |
| appDistributionType | string | Yes | No | Distribution type of the application signing certificate. The options are **app_gallery**, **enterprise**, **os_integration**, and **crowdtesting**. |
| appProvisionType | string | Yes | No | Type of the application signing certificate file. The options are **debug** and **release**. |
# BundleInfo
The **BundleInfo** module provides information about a bundle. Unless otherwise specified, the information is obtained through [GET_BUNDLE_INFO_DEFAULT](js-apis-bundle-bundleManager).
> **NOTE**
>
> 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.
## BundleInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Bundle name. |
| vendor | string | Yes | No | Vendor of the bundle. |
| versionCode | number | Yes | No | Version number of the bundle. |
| versionName | string | Yes | No | Version description of the bundle. |
| minCompatibleVersionCode | number | Yes | No | Earliest version compatible with the bundle in the distributed scenario. |
| targetVersion | number | Yes | No | Target API version required for running the bundle. |
| appInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information. The information is obtained by using **GET_BUNDLE_INFO_WITH_APPLICATION**. |
| hapModulesInfo | Array\<[HapModuleInfo](js-apis-bundleManager-hapModuleInfo.md)> | Yes | No | Module configuration information. The information is obtained by using **GET_BUNDLE_INFO_WITH_HAP_MODULE**. |
| reqPermissionDetails | Array\<[ReqPermissionDetail](#reqpermissiondetail)> | Yes | No | Detailed information of the permissions to request from the system. The information is obtained by using **GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION**.|
| permissionGrantStates | Array\<[PermissionGrantState](js-apis-bundleManager.md#permissiongrantstate)> | Yes | No | Permission grant state. The information is obtained by using **GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION**. |
| signatureInfo | [SignatureInfo](#signatureinfo) | Yes | No | Signature information of the bundle. The information is obtained by using **GET_BUNDLE_INFO_WITH_SIGNATURE_INFO**. |
| installTime | number | Yes | No | Time when the bundle was installed. |
| updateTime | number | Yes | No | Time when the bundle was updated. |
## ReqPermissionDetail
Provides the detailed information of the permissions to request from the system.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------------------- | ----------------------- | ---- | ---- | ---------------------|
| name | string | Yes | Yes | Name of the permission to request. |
| reason | string | Yes | Yes | Reason for requesting the permission. |
| reasonId | number | Yes | Yes | ID of the reason for requesting the permission.|
| usedScene | [UsedScene](#usedscene) | Yes | Yes | Application scenario and timing for using the permission.|
## UsedScene
Describes the application scenario and timing for using the permission.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------- | -------------- | ---- | ---- | --------------------------- |
| abilities | Array\<string> | Yes | Yes | Abilities that use the permission. |
| when | string | Yes | Yes | Time when the permission is used. |
## SignatureInfo
Describes the signature information of the bundle.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------- | -------------- | ---- | ---- | --------------------------- |
| appId | string | Yes | No | Application ID. |
|fingerprint| string | Yes | No | Fingerprint information of the bundle. |
# DispatchInfo
The **DispatchInfo** module provides dispatch information.
The **DispatchInfo** module provides version information about the **dispatchInfo** struct and dispatch API. The information can be obtained through [freeInstall.getDispatchInfo](js-apis-freeInstall.md).
> **NOTE**
>
......@@ -8,11 +8,11 @@ The **DispatchInfo** module provides dispatch information.
## DispatchInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
**System API**: This is a system API.
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
| Name | Type | Readable| Writable| Description |
| ----------- | ------ | ---- | ---- | ------------------------ |
| version | string | Yes | No | Version of the API to dispatch.|
| dispatchAPI | string | Yes | No | API to dispatch. |
| version | string | Yes | No | Version of the **dispatchInfo** struct.|
| dispatchAPIVersion | string | Yes | No | Version of the dispatch API. |
# ElementName
The **ElementName** module provides the element name information, which can be obtained through [Context.getElementName](js-apis-Context.md).
The **ElementName** module provides information about an element name. The information can be obtained through [Context.getElementName](js-apis-Context.md).
> **NOTE**
......@@ -19,4 +19,3 @@ The **ElementName** module provides the element name information, which can be o
| uri | string | Yes | Yes | Resource ID. |
| shortName | string | Yes | Yes | Short name of the ability. |
| moduleName | string | Yes | Yes | Module name of the HAP file to which the ability belongs. |
# ExtensionAbilityInfo
The **ExtensionAbilityInfo** module provides Extension ability information. Unless otherwise specified, all attributes are obtained through [getBundleInfo](js-apis-Bundle.md#bundlegetbundleinfo), and flags are obtained through [GET_BUNDLE_DEFAULT](js-apis-Bundle.md#bundleflag).
The **ExtensionAbilityInfo** module provides information about an Extension ability. Unless otherwise specified, all attributes are obtained through [getBundleInfo](js-apis-bundleManager.md), and flags are obtained through [GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY](js-apis-bundleManager.md#bundleflag).
> **NOTE**
>
......@@ -8,21 +8,21 @@ The **ExtensionAbilityInfo** module provides Extension ability information. Unle
## ExtensionAbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| -------------------- | ---------------------------------------------------- | ---- | ---- | -------------------------------------------------- |
| bundleName | string | Yes | No | Bundle name of the application. |
| -------------------- | ----------------------------------------------------------- | ---- | ---- | -------------------------------------------------- |
| bundleName | string | Yes | No | Bundle name. |
| moduleName | string | Yes | No | Name of the HAP file to which the Extension ability belongs. |
| name | string | Yes | No | Name of the Extension ability. |
| labelId | number | Yes | No | Label ID of the Extension ability. |
| descriptionId | number | Yes | No | Description ID of the Extension ability. |
| iconId | number | Yes | No | Icon ID of the Extension ability. |
| isVisible | boolean | Yes | No | Whether the Extension ability can be called by other applications. |
| extensionAbilityType | bundle.ExtensionAbilityType | Yes | No | Type of the Extension ability. |
| permissions | Array\<string> | Yes | No | Permissions required for other applications to call the Extension ability.|
| applicationInfo | [ApplicationInfo](js-apis-bundle-ApplicationInfo.md) | Yes | No | Application information of the Extension ability. |
| metadata | Array\<[Metadata](js-apis-bundle-Metadata.md)> | Yes | No | Metadata of the Extension ability. |
| isVisible | boolean | Yes | No | Whether the Extension ability can be called by other bundles. |
| extensionAbilityType | [ExtensionAbilityType](js-apis-bundleManager.md#extensionabilitytype) | Yes | No | Type of the Extension ability. |
| permissions | Array\<string> | Yes | No | Permissions required for other bundles to call the Extension ability.|
| applicationInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information of the Extension ability. |
| metadata | Array\<[Metadata](js-apis-bundleManager-metadata.md)> | Yes | No | Metadata of the Extension ability. |
| enabled | boolean | Yes | No | Whether the Extension ability is enabled. |
| readPermission | string | Yes | No | Permission required for reading data from the Extension ability. |
| writePermission | string | Yes | No | Permission required for writing data to the Extension ability. |
# HapModuleInfo
> **NOTE**
>
> 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.
## HapModuleInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| --------------------------------- | ------------------------------------------------------------ | ---- | ---- | -------------------- |
| name | string | Yes | No | Module name. |
| icon | string | Yes | No | Module icon. |
| iconId | number | Yes | No | ID of the module icon. |
| label | string | Yes | No | Module label. |
| labelId | number | Yes | No | ID of the module label. |
| description | string | Yes | No | Module description. |
| descriptionId | number | Yes | No | ID of the module mescription. |
| mainElementName | string | Yes | No | Name of the main ability. |
| abilitiesInfo | Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)> | Yes | No | Ability information. |
| extensionAbilitiesInfo | Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)> | Yes | No | Information about the Extension ability.|
| metadata | Array\<[Metadata](js-apis-bundleManager-metadata.md)> | Yes | No | Metadata of the ability. |
| deviceTypes | Array\<string> | Yes | No | Device types supported by the module. |
| installationFree | boolean | Yes | No | Whether installation-free is supported. |
| hashValue | string | Yes | No | Hash value of the module. |
| moduleSourceDir | string | Yes | No | Module path.|
# LauncherAbilityInfo
> **NOTE**
>
> 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.
## LauncherAbilityInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| --------------- | ----------------------------------------------------------- | ---- | ---- | ------------------------------------ |
| applicationInfo | [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Yes | No | Application information of the launcher ability.|
| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | No | Element name of the launcher ability. |
| labelId | number | Yes | No | Label ID of the launcher ability. |
| iconId | number | Yes | No | Icon ID of the launcher ability. |
| userId | number | Yes | No | User ID of the launcher ability. |
| installTime | number | Yes | No | Time when the launcher ability was installed. |
# Metadata
The **Metadata** module provides the metadata information.
The **metadata** module provides the configuration about the module, ability, and Extension ability. The value is of the array type. The configuration is valid only for the current module, ability, or Extension ability.
> **NOTE**
>
> 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.
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.
## Metadata
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Type | Readable| Writable| Description |
| -------- | ------ | ---- | ---- | ---------- |
| name | string | Yes | Yes | Metadata name.|
| value | string | Yes | Yes | Metadata value. |
| resource | string | Yes | Yes | Metadata resource.|
# PackInfo
The **PackInfo** module provides the bundle package information, which can be obtained using [bundle.getBundlePackInfo](js-apis-Bundle.md).
The **PackInfo** module provides information in the **pack.info** file. The information can be obtained using [freeInstall.getBundlePackInfo](js-apis-freeInstall.md).
> **NOTE**
>
> 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.
## BundlePackFlag
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Value | Description |
| ------------------ | ---------- | ---------------------------------- |
| GET_PACK_INFO_ALL | 0x00000000 | All information about the package. |
| GET_PACKAGES | 0x00000001 | Package information about the package.|
| GET_BUNDLE_SUMMARY | 0x00000002 | Bundle summary of the package. |
| GET_MODULE_SUMMARY | 0x00000004 | Module summary of the package. |
## BundlePackInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Readable| Writable| Description |
| -------- | --------------------------------------- | ---- | ---- | ----------------------------- |
| packages | Array\<[PackageConfig](#packageconfig)> | Yes | No | Package configuration information. |
| summary | [PackageSummary](#packagesummary) | Yes | No | Package summary.|
| -------- | --------------------------------------- | ---- | ---- | ------------------------- |
| packages | Array\<[PackageConfig](#packageconfig)> | Yes | No | Package configuration information in the **pack.info** file. |
| summary | [PackageSummary](#packagesummary) | Yes | No | Package summary information in the **pack.info** file.|
## PackageConfig
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| deviceType | Array\<string> | Yes | No | Device types supported. |
| name | string | Yes | No | Package name. |
| moduleType | string | Yes | No | Module type. |
| deliveryWithInstall | boolean | Yes | No | Whether the HAP file will be installed when the user installs the application. The value **true** means that the HAP file will be automatically installed when the user installs the application, and **false** means the opposite.|
| deviceTypes | Array\<string> | Yes | No | Device types supported by the bundle. |
| name | string | Yes | No | Bundle name. |
| moduleType | string | Yes | No | Module type of the bundle. |
| deliveryWithInstall | boolean | Yes | No | Whether the HAP file will be installed when the user installs the bundle. The value **true** means that the HAP file will be automatically installed when the user installs the bundle, and **false** means the opposite.|
## PackageSummary
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------- | --------------------------------------------- | ---- | ---- | -------------------- |
| app | [BundleConfigInfo](#bundleconfiginfo) | Yes | No | Bundle configuration information. |
| modules | Array\<[ModuleConfigInfo](#moduleconfiginfo)> | Yes | No | Module configuration information.|
| modules | Array\<[ModuleConfigInfo](#moduleconfiginfo)> | Yes | No | Module configuration information of the bundle.|
## BundleConfigInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ---------- | ------------------- | ---- | ---- | ---------------------------------- |
| bundleName | string | Yes | No | Bundle name of an application. It uniquely identifies the application.|
| bundleName | string | Yes | No | Bundle name. It uniquely identifies the application.|
| version | [Version](#version) | Yes | No | Bundle version. |
## ModuleConfigInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------------------ | ------------------------------------------------- | ---- | ---- | ---------------------------------- |
| mainAbility | string | Yes| No| Name of the main ability.|
| apiVersion | [ApiVersion](#apiversion) | Yes | No | API version of the module. |
| deviceType | Array\<string> | Yes | No | Device type of the module. |
| deviceType | Array\<string> | Yes | No | Device types supported by the module. |
| distro | [ModuleDistroInfo](#moduledistroinfo) | Yes | No | Distribution information of the module. |
| abilities | Array\<[ModuleAbilityInfo](#moduleabilityinfo)> | Yes | No | Ability information of the module. |
| extensionAbilities | Array\<[ExtensionAbilities](#extensionabilities)> | Yes | No | Extension ability information of the module.|
| extensionAbilities | Array\<[ExtensionAbilities](#extensionability)> | Yes | No | Extension ability information of the module.|
## ModuleDistroInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------------------- | ------- | ---- | ---- | ------------------------------------------------------------ |
| mainAbility | string | Yes | No | Name of the main ability. |
| deliveryWithInstall | boolean | Yes | No | Whether the HAP file will be installed when the user installs the application. The value **true** means that the HAP file will be automatically installed when the user installs the application, and **false** means the opposite.|
| deliveryWithInstall | boolean | Yes | No | Whether the HAP file will be installed when the user installs the bundle. The value **true** means that the HAP file will be automatically installed when the user installs the bundle, and **false** means the opposite.|
| installationFree | boolean | Yes | No | Whether the HAP file supports the installation-free feature. The value **true** means that the HAP file supports the installation-free feature and meets installation-free constraints, and **false** means the opposite.|
| moduleName | string | Yes | No | Module name. |
| moduleType | string | Yes | No | Module type. |
## ModuleAbilityInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------- | ------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Logical name of the ability. The name must be unique in the application. |
| name | string | Yes | No | Name of the ability. The name must be unique in the bundle. |
| label | string | Yes | No | Name of the ability displayed to users. The value is a resource index to names in multiple languages.|
| visible | boolean | Yes | No | Whether the ability can be called by other applications. The value **true** means that the ability can be called by other applications, and **false** means the opposite.|
| visible | boolean | Yes | No | Whether the ability can be called by other bundles. The value **true** means that the ability can be called by other bundles, and **false** means the opposite.|
| forms | Array\<[AbilityFormInfo](#abilityforminfo)> | Yes | No | Widget information. |
## ExtensionAbilities
## ExtensionAbility
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ----- | ------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| forms | Array\<[AbilityFormInfo](#abilityforminfo)> | Yes | No | Specification of the widget. A widget is a brief view of an application that is embedded on the home screen to receive periodical updates.|
| name | string | Yes| No| Name of the Extension ability.|
| forms | Array\<[AbilityFormInfo](#abilityforminfo)> | Yes | No | Widget information.|
## AbilityFormInfo
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| name | string | Yes | No | Widget name. |
| type | string | Yes | No | Widget type. |
| updateEnabled | boolean | Yes | No | Whether the widget supports periodical update. The value **true** means that the widget supports periodical update, and **false** means the opposite.|
| updateEnabled | boolean | Yes | No | Whether the widget supports periodic update. The value **true** means that the widget supports periodic update, and **false** means the opposite.|
| scheduledUpdateTime | string | Yes | No | Scheduled time to update the widget. The value is in 24-hour format and accurate to the minute. |
| updateDuration | number | Yes | No | Interval to update the widget. The unit is 30 minutes. The value is a multiple of 30. A widget can be updated periodically, either at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). If both are configured, **updateDuration** takes precedence.|
| supportDimensions | Array\<number> | Yes | No | Dimensions of the widget. The value can be **1\*2**, **2\*2**, **2\*4**, **4\*4**, or a combination of these options. At least one option must be specified when defining the widget.|
| defaultDimension | number | Yes | No | Default dimensions of the widget. The value must be available in the **supportDimensions** array of the widget.|
| updateDuration | number | Yes | No | Interval to update the widget. The unit is 30 minutes. The value is a multiple of 30. A widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). If both are configured, **updateDuration** takes precedence.|
| supportDimensions | Array\<string> | Yes | No | Dimensions of the widget. The value can be **1\*2**, **2\*2**, **2\*4**, **4\*4**, or a combination of these options. At least one option must be specified when defining the widget.|
| defaultDimension | string | Yes | No | Default dimensions of the widget. The value must be available in the **supportDimensions** array of the widget.|
## ApiVersion
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ----------- | ------ | ---- | ---- | -------------------- |
| releaseType | string | Yes | No | Name of the API version. |
| compatible | number | Yes | No | Minimum API version.|
| target | numbe | Yes | No | Target API version. |
| target | number | Yes | No | Target API version. |
## Version
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFrameWork.FreeInstall
| Name | Type | Readable| Writable| Description |
| ------------------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| minCompatibleVersionCode | number | Yes | No | Minimum compatible version of the application. It is used to check whether the application is compatible with a version on other devices in the cross-device scenario. The value is a 32-bit non-negative integer.|
| name | string | Yes | No | Application version number visible to users. |
| code | number | Yes | No | Application version number used only for application management. The value is a 32-bit non-negative integer. It is used only to determine whether a version is later than another version. A larger value indicates a later version.|
| minCompatibleVersionCode | number | Yes | No | Minimum compatible version of the bundle. It is used to check whether the bundle is compatible with a version on other devices in the cross-device scenario. The value is a 32-bit non-negative integer.|
| name | string | Yes | No | Version number of the bundle visible to users. |
| code | number | Yes | No | Version number of the bundle used only for bundle management. The value is a 32-bit non-negative integer. It is used only to determine whether a version is later than another version. A larger value indicates a later version.|
# PermissionDef
The **PermissionDef** module provides permission details defined in the configuration file. The information can be obtained using [bundleManager.getPermissionDef](js-apis-bundleManager.md).
> **NOTE**
>
> 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.
## **PermissionDef**
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Readable| Writable| Description |
| -------------- | ------ | ---- | ---- | -------------- |
| permissionName | string | Yes | No | Name of the permission. |
| grantMode | number | Yes | No | Grant mode of the permission.|
| labelId | number | Yes | No | Label ID of the permission. |
| descriptionId | number | Yes | No | Description ID of the permission. |
# bundleManager
The **bundleManager** module provides APIs for querying information about bundles, applications, abilities, Extension abilities, and more.
> **NOTE**
>
> 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.
## Modules to Import
```ts
import bundleManager from '@ohos.bundle.bundleManager'
```
## Required Permissions
| Required Permissions | Permission Level | Description |
| ------------------------------------------ | ------------ | ------------------|
| ohos.permission.GET_BUNDLE_INFO | normal | Permission to query information about a specified bundle. |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED| system_basic | Permission to query information about all bundles.|
| ohos.permission.REMOVE_CACHE_FILES | system_basic | Permission to clear cache files of a bundle. |
|ohos.permission.CHANGE_ABILITY_ENABLED_STATE| system_basic | Permission to enable or disable an application or ability. |
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## Enums
### BundleFlag
Enumerates the bundle flags, which indicate the type of bundle information to obtain.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
| ----------------------------------------- | ---------- | ------------------------------------------------------------ |
| GET_BUNDLE_INFO_DEFAULT | 0x00000000 | Used to obtain the default bundle information. The obtained information does not contain information about the signature, application, HAP module, ability, Extension ability, or permission.|
| GET_BUNDLE_INFO_WITH_APPLICATION | 0x00000001 | Used to obtain the bundle information with application information. The obtained information does not contain information about the signature, HAP module, ability, Extension ability, or permission.|
| GET_BUNDLE_INFO_WITH_HAP_MODULE | 0x00000002 | Used to obtain the bundle information with HAP module information. The obtained information does not contain information about the signature, application, ability, Extension ability, or permission.|
| GET_BUNDLE_INFO_WITH_ABILITY | 0x00000004 | Used to obtain the bundle information with ability information. The obtained information does not contain information about the signature, application, Extension ability, or permission. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.|
| GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY | 0x00000008 | Used to obtain the bundle information with Extension ability information. The obtained information does not contain information about the signature, application, ability, or permission. It must be used together with **GET_BUNDLE_INFO_WITH_HAP_MODULE**.|
| GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION | 0x00000010 | Used to obtain the bundle information with permission information. The obtained information does not contain information about the signature, application, HAP module, ability, or Extension ability.|
| GET_BUNDLE_INFO_WITH_METADATA | 0x00000020 | Used to obtain the metadata contained in the application, HAP module, ability, or Extension ability information. It must be used together with **GET_BUNDLE_INFO_WITH_APPLICATION**, **GET_BUNDLE_INFO_WITH_HAP_MODULE**, **GET_BUNDLE_INFO_WITH_ABILITY**, and **GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY**.|
| GET_BUNDLE_INFO_WITH_DISABLE | 0x00000040 | Used to obtain the information about disabled bundles and abilities of a bundle. The obtained bundle information does not contain information about the signature, application, HAP module, ability, Extension ability, or permission.|
| GET_BUNDLE_INFO_WITH_SIGNATURE_INFO | 0x00000080 | Used to obtain the bundle information with signature information. The obtained information does not contain information about the application, HAP module, ability, Extension ability, or permission.|
### ApplicationFlag
Enumerates the application flags, which indicate the type of application information to obtain.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| ------------------------------------ | ---------- | ------------------------------------------------------------ |
| GET_APPLICATION_INFO_DEFAULT | 0x00000000 | Used to obtain the default application information. The obtained information does not contain the permission information or metadata.|
| GET_APPLICATION_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the application information with permission information. |
| GET_APPLICATION_INFO_WITH_METADATA | 0x00000002 | Used to obtain the application information with metadata. |
| GET_APPLICATION_INFO_WITH_DISABLE | 0x00000004 | Used to obtain the application information of disabled bundles. |
### AbilityFlag
Enumerates the ability flags, which indicate the type of ability information to obtain.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| --------------------------------- | ---------- | ------------------------------------------------------------ |
| GET_ABILITY_INFO_DEFAULT | 0x00000000 | Used to obtain the default ability information. The obtained information does not contain the permission, metadata, or disabled ability information.|
| GET_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the ability information with permission information. |
| GET_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | Used to obtain the ability information with application information. |
| GET_ABILITY_INFO_WITH_METADATA | 0x00000004 | Used to obtain the ability information with metadata. |
| GET_ABILITY_INFO_WITH_DISABLE | 0x00000008 | Used to obtain the ability information of disabled abilities. |
| GET_ABILITY_INFO_ONLY_SYSTEM_APP | 0x00000010 | Used to obtain the ability information of system applications. |
### ExtensionAbilityFlag
Enumerates the Extension ability flags, which indicate the type of Extension ability information to obtain.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| ------------------------------------------- | ---------- | ------------------------------------------------------------ |
| GET_EXTENSION_ABILITY_INFO_DEFAULT | 0x00000000 | Used to obtain the default Extension ability information. The obtained information does not contain the permission, metadata, or disabled ability information.|
| GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION | 0x00000001 | Used to obtain the Extension ability information with permission information. |
| GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION | 0x00000002 | Used to obtain the Extension ability information with application information. |
| GET_EXTENSION_ABILITY_INFO_WITH_METADATA | 0x00000004 | Used to obtain the Extension ability information with metadata. |
### ExtensionAbilityType
Enumerates the types of Extension abilities.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name| Value| Description|
|:----------------:|:---:|-----|
| FORM | 0 | [FormExtensionAbility](../../ability/stage-formextension.md): provides APIs for widget development.|
| WORK_SCHEDULER | 1 | [WorkSchedulerExtensionAbility](../../task-management/work-scheduler-dev-guide.md): enables applications to execute non-real-time tasks when the system is idle.|
| INPUT_METHOD | 2 | [InputMethodExtensionAbility](js-apis-inputmethod-extension-ability.md): provides APIs for developing input method applications.|
| SERVICE | 3 | [ServiceExtensionAbility](../../ability/stage-serviceextension.md): enables applications to run in the background and provide services.|
| ACCESSIBILITY | 4 | [AccessibilityExtensionAbility](js-apis-application-AccessibilityExtensionAbility.md): provides accessibility for access to and operations on the UI.|
| DATA_SHARE | 5 | [DataShareExtensionAbility](../../database/database-datashare-guidelines.md): enables applications to read and write data.|
| FILE_SHARE | 6 | FileShareExtensionAbility: enables file sharing between applications. This ability is reserved.|
| STATIC_SUBSCRIBER| 7 | [StaticSubscriberExtensionAbility](js-apis-application-staticSubscriberExtensionAbility.md): provides APIs for processing static events, such as the startup event.|
| WALLPAPER | 8 | WallpaperExtensionAbility: provides APIs to implement the home screen wallpaper. This ability is reserved.|
| BACKUP | 9 | BackupExtensionAbility: provides APIs for backing up and restoring application data and public data. This ability is reserved.|
| WINDOW | 10 | [WindowExtensionAbility](js-apis-application-WindowExtensionAbility.md): allows system applications to display UIs of other applications.|
| ENTERPRISE_ADMIN | 11 | [EnterpriseAdminExtensionAbility](js-apis-EnterpriseAdminExtensionAbility.md): provides APIs for processing enterprise management events, such as application installation events on devices and events indicating too many incorrect screen-lock password attempts.|
| THUMBNAIL | 13 | ThumbnailExtensionAbility: provides thumbnails for files. This ability is reserved.|
| PREVIEW | 14 | PreviewExtensionAbility: provides APIs for file preview so that other applications can be embedded and displayed in the current application. This ability is reserved.|
| UNSPECIFIED | 255 | No type is specified. It is used together with **queryExtensionAbilityInfo** to query all types of Extension abilities.|
### PermissionGrantState
Enumerates the permission grant states.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name| Value| Description|
|:----------------:|:---:|:---:|
| PERMISSION_DENIED| -1 | Permission denied.|
| PERMISSION_GRANTED | 0 | Permission granted. |
### SupportWindowMode
Enumerates the window modes supported by the ability.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name| Value| Description|
|:----------------:|:---:|:---:|
| FULL_SCREEN | 0 | A window in full-screen mode is supported.|
| SPLIT | 1 | A window in split-screen mode is supported.|
| FLOATING | 2 | A floating window is supported. |
### LaunchType
Enumerates the launch types of the ability.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name| Value| Description|
|:----------------:|:---:|:---:|
| SINGLETON | 0 | The ability can have only one instance.|
| STANDARD | 1 | The ability can have multiple instances.|
| SPECIFIED | 2 | The ability can have one or multiple instances, depending on the internal service of the ability.|
### AbilityType
Enumerates the types of abilities.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name | Value | Description |
| :-----: | ---- | :--------------------------------------------------------: |
| PAGE | 1 | FA developed using the Page template to provide the capability of interacting with users. |
| SERVICE | 2 | PA developed using the Service template to provide the capability of running tasks in the background. |
| DATA | 3 | PA developed using the Data template to provide unified data access for external systems.|
### DisplayOrientation
Enumerates the display orientations of the ability. This attribute applies only to the ability using the Page template.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
| Name |Value|Description|
|:----------------------------------|---|---|
| UNSPECIFIED |0 |Unspecified. The orientation is determined by the system.|
| LANDSCAPE |1 |Landscape.|
| PORTRAIT |2 |Portrait.|
| FOLLOW_RECENT |3 |The last display orientation is used.|
| LANDSCAPE_INVERTED |4 |Reverse landscape.|
| PORTRAIT_INVERTED |5 |Reverse portrait.|
| AUTO_ROTATION |6 |Auto rotation.|
| AUTO_ROTATION_LANDSCAPE |7 |Auto rotation in the horizontal direction.|
| AUTO_ROTATION_PORTRAIT |8 |Auto rotation in the vertical direction.|
| AUTO_ROTATION_RESTRICTED |9 |Switched-determined auto rotation.|
| AUTO_ROTATION_LANDSCAPE_RESTRICTED |10|Switched-determined auto rotation in the horizontal direction.|
| AUTO_ROTATION_PORTRAIT_RESTRICTED |11|Switched-determined auto rotation in the vertical direction.|
| LOCKED |12|Locked.|
## Methods
### bundleManager.getBundleInfoForSelf
getBundleInfoForSelf(bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;
Obtains the bundle information of this bundle based on the given bundle flags. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | --------------------- |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
**Return value**
| Type | Description |
| ----------------------------------------------------------- | ------------------------------------- |
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information.|
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => {
console.info('getBundleInfoForSelf successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getBundleInfoForSelf failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInfoForSelf failed:' + error.message);
}
```
### bundleManager.getBundleInfoForSelf
getBundleInfoForSelf(bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void;
Obtains the bundle information of this bundle based on the given bundle flags. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | --------------------- |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle information obtained. Otherwise, **err** is an error object.|
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => {
if (err) {
console.error('getBundleInfoForSelf failed:' + err.message);
} else {
console.info('getBundleInfoForSelf successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleInfoForSelf failed:' + err.message);
}
```
### bundleManager.getBundleInfo
getBundleInfo(bundleName: string, bundleFlags: number, userId: number, callback: AsyncCallback\<BundleInfo>): void;
Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name. |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
// Obtain the bundle information with the ability information.
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_ABILITY;
let userId = 100;
try {
bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
if (err) {
console.error('getBundleInfo failed:' + err.message);
} else {
console.info('getBundleInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleInfo failed:' + err.message);
}
```
```ts
// Obtain the bundle information with the metadata in the application information.
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA;
let userId = 100;
try {
bundleManager.getBundleInfo(bundleName, bundleFlags, userId, (err, data) => {
if (err) {
console.error('getBundleInfo failed:' + err.message);
} else {
console.info('getBundleInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleInfo failed:' + err.message);
}
```
### bundleManager.getBundleInfo
getBundleInfo(bundleName: string, bundleFlags: number, callback: AsyncCallback\<BundleInfo>): void;
Obtains the bundle information based on the given bundle name and bundle flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name. |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
// Obtain the bundle information with the Extension ability information.
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_HAP_MODULE | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY;
try {
bundleManager.getBundleInfo(bundleName, bundleFlags, (err, data) => {
if (err) {
console.error('getBundleInfo failed:' + err.message);
} else {
console.info('getBundleInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleInfo failed:' + err.message);
}
```
### bundleManager.getBundleInfo
getBundleInfo(bundleName: string, bundleFlags: [number](#bundleflag), userId?: number): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;
Obtains the bundle information based on the given bundle name, bundle flags, and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name.|
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| ----------------------------------------------------------- | --------------------------- |
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
// Obtain the bundle information with the application and signature information.
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
let userId = 100;
try {
bundleManager.getBundleInfo(bundleName, bundleFlags, userId).then((data) => {
console.info('getBundleInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getBundleInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInfo failed. Cause: ' + error.message);
}
```
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleInfo(bundleName, bundleFlags).then((data) => {
console.info('getBundleInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getBundleInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInfo failed. Cause: ' + error.message);
}
```
### bundleManager.getApplicationInfo
getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void;
Obtains the application information based on the given bundle name, application flags, and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name.|
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the application information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;
try {
bundleManager.getApplicationInfo(bundleName, appFlags, userId, (err, data) => {
if (err) {
console.error('getApplicationInfo failed:' + err.message);
} else {
console.info('getApplicationInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getApplicationInfo failed:' + err.message);
}
```
### bundleManager.getApplicationInfo
getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), callback: AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>): void;
Obtains the application information based on the given bundle name and application flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name.|
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| callback | AsyncCallback\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the application information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
try {
bundleManager.getApplicationInfo(bundleName, appFlags, (err, data) => {
if (err) {
console.error('getApplicationInfo failed:' + err.message);
} else {
console.info('getApplicationInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getApplicationInfo failed:' + err.message);
}
```
### bundleManager.getApplicationInfo
getApplicationInfo(bundleName: string, appFlags: [number](#applicationflag), userId?: number): Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>;
Obtains the application information based on the given bundle name, application flags, and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name.|
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | No | User ID.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | -------------------------------- |
| Promise\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)> | Promise used to return the application information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_WITH_PERMISSION;
let userId = 100;
try {
bundleManager.getApplicationInfo(bundleName, appFlags, userId).then((data) => {
console.info('getApplicationInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getApplicationInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getApplicationInfo failed. Cause: ' + error.message);
}
```
### bundleManager.getAllBundleInfo
getAllBundleInfo(bundleFlags: [number](#bundleflag), userId: number, callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void;
Obtains an array of bundle information based on the given bundle flags and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------------------------------- |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of bundle information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;
try {
bundleManager.getAllBundleInfo(bundleFlags, userId, (err, data) => {
if (err) {
console.error('getAllBundleInfo failed:' + err.message);
} else {
console.info('getAllBundleInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAllBundleInfo failed:' + err.message);
}
```
### bundleManager.getAllBundleInfo
getAllBundleInfo(bundleFlags: [number](#bundleflag), callback: AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>): void;
Obtains an array of bundle information based on the given bundle flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------------------------------- |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
| callback | AsyncCallback<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of bundle information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getAllBundleInfo(bundleFlags, (err, data) => {
if (err) {
console.error('getAllBundleInfo failed:' + err.message);
} else {
console.info('getAllBundleInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAllBundleInfo failed:' + err.message);
}
```
### bundleManager.getAllBundleInfo
getAllBundleInfo(bundleFlags: [number](#bundleflag), userId?: number): Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>>;
Obtains an array of bundle information based on the given bundle flags and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------------------------------- |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ----------------------------------- |
| Promise<Array\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>> | Promise used to return the array of bundle information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getAllBundleInfo(bundleFlags).then((data) => {
console.info('getAllBundleInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getAllBundleInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getAllBundleInfo failed. Cause: ' + error.message);
}
```
### bundleManager.getAllApplicationInfo
getAllApplicationInfo(appFlags: [number](#applicationflag), userId: number, callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void;
Obtains an array of application information based on the given application flags and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ----------------------------------------------------------- |
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of application information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;
try {
bundleManager.getAllApplicationInfo(appFlags, userId, (err, data) => {
if (err) {
console.error('getAllApplicationInfo failed:' + err.message);
} else {
console.info('getAllApplicationInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAllApplicationInfo failed:' + err.message);
}
```
### bundleManager.getAllApplicationInfo
getAllApplicationInfo(appFlags: [number](#applicationflag), callback: AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>): void;
Obtains an array of application information based on the given application flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ----------------------------------------------------------- |
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| callback | AsyncCallback<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of application information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
try {
bundleManager.getAllApplicationInfo(appFlags, (err, data) => {
if (err) {
console.error('getAllApplicationInfo failed:' + err.message);
} else {
console.info('getAllApplicationInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAllApplicationInfo failed:' + err.message);
}
```
### bundleManager.getAllApplicationInfo
getAllApplicationInfo(appFlags: [number](#applicationflag), userId?: number): Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>>;
Obtains an array of application information based on the given application flags and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------------------------------------------- |
| appFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ---------------------------------------- |
| Promise<Array\<[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)>> | Promise used to return the array of application information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let appFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
try {
bundleManager.getAllApplicationInfo(appFlags).then((data) => {
console.info('getAllApplicationInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getAllApplicationInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getAllApplicationInfo failed. Cause: ' + error.message);
}
```
### bundleManager.queryAbilityInfo
queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId: number, callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void;
Obtains an array of ability information based on the given want, ability flags, and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | ------------------------------------------------------- |
| want | Want | Yes | Want containing the bundle name to query. |
| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of ability information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId, (err, data) => {
if (err) {
console.error('queryAbilityInfo failed:' + err.message);
} else {
console.info('queryAbilityInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('queryAbilityInfo failed:' + err.message);
}
```
### bundleManager.queryAbilityInfo
queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), callback: AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>): void;
Obtains an array of ability information based on the given want and ability flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | -------------------------------------------------------|
| want | Want | Yes | Want containing the bundle name to query. |
| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain. |
| callback | AsyncCallback<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of ability information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified ability is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryAbilityInfo(want, abilityFlags, (err, data) => {
if (err) {
console.error('queryAbilityInfo failed:' + err.message);
} else {
console.info('queryAbilityInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('queryAbilityInfo failed:' + err.message);
}
```
### bundleManager.queryAbilityInfo
queryAbilityInfo(want: Want, abilityFlags: [number](#abilityflag), userId?: number): Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>>;
Obtains the ability information based on the given want, ability flags, and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | ------------------------------------------------------- |
| want | Want | Yes | Want containing the bundle name to query. |
| abilityFlags | [number](#abilityflag) | Yes | Type of the ability information to obtain.|
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------ |
| Promise<Array\<[AbilityInfo](js-apis-bundleManager-abilityInfo.md)>> | Promise used to return the array of ability information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified extensionAbility is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((data) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryAbilityInfo(want, abilityFlags).then((data) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
})
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.queryExtensionAbilityInfo
queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId: number, callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void;
Obtains the Extension ability information based on the given want, Extension ability type, Extension ability flags, and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | Want | Yes | Want containing the bundle name to query. |
| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the Extension ability. |
| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the Extension ability information to obtain. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of Extension ability information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified extensionAbility is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId, (err, data) => {
if (err) {
console.error('queryExtensionAbilityInfo failed:' + err.message);
} else {
console.info('queryExtensionAbilityInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('queryExtensionAbilityInfo failed:' + err.message);
}
```
### bundleManager.queryExtensionAbilityInfo
queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), callback: AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>): void;
Obtains the Extension ability information based on the given want, Extension ability type, and Extension ability flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| want | Want | Yes | Want containing the bundle name to query. |
| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the Extension ability. |
| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the Extension ability information to obtain. |
| callback | AsyncCallback<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of Extension ability information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified extensionAbility is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, (err, data) => {
if (err) {
console.error('queryExtensionAbilityInfo failed:' + err.message);
} else {
console.info('queryExtensionAbilityInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('queryExtensionAbilityInfo failed:' + err.message);
}
```
### bundleManager.queryExtensionAbilityInfo
queryExtensionAbilityInfo(want: Want, extensionAbilityType: [ExtensionAbilityType](#extensionabilitytype), extensionAbilityFlags: [number](#extensionabilityflag), userId?: number): Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>>;
Obtains the Extension ability information based on the given want, Extension ability type, Extension ability flags, and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------------------- | --------------------------------------------- | ---- | ------------------------------------------------------- |
| want | Want | Yes | Want containing the bundle name to query. |
| extensionAbilityType | [ExtensionAbilityType](#extensionabilitytype) | Yes | Type of the Extension ability. |
| extensionAbilityFlags | [number](#extensionabilityflag) | Yes | Type of the Extension ability information to obtain.|
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| ------------------------------------------------------------ | --------------------------------------------- |
| Promise<Array\<[ExtensionAbilityInfo](js-apis-bundleManager-extensionAbilityInfo.md)>> | Promise used to return the array of Extension ability information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified extensionAbility is not found. |
| 17700004 | The specified userId is invalid. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags, userId).then((data) => {
console.info('queryExtensionAbilityInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message);
}
```
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let extensionAbilityType = bundleManager.ExtensionAbilityType.FORM;
let extensionFlags = bundleManager.ExtensionAbilityFlag.GET_EXTENSION_ABILITY_INFO_DEFAULT;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
try {
bundleManager.queryExtensionAbilityInfo(want, extensionAbilityType, extensionFlags).then((data) => {
console.info('queryExtensionAbilityInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message);
})
} catch (error) {
console.error('queryExtensionAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.getBundleNameByUid
getBundleNameByUid(uid: number, callback: AsyncCallback\<string>): void;
Obtains the bundle name based on the given UID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| uid | number | Yes | UID of the application. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle name obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------- |
| 17700021 | The uid is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let uid = 20010005;
try {
bundleManager.getBundleNameByUid(uid, (err, data) => {
if (err) {
console.error('getBundleNameByUid failed:' + err.message);
} else {
console.info('getBundleNameByUid successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleNameByUid failed:' + err.message);
}
```
### bundleManager.getBundleNameByUid
getBundleNameByUid(uid: number): Promise\<string>;
Obtains the bundle name based on the given UID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------------ |
| uid | number | Yes | UID of the application.|
**Return value**
| Type | Description |
| ---------------- | --------------------------- |
| Promise\<string> | Promise used to return the bundle name obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------|
| 17700021 | The uid is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let uid = 20010005;
try {
bundleManager.getBundleNameByUid(uid).then((data) => {
console.info('getBundleNameByUid successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getBundleNameByUid failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleNameByUid failed. Cause: ' + error.message);
}
```
### bundleManager.getBundleArchiveInfo
getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag), callback: AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>): void;
Obtains the bundle information based on the given HAP file path and bundle flags. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------------------------------------------- |
| hapFilePath | string | Yes | Path where the HAP file is stored. The path must be the relative path of the current bundle's data directory.|
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Yes| Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the bundle information obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------- |
| 17700022 | The hapFilePath is invalid. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags, (err, data) => {
if (err) {
console.error('getBundleArchiveInfo failed:' + err.message);
} else {
console.info('getBundleArchiveInfo successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getBundleArchiveInfo failed:' + err.message);
}
```
### bundleManager.getBundleArchiveInfo
getBundleArchiveInfo(hapFilePath: string, bundleFlags: [number](#bundleflag)): Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)>;
Obtains the bundle information based on the given HAP file path and bundle flags. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------------------------------------------ |
| hapFilePath | string | Yes | Path where the HAP file is stored. The path must be the relative path of the current bundle's data directory.|
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain. |
**Return value**
| Type | Description |
| ----------------------------------------------------------- | --------------------------- |
| Promise\<[BundleInfo](js-apis-bundleManager-bundleInfo.md)> | Promise used to return the bundle information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------- |
| 17700022 | The hapFilePath is invalid. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let hapFilePath = "/data/xxx/test.hap";
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT;
try {
bundleManager.getBundleArchiveInfo(hapFilePath, bundleFlags).then((data) => {
console.info('getBundleArchiveInfo successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getBundleArchiveInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleArchiveInfo failed. Cause: ' + error.message);
}
```
### bundleManager.cleanBundleCacheFiles
cleanBundleCacheFiles(bundleName: string, callback: AsyncCallback\<void>): void;
Clears cache files of a bundle. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.REMOVE_CACHE_FILES
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700001 | The specified bundleName is not found. |
| 17700030 | The specified bundle does not support clearing of cache files. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = "com.ohos.myapplication";
try {
bundleManager.cleanBundleCacheFiles(bundleName, err => {
if (err) {
console.error('cleanBundleCacheFiles failed:' + err.message);
} else {
console.info('cleanBundleCacheFiles successfully.');
}
});
} catch (err) {
console.error('cleanBundleCacheFiles failed:' + err.message);
}
```
### bundleManager.cleanBundleCacheFiles
cleanBundleCacheFiles(bundleName: string): Promise\<void>;
Clears cache files of a bundle. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.REMOVE_CACHE_FILES
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------------------------ |
| bundleName | string | Yes | Bundle name.|
**Return value**
| Type | Description |
| -------------- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result. If the operation is successful, no value is returned. Otherwise, an error message is returned.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700030 | The specified bundle does not support cleaning cache files. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = "com.ohos.myapplication";
try {
bundleManager.cleanBundleCacheFiles(bundleName).then(()=> {
console.info('cleanBundleCacheFiles successfully.');
}).catch(err=> {
console.error('cleanBundleCacheFiles failed:' + err.message);
});
} catch (err) {
console.error('cleanBundleCacheFiles failed:' + err.message);
}
```
### bundleManager.setApplicationEnabled
setApplicationEnabled(bundleName: string, isEnabled: boolean, callback: AsyncCallback\<void>): void;
Enables or disables an application. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------- | ---- | ------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| isEnabled | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means to disable the application.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = "com.ohos.myapplication";
try {
bundleManager.setApplicationEnabled(bundleName, false, err => {
if (err) {
console.error('setApplicationEnabled failed:' + err.message);
} else {
console.info('setApplicationEnabled successfully.');
}
});
} catch (err) {
console.error('setApplicationEnabled failed:' + err.message);
}
```
### bundleManager.setApplicationEnabled
setApplicationEnabled(bundleName: string, isEnabled: boolean): Promise\<void>;
Enables or disables an application. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------- | ---- | ------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| isEnabled | boolean | Yes | Whether to enable the application. The value **true** means to enable the application, and **false** means to disable the application.|
**Return value**
| Type | Description |
| -------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = "com.ohos.myapplication";
try {
bundleManager.setApplicationEnabled(bundleName, false).then(()=> {
console.info('setApplicationEnabled successfully.');
}).catch(err=> {
console.error('setApplicationEnabled failed:' + err.message);
});
} catch (err) {
console.error('setApplicationEnabled failed:' + err.message);
}
```
### bundleManager.setAbilityEnabled
setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean, callback: AsyncCallback\<void>): void;
Enables or disables an ability. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------- | ---- | ------------------------------------- |
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. |
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified abilityInfo is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
var info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false, err => {
if (err) {
console.error('setAbilityEnabled failed:' + err.message);
} else {
console.info('setAbilityEnabled successfully.');
}
});
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.setAbilityEnabled
setAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), isEnabled: boolean): Promise\<void>;
Enables or disables an ability. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CHANGE_ABILITY_ENABLED_STATE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------- | ---- | ------------------------------------- |
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability. |
| isEnabled| boolean | Yes | Whether to enable the ability. The value **true** means to enable the ability, and **false** means to disable the ability.|
**Return value**
| Type | Description |
| -------------- | --------------------------------- |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified abilityInfo is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
var info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
bundleManager.setAbilityEnabled(info, false).then(()=> {
console.info('setAbilityEnabled successfully.');
}).catch(err=> {
console.error('setAbilityEnabled failed:' + err.message);
});
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.isApplicationEnabled
isApplicationEnabled(bundleName: string, callback: AsyncCallback\<boolean>): void;
Checks whether an application is enabled. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------------------- |
| bundleName | string | Yes | Bundle name.|
| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. The value **true** means that the application is enabled, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
try {
bundleManager.isApplicationEnabled(bundleName, (err, data) => {
if (err) {
console.error('isApplicationEnabled failed:' + err.message);
} else {
console.info('isApplicationEnabled successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('isApplicationEnabled failed:' + err.message);
}
```
### bundleManager.isApplicationEnabled
isApplicationEnabled(bundleName: string): Promise\<boolean>;
Checks whether an application is enabled. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------------------- |
| bundleName | string | Yes | Bundle name. |
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the application is enabled, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
try {
bundleManager.isApplicationEnabled(bundleName).then((data) => {
console.info('isApplicationEnabled successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('isApplicationEnabled failed. Cause: ' + error.message);
});
} catch (error) {
console.error('isApplicationEnabled failed. Cause: ' + error.message);
}
```
### bundleManager.isAbilityEnabled
isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md), callback: AsyncCallback\<boolean>): void;
Checks whether an ability is enabled. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ----------- | ---- | --------------------------- |
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability.|
| callback | AsyncCallback\<boolean> | Yes| Callback used to return the result. The value **true** means that the ability is enabled, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified abilityName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
var info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info, (err, data) => {
if (err) {
console.error('isAbilityEnabled failed:' + err.message);
} else {
console.info('isAbilityEnabled successfully:' + JSON.stringify(data));
}
});
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.isAbilityEnabled
isAbilityEnabled(info: [AbilityInfo](js-apis-bundleManager-abilityInfo.md)): Promise\<boolean>;
Checks whether an ability is enabled. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ---- | ----------- | ---- | --------------------------- |
| info | [AbilityInfo](js-apis-bundleManager-abilityInfo.md) | Yes | Information about the target ability.|
**Return value**
| Type | Description |
| ----------------- | ------------------------------------------------------------ |
| Promise\<boolean> | Promise used to return the result. The value **true** means that the ability is enabled, and **false** means the opposite.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700003 | The specified abilityName is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let abilityFlags = bundleManager.AbilityFlag.GET_ABILITY_INFO_DEFAULT;
let userId = 100;
let want = {
bundleName : "com.example.myapplication",
abilityName : "com.example.myapplication.MainAbility"
};
var info;
try {
bundleManager.queryAbilityInfo(want, abilityFlags, userId).then((abilitiesInfo) => {
console.info('queryAbilityInfo successfully. Data: ' + JSON.stringify(abilitiesInfo));
info = abilitiesInfo[0];
bundleManager.isAbilityEnabled(info).then((data) => {
console.info('isAbilityEnabled successfully. Data: ' + JSON.stringify(data));
}).catch(err => {
console.error('isAbilityEnabled failed. Cause: ' + err.message);
});
}).catch(error => {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
});
} catch (error) {
console.error('queryAbilityInfo failed. Cause: ' + error.message);
}
```
### bundleManager.getLaunchWantForBundle
getLaunchWantForBundle(bundleName: string, userId: number, callback: AsyncCallback\<Want>): void;
Obtains the want used to launch the bundle based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **Want** object obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let userId = 100;
try {
bundleManager.getLaunchWantForBundle(bundleName, userId, (err, data) => {
if (err) {
console.error('getLaunchWantForBundle failed:' + err.message);
} else {
console.info('getLaunchWantForBundle successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getLaunchWantForBundle failed:' + err.message);
}
```
### bundleManager.getLaunchWantForBundle
getLaunchWantForBundle(bundleName: string, callback: AsyncCallback\<Want>): void;
Obtains the want used to launch the bundle based on the given bundle name. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | -------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| callback | AsyncCallback\<Want> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **Want** object obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
try {
bundleManager.getLaunchWantForBundle(bundleName, (err, data) => {
if (err) {
console.error('getLaunchWantForBundle failed:' + err.message);
} else {
console.info('getLaunchWantForBundle successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getLaunchWantForBundle failed:' + err.message);
}
```
### bundleManager.getLaunchWantForBundle
getLaunchWantForBundle(bundleName: string, userId?: number): Promise\<Want>;
Obtains the want used to launch the bundle based on the given bundle name and user ID. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------- |
| bundleName | string | Yes | Bundle name.|
| userId | number | No | User ID. |
**Return value**
| Type | Description |
| -------------- | ------------------------- |
| Promise\<Want> | Promise used to return the **Want** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------|
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let userId = 100;
try {
bundleManager.getLaunchWantForBundle(bundleName, userId).then((data) => {
console.info('getLaunchWantForBundle successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getLaunchWantForBundle failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getLaunchWantForBundle failed. Cause: ' + error.message);
}
```
### bundleManager.getProfileByAbility
getProfileByAbility(moduleName: string, abilityName: string, metadataName: string, callback: AsyncCallback<Array\<string>>): void;
Obtains the JSON strings of the configuration file based on the given module ame, ability name, and metadata name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name. |
| metadataName | string | Yes | Metadata name. |
| callback | AsyncCallback<Array\<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of JSON strings obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700002 | The specified moduleName is not existed. |
| 17700003 | The specified abilityName is not existed. |
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'com.example.myapplication.metadata';
try {
bundleManager.getProfileByAbility(moduleName, abilityName, metadataName, (err, data) => {
if (err) {
console.error('getProfileByAbility failed:' + err.message);
} else {
console.info('getProfileByAbility successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getProfileByAbility failed:' + err.message);
}
```
### bundleManager.getProfileByAbility
getProfileByAbility(moduleName: string, abilityName: string, metadataName?: string): Promise<Array\<string>>;
Obtains the JSON strings of the configuration file based on the given module ame, ability name, and metadata name. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | -------------------------- |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name. |
| metadataName | string | No | Metadata name.|
**Return value**
| Type | Description |
| ----------------------- | ------------------------------- |
| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700002 | The specified moduleName is not existed. |
| 17700003 | The specified abilityName is not existed. |
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let moduleName = 'entry';
let abilityName = 'MainAbility';
try {
bundleManager.getProfileByAbility(moduleName, abilityName).then((data) => {
console.info('getProfileByAbility successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getProfileByAbility failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getProfileByAbility failed. Cause: ' + error.message);
}
```
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let moduleName = 'entry';
let abilityName = 'MainAbility';
let metadataName = 'com.example.myapplication.metadata';
try {
bundleManager.getProfileByAbility(moduleName, abilityName, metadataName).then((data) => {
console.info('getProfileByAbility successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getProfileByAbility failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getProfileByAbility failed. Cause: ' + error.message);
}
```
### bundleManager.getProfileByExtensionAbility
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName: string, callback: AsyncCallback<Array\<string>>): void;
Obtains the JSON strings of the configuration file based on the given module ame, Extension ability name, and metadata name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ----------------------------- | ---- | ------------------------------------------------------------ |
| moduleName | string | Yes | Module name. |
| extensionAbilityName | string | Yes | Extension ability name. |
| metadataName | string | Yes | Metadata name. |
| callback | AsyncCallback<Array\<string>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of JSON strings obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700002 | The specified moduleName is not existed. |
| 17700003 | The specified extensionAbilityName is not existed. |
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';
try {
bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName, (err, data) => {
if (err) {
console.error('getProfileByExtensionAbility failed:' + err.message);
} else {
console.info('getProfileByExtensionAbility successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getProfileByExtensionAbility failed:' + err.message);
}
```
### bundleManager.getProfileByExtensionAbility
getProfileByExtensionAbility(moduleName: string, extensionAbilityName: string, metadataName?: string): Promise<Array\<string>>;
Obtains the JSON strings of the configuration file based on the given module ame, Extension ability name, and metadata name. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------------------- | ------ | ---- | ---------------------------------- |
| moduleName | string | Yes | Module name. |
| extensionAbilityName | string | Yes | Extension ability name.|
| metadataName | string | No | Metadata name. |
**Return value**
| Type | Description |
| ----------------------- | ----------------------------------- |
| Promise<Array\<string>> | Promise used to return the array of JSON strings obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700002 | The specified moduleName is not existed. |
| 17700003 | The specified extensionAbilityName is not existed. |
| 17700024 | Failed to get the profile because there is no profile in the HAP. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let moduleName = 'entry';
let extensionAbilityName = 'com.example.myapplication.extension';
let metadataName = 'com.example.myapplication.metadata';
try {
bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName).then((data) => {
console.info('getProfileByExtensionAbility successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getProfileByExtensionAbility failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getProfileByExtensionAbility failed. Cause: ' + error.message);
}
try {
bundleManager.getProfileByExtensionAbility(moduleName, extensionAbilityName, metadataName).then((data) => {
console.info('getProfileByExtensionAbility successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getProfileByExtensionAbility failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getProfileByExtensionAbility failed. Cause: ' + error.message);
}
```
### bundleManager.getPermissionDef
getPermissionDef(permissionName: string, callback: AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>): void;
Obtains the details of a permission. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| permissionName | string | Yes | Name of the permission. |
| callback | AsyncCallback\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of **PermissionDef** objects obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700006 | The specified permission is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let permission = "ohos.permission.GET_BUNDLE_INFO";
try {
bundleManager.getPermissionDef(permission, (err, data) => {
if (err) {
console.error('getPermissionDef failed:' + err.message);
} else {
console.info('getPermissionDef successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getPermissionDef failed:' + err.message);
}
```
### bundleManager.getPermissionDef
getPermissionDef(permissionName: string): Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)>;
Obtains the details of a permission. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------ | ---- | -------------- |
| permissionName | string | Yes | Name of the permission.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------ |
| Promise\<[PermissionDef](js-apis-bundleManager-permissionDef.md)> | Promise used to return the array of **PermissionDef** objects obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700006 | The specified permission is not found. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let permissionName = "ohos.permission.GET_BUNDLE_INFO";
try {
bundleManager.getPermissionDef(permissionName).then((data) => {
console.info('getPermissionDef successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getPermissionDef failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getPermissionDef failed. Cause: ' + error.message);
}
```
### bundleManager.getAbilityLabel
getAbilityLabel(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback\<string>): void;
Obtains the ability label based on the given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Resource
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name. |
| callback | AsyncCallback\<string> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the label obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';
try {
bundleManager.getAbilityLabel(bundleName, moduleName, abilityName, (err, data) => {
if (err) {
console.error('getAbilityLabel failed:' + err.message);
} else {
console.info('getAbilityLabel successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAbilityLabel failed:' + err.message);
}
```
### bundleManager.getAbilityLabel
getAbilityLabel(bundleName: string, moduleName: string, abilityName: string): Promise\<string>;
Obtains the ability label based on the given bundle name, module name, and ability name. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Resource
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------- |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name.|
**Return value**
| Type | Description |
| ---------------- | ----------------------------------- |
| Promise\<string> | Promise used to return the label.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | --------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';
try {
bundleManager.getAbilityLabel(bundleName, moduleName, abilityName).then((data) => {
console.info('getAbilityLabel successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getAbilityLabel failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getAbilityLabel failed. Cause: ' + error.message);
}
```
### bundleManager.getAbilityIcon
getAbilityIcon(bundleName: string, moduleName: string, abilityName: string, callback: AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)>): void;
Obtains the ability icon based on the given bundle name, module name, and ability name. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Resource
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name. |
| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **PixelMap** object of the icon. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';
try {
bundleManager.getAbilityIcon(bundleName, moduleName, abilityName, (err, data) => {
if (err) {
console.error('getAbilityIcon failed:' + err.message);
} else {
console.info('getAbilityIcon successfully:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('getAbilityIcon failed:' + err.message);
}
```
### bundleManager.getAbilityIcon
getAbilityIcon(bundleName: string, moduleName: string, abilityName: string): Promise<[image.PixelMap](js-apis-image.md#pixelmap7)>;
Obtains the ability icon based on the given bundle name, module name, and ability name. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Resource
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ------------------------- |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| abilityName | string | Yes | Ability name.|
**Return value**
| Type | Description |
| ----------------------------------------------------- | ------------------------------------------- |
| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the **PixelMap** object of the icon.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700002 | The specified moduleName is not found. |
| 17700003 | The specified abilityName is not found. |
| 17700026 | The specified bundle is disabled. |
| 17700029 | The specified ability is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let abilityName = 'MainAbility';
try {
bundleManager.getAbilityIcon(bundleName, moduleName, abilityName).then((data) => {
console.info('getAbilityIcon successfully. Data: ' + JSON.stringify(data));
}).catch(error => {
console.error('getAbilityIcon failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getAbilityIcon failed. Cause: ' + error.message);
}
```
### bundleManager.getApplicationInfoSync
getApplicationInfoSync(bundleName: string, applicationFlags: number, userId: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
Synchronously obtains the application information based on the given bundle name, application flags, and user ID.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------------------------------------------|
| bundleName | string | Yes | Bundle name. |
| applicationFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
| userId | number | Yes | User ID. |
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Application information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified userId is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
let userId = 100;
try {
let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags, userId);
console.info("getApplicationInfoSync successfully:" + JSON.stringify(data));
} catch (err) {
console.error('getApplicationInfoSync failed:' + err.message);
}
```
### bundleManager.getApplicationInfoSync
getApplicationInfoSync(bundleName: string, applicationFlags: number) : [ApplicationInfo](js-apis-bundleManager-applicationInfo.md);
Synchronously obtains the application information based on the given bundle name and application flags.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ----------------------------------------------------------|
| bundleName | string | Yes | Bundle name. |
| applicationFlags | [number](#applicationflag) | Yes | Type of the application information to obtain. |
**Return value**
| Type | Description |
| --------------- | ------------------------- |
| [ApplicationInfo](js-apis-bundleManager-applicationInfo.md) | Application information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | -------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let applicationFlags = bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT;
try {
let data = bundleManager.getApplicationInfoSync(bundleName, applicationFlags);
console.info("getApplicationInfoSync successfully:" + JSON.stringify(data));
} catch (err) {
console.error('getApplicationInfoSync failed:' + err.message);
}
```
### bundleManager.getBundleInfoSync
getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag), userId: number): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
Synchronously obtains the bundle information based on the given bundle name, bundle flags, and user ID.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
| userId | number | Yes | User ID. |
**Return value**
| Type | Description |
| ---------- | -------------------- |
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
let userId = 100;
try {
let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags, userId);
console.info("getBundleInfoSync successfully :" + JSON.stringify(data));
} catch (err) {
console.error('getBundleInfoSync failed:' + err.message);
}
```
### bundleManager.getBundleInfoSync
getBundleInfoSync(bundleName: string, bundleFlags: [number](#bundleflag)): [BundleInfo](js-apis-bundleManager-bundleInfo.md);
Synchronously obtains the bundle information based on the given bundle name and bundle flags.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED or ohos.permission.GET_BUNDLE_INFO
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------------------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| bundleFlags | [number](#bundleflag) | Yes | Type of the bundle information to obtain.|
**Return value**
| Type | Description |
| ---------- | -------------------- |
| [BundleInfo](js-apis-bundleManager-bundleInfo.md) | Bundle information obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------- |
| 17700001 | The specified bundleName is not found. |
| 17700004 | The specified user ID is not found. |
| 17700026 | The specified bundle is disabled. |
**Example**
```ts
import bundleManager from '@ohos.bundle.bundleManager'
let bundleName = 'com.example.myapplication';
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
try {
let data = bundleManager.getBundleInfoSync(bundleName, bundleFlags);
console.info("getBundleInfoSync successfully :" + JSON.stringify(data));
} catch (err) {
console.error('getBundleInfoSync failed:' + err.message);
}
```
# Bundle.bundleMonitor
The **Bundle.bundleMonitor** module provides APIs for listens for bundle installation, uninstall, and updates.
> **NOTE**
>
> 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.
## Modules to Import
```ts
import bundleMonitor from '@ohos.bundle.bundleMonitor';
```
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------------ | ----------- | ------------------------------ |
| ohos.permission.LISTEN_BUNDLE_CHANGE | system_core | Permission to listen for bundle installation, uninstall, and updates.|
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## BundleChangeInfo
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Template | Readable| Writable| Description |
| ---------- | ------ | ---- | ---- | -------------------------- |
| bundleName | string | Yes | No | Name of the bundle whose status changes.|
| userId | number | Yes | No | ID of the user whose bundle status changes. |
## bundleMonitor.on
on(type: BundleChangedEvent, callback: Callback\<BundleChangedInfo>): void;
Subscribes to bundle installation, uninstall, and update events.
**Required permissions**: ohos.permission.LISTEN_BUNDLE_CHANGE
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------------------------- | -------- | ---- | ------------------ |
| BundleChangedEvent | string | Yes | Type of the event to subscribe to.|
| Callback\<BundleChangedInfo> | callback | Yes | Callback used for the subscription.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```ts
import bundleMonitor from '@ohos.bundle.bundleMonitor';
try {
bundleMonitor.on('add', (bundleChangeInfo) => {
console.info(`bundleName : ${bundleChangeInfo.bundleName} userId : ${bundleChangeInfo.userId}`);
})
} catch (errData) {
console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
}
```
## bundleMonitor.off
off(type: BundleChangedEvent, callback?: Callback\<BundleChangedInfo>): void;
Unsubscribes from bundle installation, uninstall, and update events.
**Required permissions**: ohos.permission.LISTEN_BUNDLE_CHANGE
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------------------------- | -------- | ---- | ---------------------------------------------------------- |
| BundleChangedEvent | string | Yes | Type of the event to unsubscribe from. |
| Callback\<BundleChangedInfo> | callback | Yes | Callback used for the unsubscription. If this parameter is left empty, all callbacks of the current event are unsubscribed from.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```ts
import bundleMonitor from '@ohos.bundle.bundleMonitor';
try {
bundleMonitor.off('add');
} catch (errData) {
console.log(`errData is errCode:${errData.errCode} message:${errData.message}`);
}
```
# Certificate
The **certificate** module provides APIs for performing certificate operations. The APIs of this module depend on the basic algorithm capabilities provided by the cryptography framework. For details about the cryptography framework APIs, see [Cryptography Framework](./js-apis-cryptoFramework.md).
> **NOTE**
>
> The initial APIs of this module are supported since API version 9.
## Modules to Import
```javascript
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
```
## CertResult
Enumerates the error codes.
**System capability**: SystemCapability.Security.Cert
| Name | Default Value | Description |
| --------------------------------------| -------- | -----------------------------|
| INVALID_PARAMS | 401 | Invalid parameters. |
| NOT_SUPPORT | 801 | This operation is not supported. |
| ERR_OUT_OF_MEMORY | 19020001 | Memory error. |
| ERR_RUNTIME_ERROR | 19020002 | Runtime error. |
| ERR_CRYPTO_OPERATION | 19030001 | Crypto operation error. |
| ERR_CERT_SIGNATURE_FAILURE | 19030002 | The certificate signature verification failed. |
| ERR_CERT_NOT_YET_VALID | 19030003 | The certificate has not taken effect. |
| ERR_CERT_HAS_EXPIRED | 19030004 | The certificate has expired. |
| ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY | 19030005 | Failed to obtain the certificate issuer. |
| ERR_KEYUSAGE_NO_CERTSIGN | 19030006 | The key cannot be used for signing a certificate. |
| ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE | 19030007 | The key cannot be used for digital signature. |
## DataBlob
Defines a binary data array.
**System capability**: SystemCapability.Security.Cert
| Name | Type | Readable| Writable| Description |
| -------------- | -------------- | ---- | ---- | ----------------|
| data | Uint8Array | Yes | Yes | Data. |
## DataArray
Defines a list of data arrays.
**System capability**: SystemCapability.Security.Cert
| Name | Type | Readable| Writable| Description |
| -------------- | -------------- | ---- | ---- | ----------------|
| data | Uint8Array | Yes | Yes | Data list. |
## EncodingFormat
Enumerates the certificate encoding formats.
**System capability**: SystemCapability.Security.Cert
| Name | Default Value | Description |
| ------------| ---------| -----------|
| FORMAT_DER | 0 | Distinguished Encoding Rules (DER) format. |
| FORMAT_PEM | 1 | Privacy-Enhanced Mail (PEM) format. |
## EncodingBlob
Defines a certificate binary array in encoding format.
### Attributes
**System capability**: SystemCapability.Security.Cert
| Name | Type | Readable| Writable| Description |
| -------------- | -------------- | ---- | ---- | ----------------------------------|
| data | Uint8Array | Yes | Yes | Certificate data. |
| encodingFormat | [EncodingFormat](#encodingformat) | Yes | Yes | Certificate encoding format.|
## CertChainData
Defines the certificate chain data, which is passed in as input parameters during certificate chain verification.
### Attributes
**System capability**: SystemCapability.Security.Cert
| Name | Type | Readable| Writable| Description |
| -------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| data | Uint8Array | Yes | Yes | Certificate data, in the *length* (2 bytes) + *data* format. For example, **08ABCDEFGH07ABCDEFG**. The first two bytes indicate the length of the first certificate is eight bytes, and the following eight bytes indicate the certificate data. Then, the next two bytes indicates the length of another certificate is seven bytes, and the seven bytes followed indicate the certificate data. |
| count | number | Yes | Yes | Number of certificates contained in the input data. |
| encodingFormat | [EncodingFormat](#encodingformat) | Yes | Yes | Certificate encoding format.|
## cryptoCert.createX509Cert
createX509Cert(inStream : EncodingBlob, callback : AsyncCallback\<X509Cert>) : void
Creates an **X509Cert** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------ |
| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data.|
| callback | AsyncCallback\<X509Cert> | No | Callback invoked to return the **X509Cert** instance created. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
}
});
```
## cryptoCert.createX509Cert
createX509Cert(inStream : EncodingBlob) : Promise\<X509Cert>
Creates an **X509Cert** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------ | ---- | ------------------ |
| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data.|
**Return value**
| Type | Description |
| :------- | ---------------- |
| Promise\<X509Cert> |Promise used to return the **X509Cer** instance created.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
Console.log("createX509Cert success");
}, error => {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
## X509Cert
Provides APIs for X.509 certificate operations.
### verify
verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void
Verifies the certificate signature. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------ |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification.|
| callback | AsyncCallback\<void>) | No | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
// Generate a public key by AsyKeyGenerator or obtain the public key by using getPublicKey() of the X509Cert instance.
let pubKey = null;
x509Cert.verify(pubKey, function (error, data) {
if (error != null) {
Console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("verify success");
}
});
}
});
```
### verify
verify(key : cryptoFramework.PubKey) : Promise\<void>
Verifies the certificate signature. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification.|
**Return value**
| Type| Description |
| ---- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
Console.log("createX509Cert success");
// Generate a public key by AsyKeyGenerator or obtain the public key by using getPublicKey() of the X509Cert instance.
let pubKey = null;
x509Cert.verify(pubKey).then(result => {
Console.log("verify success");
}, error => {
Console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getEncoded
getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
Obtains the serialized X.509 certificate data. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | No | Callback invoked to return the serialized X.509 certificate data obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
x509Cert.getEncoded(function (error, data) {
if (error != null) {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getEncoded success");
}
});
}
});
```
### getEncoded
getEncoded() : Promise\<EncodingBlob>
Obtains the serialized X.509 certificate data. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------------ | ---------------------- |
| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized X.509 certificate data obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
Console.log("createX509Cert success");
x509Cert.getEncoded().then(result => {
Console.log("getEncoded success");
}, error => {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getPublicKey
getPublicKey(callback : AsyncCallback\<cryptoFramework.PubKey>) : void
Obtains the public key of this X.509 certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback | No | Callback invoked to return the public key obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
x509Cert.getPublicKey(function (error, pubKey) {
if (error != null) {
Console.log("getPublicKey failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getPublicKey success");
}
});
}
});
```
### getPublicKey
getPublicKey() : Promise\<cryptoFramework.PubKey>
Obtains the public key of this X.509 certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ---------------- |
| cryptoFramework.PubKey | X.509 certificate public key obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
Console.log("createX509Cert success");
x509Cert.getPublicKey().then(pubKey => {
Console.log("getPublicKey success");
}, error => {
Console.log("getPublicKey failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### checkValidityWithDate
checkValidityWithDate(date: string, callback : AsyncCallback\<void>) : void
Checks the validity period of this X.509 certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| date | string | Yes | Date of the certificate to check. |
| callback | AsyncCallback\<void> | No | Callback invoked to return the result. If **error** is **null**, the certificate is valid. If **error** is not **null**, the certificate has expired.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let date = "150527000001Z";
x509Cert.checkValidityWithDate(date, function (error, data) {
if (error != null) {
Console.log("checkValidityWithDate failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("checkValidityWithDate success");
}
});
}
});
```
### checkValidityWithDate
checkValidityWithDate(date: string) : Promise\<void>
Checks the validity period of this X.509 certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name| Type | Mandatory| Description|
| ------ | ------ | ---- | ---- |
| date | string | Yes | Date of the certificate to check.|
**Return value**
| Type| Description |
| ---- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
Console.log("createX509Cert success");
let date = "150527000001Z";
x509Cert.checkValidityWithDate(date).then(result => {
Console.log("checkValidityWithDate success");
}, error => {
Console.log("checkValidityWithDate failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getVersion
getVersion() : number
Obtains the X.509 certificate version.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ---------------- |
| number | X.509 certificate version obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let version = x509Cert.getVersion();
}
});
```
### getSerialNumber
getSerialNumber() : number
Obtains the X.509 certificate serial number.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ------------------ |
| number | X.509 certificate serial number obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let serialNumber = x509Cert.getSerialNumber();
}
});
```
### getIssuerName
getIssuerName() : DataBlob
Obtains the X.509 certificate issuer.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | ---------------------- |
| [DataBlob](#datablob) | X.509 certificate issuer obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let issuerName = x509Cert.getIssuerName();
}
});
```
### getSubjectName
getSubjectName() : DataBlob
Obtains the subject of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | -------------------- |
| [DataBlob](#datablob) | Subject name obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let subjectName = x509Cert.getSubjectName();
}
});
```
### getNotBeforeTime
getNotBeforeTime() : string
Obtains the start time of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------------- |
| string | Start time of the X.509 certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let notBefore = x509Cert.getNotBeforeTime();
}
});
```
### getNotAfterTime
getNotAfterTime() : string
Obtains the expiration time of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------------- |
| string | Expiration time of the X.509 certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let notAfter = x509Cert.getNotAfterTime();
}
});
```
### getSignature
getSignature() : DataBlob
Obtains the signature data of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | -------------------- |
| [DataBlob](#datablob) | Signature data obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let signature = x509Cert.getSignature();
}
});
```
### getSignatureAlgName
getSignatureAlgName() : string
Obtains the signing algorithm of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ------------------------ |
| string | X.509 certificate signing algorithm obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let sigAlgName = x509Cert.getSignatureAlgName();
}
});
```
### getSignatureAlgOid
getSignatureAlgOid() : string
Obtains the object identifier (OID) of the X.509 certificate signing algorithm. OIDs are allocated by the International Organization for Standardization (ISO).
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | --------------------------------- |
| string | OID obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let sigAlgOid = x509Cert.getSignatureAlgOid();
}
});
```
### getSignatureAlgParams
getSignatureAlgParams() : DataBlob
Obtains the signing algorithm parameters of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | ------------------------ |
| [DataBlob](#datablob) | X.509 certificate signing algorithm parameters obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let sigAlgParams = x509Cert.getSignatureAlgParams();
}
});
```
### getKeyUsage
getKeyUsage() : DataBlob
Obtains the key usage of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | -------------------- |
| [DataBlob](#datablob) | Key usage of the X.509 certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let keyUsage = x509Cert.getKeyUsage();
}
});
```
### getExtKeyUsage
getExtKeyUsage() : DataArray
Obtains the usage of the extended key of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| --------- | ------------------------ |
| [DataArray](#dataarray) | Usage of the extended key obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let extKeyUsage = x509Cert.getExtKeyUsage();
}
});
```
### getBasicConstraints
getBasicConstraints() : number
Obtains the basic constraints for obtaining this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------- |
| number | Basic constraints obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let basicConstraints = x509Cert.getBasicConstraints();
}
});
```
### getSubjectAltNames
getSubjectAltNames() : DataArray
Obtains the Subject Alternative Names (SANs) of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| --------- | ------------------------ |
| [DataArray](#dataarray) | SANs obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let subjectAltNames = x509Cert.getSubjectAltNames();
}
});
```
### getIssuerAltNames
getIssuerAltNames() : DataArray
Obtains the Issuer Alternative Names (IANs) of this X.509 certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| --------- | -------------------------- |
| [DataArray](#dataarray) | IANs obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Certificate binary data, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
if (error != null) {
Console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Cert success");
let issuerAltNames = x509Cert.getIssuerAltNames();
}
});
```
## cryptoCert.createX509Crl
createX509Crl(inStream : EncodingBlob, callback : AsyncCallback\<X509Crl>) : void
Creates an **X509Crl** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------------------------- |
| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized certificate revocation list (CRL) data.|
| callback | AsyncCallback\<X509Crl> | No | Callback invoked to return the **X509Crl** instance created. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
}
});
```
## cryptoCert.createX509Crl
createX509Crl(inStream : EncodingBlob) : Promise\<X509Crl>
Creates an **X509Crl** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------ | ---- | -------------------------- |
| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized CRL data.|
**Return value**
| Type | Description |
| ------- | -------------------- |
| Promise\<X509Crl> | Promise used to return the **X509Crl** instance created.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
## X509Crl
Provides APIs for X.509 certificate CRL operations.
### isRevoked
isRevoked(cert : X509Cert, callback : AsyncCallback\<boolean>) : void
Checks whether an X.509 certificate is revoked. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------------------- |
| cert | [X509Cert](#x509cert) | Yes | X.509 certificate to check.|
| callback | AsyncCallback\<boolean> | No | Callback invoked to return the result. The value **true** indicates that the certificate is revoked, and **false** indicates the opposite. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
// Create an X509Cert instance.
let x509Cert = null;
x509Crl.isRevoked(x509Cert, function (error, isRevoked) {
if (error != null) {
Console.log("call isRevoked failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("call isRevoked success");
}
});
}
});
```
### isRevoked
isRevoked(cert : X509Cert) : Promise\<boolean>
Checks whether an X.509 certificate is revoked. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------- | ---- | -------------------- |
| cert | X509Cert | Yes | X.509 certificate to check.|
**Return value**
| Type | Description |
| ------- | ------------------------------------------------- |
| Promise\<boolean> | Promise used to return the result. The value **true** indicates the certificate is revoked; the value **false** indicates the opposite.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
// Create an X509Cert instance.
let x509Cert = null;
x509Crl.isRevoked(x509Cert).then(isRevoked => {
Console.log("call isRevoked success");
}, error => {
Console.log("call isRevoked failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getType
getType() : string
Obtains the CRL type.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------- |
| string | CRL type obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let type = x509Crl.getType();
}
});
```
### getEncoded
getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
Obtains the serialized X.509 CRL data. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<EncodingBlob> | No | Callback invoked to return the serialized X.509 CRL data obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
x509Crl.getEncoded(function (error, data) {
if (error != null) {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getEncoded success");
}
});
}
});
```
### getEncoded
getEncoded() : Promise\<EncodingBlob>
Obtains the serialized X.509 CRL data. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------------ | -------------------------------- |
| Promise\<EncodingBlob> | Promise used to return the serialized X.509 CRL data obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
x509Crl.getEncoded().then(result => {
Console.log("getEncoded success");
}, error => {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### verify
verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void
Verifies the signature of the X.509 CRL. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ---------------------- |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification.|
| callback | AsyncCallback\<void> | No | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
// Generate the public key by AsyKeyGenerator.
let pubKey = null;
x509Crl.verify(pubKey, function (error, data) {
if (error != null) {
Console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("verify success");
}
});
}
});
```
### verify
verify(key : cryptoFramework.PubKey) : Promise\<void>
Verifies the signature of the X.509 CRL. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------- |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification.|
**Return value**
| Type| Description |
| ---- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
// Generate the public key by AsyKeyGenerator.
let pubKey = null;
x509Crl.verify(pubKey).then(result => {
Console.log("verify success");
}, error => {
Console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getVersion
getVersion() : number
Obtains the version of the X.509 CRL.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------------------- |
| number | Version of the X.509 CRL obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let version = x509Crl.getVersion();
}
});
```
### getIssuerName
getIssuerName() : DataBlob
Obtains the issuer of the X.509 CRL.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | ------------------------------ |
| [DataBlob](#datablob) | Issuer of the X.509 CRL obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let issuerName = x509Crl.getIssuerName();
}
});
```
### getLastUpdate
getLastUpdate() : string
Obtains the date when the X.509 CRL was last updated.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ------------------------------------ |
| string | Last update date of the X.509 CRL.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let lastUpdate = x509Crl.getLastUpdate();
}
});
```
### getNextUpdate
getNextUpdate() : string
Obtains the date when the CRL will be updated the next time.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ------------------------------------ |
| string | Next update date obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let nextUpdate = x509Crl.getNextUpdate();
}
});
```
### getRevokedCert
getRevokedCert(serialNumber : number, callback : AsyncCallback\<X509CrlEntry>) : void
Obtains the revoked X.509 certificate based on the specified serial number of the certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------- | ---- | -------------- |
| serialNumber | number | Yes | Serial number of the certificate.|
| callback | AsyncCallback\<X509CrlEntry> | No | Callback invoked to return the revoked X.509 certificate. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
// Set the serial number of the corresponding certificate.
let serialNumber = 1000;
x509Crl.getRevokedCert(serialNumber, function (error, entry) {
if (error != null) {
Console.log("getRevokedCert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getRevokedCert success");
}
});
}
});
```
### getRevokedCert
getRevokedCert(serialNumber : number) : Promise\<X509CrlEntry>
Obtains the revoked X.509 certificate based on the specified serial number of the certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | -------------- |
| serialNumber | number | Yes | Serial number of the certificate.|
**Return value**
| Type | Description |
| ------------ | ---------------------- |
| Promise\<X509CrlEntry> | Promise used to return the revoked X.509 certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
// Set the serial number of the corresponding certificate.
let serialNumber = 1000;
x509Crl.getRevokedCert(serialNumber).then(entry => {
Console.log("getRevokedCert success");
}, error => {
Console.log("getRevokedCert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getRevokedCertWithCert
getRevokedCertWithCert(cert : X509Cert, callback : AsyncCallback\<X509CrlEntry>) : void
Obtains the revoked X.509 certificate based on the specified certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------ |
| cert | X509Cert | Yes | Certificate based on which the revoked certificate is obtained.|
| callback | AsyncCallback\<X509CrlEntry> | No | Callback invoked to return the revoked X.509 certificate obtained. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
// Create an X509Cert instance.
let x509Cert = null;
x509Crl.getRevokedCertWithCert(x509Cert, function (error, entry) {
if (error != null) {
Console.log("getRevokedCertWithCert failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getRevokedCertWithCert success");
}
});
}
});
```
### getRevokedCertWithCert
getRevokedCertWithCert(cert : X509Cert) : Promise\<X509CrlEntry>
Obtains the revoked X.509 certificate based on the specified certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | -------- | ---- | ------------ |
| cert | X509Cert | Yes | Certificate based on which the revoked certificate is obtained.|
**Return value**
| Type | Description |
| ------------ | ---------------------- |
| Promise\<X509CrlEntry> | Promise used to return the revoked X.509 certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
// Create an X509Cert instance.
let x509Cert = null;
x509Crl.getRevokedCertWithCert(x509Cert).then(entry => {
Console.log("getRevokedCertWithCert success");
}, error => {
Console.log("getRevokedCertWithCert failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getRevokedCerts
getRevokedCerts(callback : AsyncCallback<Array\<X509CrlEntry>>) : void
Obtains all the revoked X.509 certificates. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback<Array\<X509CrlEntry>> | No | Callback invoked to return the revoked X.509 certificates obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
x509Crl.getRevokedCerts(function (error, array) {
if (error != null) {
Console.log("getRevokedCerts failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getRevokedCerts success");
}
});
}
});
```
### getRevokedCerts
getRevokedCerts() : Promise<Array\<X509CrlEntry>>
Obtains all the revoked X.509 certificates. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------------------- | ---------------------- |
|Promise<Array\<X509CrlEntry>> | Promise used to return a list of revoked X.509 certificates.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
x509Crl.getRevokedCerts().then(array => {
Console.log("getRevokedCerts success");
}, error => {
Console.log("getRevokedCerts failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getTbsInfo
getTbsInfo(callback : AsyncCallback\<DataBlob>) : void
Obtains the DER-encoded CRL information, the **tbsCertList** from this CRL. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<[DataBlob](#datablob)> | No | Callback invoked to return the tbsCertList information obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
x509Crl.getTbsInfo(function (error, tbsInfo) {
if (error != null) {
Console.log("getTbsInfo failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getTbsInfo success");
}
});
}
});
```
### getTbsInfo
getTbsInfo() : Promise\<DataBlob>
Obtains the DER-encoded CRL information, the **tbsCertList** from this CRL. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | --------------------------------- |
| Promise\<[DataBlob](#datablob)> | Promise used to return the **tbsCertList** information obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
Console.log("createX509Crl success");
x509Crl.getTbsInfo().then(tbsInfo => {
Console.log("getTbsInfo success");
}, error => {
Console.log("getTbsInfo failed, errCode: " + error.code + ", errMsg: " + error.message);
});
}, error => {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getSignature
getSignature() : DataBlob
Obtains the signature data of the X.509 CRL.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | ------------------------------ |
| [DataBlob](#datablob) | Signature data of the X.509 CRL obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let signature = x509Crl.getSignature();
}
});
```
### getSignatureAlgName
getSignatureAlgName() : string
Obtains the signing algorithm of the X.509 CRL.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------------------- |
| string | Signing algorithm obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let sigAlgName = x509Crl.getSignatureAlgName();
}
});
```
### getSignatureAlgOid
getSignatureAlgOid() : string
Obtains the OID of the X.509 CRL signing algorithm. OIDs are allocated by the International Organization for Standardization (ISO).
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | --------------------------------------------- |
| string | OID of the X.509 CRL signing algorithm obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let sigAlgOid = x509Crl.getSignatureAlgOid();
}
});
```
### getSignatureAlgParams
getSignatureAlgParams() : DataBlob
Obtains the parameters of the X.509 CRL signing algorithm.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | ---------------------------------- |
| [DataBlob](#datablob) | Algorithm parameters obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Binary data of the CRL, which must be set based on the service.
let encodingData = null;
let encodingBlob = {
data: encodingData,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
if (error != null) {
Console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("createX509Crl success");
let sigAlgParams = x509Crl.getSignatureAlgParams();
}
});
```
## cryptoCert.createCertChainValidator
createCertChainValidator(algorithm :string) : CertChainValidator
Creates a **CertChainValidator** object.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------------------------------------ |
| algorithm | string | Yes | Certificate chain validator algorithm. Currently, only **PKIX** is supported.|
**Return value**
| Type | Description |
| ------------------ | -------------------- |
| CertChainValidator | **CertChainValidator** object created.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
let validator = cryptoCert.createCertChainValidator("PKIX");
```
## CertChainValidator
Provides APIs for certificate chain validator operations.
### validate
validate(certChain : CertChainData, callback : AsyncCallback\<void>) : void
Validates the X.509 certificate chain. This API uses an asynchronous callback to return the result.
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications).
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------- | ---- | ------------------------ |
| certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data.|
| callback | AsyncCallback\<void> | No | Callback invoked to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid. |
**Example**
```js
import cryptoCert from '@ohos.security.cert';
let validator = cryptoCert.createCertChainValidator("PKIX");
// Certificate chain binary data, which must be set based on the service.
let encodingData = null;
// Number of certificates in the certificate chain. It must be set based on the service.
let certCount = 2;
let certChainData = {
data: encodingData,
count: certCount,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
validator.validate(certChainData, function (error, data) {
if (error != null) {
Console.log("validate failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("validate success");
}
});
```
### validate
validate(certChain : CertChainData) : Promise\<void>
Validates the X.509 certificate chain. This API uses a promise to return the result.
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications).
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------- | ---- | ------------------------ |
| certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data.|
**Return value**
| Type| Description |
| ---- | ------------------------------------------------------------ |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
let validator = cryptoCert.createCertChainValidator("PKIX");
// Certificate chain binary data, which must be set based on the service.
let encodingData = null;
// Number of certificates in the certificate chain. It must be set based on the service.
let certCount = 2;
let certChainData = {
data: encodingData,
count: certCount,
// Set the encoding format, which can be FORMAT_PEM or FORMAT_DER.
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
};
validator.validate(certChainData).then(result => {
Console.log("validate success");
}, error => {
Console.log("validate failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### algorithm
algorithm : string
Obtains the algorithm of the X.509 certificate chain validator.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ------------------------ |
| string | Algorithm of the X.509 certificate chain validator obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
let validator = cryptoCert.createCertChainValidator("PKIX");
let algorithm = validator.algorithm;
```
## X509CrlEntry
Provides APIs for operating the revoked certificates.
### getEncoded
getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
Obtains the serialized data of this revoked certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | No | Callback invoked to return the serialized data of the revoked certificate.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getEncoded(function (error, data) {
if (error != null) {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getEncoded success");
}
});
```
### getEncoded
getEncoded() : Promise\<EncodingBlob>
Obtains the serialized data of this revoked certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------------ | -------------------------- |
| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized data of the revoked certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getEncoded().then(result => {
Console.log("getEncoded success");
}, error => {
Console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getSerialNumber
getSerialNumber() : number
Obtains the serial number of this revoked certificate.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | ---------------------- |
| number | Serial number of the revoked certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
let serialNumber = x509CrlEntry.getSerialNumber();
```
### getCertIssuer
getCertIssuer(callback : AsyncCallback\<DataBlob>) : void
Obtains the issuer of this revoked certificate. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<[DataBlob](#datablob)> | No | Callback invoked to return the issuer of the revoked certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getCertIssuer(function (error, issuer) {
if (error != null) {
Console.log("getCertIssuer failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getCertIssuer success");
}
});
```
### getCertIssuer
getCertIssuer() : Promise\<DataBlob>
Obtains the issuer of this revoked certificate. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| -------- | -------------------------- |
| Promise\<[DataBlob](#datablob)> | Promise used to return the issuer of the revoked certificate obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getCertIssuer().then(issuer => {
Console.log("getCertIssuer success");
}, error => {
Console.log("getCertIssuer failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
### getRevocationDate
getRevocationDate(callback : AsyncCallback\<string>) : void
Obtains the date when the certificate was revoked. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Security.Cert
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | -------- |
| callback | AsyncCallback\<string> | No | Callback invoked to return the certificate revocation date obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getRevocationDate(function (error, date) {
if (error != null) {
Console.log("getRevocationDate failed, errCode: " + error.code + ", errMsg: " + error.message);
} else {
Console.log("getRevocationDate success");
}
});
```
### getRevocationDate
getRevocationDate() : Promise\<string>
Obtains the date when the certificate was revoked. This API uses a promise to return the result.
**System capability**: SystemCapability.Security.Cert
**Return value**
| Type | Description |
| ------ | -------------------- |
| Promise\<string> | Promise used to return the certificate revocation date obtained.|
**Example**
```js
import cryptoCert from '@ohos.security.cert';
// Obtain X509CrlEntry by using getRevokedCert() of X509Crl.
let x509CrlEntry = null;
x509CrlEntry.getRevocationDate().then(date => {
Console.log("getRevocationDate success");
}, error => {
Console.log("getRevocationDate failed, errCode: " + error.code + ", errMsg: " + error.message);
});
```
......@@ -9,24 +9,34 @@ The **DefaultAppManager** module provides APIs to query whether the current appl
## Modules to Import
```
import defaultAppMgr from '@ohos.bundle.defaultAppManager'
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
```
## Required Permissions
| Permission | Permission Level | Description |
| --------------------------------------- | ----------- | ---------------- |
| ohos.permission.GET_DEFAULT_APPLICATION | system_core | Permission related to the default application.|
For details, see in [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## defaultAppMgr.ApplicationType
Enumerates the application types.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
| Name | Type | Description |
| -------- | -------- | -------------------------------------- |
| BROWSER | string | Default browser. |
| IMAGE | string | Default image viewer. |
| AUDIO | string | Default audio player. |
| VIDEO | string | Default video player. |
| PDF | string | Default PDF reader. |
| WORD | string | Default Word viewer. |
| EXCEL | string | Default Excel viewer. |
| PPT | string | Default PowerPoint viewer. |
| Name | Type | Value | Description |
| -------- | -------- | -------------------------------------- | -------------------------------------- |
| BROWSER | string | Web Browser | Default browser. |
| IMAGE | string | Image Gallery | Default image viewer. |
| AUDIO | string | Audio Player | Default audio player. |
| VIDEO | string | Video Player | Default video player. |
| PDF | string | PDF Viewer | Default PDF reader. |
| WORD | string | Word Viewer | Default Word viewer. |
| EXCEL | string | Excel Viewer | Default Excel viewer. |
| PPT | string | PPT Viewer | Default PowerPoint viewer. |
## defaultAppMgr.isDefaultApplication
......@@ -34,7 +44,7 @@ isDefaultApplication(type: string): Promise\<boolean>
Checks whether this application is the default application of a system-defined application type. This API uses a promise to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**Parameters**
......@@ -48,9 +58,15 @@ Checks whether this application is the default application of a system-defined a
| ------------------------- | ------------------ |
| Promise\<boolean> | Promise used to return the result. If the application is the default application, `true` is returned; otherwise, `false` is returned.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```js
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. IsDefaultApplication ? ' + JSON.stringify(data));
......@@ -65,7 +81,7 @@ isDefaultApplication(type: string, callback: AsyncCallback\<boolean>): void
Checks whether this application is the default application of a system-defined application type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**Parameters**
......@@ -74,9 +90,14 @@ Checks whether this application is the default application of a system-defined a
| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype). |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the application is the default application, `true` is returned; otherwise, `false` is returned.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```js
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.isDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
......@@ -94,7 +115,7 @@ Obtains the default application based on a system-defined application type or a
**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -111,9 +132,20 @@ Obtains the default application based on a system-defined application type or a
| ------------------------- | ------------------ |
| Promise\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Promise used to return the default application.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700023 | The specified default app does not exist. |
| 17700025 | The specified type is invalid. |
**Example**
```js
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
.then((data) => {
console.info('Operation successful. bundleInfo: ' + JSON.stringify(data));
......@@ -139,7 +171,7 @@ Obtains the default application of a user based on a system-defined application
**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -151,10 +183,22 @@ Obtains the default application of a user based on a system-defined application
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the default application. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700023 | The specified default app does not exist. |
| 17700025 | The specified type is invalid. |
**Example**
```js
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, 100, (err, data) => {
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100;
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -162,7 +206,7 @@ defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, 100,
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
defaultAppMgr.getDefaultApplication("image/png", 100, (err, data) => {
defaultAppMgr.getDefaultApplication("image/png", userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -179,7 +223,7 @@ Obtains the default application based on a system-defined application type or a
**Required permissions**: ohos.permission.GET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -190,9 +234,20 @@ Obtains the default application based on a system-defined application type or a
| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype) or a file type that complies with the media type format. |
| callback | AsyncCallback\<[BundleInfo](js-apis-bundle-BundleInfo.md)> | Yes | Callback used to return the default application. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700023 | The specified default app does not exist. |
| 17700025 | The specified type is invalid. |
**Example**
```js
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
......@@ -200,7 +255,6 @@ defaultAppMgr.getDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err,
}
console.info('Operation successful. bundleInfo:' + JSON.stringify(data));
});
defaultAppMgr.getDefaultApplication("image/png", (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
......@@ -218,7 +272,7 @@ Sets the default application based on a system-defined application type or a fil
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -230,18 +284,44 @@ Sets the default application based on a system-defined application type or a fil
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application. |
| userId | number | No | User ID. The default value is the user ID of the caller. |
**Return value**
| Type | Description |
| -------------- | ---------------------------------- |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
| 17700028 | The specified ability does not match the type. |
**Example**
```js
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.test.app",
moduleName: "module01",
abilityName: "MainAbility"
})
.then((data) => {
}).then((data) => {
console.info('Operation successful.');
})
.catch((error) => {
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
let userId = 100;
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.test.app",
moduleName: "module01",
abilityName: "MainAbility"
}, userId).then((data) => {
console.info('Operation successful.');
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
......@@ -249,11 +329,9 @@ defaultAppMgr.setDefaultApplication("image/png", {
bundleName: "com.test.app",
moduleName: "module01",
abilityName: "MainAbility"
})
.then((data) => {
}, userId).then((data) => {
console.info('Operation successful.');
})
.catch((error) => {
}).catch((error) => {
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
```
......@@ -266,7 +344,7 @@ Sets the default application for a user based on a system-defined application ty
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -279,14 +357,26 @@ Sets the default application for a user based on a system-defined application ty
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
| 17700028 | The specified ability does not match the type. |
**Example**
```js
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100;
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.test.app",
moduleName: "module01",
abilityName: "MainAbility"
}, 100, (err, data) => {
}, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -298,7 +388,7 @@ defaultAppMgr.setDefaultApplication("image/png", {
bundleName: "com.test.app",
moduleName: "module01",
abilityName: "MainAbility"
}, 100, (err, data) => {
}, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -315,7 +405,7 @@ Sets the default application based on a system-defined application type or a fil
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -327,9 +417,20 @@ Sets the default application based on a system-defined application type or a fil
| elementName | [ElementName](js-apis-bundle-ElementName.md) | Yes | Information about the element to be set as the default application. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
| 17700028 | The specified ability does not match the type. |
**Example**
```js
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.setDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, {
bundleName: "com.test.app",
moduleName: "module01",
......@@ -363,7 +464,7 @@ Resets the default application based on a system-defined application type or a f
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -374,10 +475,21 @@ Resets the default application based on a system-defined application type or a f
| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype) or a file type that complies with the media type format. |
| userId | number | No | User ID. The default value is the user ID of the caller. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
**Example**
```js
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId)
.then((data) => {
console.info('Operation successful.');
})
......@@ -385,7 +497,7 @@ defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER)
console.error('Operation failed. Cause: ' + JSON.stringify(error));
});
defaultAppMgr.resetDefaultApplication("image/png")
defaultAppMgr.resetDefaultApplication("image/png", userId)
.then((data) => {
console.info('Operation successful.');
})
......@@ -402,7 +514,7 @@ Resets the default application for a user based on a system-defined application
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -414,10 +526,21 @@ Resets the default application for a user based on a system-defined application
| userId | number | Yes | User ID. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
**Example**
```js
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, 100, (err, data) => {
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
let userId = 100;
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -425,7 +548,7 @@ defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, 100
console.info('Operation successful.');
});
defaultAppMgr.resetDefaultApplication("image/png", 100, (err, data) => {
defaultAppMgr.resetDefaultApplication("image/png", userId, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
return;
......@@ -442,7 +565,7 @@ Resets the default application based on a system-defined application type or a f
**Required permissions**: ohos.permission.SET_DEFAULT_APPLICATION
**System capability**: SystemCapability.BundleManager.BundleFramework
**System capability**: SystemCapability.BundleManager.BundleFramework.DefaultApp
**System API**: This is a system API and cannot be called by third-party applications.
......@@ -453,9 +576,19 @@ Resets the default application based on a system-defined application type or a f
| type | string | Yes | Type of the target application. It must be set to a value defined by [ApplicationType](#defaultappmgrapplicationtype) or a file type that complies with the media type format. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
| 17700025 | The specified type is invalid. |
**Example**
```js
```ts
import defaultAppMgr from '@ohos.bundle.defaultAppManager';
defaultAppMgr.resetDefaultApplication(defaultAppMgr.ApplicationType.BROWSER, (err, data) => {
if (err) {
console.error('Operation failed. Cause: ' + JSON.stringify(err));
......
......@@ -5,8 +5,8 @@ The **distributedBundle** module provides APIs for managing distributed bundles.
> **NOTE**
>
> 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.
The APIs provided by this module are system APIs.
>
> The APIs provided by this module are system APIs.
## Modules to Import
......@@ -22,9 +22,9 @@ SystemCapability.BundleManager.DistributedBundleFramework
| Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ------------------ |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all applications.|
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.|
For details, see "Permission Levels" in [Access Control Overview](../../security/accesstoken-overview.md).
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## distributedBundle.getRemoteAbilityInfo
......@@ -41,27 +41,24 @@ Obtains information about the remote ability that matches the given element name
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| elementName | [ElementName](js-apis-bundleManager-elementName.md) | Yes | Target element name. |
| callback | AsyncCallback<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the **RemoteAbilityInfo** object obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|--------------------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
{
......@@ -106,21 +103,18 @@ Obtains information about the remote ability that matches the given element name
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
{
......@@ -152,27 +146,24 @@ Obtains information about remote abilities that match the given element names. T
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------------------------------ | ---- | -------------------------------------------------- |
| ------------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| elementNames | Array<[ElementName](js-apis-bundleManager-elementName.md)> | Yes | **ElementName** array, whose maximum length is 10. |
| callback | AsyncCallback\<Array\<[RemoteAbilityInfo](js-apis-bundleManager-remoteAbilityInfo.md)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the array of **RemoteAbilityInfo** objects obtained. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
[
......@@ -202,7 +193,7 @@ try {
getRemoteAbilityInfo(elementNames: Array\<ElementName>): Promise\<Array\<RemoteAbilityInfo>>;
Obtains information about remote abilities that match the given element names. This API uses a promise to return the result.
Obtains information about remote abilities that match the given element names and locales. This API uses a promise to return the result.
**System API**: This is a system API.
......@@ -224,21 +215,18 @@ Obtains information about remote abilities that match the given element names. T
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
[
......@@ -284,21 +272,18 @@ Obtains information about the remote ability that matches the given element name
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
{
......@@ -344,21 +329,18 @@ Obtains information about the remote ability that matches the given element name
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
{
......@@ -397,21 +379,18 @@ Obtains information about remote abilities that match the given element names an
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
[
......@@ -464,21 +443,18 @@ Obtains information about remote abilities that match the given element names an
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errcode-bundle.md).
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID | Error Message |
|---------------|-------------------------|
| 201 | Permission denied.|
| 401 | The parameter check failed. |
| 801 | Capability not supported. |
| 17700001 | The specified bundle name is not found |
| ID| Error Message |
|----------|-------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700003 | The specified ability name is not found. |
| 17700007 | The specified device id is not found. |
| 17700007 | The specified device ID is not found. |
| 17700027 | The distributed service is not running. |
**Example**
```js
```ts
try {
distributedBundle.getRemoteAbilityInfo(
[
......
# Enterprise Device Management
The **enterpriseDeviceManager** module provides enterprise device management capabilities so that devices have the customization capabilities required in enterprise scenarios.
> **NOTE**
>
> 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.
## Modules to Import
```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager';
```
## enterpriseDeviceManager.enableAdmin
enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, callback: AsyncCallback\<void>): void
Enables a device administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ----------------------------------- | ---- | ------------------ |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. |
| type | [AdminType](#admintype) | Yes | Type of the device administrator to enable. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Error codes**
| Type | Description |
| ------- | --------------------------------------------------------------- |
| 9200003 | The administrator ability component is invalid. |
| 9200004 | Failed to activate the administrator application of the device. |
| 9200007 | The system ability work abnormally. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("enableAdmin success");
});
```
## enterpriseDeviceManager.enableAdmin
enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId: number, callback: AsyncCallback\<void>): void
Enables a device administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. |
| type | [AdminType](#admintype) | Yes | Type of the device administrator to enable. |
| userId | number | Yes | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
| Type | Description |
| ------- | --------------------------------------------------------------- |
| 9200003 | The administrator ability component is invalid. |
| 9200004 | Failed to activate the administrator application of the device. |
| 9200007 | The system ability work abnormally. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, 100, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("enableAdmin success");
});
```
## enterpriseDeviceManager.enableAdmin
enableAdmin(admin: Want, enterpriseInfo: EnterpriseInfo, type: AdminType, userId?: number): Promise\<void>
Enables a device administrator application based on the specified bundle name and class name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. |
| type | [AdminType](#admintype) | Yes | Type of the device administrator to enable. |
| userId | number | No | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
**Return value**
| Type | Description |
| ----------------- | ----------------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| Type | Description |
| ------- | --------------------------------------------------------------- |
| 9200003 | The administrator ability component is invalid. |
| 9200004 | Failed to activate the administrator application of the device. |
| 9200007 | The system ability work abnormally. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
}
enterpriseDeviceManager.enableAdmin(wantTemp, enterpriseInfo, enterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL, 100)
.catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.disableAdmin
disableAdmin(admin: Want, callback: AsyncCallback\<void>): void
Disables a device common administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device common administrator application. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("disableAdmin success ");
});
```
## enterpriseDeviceManager.disableAdmin
disableAdmin(admin: Want, userId: number, callback: AsyncCallback\<void>): void
Disables a device common administrator application based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device common administrator application. |
| userId | number | Yes | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, 100, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("disableAdmin success ");
});
```
## enterpriseDeviceManager.disableAdmin
disableAdmin(admin: Want, userId?: number): Promise\<void>
Disables a device common administrator application based on the specified bundle name and class name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device common administrator application. |
| userId | number | No | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
**Return value**
| Type | Description |
| ----------------- | ----------------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.disableAdmin(wantTemp, 100).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.disableSuperAdmin
disableSuperAdmin(bundleName: String, callback: AsyncCallback\<void>): void
Disables a device super administrator application based on the specified bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ----------------------- | ---- | ------------------- |
| bundleName | String | Yes | Bundle name of the device super administrator application. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.disableSuperAdmin(bundleName, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("disableSuperAdmin success");
});
```
## enterpriseDeviceManager.disableSuperAdmin
disableSuperAdmin(bundleName: String): Promise\<void>
Disables a device super administrator application based on the specified bundle name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_ENTERPRISE_DEVICE_ADMIN
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | ------------ |
| bundleName | String | Yes | Bundle name of the device super administrator application.|
**Return value**
| Type | Description |
| ----------------- | ----------------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.disableSuperAdmin(bundleName).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.isAdminEnabled
isAdminEnabled(admin: Want, callback: AsyncCallback\<boolean>): void
Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | -------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------------------- |
| 9200005 | Failed to deactivate the administrator application of the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("result is " + result);
});
```
## enterpriseDeviceManager.isAdminEnabled
isAdminEnabled(admin: Want, userId: number, callback: AsyncCallback\<boolean>): void
Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| userId | number | Yes | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, 100, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("result is " + result);
});
```
## enterpriseDeviceManager.isAdminEnabled
isAdminEnabled(admin: Want, userId?: number): Promise\<boolean>
Checks whether a device administrator application is enabled based on the specified bundle name and class name. This API uses a promise to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ----------------------------------- | ---- | ---------------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| userId | number | No | User ID The default value is the user ID of the caller. The value must be greater than or equal to 0.|
**Return value**
| Type | Description |
| ----------------- | ------------------- |
| Promise\<boolean> | Promise used to return the result.|
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.isAdminEnabled(wantTemp, 100).then((result) => {
console.log("result is " + result);
}).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.isSuperAdmin
isSuperAdmin(bundleName: String, callback: AsyncCallback\<boolean>): void
Checks whether a device super administrator application is enabled based on the specified bundle name. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ----------------------- | ---- | -------------------- |
| bundleName | String | Yes | Device administrator application. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result.|
**Example**
```js
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("result is " + result);
});
```
## enterpriseDeviceManager.isSuperAdmin
isSuperAdmin(bundleName: String): Promise\<boolean>
Checks whether a device super administrator application is enabled based on the specified bundle name. This API uses a promise to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | --------- |
| bundleName | String | Yes | Device super administrator application.|
**Return value**
| Type | Description |
| ----------------- | ------------------- |
| Promise\<boolean> | Promise used to return the result.|
**Example**
```js
let bundleName = "com.example.myapplication";
enterpriseDeviceManager.isSuperAdmin(bundleName).then((result) => {
console.log("result is " + result);
}).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.getDeviceSettingsManager
getDeviceSettingsManager(callback: AsyncCallback&lt;DeviceSettingsManager&gt;): void
Obtains a **DeviceSettingsManager** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback<[DeviceSettingsManager](js-apis-enterpriseDeviceManager-DeviceSettingsManager.md)&gt; | Yes | Callback used to return the **DeviceSettingsManager** object obtained.|
**Error codes**
| Type | Description |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
if (error != null) {
console.log("error code:" + error.code);
return;
}
mgr.setDateTime(wantTemp, 1526003846000, (error) => {
if (error != null) {
console.log("error code:" + error.code);
}
});
});
```
## enterpriseDeviceManager.getDeviceSettingsManager
getDeviceSettingsManager(): Promise&lt;DeviceSettingsManager&gt;
Obtains a **DeviceSettingsManager** object. This API uses a promise to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**Return value**
| Type | Description |
| ------------------------------------ | ---------------------------------- |
| Promise&lt;[DeviceSettingsManager](js-apis-enterpriseDeviceManager-DeviceSettingsManager.md)&gt; | Promise used to return the **DeviceSettingsManager** object obtained.|
**Error codes**
| Type | Description |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager().then((mgr) => {
mgr.setDateTime(wantTemp, 1526003846000).catch((error) => {
console.log("error code:" + error.code);
})
}).catch((error) => {
console.log("error code:" + error.code);
})
```
## enterpriseDeviceManager.setEnterpriseInfo
setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo, callback: AsyncCallback\<void>;): void
Sets the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ----------------------------------- | ---- | ---------------------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application. |
| callback | AsyncCallback\<void>; | Yes | Callback used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo, error => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log("setEnterpriseInfo success");
});
```
## enterpriseDeviceManager.setEnterpriseInfo
setEnterpriseInfo(admin: Want, enterpriseInfo: EnterpriseInfo): Promise\<void>;
Sets the enterprise information of a device administrator application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.SET_ENTERPRISE_INFO
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------------- | ----------------------------------- | ---- | ------------ |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| enterpriseInfo | [EnterpriseInfo](#enterpriseinfo) | Yes | Enterprise information of the device administrator application.|
**Return value**
| Type | Description |
| ----------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
let enterpriseInfo = {
name: "enterprise name",
description: "enterprise description"
}
enterpriseDeviceManager.setEnterpriseInfo(wantTemp, enterpriseInfo).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.getEnterpriseInfo
getEnterpriseInfo(admin: Want, callback: AsyncCallback&lt;EnterpriseInfo&gt;): void
Obtains the enterprise information of a device administrator application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------ |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application. |
| callback | AsyncCallback&lt;[EnterpriseInfo](#enterpriseinfo)&gt; | Yes | Callback used to return the enterprise information of the device administrator application.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp, (error, result) => {
if (error != null) {
console.log("error occurs" + error);
return;
}
console.log(result.name);
console.log(result.description);
});
```
## enterpriseDeviceManager.getEnterpriseInfo
getEnterpriseInfo(admin: Want): Promise&lt;EnterpriseInfo&gt;
Obtains the enterprise information of a device administrator application. This API uses a promise to return the result.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| ---------------------------------------- | ------------------------- |
| Promise&lt;[EnterpriseInfo](#enterpriseinfo)&gt; | Promise used to return the enterprise information of the device administrator application.|
**Error codes**
| Type | Description |
| ------- | ----------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
**Example**
```js
let wantTemp = {
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
};
enterpriseDeviceManager.getEnterpriseInfo(wantTemp).then((result) => {
console.log(result.name);
console.log(result.description);
}).catch(error => {
console.log("error occurs" + error);
});
```
## enterpriseDeviceManager.subscribeManagedEvent
subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void
Subscribes to system management events. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to subscribe to.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the subscription is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
let events = [0, 1];
enterpriseDeviceManager.subscribeManagedEvent(wantTemp, events, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## enterpriseDeviceManager.subscribeManagedEvent
subscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void>
Subscribes to system management events. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to subscribe to.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise used to return the result. Promise that returns no value.|
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
let events = [0, 1];
enterpriseDeviceManager.subscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
})
```
## enterpriseDeviceManager.unsubscribeManagedEvent
unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>, callback: AsyncCallback\<void>): void
Unsubscribes from system management events. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to unsubscribe from.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the unsubscription is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
let events = [0, 1];
enterpriseDeviceManager.unsubscribeManagedEvent(wantTemp, events, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
```
## enterpriseDeviceManager.unsubscribeManagedEvent
unsubscribeManagedEvent(admin: Want, managedEvents: Array\<ManagedEvent>): Promise\<void>
Unsubscribes from system management events. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SUBSCRIBE_MANAGED_EVENT
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| managedEvents | Array\<[ManagedEvent](#managedevent)> | Yes| Array of events to unsubscribe from.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise used to return the result. Promise that returns no value.|
**Example**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
let events = [0, 1];
enterpriseDeviceManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
})
```
## EnterpriseInfo
Describes the enterprise information of a device administrator application.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
| Name | Readable/Writable| Type | Mandatory | Description |
| ----------- | ---- | ------ | ---- | ----------------- |
| name | Read only | string | Yes | Name of the enterprise to which the device administrator application belongs.|
| description | Read only | string | Yes | Description of the enterprise to which the device administrator application belongs.|
## AdminType
Enumerates the administrator types of the device administrator application.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
| Name | Default Value | Description |
| ----------------- | ---- | ----- |
| ADMIN_TYPE_NORMAL | 0x00 | Common administrator.|
| ADMIN_TYPE_SUPER | 0x01 | Super administrator.|
## ManagedEvent
Enumerates the system management events that can be subscribed to.
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
| Name | Default Value | Description |
| ----------------- | ---- | ----- |
| MANAGED_EVENT_BUNDLE_ADDED | 0 | Application installation event.|
| MANAGED_EVENT_BUNDLE_REMOVED | 1 | Application uninstallation event.|
# Device Settings Management
The **EnterpriseDeviceManager** module provides capabilities to manage device settings, such as time settings. The APIs of this module can only be called by enterprise device administrator applications.
> **NOTE**
>
> 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.
## Usage
Before calling any API in **EnterpriseDeviceManager**, use **getDeviceSettingsManager** to create an **EnterpriseDeviceManager** instance.
```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
return;
}
let deviceMgr = mgr;
});
```
## DeviceSettingsManager.setDateTime
setDateTime(admin: Want, time: number, callback: AsyncCallback\<void>): void
Sets the system time. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| time | number | Yes| Timestamp (ms).|
| callback | AsyncCallback\<void> | Yes| Callback used to the result. If the system time is set successfully, **err** is **null**; otherwise, **err** is an error object.|
**Error codes**
| Type | Description |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
**Example**
```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager((error, mgr) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
return;
}
mgr.setDateTime(wantTemp, 1526003846000, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
}
});
});
```
## DeviceSettingsManager.setDateTime
setDateTime(admin: Want, time: number): Promise\<void>
Sets the system time. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_SET_DATETIME
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-application-Want.md) | Yes | Device administrator application.|
| time | number | Yes| Timestamp (ms).|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise that returns no value.|
**Error codes**
| Type | Description |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not a administrator of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
**Example**
```js
import enterpriseDeviceManager from '@ohos.enterpriseDeviceManager'
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
enterpriseDeviceManager.getDeviceSettingsManager().then((mgr) => {
mgr.setDateTime(wantTemp, 1526003846000).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
})
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
})
```
# Bundle.freeInstall
The **Bundle.freeInstall** module provides APIs for setting and obtaining installation-free information and APIs for obtaining **BundlePackInfo** and **DispatchInfo**.
> **NOTE**
>
> 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.
>
> The APIs provided by this module are system APIs.
## Modules to Import
```js
import freeInstall from '@ohos.bundle.freeInstall';
```
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------------------ | ------------ | ------------------ |
| ohos.permission.GET_BUNDLE_INFO_PRIVILEGED | system_basic | Permission to query information about all bundles.|
| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles. |
For details, see [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## UpgradeFlag
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
| Name | Value | Description |
| ---------------- | ---- | ---------------- |
| NOT_UPGRADE | 0 | No module needs an upgrade. |
| SINGLE_UPGRADE | 1 | A single module needs an upgrade.|
| RELATION_UPGRADE | 2 | The module that has a relationship with the current one needs an upgrade.|
## BundlePackFlag
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
| Name | Value | Description |
| ------------------ | ---------- | ---------------------------------- |
| GET_PACK_INFO_ALL | 0x00000000 | All information in the **pack.info** file. |
| GET_PACKAGES | 0x00000001 | Package information in the **pack.info** file.|
| GET_BUNDLE_SUMMARY | 0x00000002 | Bundle summary information in the **pack.info** file. |
| GET_MODULE_SUMMARY | 0x00000004 | Module summary information in the **pack.info** file. |
## freeInstall.setHapModuleUpgradeFlag
setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag, callback: AsyncCallback\<void>):void;
Sets an upgrade flag for a module. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INSTALL_BUNDLE
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ---------------------------- |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is for internal use only. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **null**; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|---------------------------------------- |
| 17700001 | The specified bundle name is not found. |
| 17700002 | The specified module name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
try {
freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag, err => {
if (err) {
console.error('Operation failed:' + JSON.stringify(err));
} else {
console.info('Operation succeed');
}
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## setHapModuleUpgradeFlag
setHapModuleUpgradeFlag(bundleName: string, moduleName: string, upgradeFlag: UpgradeFlag): Promise\<void>;
Sets an upgrade flag for a module. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| ----------- | --------------------------- | ---- | ---------------------- |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| upgradeFlag | [UpgradeFlag](#upgradeflag) | Yes | Upgrade flag, which is for internal use only.|
**Return value**
| Type | Description |
| ------------- | ------------------------------------ |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|----------------------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700002 | The specified module name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
let upgradeFlag = freeInstall.UpgradeFlag.SINGLE_UPGRADE;
try {
freeInstall.setHapModuleUpgradeFlag(bundleName, moduleName, upgradeFlag).then(() => {
console.info('Operation succeed')
}).catch(err => {
console.error('Operation failed:' + JSON.stringify(err));
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## isHapModuleRemovable
isHapModuleRemovable(bundleName: string, moduleName: string, callback: AsyncCallback\<boolean>): void;
Checks whether a module can be removed. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------- | ---- | --------------------------------------------- |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name. |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|----------------------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700002 | The specified module name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
try {
freeInstall.isHapModuleRemovable(bundleName, moduleName, (err, data) => {
if (err) {
console.error('Operation failed:' + JSON.stringify(err));
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## isHapModuleRemovable
isHapModuleRemovable(bundleName: string, moduleName: string): Promise\<boolean>;
Checks whether a module can be removed. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------ |
| bundleName | string | Yes | Bundle name. |
| moduleName | string | Yes | Module name.|
**Return value**
| Type | Description |
| ---------------- | ---------------------------- |
| Promise\<boolean> | Promise used to return the result. If the module can be removed, **true** is returned; otherwise, **false** is returned.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|----------------------------------------|
| 17700001 | The specified bundle name is not found. |
| 17700002 | The specified module name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let moduleName = 'entry';
try {
freeInstall.isHapModuleRemovable(bundleName, moduleName).then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed:' + JSON.stringify(err));
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## getBundlePackInfo
getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag, callback: AsyncCallback\<BundlePackInfo>): void;
Obtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Bundle name. |
| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes | Flag of the bundle package. |
| callback | AsyncCallback<[BundlePackInfo](js-apis-bundleManager-packInfo.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.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|----------------------------------------|
| 17700001 | The specified bundle name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
try {
freeInstall.getBundlePackInfo(bundleName, bundlePackFlag, (err, data) => {
if (err) {
console.error('Operation failed:' + JSON.stringify(err));
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## getBundlePackInfo
getBundlePackInfo(bundleName: string, bundlePackFlag : BundlePackFlag): Promise\<BundlePackInfo>;
Obtains **bundlePackInfo** based on **bundleName** and **bundlePackFlag**. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | --------------------------------- | ---- | ---------------------- |
| bundleName | string | Yes | Bundle name. |
| bundlePackFlag | [BundlePackFlag](#bundlepackflag) | Yes | Flag of the bundle package.|
**Return value**
| Type | Description |
| ---------------------------------------------------------- | ----------------------------------- |
| Promise<[BundlePackInfo](js-apis-bundleManager-packInfo.md)> | Promise used to return the **BundlePackInfo** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
|----------|----------------------------------------|
| 17700001 | The specified bundle name is not found. |
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
let bundleName = 'com.example.myapplication';
let bundlePackFlag = freeInstall.BundlePackFlag.GET_PACK_INFO_ALL;
try {
freeInstall.getBundlePackInfo(bundleName, bundlePackFlag).then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed:' + JSON.stringify(err));
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## getDispatchInfo
getDispatchInfo(callback: AsyncCallback\<DispatchInfo>): void;
Obtains the dispatch information. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| 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.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
try {
freeInstall.getDispatchInfo((err, data) => {
if (err) {
console.error('Operation failed:' + JSON.stringify(err));
} else {
console.info('Operation succeed:' + JSON.stringify(data));
}
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
## getDispatchInfo
getDispatchInfo(): Promise\<DispatchInfo>;
Obtains the dispatch information. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System capability**: SystemCapability.BundleManager.BundleFramework.FreeInstall
**Return value**
| Type | Description |
| ------------------------------------------------ | ------------------------------------------------------------ |
| Promise<[DispatchInfo](js-apis-bundleManager-dispatchInfo.md)> | Promise used to return the [DispatchInfo](js-apis-bundleManager-dispatchInfo.md) object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```js
import freeInstall from '@ohos.bundle.freeInstall';
try {
freeInstall.getDispatchInfo().then(data => {
console.info('Operation succeed:' + JSON.stringify(data));
}).catch(err => {
console.error('Operation failed:' + JSON.stringify(err));
});
} catch (err) {
console.error('Operation failed:' + JSON.stringify(err));
}
```
# BundleInstaller
The **BundleInstaller** module provides APIs for you to install, uninstall, and recover bundles on devices.
> **NOTE**
>
> 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.
## Modules to Import
```js
import installer from '@ohos.bundle.installer';
```
## Required Permissions
| Permission | Permission Level | Description |
| ------------------------------ | ----------- | ---------------- |
| ohos.permission.INSTALL_BUNDLE | system_core | Permission to install or uninstall bundles.|
For details, see in [Permission Levels](../../security/accesstoken-overview.md#permission-levels).
## BundleInstaller.getBundleInstaller
getBundleInstaller(callback: AsyncCallback\<BundleInstaller>): void;
Obtains a **BundleInstaller** object. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[BundleInstaller](js-apis-installer.md#BundleInstaller)> | Yes | Callback used to return the result. If the operation is successful, **err** is undefined and **data** is the **BundleInstaller** object obtained; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```ts
import installer from '@ohos.bundle.installer';
try {
installer.getBundleInstaller((err, data) => {
if (err) {
console.error('getBundleInstaller failed:' + err.message);
} else {
console.info('getBundleInstaller successfully');
}
});
} catch (error) {
console.error('getBundleInstaller failed:' + error.message);
}
```
## BundleInstaller.getBundleInstaller
getBundleInstaller(): Promise\<BundleInstaller>;
Obtains a **BundleInstaller** object. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------ |
| Promise\<[BundleInstaller](js-apis-installer.md#BundleInstaller)> | Promise used to return the **BundleInstaller** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
**Example**
```ts
import installer from '@ohos.bundle.installer';
try {
installer.getBundleInstaller().then((data) => {
console.info('getBundleInstaller successfully.');
}).catch((error) => {
console.error('getBundleInstaller failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message);
}
```
## BundleInstaller.install
install(hapFilePaths: Array&lt;string&gt;, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void;
Installs a bundle. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| installParam | [InstallParam](#installparam) | Yes | Parameters required for the installation. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is undefined; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700004 | The specified user ID is not found. |
| 17700010 | Failed to install the HAP because the HAP fails to be parsed. |
| 17700011 | Failed to install the HAP because the HAP signature fails to be verified. |
| 17700012 | Failed to install the HAP because the HAP path is invalid or the HAP is too large. |
| 17700015 | Failed to install the HAPs because they have different configuration information. |
| 17700016 | Failed to install the HAP because of insufficient system disk space. |
| 17700017 | Failed to install the HAP since the version of the HAP to install is too early. |
| 17700101 | The system service is excepted. |
| 17700103 | I/O operation is failed. |
**Example**
```ts
import installer from '@ohos.bundle.installer';
let hapFilePaths = ['/data/storage/el2/base/haps/entry/files/'];
let installParam = {
userId: 100,
isKeepData: false,
installFlag: 1,
};
try {
installer.getBundleInstaller().then(data => {
data.install(hapFilePaths, installParam, err => {
if (err) {
console.error('install failed:' + err.message);
} else {
console.info('install successfully.');
}
});
}).catch(error => {
console.error('getBundleInstaller failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message);
}
```
## BundleInstaller.uninstall
uninstall(bundleName: string, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void;
Uninstalls a bundle. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Name of the target bundle. |
| installParam | [InstallParam](#installparam) | Yes | Parameters required for the installation. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is undefined; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 17700004 | The specified user ID is not found. |
| 17700020 | The specified bundle is pre-installed bundle which cannot be uninstalled. |
| 17700101 | The system service is excepted. |
**Example**
```ts
import installer from '@ohos.bundle.installer';
let bundleName = 'com.ohos.demo';
let installParam = {
userId: 100,
isKeepData: false,
installFlag: 1
};
try {
installer.getBundleInstaller().then(data => {
data.uninstall(bundleName, installParam, err => {
if (err) {
console.error('uninstall failed:' + err.message);
} else {
console.info('uninstall successfully.');
}
});
}).catch(error => {
console.error('getBundleInstaller failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message);
}
```
## BundleInstaller.recover
recover(bundleName: string, installParam: InstallParam, callback: AsyncCallback&lt;void&gt;): void;
Recovers a bundle. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**Required permissions**: ohos.permission.INSTALL_BUNDLE
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------------------- | ---- | ---------------------------------------------- |
| bundleName | string | Yes | Name of the target bundle. |
| installParam | [InstallParam](#installparam) | Yes | Parameters required for the installation. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is undefined; otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ----------------------------------- |
| 17700004 | The specified user ID is not found. |
**Example**
```ts
import installer from '@ohos.bundle.installer';
let bundleName = 'com.ohos.demo';
let installParam = {
userId: 100,
isKeepData: false,
installFlag: 1
};
try {
installer.getBundleInstaller().then(data => {
data.recover(bundleName, installParam, err => {
if (err) {
console.error('recover failed:' + err.message);
} else {
console.info('recover successfully.');
}
});
}).catch(error => {
console.error('getBundleInstaller failed. Cause: ' + error.message);
});
} catch (error) {
console.error('getBundleInstaller failed. Cause: ' + error.message);
}
```
## HashParam
Defines the hash parameters for bundle installation and uninstall.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Description |
| ---------- | ------ | ---------------- |
| moduleName | string | Module name of the bundle.|
| hashValue | string | Hash value. |
## InstallParam
Defines the parameters that need to be specified for bundle installation, uninstall, or recovering.
**System capability**: SystemCapability.BundleManager.BundleFramework.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Type | Description |
| ------------------------------ | ------------------------------ | ------------------ |
| userId | number | User ID. You can use [queryOsAccountLocalIdFromProcess](js-apis-osAccount.md#queryosaccountlocalidfromprocess9) to obtain the user of the current process.|
| installFlag | number | Installation flag. The value **0** means initial installation and **1** means overwrite installation.|
| isKeepData | boolean | Whether to retain the data directory during bundle uninstall.|
| hashParams | Array<[HashParam](#hashparam)> | Hash parameters. |
| crowdtestDeadline| number |End date of crowdtesting.|
# Bundle.launcherBundleManager
The **Bundle.launcherBundleManager** module providers APIs for the **Home Screen** application to obtain the launcher ability information and shortcut information.
> **NOTE**
>
> 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.
## Modules to Import
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
```
## launcherBundlemanager.getLauncherAbilityInfo<sup>9+</sup>
getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>) : void;
Obtains the launcher ability information based on the given bundle name and user ID. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes | Bundle name of the application.|
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| ----------------------------------- | --------------------------------------------------- |
| AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Callback used to return the **LauncherAbilityInfo** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700001 | The specified bundle name is not found. |
| 17700004 | The specified userId is not found. |
**Example**
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getLauncherAbilityInfo('com.example.demo', 100, (errData, data) => {
if (errData !== null) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
console.log("data is " + JSON.stringify(data));
})
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
## launcherBundlemanager.getLauncherAbilityInfo<sup>9+</sup>
getLauncherAbilityInfo(bundleName: string, userId: number) : Promise<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>;
Obtains the launcher ability information based on the given bundle name and user ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes | Bundle name of the application.|
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| ----------------------------- | -------------------------------------------------- |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise used to return the **LauncherAbilityInfo** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700001 | The specified bundle name is not found. |
| 17700004 | The specified userId is not found. |
**Example**
```typescript
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getLauncherAbilityInfo("com.example.demo", 100).then(data => {
console.log("data is " + JSON.stringify(data));
}).catch (errData => {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
})
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
## launcherBundlemanager.getAllLauncherAbilityInfo<sup>9+</sup>
getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>) : void;
Obtains the launcher ability information of all applications based on the given user ID. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------- |
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| ----------------------------------- | ------------------------------------------------------- |
| AsyncCallback\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Callback used to return the array of **LauncherAbilityInfo** objects obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700004 | The specified userId is not found. |
Example
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getAllLauncherAbilityInfo(100, (errData, data) => {
if (errData !== null) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
console.log("data is " + JSON.stringify(data));
});
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
## launcherBundlemanager.getAllLauncherAbilityInfo<sup>9+</sup>
getAllLauncherAbilityInfo(userId: number) : Promise<Array\<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>>;
Obtains the launcher ability information of all applications based on the given user ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------- |
| userId | number | Yes | User ID.|
**Return value**
| Type | Description |
| ----------------------------- | ------------------------------------------------------ |
| Promise\<Array<[LauncherAbilityInfo](js-apis-bundleManager-launcherAbilityInfo.md)>> | Promise used to return the array of **LauncherAbilityInfo** objects obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700004 | The specified userId is not found. |
**Example**
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getAllLauncherAbilityInfo(100).then(data => {
console.log("data is " + JSON.stringify(data));
}).catch (errData => {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
});
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
## launcherBundlemanager.getShortcutInfo<sup>9+</sup>
getShortcutInfo(bundleName :string, callback: AsyncCallback<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>) : void;
Obtains the shortcut information of the current user based on the given bundle name. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes | Bundle name of the application.|
**Return value**
| Type | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| AsyncCallback\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Callback used to return the **ShortcutInfo** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700001 | The specified bundle name is not found. |
**Example**
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getShortcutInfo("com.example.demo", (errData, data) => {
if (errData !== null) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
console.log("data is " + JSON.stringify(data));
});
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
## launcherBundlemanager.getShortcutInfo<sup>9+</sup>
getShortcutInfo(bundleName : string) : Promise<Array\<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>>;
Obtains the shortcut information of the current user based on the given bundle name. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_BUNDLE_INFO_PRIVILEGED
**System API**: This is a system API.
**System capability**: SystemCapability.BundleManager.BundleFramework.Launcher
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes | Bundle name of the application.|
**Return value**
| Template | Description |
| ---------------------- | ----------------------------------------------- |
| Promise\<Array<[ShortcutInfo](js-apis-bundleManager-shortcutInfo.md)>> | Promise used to return the **ShortcutInfo** object obtained.|
**Error codes**
For details about the error codes, see [Bundle Error Codes](../errorcodes/errorcode-bundle.md).
| ID| Error Message |
| -------- | ---------------------------------------- |
| 17700001 | The specified bundle name is not found. |
**Example**
```ts
import launcherBundleManager from '@ohos.bundle.launcherBundleManager';
try {
launcherBundleManager.getShortcutInfo("com.example.demo").then(data => {
console.log("data is " + JSON.stringify(data));
}).catch (errData => {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
});
} catch (errData) {
console.log(`errData is errCode:${errData.code} message:${errData.message}`);
}
```
# Network Policy Management
The Network Policy Management module provides APIs for managing network policies, through which you can control and manage the data volume used.
> **NOTE**
>
> 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.
## Modules to Import
```js
import policy from '@ohos.net.policy'
```
## policy.setBackgroundPolicy
setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\<void>): void
Sets a background network policy. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| isAllowed | boolean | Yes | Whether applications running in the background are allowed to use mobile data.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))), (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
});
```
## policy.setBackgroundPolicy
setBackgroundPolicy(isAllowed: boolean): Promise\<void>
Sets a background network policy. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| isAllowed | boolean | Yes | Whether applications running in the background are allowed to use mobile data.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getBackgroundPolicy
getBackgroundPolicy(callback: AsyncCallback\<boolean>): void;
Obtains the background network policy. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. If **true** is returned, applications running in the background are allowed to use mobile data.|
**Example**
```js
policy.getBackgroundPolicy((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
});
```
## policy.getBackgroundPolicy
getBackgroundPolicy(): Promise\<boolean>;
Obtains the background network policy. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|
**Example**
```js
policy.getBackgroundPolicy().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setPolicyByUid
setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\<void>): void;
Sets an application-specific network policy. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Unique ID of the application.|
| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
}
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (err, data) => {
this.callBack(err, data);
});
```
## policy.setPolicyByUid
setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
Sets an application-specific network policy. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Unique ID of the application.|
| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
}
policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getPolicyByUid
getPolicyByUid(uid: number, callback: AsyncCallback\<NetUidPolicy>): void;
Obtains an application-specific network policy by **uid**. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| callback | AsyncCallback\<[NetUidPolicy](#netuidpolicy)> | Yes | Callback used to return the result.|
**Example**
```js
policy.getPolicyByUid(Number.parseInt(this.firstParam), (err, data) => {
this.callBack(err, data);
});
```
## policy.getPolicyByUid
getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
Obtains an application-specific network policy by **uid**. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<[NetUidPolicy](#netuidpolicy)> | Promise used to return the result.|
**Example**
```js
policy.getPolicyByUid(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getUidsByPolicy
getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback\<Array\<number>>): void;
Obtains the UID array of applications configured with a certain application-specific network policy. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
| callback | AsyncCallback\<Array\<number>> | Yes | Callback used to return the result.|
**Example**
```js
policy.getUidsByPolicy(Number.parseInt(this.currentNetUidPolicy), (err, data) => {
this.callBack(err, data);
});
```
## policy.getUidsByPolicy
function getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
Obtains the UID array of applications configured with a certain application-specific network policy. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<number>> | Promise used to return the result.|
**Example**
```js
policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getNetQuotaPolicies
getNetQuotaPolicies(callback: AsyncCallback\<Array\<NetQuotaPolicy>>): void;
Obtains the network quota policies. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Yes | Callback used to return the result.|
**Example**
```js
policy.getNetQuotaPolicies((err, data) => {
this.callBack(err, data);
});
```
## policy.getNetQuotaPolicies
getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
Obtains the network quota policies. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Promise used to return the result.|
**Example**
```js
policy.getNetQuotaPolicies().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setNetQuotaPolicies
setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>, callback: AsyncCallback\<void>): void;
Sets an array of network quota policies. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList, (err, data) => {
this.callBack(err, data);
});
```
## policy.setNetQuotaPolicies
setNetQuotaPolicies(quotaPolicies: Array\<NetQuotaPolicy>): Promise\<void>;
Sets an array of network quota policies. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
this.netQuotaPolicyList.push(param);
policy.setNetQuotaPolicies(this.netQuotaPolicyList).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.restoreAllPolicies
restoreAllPolicies(iccid: string, callback: AsyncCallback\<void>): void;
Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | Yes| SIM card ID.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.restoreAllPolicies
restoreAllPolicies(iccid: string): Promise\<void>;
Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | Yes| SIM card ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
this.firstParam = iccid;
policy.restoreAllPolicies(this.firstParam).then((err, data){
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\<boolean>): void;
Checks whether an application is allowed to access metered networks. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| isMetered | boolean | Yes| Whether the network is a metered network.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the application is allowed to access metered networks, and **false** means the opposite.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (err, data) => {
this.callBack(err, data);
});
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
Checks whether an application is allowed to access metered networks. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| isMetered | boolean | Yes| Whether the network is a metered network.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\<boolean>): void;
Checks whether an application is allowed to access the given network. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| iface | string | Yes| Name of the target network.|
| callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the application is allowed to access the given network, and **false** means the opposite.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), iface: this.secondParam
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.isUidNetAllowed
isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
Checks whether an application is allowed to access the given network. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| iface | string | Yes| Name of the target network.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<boolean> | Promise used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), iface: this.secondParam
}
policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.setDeviceIdleAllowlist
setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\<void>): void;
Sets whether to add an application to the device idle allowlist. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
| callback | callback: AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
}
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (err, data) => {
this.callBack(err, data);
});
```
## policy.setDeviceIdleAllowlist
setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
Sets whether to add an application to the device idle allowlist. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
let param = {
uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
}
policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getDeviceIdleAllowlist
getDeviceIdleAllowList(callback: AsyncCallback\<Array\<number>>): void;
Obtains the UID array of applications that are on the device idle allowlist. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<Array\<number>> | Yes | Callback used to return the result.|
**Example**
```js
policy.getDeviceIdleAllowList((err, data) => {
this.callBack(err, data);
});
```
## policy.getDeviceIdleAllowlist
getDeviceIdleAllowList(): Promise\<Array\<number>>;
Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<Array\<number>> | Promise used to return the result.|
**Example**
```js
policy.getDeviceIdleAllowList().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.getBackgroundPolicyByUid
getBackgroundPolicyByUid(uid: number, callback: AsyncCallback\<NetBackgroundPolicy>): void;
Obtains the background network policies configured for the given application. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
| callback | AsyncCallback\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Yes | Callback used to return the result.|
**Example**
```js
this.firstParam = uid
policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam), (err, data) => {
this.callBack(err, data);
});
```
## policy.getBackgroundPolicyByUid
getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
Obtains the background network policies configured for the given application. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes| Unique ID of the application.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Promise used to return the result.|
**Example**
```js
this.firstParam = uid
policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.resetPolicies
resetPolicies(iccid: string, callback: AsyncCallback\<void>): void;
Resets the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | Yes| SIM card ID.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
this.firstParam = iccid
policy.resetPolicies(this.firstParam, (err, data) => {
this.callBack(err, data);
});
```
## policy.resetPolicies
resetPolicies(iccid: string): Promise\<void>;
Resets the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| iccid | string | Yes| SIM card ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then((err, data) {
})
this.firstParam = iccid
policy.resetPolicies(this.firstParam).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.updateRemindPolicy
updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback\<void>): void;
Updates a reminder policy. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
| iccid | string | Yes| SIM card ID.|
| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
}
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (err, data) => {
this.callBack(err, data);
});
```
## policy.updateRemindPolicy
updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise\<void>;
Updates a reminder policy. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
| iccid | string | Yes| SIM card ID.|
| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
let param = {
netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
}
policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## policy.on
Functions as the handle to a network policy.
### on('netUidPolicyChange')
on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUidPolicy }>): void;
Subscribes to policy changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netUidPolicyChange | Yes| Event type. The value **netUidPolicyChange** indicates a policy change event.|
| callback | Callback\<{ uid: number, policy: [NetUidPolicy](#netuidpolicy) }> | Yes | Callback used to return the result.|
**Example**
```js
policy.on('netUidPolicyChange', (data) => {
this.log('on netUidPolicyChange: ' + JSON.stringify(data));
})
```
### on('netUidRuleChange')
on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule }>): void;
Subscribes to rule changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netUidRuleChange | Yes| Event type. The value **netUidRuleChange** indicates a rule change event.|
| callback | Callback\<{ uid: number, rule: [NetUidRule](#netuidrule) }> | Yes | Callback used to return the result.|
**Example**
```js
policy.on('netUidRuleChange', (data) => {
this.log('on netUidRuleChange: ' + JSON.stringify(data));
})
```
### on('netMeteredIfacesChange')
on(type: "netMeteredIfacesChange", callback: Callback\<Array\<string>>): void;
Subscribes to metered network name (specified by **iface**) changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netMeteredIfacesChange | Yes| Event type. The value **netMeteredIfacesChange** indicates a metered network name change event.|
| callback | Callback\<Array\<string>> | Yes | Callback used to return the result.|
**Example**
```js
policy.on('netMeteredIfacesChange', (data) => {
this.log('on netMeteredIfacesChange: ' + JSON.stringify(data));
})
```
### on('netQuotaPolicyChange')
on(type: "netQuotaPolicyChange", callback: Callback\<Array\<NetQuotaPolicy>>): void;
Subscribes to network quota policy changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netQuotaPolicyChange | Yes| Event type. The value **netQuotaPolicyChange** indicates a network quota policy change event.|
| callback | Callback\<Array\<[NetQuotaPolicy](#netquotapolicy)>> | Yes | Callback used to return the result.|
**Example**
```js
policy.on('netQuotaPolicyChange', (data) => {
this.log('on netQuotaPolicyChange: ' + JSON.stringify(data));
})
```
### on('netBackgroundPolicyChange')
on(type: "netBackgroundPolicyChange", callback: Callback\<boolean>): void;
Subscribes to background network policy changes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
| type | netBackgroundPolicyChange | Yes| Event type. The value **netBackgroundPolicyChange** indicates a background network policy change event.|
| callback | Callback\<boolean> | Yes | Callback used to return the result.|
**Example**
```js
policy.on('netBackgroundPolicyChange', (data) => {
this.log('on netBackgroundPolicyChange: ' + JSON.stringify(data));
})
```
## NetBackgroundPolicy
Enumerates the background network policies.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value | Description |
| ------------------------ | ---- | ---------------------- |
| NET_BACKGROUND_POLICY_NONE | 0 | Default policy.|
| NET_BACKGROUND_POLICY_ENABLE | 1 | Applications running in the background are allowed to access metered networks.|
| NET_BACKGROUND_POLICY_DISABLE | 2 | Applications running in the background are not allowed to access metered networks.|
| NET_BACKGROUND_POLICY_ALLOW_LIST | 3 | Only applications on the device idle allowlist are allowed to access metered networks when they are running in the background.|
## NetQuotaPolicy
Defines a network quota policy.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Description |
| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Network type.|
| iccid | string | Identifier of the SIM card on the metered cellular network. It is not used for Wi-Fi networks.|
| ident | string | Identifier of the SIM card on the metered cellular network. It is used for Wi-Fi networks. It is used together with **iccid**.|
| periodDuration | string | Start time of metering.|
| warningBytes | number | Data volume threshold for generating an alarm.|
| limitBytes | number | Data volume quota.|
| lastWarningRemind | string | Last time when an alarm was generated.|
| lastLimitRemind | string | Last time when the quota was exhausted.|
| metered | string | Whether the network is a metered network.|
| limitAction | [LimitAction](#limitaction) | Action to take when the data volume quota is reached.|
## LimitAction
Enumerates the actions that can be taken when the data volume quota is reached.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value| Description |
| ---------------------- | ----- | ------------ |
| LIMIT_ACTION_NONE | -1 | Default action.|
| LIMIT_ACTION_DISABLE | 0 | Internet access is disabled.|
| LIMIT_ACTION_AUTO_BILL| 1 | Users will be automatically charged for the data volume they use.|
## NetUidRule
Enumerates the metered network rules.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value| Description |
| ---------------------- | ----- | ------------ |
| NET_RULE_NONE | 0 | Default rule.|
| NET_RULE_ALLOW_METERED_FOREGROUND | 1 | Applications running in the foreground are allowed to access metered networks.|
| NET_RULE_ALLOW_METERED | 2 | Applications are allowed to access metered networks.|
| NET_RULE_REJECT_METERED | 4 | Applications are not allowed to access metered networks.|
| NET_RULE_ALLOW_ALL | 32 | Applications are allowed to access all networks (metered or non-metered).|
| NET_RULE_REJECT_ALL | 64 | Applications are not allowed to access any networks (metered or non-metered).|
## RemindType
Enumerates the reminder types.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value| Description |
| ---------------------- | - | ------- |
| REMIND_TYPE_WARNING | 1 | Warning.|
| REMIND_TYPE_LIMIT | 2 | Limit.|
## NetUidPolicy
Enumerates the application-specific network policies.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value| Description |
| ---------------------- | ----- | ------------ |
| NET_POLICY_NONE | 0 | Default network policy.|
| NET_POLICY_ALLOW_METERED_BACKGROUND | 1 | Applications running in the background are allowed to access metered networks.|
| NET_POLICY_REJECT_METERED_BACKGROUND | 2 | Applications running in the background are not allowed to access metered networks.|
# Network Traffic Management
The Network Traffic Management module collects statistics on the mobile data traffic and allows you to query the data volume by network interface (cellular or Wi-Fi) or application.
> **NOTE**
>
> 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.
## Modules to Import
```js
import statistics from '@ohos.net.statistics'
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string, callback: AsyncCallback\<number>): void
Obtains the volume of mobile data traffic received by a specified NIC. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceRxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string): Promise\<number>;
Obtains the volume of mobile data traffic received by a specified NIC. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceRxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string, callback: AsyncCallback\<number>): void
Obtains the volume of mobile data traffic sent by a specified NIC. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceTxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string): Promise\<number>;
Obtains the volume of mobile data traffic sent by a specified NIC. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceTxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by the cellular network. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularRxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic received by the cellular network. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by the cellular network. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic sent by the cellular network. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by all NICs. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllRxBytes(err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic received by all NICs. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by all NICs. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic sent by all NICs. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number, callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidRxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number): Promise\<number>;
Obtains the volume of mobile data traffic received by a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidRxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number, callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidTxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number): Promise\<number>;
Obtains the volume of mobile data traffic sent by a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidTxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
# TLSSocket
The Transport Layer Security (TLS) protocol is designed to help protect the privacy of information at the transport layer. TLSSocket is an extension to socket communication. It provides higher security than socket communication by adding a security protection layer, which consists of the following submodules: key, certificate, and communication.
> **NOTE**
>
> 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.
## Modules to Import
```js
import socket from '@ohos.net.tlssocket'
```
## socket.constructTLSSocketInstance
constructTLSSocketInstance(): TLSSocket
Creates a **TLSSocket** object.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Example**
```js
let tlssocket = socket.constructTLSSocketInstance();
```
## tlssocket.connect
connect(options: TLSConnectOptions, callback: AsyncCallback\<void>): void
Sets up a TLSSocket connection, and creates and initializes a TLS session. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ---------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | Yes | Parameters required for the connection.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
**Example**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options, (err, data) => {
console.info(err);
console.info(data);
});
```
## tlssocket.connect
connect(options: TLSConnectOptions): Promise\<void>;
Sets up a TLSSocket connection, and creates and initializes a TLS session. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | --------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | Yes | Parameters required for the connection.|
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
**Example**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options).then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCertificate
getCertificate(callback: AsyncCallback\<string>): void;
Obtains the local digital certificate after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result.|
**Example**
```js
tlssocket.getCertificate((err, data) => {
if (err) {
console.log("getCertificate callback error = " + err);
} else {
console.log("getCertificate callback = " + data);
}
});
```
## tlssocket.getCertificate
getCertificate():Promise\<string>;
Obtains the local digital certificate after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate(callback: AsyncCallback\<string>): void;
Obtains the remote digital certificate after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result.|
**Example**
```js
tlssocket.getRemoteCertificate((err, data) => {
if (err) {
console.log("getRemoteCertificate callback error = " + err);
} else {
console.log("getRemoteCertificate callback = " + data);
}
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate():Promise\<string>;
Obtains the remote digital certificate after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getRemoteCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getProtocol
getProtocol(callback: AsyncCallback\<string>): void;
Obtains the communication protocol after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getProtocol((err, data) => {
if (err) {
console.log("getProtocol callback error = " + err);
} else {
console.log("getProtocol callback = " + data);
}
});
```
## tlssocket.getProtocol
getProtocol():Promise\<string>;
Obtains the communication protocol after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getProtocol().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCipherSuites
getCipherSuites(callback: AsyncCallback\<Array\<string>>): void;
Obtains the cipher suites supported by both parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getCipherSuites((err, data) => {
if (err) {
console.log("getCipherSuites callback error = " + err);
} else {
console.log("getCipherSuites callback = " + data);
}
});
```
## tlssocket.getCipherSuites
getCipherSuites(): Promise\<Array\<string>>;
Obtains the cipher suites supported by both parties after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| ---------------------- | --------------------- |
| Promise\<Array\<string>> | Promise used to return the result.|
**Example**
```js
tlssocket.getCipherSuites().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string>>): void;
Obtains the signing algorithms supported by both parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getSignatureAlgorithms((err, data) => {
if (err) {
console.log("getSignatureAlgorithms callback error = " + err);
} else {
console.log("getSignatureAlgorithms callback = " + data);
}
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(): Promise\<Array\<string>>;
Obtains the signing algorithms supported by both parties after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| ---------------------- | -------------------- |
| Promise\<Array\<string>> | Promise used to return the result.|
**Example**
```js
tlssocket.getSignatureAlgorithms().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.close
close(callback: AsyncCallback\<void>): void;
Closes a TLSSocket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------------------| ---- | ---------------|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.close((err) => {
if (err) {
console.log("close callback error = " + err);
} else {
console.log("close success");
}
});
```
## tlssocket.close
close(): Promise\<void>;
Closes a TLSSocket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
tlssocket.close().then(() =>
console.log("close success");
}).catch(err => {
console.error(err);
});
```
## TLSConnectOptions
Defines a TLSSocket connection.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| -------------- | ------------------------------------- | -------------- |
| address | [NetAddress](#netaddress) | Gateway address. |
| secureOptions | [TLSSecureOptions](#tlssecureoptions) | TLS security options.|
| ALPNProtocols | Array\<string> | Application Layer Protocol Negotiation (ALPN) protocols. |
## NetAddress
Defines a network address.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| ------- | ------ | ---------------------------- |
| address | string | Network address. |
| family | number | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.|
| port | number | Port number. The value ranges from **0** to **65535**. |
## TLSSecureOptions
Defines TLS security options.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| --------------------- | ---------------------- | ---------------------- |
| ca | string \| Array\<string> | CA certificate. |
| cert | string | Local digital certificate. |
| key | string | Private key of the local digital certificate. |
| passwd | string | Password. |
| protocols | string | Protocols. |
| useRemoteCipherPrefer | boolean | Whether to use the remote cipher suite preferentially.|
| signatureAlgorithms | string | Signing algorithms. |
| cipherSuites | string | Cipher suites. |
# Bundle Error Codes
## 17700001 Nonexistent Bundle Name
## 17700001 Bundle Name Does Not Exist
**Error Message**
The specified bundle name is not found.
**Description**
This error code is reported when the bundle name passed in the API does not exist.
When a query API is called, the bundle name passed in does not exist.
**Possible Causes**
1. The bundle name is misspelled.
2. The corresponding application is not installed.
2. The corresponding bundle is not installed.
**Solution**
1. Check whether the spelling of the bundle name is correct.
2. Check whether the corresponding application is installed.
2. Check whether the corresponding bundle is installed.
## 17700002 Nonexistent Module Name
## 17700002 Module Name Does Not Exist
**Error Message**
The specified module name is not found.
**Description**
This error code is reported when the module name passed in the API does not exist.
When a query API or an installation-free API is called, the module name passed in does not exist.
**Possible Causes**
1. The module name is misspelled.
2. The module is not installed for the application.
2. The module is not installed.
**Solution**
1. Check whether the spelling of the module name is correct.
2. Check whether the module is installed for the application.
2. Check whether the module is installed.
## 17700003 Nonexistent Ability Name
## 17700003 Ability Name Does Not Exist
**Error Message**
The specified ability name is not found.
**Description**
This error code is reported when the ability name passed in the API does not exist.
When a query API is called, the ability name passed in does not exist.
**Possible Causes**
1. The ability name is misspelled.
2. The corresponding application is not installed.
2. The corresponding bundle is not installed.
**Solution**
1. Check whether the spelling of the ability name is correct.
2. Check whether the ability is installed for the application.
2. Check whether the ability is installed.
## 17700004 Nonexistent User ID
## 17700004 User ID Does Not Exist
**Error Message**
The specified user id is not found.
The specified user ID is not found.
**Description**
This error code is reported when the user ID passed in the API does not exist.
When a user-related API is called, the user ID passed in does not exist.
**Possible Causes**
The user ID is incorrect. The user does not exist.
......@@ -63,13 +63,13 @@ The user ID is incorrect. The user does not exist.
1. Check whether the user ID is correct.
2. Check whether the user exists.
## 17700005 Nonexistent Application ID
## 17700005 Application ID Does Not Exist
**Error Message**
The specified appId is not found.
The specified app ID is not found.
**Description**
This error code is reported when the value of **appId** passed in the API is an empty string.
When an API of the **appControl** module is called, the application ID passed in does not exist.
**Possible Causes**
**appId** is an empty string.
......@@ -77,13 +77,13 @@ This error code is reported when the value of **appId** passed in the API is an
**Solution**
Check whether **appId** is an empty string.
## 17700006 Nonexistent Permission
## 17700006 Permission Does Not Exist
**Error Message**
The specified permission is not found.
**Description**
This error code is reported when the permission passed in the API does not exist.
When the **getPermissionDef** API of the **bundleManager** module is called, the permission passed in does not exist.
**Possible Causes**
1. The permission name is misspelled.
......@@ -96,10 +96,10 @@ This error code is reported when the permission passed in the API does not exist
## 17700007 Incorrect Device ID
**Error Message**
The specified deviceId is not found.
The specified device ID is not found.
**Description**
This error code is reported when the device ID passed in the API is incorrect.
When an API of the **distributedBundle** module is called, the device ID passed in does not exist.
**Possible Causes**
1. The device ID is incorrect.
......@@ -109,13 +109,13 @@ This error code is reported when the device ID passed in the API is incorrect.
1. Check whether the device ID is correct.
2. Check whether the device ID exists.
## 17700010 Application Installation Failure Due to File Parsing Failure
## 17700010 Bundle Installation Failure Due to File Parsing Failure
**Error Message**
Failed to install the hap since the hap fails to be parsed.
Failed to install the HAP because the HAP fails to be parsed.
**Description**
This error code is reported when the application fails to be installed because the HAP fails to be parsed.
When the **install** API of the **installer** module is called, the HAP passed in fails to be parsed.
**Possible Causes**
1. The HAP is not in ZIP format.
......@@ -127,13 +127,13 @@ This error code is reported when the application fails to be installed because t
2. Check whether the configuration file is in [JSON format](../../quick-start/stage-structure.md).
3. Check whether an error message is displayed when DevEco Studio compiles the HAP. If necessary fields are missing, an error message will be displayed.
## 17700011 Application Installation Failure Due to Signature Verification Failure
## 17700011 Bundle Installation Failure Due to Signature Verification Failure
**Error Message**
Failed to install the hap since the hap signature fails to be verified.
Failed to install the HAP because the HAP signature fails to be verified.
**Description**
This error code is reported when the application fails to be installed due to signature verification failure.
Calling the **install** API of the **installer** module to install the bundle fails due to signature verification failure.
**Possible Causes**
......@@ -147,13 +147,13 @@ This error code is reported when the application fails to be installed due to si
2. Check whether the same certificate is used for signing multiple HAPs.
3. Check whether the certificate used for signing the upgrade HAP is the same as the certificate used for signing the installed HAP.
## 17700012 Application Installation Failure Due to Invalid File Path or Too Large File
## 17700012 Bundle Installation Failure Due to Invalid File Path or Too Large File
**Error Message**
Failed to install the hap since the path of the hap is invalid or too large size.
Failed to install the HAP because the HAP path is invalid or the HAP is too large.
**Description**
This error code is reported when the application fails to be installed because the HAP path is invalid or the HAP is too large.
Calling the **install** API of the **installer** module to install the bundle fails because the HAP path is invalid or the HAP is too large.
**Possible Causes**
1. The path of the HAP does not exist.
......@@ -165,13 +165,13 @@ This error code is reported when the application fails to be installed because t
2. Check whether the HAP is read only or executable.
3. Check whether the size of the HAP exceeds 4 GB.
## 17700015 Application Installation Failure Due to Different Configuration Information of Multiple HAP Packages
## 17700015 Bundle Installation Failure Due to Different Configuration Information of Multiple HAP Packages
**Error Message**
Failed to install haps since the configuration information of multi haps is inconsistent.
Failed to install the HAPs because they have different configuration information.
**Description**
This error code is reported when the application fails to be installed because the HAPs have different configuration information.
Calling the **install** API of the **installer** module to install the bundle fails because the HAPs have different configuration information.
**Possible Causes**
The fields under **app** in the configuration files of these HAPs are inconsistent.
......@@ -179,13 +179,13 @@ The fields under **app** in the configuration files of these HAPs are inconsiste
**Solution**
Check whether the fields under **app** are the same.
## 17700016 Application Installation Failure Due to Insufficient System Disk Space
## 17700016 Bundle Installation Failure Due to Insufficient System Disk Space
**Error Message**
Failed to install the hap since the system disk space is insufficient.
Failed to install the HAP because of insufficient system disk space.
**Description**
This error code is reported when the application fails to be installed due to insufficient system disk space.
Calling the **install** API of the **installer** module to install the bundle fails due to insufficient system disk space.
**Possible Causes**
The system disk space is insufficient.
......@@ -193,19 +193,19 @@ The system disk space is insufficient.
**Solution**
Check whether the system has sufficient disk space.
## 17700017 Application Installation Failure Because the Version to Install is Too Earlier
## 17700017 Bundle Installation Failure Because the Version to Install is Too Earlier
**Error Message**
Failed to install the hap since the version of the newly installed hap is too early.
Failed to install the HAP since the version of the HAP to install is too early.
**Description**
This error code is reported when the version number of the application to install is earlier than the version in use.
Calling the **install** API of the **installer** module to install the bundle fails because the version to install is earlier than the version in use.
**Possible Causes**
The version number is earlier than the version in use.
**Solution**
Ensure that the version of the application to install is later than the version in use.
Ensure that the version of the bundle to install is later than the version in use.
## 17700020 Failure to Uninstall Preinstalled Applications
......@@ -213,7 +213,7 @@ Ensure that the version of the application to install is later than the version
The preinstalled app cannot be uninstalled.
**Description**
This error code is reported when you attempt to uninstall a preinstalled application.
Calling the **uninstall** API of the **installer** module to uninstall a preinstalled application fails.
**Possible Causes**
1. You might want to uninstall a non-preinstalled application but passed the bundle name of a preinstalled app.
......@@ -229,7 +229,7 @@ This error code is reported when you attempt to uninstall a preinstalled applica
The specified uid is invalid.
**Description**
This error code is reported when the UID passed in the API is invalid.
When the **getBundleNameByUid** API of the **bundleManager** module is called, the UID passed in is invalid.
**Possible Causes**
1. The UID is misspelled.
......@@ -245,7 +245,7 @@ This error code is reported when the UID passed in the API is invalid.
The input source file is invalid.
**Description**
This error code is reported when the source file to be parsed is invalid.
When the **getBundleArchiveInfo** API of the **bundleManager** module is called, the HAP path passed in is invalid.
**Possible Causes**
1. The source file to be parsed does not exist.
......@@ -255,13 +255,13 @@ This error code is reported when the source file to be parsed is invalid.
1. Check whether the source file to be parsed exists.
2. Check whether the source file to be parsed is in ZIP format.
## 17700023 Nonexistent Default Application
## 17700023 Default Application Does Not Exist
**Error Message**
The specified default app does not exist.
**Description**
This error code is reported when the specified default application does not exist.
When the **getDefaultApplication** API of the **defaultAppManager** module is called, the specified default application does not exist.
**Possible Causes**
No default application is set for the device.
......@@ -269,13 +269,13 @@ No default application is set for the device.
**Solution**
Check whether the default application is set on the device.
## 17700024 Nonexistent Configuration File
## 17700024 Configuration File Does Not Exist
**Error Message**
Failed to get profile since no profile in the hap.
Failed to get the profile because there is no profile in the HAP.
**Description**
This error code is reported when you attempt to obtain the configuration file that does not exist.
When an API for querying the profile is called, the configuration file does not exist
**Possible Causes**
1. The metadata name passed in the API does not exist in the configuration file.
......@@ -291,7 +291,7 @@ This error code is reported when you attempt to obtain the configuration file th
The specified type is invalid.
**Description**
The type is invalid.
When an API of the **defaultAppManager** module is called, the type passed in is invalid.
**Possible Causes**
1. The type passed in the API is misspelled.
......@@ -300,27 +300,27 @@ The type is invalid.
**Solution**
Check whether the spelling of type is correct.
## 17700026 Application Disabled
## 17700026 Bundle Disabled
**Error Message**
The specified bundle is disabled.
**Description**
This error code is reported when the specified application is disabled.
When an API for querying bundle information is called, the specified bundle is disabled.
**Possible Causes**
The application on the device has been disabled and cannot be queried.
The bundle on the device has been disabled and cannot be queried.
**Solution**
Check whether the application on the device is disabled.
Check whether the bundle on the device is disabled.
## 17700027 Distributed Service Not Started
## 17700027 Distributed Service Is Not Started
**Error Message**
The distributed service is not running.
**Description**
This error code is reported when the distributed service is not started.
When an API of the **distributedBundle** module is called, the distributed service is not started.
**Possible Causes**
The device is not networked.
......@@ -333,7 +333,7 @@ Check whether the device is networked.
The ability does not match the type.
**Description**
This error code is reported when the ability and type passed in the API do not match.
When the **setDefaultApplication** API of the **defaultAppManager** module is called, the **ability** and **type** passed in do not match.
**Possible Causes**
The ability and type are misspelled.
......@@ -347,21 +347,21 @@ Check whether the spellings of ability and type are correct.
The specified ability is disabled.
**Description**
This error code is reported when the specified ability is disabled.
When an API for querying ability information is called, the specified ability is disabled.
**Possible Causes**
The specified ability is disabled.
**Solution**
Check whether the ability is disabled. You can run the [bm commands](../../../readme/bundle-management.md#bm-commands) to query the application information.
Check whether the ability is disabled. You can run the [bm commands](../../../readme/bundle-management.md#bm-commands) to query the information.
## 17700030 Failure in Clearing Cache Files
**Error Message**
The specified bundle does not support clearing cache files.
The specified bundle does not support clearing of cache files.
**Description**
This error code is reported when the application does not support cache file clearing.
When the **cleanBundleCacheFiles** API of the **bundleManager** module is called, the specified bundle does not support cache file clearing.
**Possible Causes**
The application is a system application and the **AllowAppDataNotCleared** field is configured in the signing certificate.
......
# Pan-Sensor Error Codes
## 14500101 Service exception.
### Error information
Service exception.
### Description
This error code is reported if the HDI service is abnormal when the **on**, **once**, or **off** interface of the sensor module is called.
### Possible Causes
The HDI service is abnormal.
### Procedure
1. Retry the operation at a specified interval (for example, 1s) or at an exponential increase interval.
2. If the operation fails for three consecutive times, stop the attempt. You can also attempt to obtain the sensor list to check for device availability.
## 14600101 Device operation failed.
### Error Message
Device operation failed.
### Description
This error code is reported if the HDI service is abnormal or the device is occupied when the **startVibration** interface of the vibrator module is called.
### Possible Causes
1. The HDI service is abnormal.
2. The device is occupied.
### Procedure
1. Retry the operation at a specified interval or at an exponential increase interval. If the operation fails for three consecutive times, stop the retry. You can also obtain the vibrator list to check for device availability.
2. Set a higher priority for the vibrator.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册