提交 68c9f0fd 编写于 作者: H HelloCrease

Merge branch 'OpenHarmony-4.0-Beta1' of https://gitee.com/HelloCrease/docs...

Merge branch 'OpenHarmony-4.0-Beta1' of https://gitee.com/HelloCrease/docs into OpenHarmony-4.0-Beta1
......@@ -187,7 +187,8 @@ zh-cn/application-dev/dfx/errormanager-guidelines.md @littlejerry1 @ccllee @chen
zh-cn/application-dev/key-features/multi-device-app-dev/ @lingminghw @crazyracing0726
zh-cn/application-dev/database/ @ge-yafang @feng-aiwen @gong-a-shi @logic42
zh-cn/application-dev/napi/native-window-guidelines.md @ge-yafang @zhangqiang183 @zhouyaoying @zxg-gitee
zh-cn/application-dev/napi/mindspore-lite-guidelines.md @ge-yafang @grbuzhidao @jianghui58 @auraxu
zh-cn/application-dev/napi/mindspore-lite-guidelines.md @ge-yafang @principal87 @jianghui58
zh-cn/application-dev/napi/neural-network-runtime-guidelines.md @ge-yafang @principal87 @win10wei
zh-cn/application-dev/napi/rawfile_guidelines.md @ningningW
zh-cn/application-dev/background-agent-scheduled-reminder/ @RayShih
zh-cn/application-dev/background-task-management/ @ningningW @wangwenli_wolf @tangtiantian2021 @nan-xiansen
......
# InputMethodExtensionAbility Development
# InputMethodExtensionAbility
## When to Use
[InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod-extension-ability.md), inherited from [ExtensionAbility](extensionability-overview.md), is used for developing input method applications.
......
......@@ -21,7 +21,7 @@ Due to the asynchronous I/O feature of JS, the hiTraceMeter module provides only
## Available APIs
The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference]( ../reference/apis/js-apis-hitracemeter.md).
The performance tracing APIs are provided by the **hiTraceMeter** module. For details, see [API Reference](../reference/apis/js-apis-hitracemeter.md).
**APIs for performance tracing**
......
# Notification
- [Notification Overview](notification-overview.md)
- [Notification Subscription (for System Applications Only)](notification-subscription.md)
- [Subscribing to Notifications (for System Applications Only)](notification-subscription.md)
- [Enabling Notification](notification-enable.md)
- [Notification Badge](notification-badge.md)
- [Managing the Notification Badge](notification-badge.md)
- Publishing a Notification
- [Publishing a Basic Notification](text-notification.md)
- [Publishing a Progress Notification](progress-bar-notification.md)
......
# Notification Badge
# Managing the Notification Badge
OpenHarmony provides APIs for setting the notification badge, which is displayed in the upper right corner of the application icon on the home screen to notify the user of the count of unread notifications.
......@@ -11,11 +11,11 @@ After a notification is read, the count on the badge is decremented by 1. If the
1. The notification service provides two methods to increase the count on the notification badge:
- When publishing a notification, pass the **badgeNumber** parameter in [NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest). After the notification is received, the count on the badge is incremented.
- When publishing a notification, pass the **badgeNumber** parameter in [NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest). After the notification is received, the count on the badge is incremented.
- Call the [setBadgeNumber](../reference/apis/js-apis-notificationManager.md#setbadgenumber) API to set the count on the badge.
- Call the [setBadgeNumber()](../reference/apis/js-apis-notificationManager.md#notificationmanagersetbadgenumber10) API to set the count on the badge.
2. To decrease the count on the badge, call the **setBadgeNumber** API.
2. To decrease the count on the badge, call the [setBadgeNumber()](../reference/apis/js-apis-notificationManager.md#notificationmanagersetbadgenumber10) API.
| API| Description|
| -------- | -------- |
......@@ -32,37 +32,37 @@ After a notification is read, the count on the badge is decremented by 1. If the
2. Increase the count on the badge.
When publishing a notification, pass the **badgeNumber** parameter in [NotificationRequest](../reference/apis/js-apis-notificationManager.md#notificationrequest). For details, see [Publishing a Basic Notification](text-notification.md).
When publishing a notification, pass the **badgeNumber** parameter in [NotificationRequest](../reference/apis/js-apis-inner-notification-notificationRequest.md#notificationrequest). For details, see [Publishing a Basic Notification](text-notification.md).
In this example, the **setBadgeNumber** API is called to add a badge. This API is called after a new notification is published.
```ts
function setBadgeNumberCallback(err) {
if (err) {
console.info(`Set badge failed code is ${err.code}, message is ${err.message}`);
} else {
console.info(`Set badge success`);
}
if (err) {
console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in seting badge number.`);
}
let badgeNumber = 10
let badgeNumber = 10;
notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback);
```
3. Reduce the count on the badge.
3. Decrease the count on the badge.
After a notification is read, the application needs to call the API to set the number of remaining unread notifications. The badge is then updated.
```ts
function setBadgeNumberCallback(err) {
if (err) {
console.info(`Set badge failed code is ${err.code}, message is ${err.message}`);
} else {
console.info(`Set badge success`);
}
if (err) {
console.error(`Failed to set badge number. Code is ${err.code}, message is ${err.message}`);
return;
}
console.info(`Succeeded in seting badge number.`);
}
let badgeNumber = 9
let badgeNumber = 9;
notificationManager.setBadgeNumber(badgeNumber, setBadgeNumberCallback);
```
......
# Notification Subscription (for System Applications Only)
# Subscribing to Notifications (for System Applications Only)
To receive notifications, an application must subscribe to notifications first. The notification subsystem provides two types of subscription APIs, allowing applications to subscribe to notifications from all applications or notifications from a specific application.
......@@ -13,14 +13,14 @@ The major APIs for notification subscription are described as follows. For detai
**Table 1** Major APIs for notification subscription
| Name | Description|
| API| Description|
| -------- | -------- |
| subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback<void>): void | Subscribes to notifications from a specific application.|
| subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void | Subscribes to notifications from all applications. |
**Table 2** Callbacks for notification subscription
| Name | Description|
| API| Description|
| -------- | -------- |
| onConsume?:(data: SubscribeCallbackData) => void | Callback for receiving notifications. |
| onCancel?:(data: SubscribeCallbackData) => void | Callback for canceling notifications. |
......
......@@ -13,7 +13,7 @@ Below you can see the process of adding a **WantAgent** object to a notification
For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md).
| Name| Description|
| API | Description|
| -------- | -------- |
| getWantAgent(info: WantAgentInfo, callback: AsyncCallback<WantAgent>): void | Creates a **WantAgent** object.|
| trigger(agent: WantAgent, triggerInfo: TriggerInfo, callback?: Callback<CompleteData>): void | Triggers a **WantAgent** object.|
......
......@@ -74,7 +74,7 @@ As shown above, the **module.json5** file contains several tags.
| Name| Description| Data Type| Initial Value Allowed|
| -------- | -------- | -------- | -------- |
| name | Name of the module. The value is a string with a maximum of 31 bytes and must be unique in the entire application. Chinese characters are not allowed.| String| No|
| name | Name of the module. The value is a string with a maximum of 31 bytes and must be unique in the entire application. | String| No|
| type | Type of the module. The options are as follows:<br>- **entry**: main module of the application.<br>- **feature**: dynamic feature module of the application.<br>- **har**: static shared module.<br>- **shared**: dynamic shared module.| String| No|
| srcEntry | Code path corresponding to the module. The value is a string with a maximum of 127 bytes.| String| Yes (initial value: left empty)|
| description | Description of the module. The value is a string with a maximum of 255 bytes or a string resource index.| String| Yes (initial value: left empty)|
......@@ -228,73 +228,6 @@ The **metadata** tag represents the custom metadata of the HAP file. The tag val
UIAbility configuration of the module, which is valid only for the current UIAbility component.
**By default, application icons cannot be hidden from the home screen in OpenHarmony.**
The OpenHarmony system imposes a strict rule on the presence of application icons. If no icon is configured in the HAP file of an application, the system uses the icon specified in the **app.json** file as the application icon and displays it on the home screen.
Touching this icon will direct the user to the application details screen in **Settings**, as shown in Figure 1.
To hide an application icon from the home screen, you must configure the **AllowAppDesktopIconHide** privilege. For details, see [Application Privilege Configuration Guide](../../device-dev/subsystems/subsys-app-privilege-config-guide.md).
**Objectives**:
This requirement on application icons is intended to prevent malicious applications from deliberately configuring no icon to block uninstallation attempts.
**Setting the application icon to be displayed on the home screen**:
Set **icon**, **label**, and **skills** under **abilities** in the **module.json5** file. In addition, make sure the **skills** configuration contains **ohos.want.action.home** and **entity.system.home**.
```
{
"module":{
...
"abilities": [{
"icon": "$media:icon",
"label": "Login",
"skills": [{
"actions": ["ohos.want.action.home"],
"entities": ["entity.system.home"],
"uris": []
}]
}],
...
}
}
```
**Display rules of application icons and labels on the home screen:**
* The HAP file contains UIAbility configuration.
* The application icon on the home screen is set under **abilities** in the **module.json5** file.
* The application does not have the privilege to hide its icon from the home screen.
* The application icon displayed on the home screen is the icon configured for the UIAbility.
* The application label displayed on the home screen is the label configured for the UIAbility. If no label is configured, the bundle name is returned.
* The name of the UIAbility is displayed.
* When the user touches the home screen icon, the home screen of the UIAbility is displayed.
* The application has the privilege to hide its icon from the home screen.
* The information about the application is not returned during home screen information query, and the icon of the application is not displayed on the home screen.
* The application icon on the home screen is not set under **abilities** in the **module.json5** file.
* The application does not have the privilege to hide its icon from the home screen.
* The application icon displayed on the home screen is the icon specified under **app**. (The **icon** field in the **app.json** file is mandatory.)
* The application label displayed on the home screen is the label specified under **app**. (The **label** field in the **app.json** file is mandatory.)
* Touching the application icon on the home screen will direct the user to the application details screen shown in Figure 1.
* The application has the privilege to hide its icon from the home screen.
* The information about the application is not returned during home screen information query, and the icon of the application is not displayed on the home screen.
* The HAP file does not contain UIAbility configuration.
* The application does not have the privilege to hide its icon from the home screen.
* The application icon displayed on the home screen is the icon specified under **app**. (The **icon** field in the **app.json** file is mandatory.)
* The application label displayed on the home screen is the label specified under **app**. (The **label** field in the **app.json** file is mandatory.)
* Touching the application icon on the home screen will direct the user to the application details screen shown in Figure 1.
* The application has the privilege to hide its icon from the home screen.
* The information about the application is not returned during home screen information query, and the icon of the application is not displayed on the home screen.<br><br>
**Figure 1** Application details screen
![Application details screen](figures/application_details.jpg)
**Table 6** abilities
| Name| Description| Data Type| Initial Value Allowed|
......@@ -325,6 +258,7 @@ Set **icon**, **label**, and **skills** under **abilities** in the **module.json
| minWindowHeight | Minimum window height supported by the UIAbility component, in vp. The minimum value is 0, and the value cannot be less than the minimum window height allowed by the platform or greater than the value of **maxWindowHeight**. For details about the window size, see [Constraints](../windowmanager/window-overview.md#constraints).| Number| Yes (initial value: minimum window height supported by the platform)|
| excludeFromMissions | Whether the UIAbility component is displayed in the recent task list.<br>- **true**: displayed in the recent task list.<br>- **false**: not displayed in the recent task list.<br>**NOTE**<br>This attribute applies only to system applications and does not take effect for third-party applications.| Boolean| Yes (initial value: **false**)|
| recoverable | Whether the application can be recovered to its previous state in case of a detected fault.<br>- **true**: The application can be recovered to its previous state in case of a detected fault.<br>- **false**: The application cannot be recovered to its previous state in case of a detected fault.| Boolean| Yes (initial value: **false**)|
| unclearableMission | Whether the UIAbility component is unclearable in the recent tasks list.<br>- **true**: The UIAbility component is unclearable in the recent tasks list.<br>- **false**: The UIAbility component is clearable in the recent tasks list.<br>**NOTE**<br>This attribute works only after the [AllowMissionNotCleared](../../device-dev/subsystems/subsys-app-privilege-config-guide.md) privilege is obtained.| Boolean| Yes (initial value: **false**)|
Example of the **abilities** structure:
......@@ -369,7 +303,8 @@ Example of the **abilities** structure:
"minWindowWidth": 1400,
"maxWindowHeight": 300,
"minWindowHeight": 200,
"excludeFromMissions": false
"excludeFromMissions": false,
"unclearableMission": false
}]
}
```
......@@ -441,12 +376,12 @@ The **extensionAbilities** tag represents the configuration of extensionAbilitie
| description | Description of the ExtensionAbility component. The value is a string with a maximum of 255 bytes or a resource index to the description.| String| Yes (initial value: left empty)|
| icon | Icon of the ExtensionAbility component. The value is an icon resource index. If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| Yes (initial value: left empty)|
| label | Name of the ExtensionAbility component displayed to users. The value is a string resource index.<br>**NOTE**<br>If **ExtensionAbility** is set to **MainElement** of the current module, this attribute is mandatory and its value must be unique in the application.| String| No|
| type | Type of the ExtensionAbility component. The options are as follows:<br>- **form**: ExtensionAbility of a widget.<br>- **workScheduler**: ExtensionAbility of a Work Scheduler task.<br>- **inputMethod**: ExtensionAbility of an input method.<br>- **service**: service component running in the background.<br>- **accessibility**: ExtensionAbility of an accessibility feature.<br>- **dataShare**: ExtensionAbility for data sharing.<br>- **fileShare**: ExtensionAbility for file sharing.<br>- **staticSubscriber**: ExtensionAbility for static broadcast.<br>- **wallpaper**: ExtensionAbility of the wallpaper.<br>- **backup**: ExtensionAbility for data backup.<br>- **window**: ExtensionAbility of a window. This type of ExtensionAbility creates a window during startup for which you can develop the GUI. The window is then combined with other application windows through **abilityComponent**.<br>- **thumbnail**: ExtensionAbility for obtaining file thumbnails. You can provide thumbnails for files of customized file types.<br>- **preview**: ExtensionAbility for preview. This type of ExtensionAbility can parse the file and display it in a window. You can combine the window with other application windows.<br>- **print**: ExtensionAbility for the print framework.<br>- **driver**: ExtensionAbility for the driver framework.<br>**NOTE**<br>The **service** and **dataShare** types apply only to system applications and do not take effect for third-party applications.| String| No|
| type | Type of the ExtensionAbility component. The options are as follows:<br>- **form**: ExtensionAbility of a widget.<br>- **workScheduler**: ExtensionAbility of a Work Scheduler task.<br>- **inputMethod**: ExtensionAbility of an input method.<br>- **service**: service component running in the background.<br>- **accessibility**: ExtensionAbility of an accessibility feature.<br>- **dataShare**: ExtensionAbility for data sharing.<br>- **fileShare**: ExtensionAbility for file sharing.<br>- **staticSubscriber**: ExtensionAbility for static broadcast.<br>- **wallpaper**: ExtensionAbility of the wallpaper.<br>- **backup**: ExtensionAbility for data backup.<br>- **window**: ExtensionAbility of a window. This type of ExtensionAbility creates a window during startup for which you can develop the GUI. The window is then combined with other application windows through **abilityComponent**.<br>- **thumbnail**: ExtensionAbility for obtaining file thumbnails. You can provide thumbnails for files of customized file types.<br>- **preview**: ExtensionAbility for preview. This type of ExtensionAbility can parse the file and display it in a window. You can combine the window with other application windows.<br>- **print**: ExtensionAbility for the print framework.<br>- **push**: ExtensionAbility to be pushed.<br>- **driver**: ExtensionAbility for the driver framework.<br>**NOTE**<br>The **service** and **dataShare** types apply only to system applications and do not take effect for third-party applications.| String| No|
| permissions | Permissions required for another application to access the ExtensionAbility component.<br>The value is generally in the reverse domain name notation and contains a maximum of 255 bytes. It is an array of permission names predefined by the system or customized. The name of a customized permission must be the same as the **name** value of a permission defined in the **defPermissions** attribute.| String array| Yes (initial value: left empty)|
| uri | Data URI provided by the ExtensionAbility component. The value is a string with a maximum of 255 bytes, in the reverse domain name notation.<br>**NOTE**<br>This attribute is mandatory when the type of the ExtensionAbility component is set to **dataShare**.| String| Yes (initial value: left empty)|
|skills | Feature set of [wants](../application-models/want-overview.md) that can be received by the ExtensionAbility component.<br>Configuration rule: In an entry package, you can configure multiple **skills** attributes with the entry capability. (A **skills** attribute with the entry capability is the one that has **ohos.want.action.home** and **entity.system.home** configured.) The **label** and **icon** in the first ExtensionAbility that has **skills** configured are used as the **label** and **icon** of the entire OpenHarmony service/application.<br>**NOTE**<br>The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application, but not for an OpenHarmony service.| Array| Yes (initial value: left empty)|
| [metadata](#metadata)| Metadata of the ExtensionAbility component.| Object| Yes (initial value: left empty)|
| exported | Whether the ExtensionAbility component can be called by other applications. <br>- **true**: The ExtensionAbility component can be called by other applications.<br>- **false**: The UIAbility component cannot be called by other applications.| Boolean| Yes (initial value: **false**)|
| exported | Whether the ExtensionAbility component can be called by other applications. <br>- **true**: The ExtensionAbility component can be called by other applications.<br>- **false**: The ExtensionAbility component cannot be called by other applications.| Boolean| Yes (initial value: **false**)|
Example of the **extensionAbilities** structure:
......
......@@ -145,9 +145,12 @@
- [NotificationTemplate](js-apis-inner-notification-notificationTemplate.md)
- [NotificationUserInput](js-apis-inner-notification-notificationUserInput.md)
- Common Events
- [Common Events of the Ability Subsystem](common_event/commonEvent-ability.md)
- [Common Events of the Bundle Management Subsystem](common_event/commonEvent-bundleManager.md)
- [Common Events of the Notification Service](common_event/commonEvent-ans.md)
- [Common Events of the Resource Scheduling Subsystem](common_event/commonEvent-resourceschedule.md)
- [Common Events of the Telephony Subsystem](common_event/commonEvent-telephony.md)
- [Common Events of the USB Subsystem](common_event/commonEvent-usb.md)
- Bundle Management
- [@ohos.bundle.appControl (appControl)](js-apis-appControl.md)
- [@ohos.bundle.bundleManager (bundleManager)](js-apis-bundleManager.md)
......@@ -211,9 +214,9 @@
- [@ohos.multimedia.image (Image Processing)](js-apis-image.md)
- [@ohos.multimedia.media (Media)](js-apis-media.md)
- [@ohos.multimedia.systemSoundManager (System Sound Management)](js-apis-systemSoundManager.md)
- multimedia
- Multimedia
- [ringtonePlayer (Ringtone Player)](js-apis-inner-multimedia-ringtonePlayer.md)
- Resource Manager
- [@ohos.i18n (Internationalization)](js-apis-i18n.md)
- [@ohos.intl (Internationalization)](js-apis-intl.md)
......@@ -241,6 +244,7 @@
- [PermissionRequestResult](js-apis-permissionrequestresult.md)
- Data Management
- [@ohos.data.cloudData (Device-Cloud Synergy)](js-apis-data-cloudData.md)
- [@ohos.data.dataAbility (DataAbility Predicates)](js-apis-data-ability.md)
- [@ohos.data.dataShare (DataShare)](js-apis-data-dataShare.md)
- [@ohos.data.dataSharePredicates (DataShare Predicates)](js-apis-data-dataSharePredicates.md)
......
......@@ -64,7 +64,7 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 or the permissionName exceeds 256 bytes. |
| 12100001 | The parameter is invalid. The tokenID is 0, or the permissionName exceeds 256 bytes. |
**Example**
......@@ -74,7 +74,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
try {
atManager.checkAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
atManager.checkAccessToken(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS').then((data) => {
console.log(`checkAccessToken success, data->${JSON.stringify(data)}`);
}).catch((err) => {
console.log(`checkAccessToken fail, err->${JSON.stringify(err)}`);
......@@ -111,14 +111,14 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 or the permissionName exceeds 256 bytes. |
| 12100001 | The parameter is invalid. The tokenID is 0, or the permissionName exceeds 256 bytes. |
**Example**
```js
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let data = atManager.verifyAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
let data = atManager.verifyAccessTokenSync(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS');
console.log(`data->${JSON.stringify(data)}`);
```
......@@ -154,7 +154,7 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0, the permissionName is greater than 256 bytes, or the flags value is invalid. |
| 12100001 | The parameter is invalid. The tokenID is 0, the permissionName exceeds 256 bytes, or the flags value is invalid. |
| 12100002 | The specified tokenID does not exist. |
| 12100003 | The specified permission does not exist. |
| 12100006 | The application specified by the tokenID is not allowed to be granted with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
......@@ -169,7 +169,7 @@ let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlags = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
atManager.grantUserGrantedPermission(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS', permissionFlags).then(() => {
console.log('grantUserGrantedPermission success');
}).catch((err) => {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
......@@ -221,7 +221,7 @@ let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlags = 1;
try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
atManager.grantUserGrantedPermission(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS', permissionFlags, (err, data) => {
if (err) {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -280,7 +280,7 @@ let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlags = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
atManager.revokeUserGrantedPermission(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS', permissionFlags).then(() => {
console.log('revokeUserGrantedPermission success');
}).catch((err) => {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
......@@ -332,7 +332,7 @@ let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let permissionFlags = 1;
try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
atManager.revokeUserGrantedPermission(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS', permissionFlags, (err, data) => {
if (err) {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -375,7 +375,7 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 or the permissionName exceeds 256 bytes. |
| 12100001 | The parameter is invalid. The tokenID is 0, or the permissionName exceeds 256 bytes. |
| 12100002 | The specified tokenID does not exist. |
| 12100003 | The specified permission does not exist. |
| 12100006 | The operation is not allowed. Either the application is a sandbox or the tokenID is from a remote device. |
......@@ -389,7 +389,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
try {
atManager.getPermissionFlags(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS").then((data) => {
atManager.getPermissionFlags(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS').then((data) => {
console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`);
}).catch((err) => {
console.log(`getPermissionFlags fail, err->${JSON.stringify(err)}`);
......@@ -443,7 +443,7 @@ Subscribes to permission state changes of the specified applications and permiss
| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type to subscribe to. The value is **'permissionStateChange'**, which indicates the permission grant state change. |
| tokenIDList | Array&lt;number&gt; | Yes | Token IDs of the applications to observe. If this parameter is left empty, the permission grant state changes of all applications are observed. |
| permissionList | Array&lt;Permissions&gt; | Yes | Permissions to observe. If this parameter is left empty, the grant state changes of all permissions are observed. |
| permissionList | Array&lt;Permissions&gt; | Yes | List of permission names. If this parameter is left empty, the grant state changes of all permissions are subscribed to. |
| callback | Callback&lt;[PermissionStateChangeInfo](#permissionstatechangeinfo9)&gt; | Yes| Callback invoked to return the permission grant state change.|
**Error codes**
......@@ -452,7 +452,7 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 or the permissionName exceeds 256 bytes. |
| 12100001 | The parameter is invalid. The tokenID is 0, or the permissionName exceeds 256 bytes. |
| 12100004 | The interface is called repeatedly with the same input. |
| 12100005 | The registration time has exceeded the limitation. |
| 12100007 | Service is abnormal. |
......@@ -461,16 +461,16 @@ For details about the error codes, see [Application Access Control Error Codes](
**Example**
```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
import {Permissions} from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
let permissionList: Array<Permissions> = ['ohos.permission.DISTRIBUTED_DATASYNC'];
try {
atManager.on('permissionStateChange', tokenIDList, permissionList, (data) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
console.debug('receive permission state change, data:' + JSON.stringify(data));
});
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
......@@ -505,20 +505,20 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenIDs or permissionNames in the list are all invalid. |
| 12100004 | The interface is not used together with "on". |
| 12100004 | The interface is not used together with 'on'. |
| 12100007 | Service is abnormal. |
| 12100008 | Out of memory. |
**Example**
```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
import {Permissions} from '@ohos.abilityAccessCtrl';
import bundleManager from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
let permissionList: Array<Permissions> = ['ohos.permission.DISTRIBUTED_DATASYNC'];
try {
atManager.off('permissionStateChange', tokenIDList, permissionList);
} catch(err) {
......@@ -558,7 +558,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
let promise = atManager.verifyAccessToken(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS');
promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
......@@ -599,10 +599,10 @@ For details about the error codes, see [Application Access Control Error Codes](
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"], (err, data)=>{
console.info("data:" + JSON.stringify(data));
console.info("data permissions:" + data.permissions);
console.info("data authResults:" + data.authResults);
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.CAMERA'], (err, data)=>{
console.info('data:' + JSON.stringify(data));
console.info('data permissions:' + data.permissions);
console.info('data authResults:' + data.authResults);
});
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
......@@ -650,12 +650,12 @@ For details about the error codes, see [Application Access Control Error Codes](
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, ["ohos.permission.CAMERA"]).then((data) => {
console.info("data:" + JSON.stringify(data));
console.info("data permissions:" + data.permissions);
console.info("data authResults:" + data.authResults);
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.CAMERA']).then((data) => {
console.info('data:' + JSON.stringify(data));
console.info('data permissions:' + data.permissions);
console.info('data authResults:' + data.authResults);
}).catch((err) => {
console.info("data:" + JSON.stringify(err));
console.info('data:' + JSON.stringify(err));
})
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
......@@ -694,7 +694,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let promise = atManager.verifyAccessToken(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
let promise = atManager.verifyAccessToken(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS');
promise.then(data => {
console.log(`promise: data->${JSON.stringify(data)}`);
});
......@@ -727,14 +727,14 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 or the permissionName exceeds 256 bytes. |
| 12100001 | The parameter is invalid. The tokenID is 0, or the permissionName exceeds 256 bytes. |
**Example**
```js
let atManager = abilityAccessCtrl.createAtManager();
let tokenID = 0; // Use bundleManager.getApplicationInfo() to obtain the token ID for a system application, and use bundleManager.getBundleInfoForSelf() to obtain the token ID for a non-system application.
let data = atManager.checkAccessTokenSync(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS");
let data = atManager.checkAccessTokenSync(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS');
console.log(`data->${JSON.stringify(data)}`);
```
......
......@@ -17,16 +17,15 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
Enumerates the NFC card emulation types.
> **NOTE**
>
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description|
| -------- | -------- | -------- |
| HCE | 0 | HCE.|
| UICC | 1 | Subscriber identity module (SIM) card emulation.|
| ESE | 2 | embedded Secure Element (eSE) emulation.|
| Name | Value | Description |
| ---- | ---- | -------- |
| HCE | 0 | HCE.|
| UICC | 1 | Subscriber identity module (SIM) card emulation.|
| ESE | 2 | embedded Secure Element (eSE) emulation. |
## CardType<sup>9+</sup>
......@@ -34,10 +33,10 @@ Enumerates the types of services used by the card emulation application.
**System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description|
| -------- | -------- | -------- |
| Name | Value | Description |
| ------- | --------- | ----------------- |
| PAYMENT | "payment" | Payment type.|
| OTHER | "other" | Other types.|
| OTHER | "other" | Other types.|
## isSupported
......@@ -46,21 +45,20 @@ isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported.
> **NOTE**
>
> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9).
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- |
| feature | number | Yes | Card emulation type. For details, see [FeatureType](#featuretype).|
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ---------------------------------------- |
| feature | number | Yes | Card emulation type. For details, see [FeatureType](#featuretype).|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| **Type** | **Description** |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
## hasHceCapability<sup>9+</sup>
......@@ -75,8 +73,8 @@ Checks whether HCE is supported.
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| **Type** | **Description** |
| ------- | -------------------------------- |
| boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
## isDefaultService<sup>9+</sup>
......@@ -91,15 +89,15 @@ Checks whether an application is the default application of the specified servic
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which consists of the bundle name and component name.|
| type | [CardType](#cardtype9) | Yes| Card emulation service type.|
| Name | Type | Mandatory | Description |
| ----------- | ---------------------------------------- | ---- | ----------------------- |
| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes | Application description, which consists of the bundle name and component name.|
| type | [CardType](#cardtype9) | Yes | Card emulation service type. |
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| **Type** | **Description** |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
**Example**
......@@ -110,13 +108,11 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
var isHceSupported = cardEmulation.isSupported(cardEmulation.FeatureType.HCE);
if (!isHceSupported) {
console.log('this device is not supported for HCE, ignore it.');
return;
}
var hasHceCap = cardEmulation.hasHceCapability();
if (!hasHceCap) {
console.log('this device hasHceCapability false, ignore it.');
return;
}
var elementName = {
......
......@@ -28,6 +28,23 @@ Initializes the active tag chip.
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.initialize<sup>9+</sup>
initialize(): void
Initializes the active tag chip.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
## connectedTag.uninit
uninit(): boolean
......@@ -44,6 +61,23 @@ Uninitializes the active tag resources.
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## connectedTag.uninitialize<sup>9+</sup>
uninitialize(): void
Uninitializes the active tag resources.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
## connectedTag.readNdefTag
readNdefTag(): Promise&lt;string&gt;
......@@ -72,6 +106,41 @@ connectedTag.readNdefTag().then((data) => {
});
```
## connectedTag.read<sup>9+</sup>
read(): Promise&lt;number[]&gt;
Reads the content of this active tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;number[]&gt; | Promise used to return the content of the active tag.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
connectedTag.read().then((data) => {
console.log("connectedTag read Promise data = " + data);
}).catch((err)=> {
console.log("connectedTag read Promise err: " + err);
});
```
## connectedTag.readNdefTag
readNdefTag(callback: AsyncCallback&lt;string&gt;): void
......@@ -102,6 +171,43 @@ connectedTag.readNdefTag((err, data)=> {
});
```
## connectedTag.read<sup>9+</sup>
read(callback: AsyncCallback&lt;number[]&gt;): void
Reads the content of this active tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number[]&gt; | Yes| Callback invoked to return the active tag content obtained.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
connectedTag.read((err, data)=> {
if (err) {
console.log("connectedTag read AsyncCallback err: " + err);
} else {
console.log("connectedTag read AsyncCallback data: " + data);
}
});
```
## connectedTag.writeNdefTag
writeNdefTag(data: string): Promise&lt;void&gt;
......@@ -137,6 +243,48 @@ connectedTag.writeNdefTag(rawData).then(() => {
});
```
## connectedTag.write<sup>9+</sup>
write(data: number[]): Promise&lt;void&gt;
Writes data to this active tag. This API uses a promise to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | number[] | Yes| Data to be written to the active tag. The value is a hexadecimal number ranging from 0x00 to 0xFF.|
**Return value**
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
var rawData = [0x01, 0x02, 0x03]; // change it tobe correct.
connectedTag.write(rawData).then(() => {
console.log("connectedTag write NdefTag Promise success.");
}).catch((err)=> {
console.log("connectedTag write NdefTag Promise err: " + err);
});
```
## connectedTag.writeNdefTag
writeNdefTag(data: string, callback: AsyncCallback&lt;void&gt;): void
......@@ -169,6 +317,45 @@ connectedTag.writeNdefTag(rawData, (err)=> {
});
```
## connectedTag.write<sup>9+</sup>
write(data: number[], callback: AsyncCallback&lt;void&gt;): void
Writes data to this active tag. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.ConnectedTag
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| data | number[] | Yes| Data to be written to the active tag. The value is a hexadecimal number ranging from 0x00 to 0xFF.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the active tag content obtained.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error Message|
| -------- | -------- |
| 3200101 | Connected NFC tag running state is abnormal in service. |
**Example**
```js
import connectedTag from '@ohos.connectedTag';
var rawData = [0x01, 0x02, 0x03]; // change it tobe correct.
connectedTag.write(rawData, (err)=> {
if (err) {
console.log("connectedTag write NdefTag AsyncCallback err: " + err);
} else {
console.log("connectedTag write NdefTag AsyncCallback success.");
}
});
```
## connectedTag.on('notify')
on(type: "notify", callback: Callback&lt;number&gt;): void
......
# @ohos.data.cloudData (Device-Cloud Synergy)
The **cloudData** module provides the capability of synchronizing the structured data (in RDB stores) between the device and cloud. The cloud serves as the central node of data. The devices synchronize data with the data in the cloud to implement cloud data backup and data consistency between the devices with the same account.
This module provides the following common functions:
- [Config](#config): provides methods for configuring device-cloud synergy, including enabling and disabling cloud synchronization, clearing data, and notifying data changes.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import cloudData from '@ohos.data.cloudData';
```
## Action
Enumerates the actions for clearing the cloud information about the local data.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
| Name | Description |
| --------- | ---------------------------- |
| CLEAR_CLOUD_INFO | Clear the cloud ID information.|
| CLEAR_CLOUD_DATA_AND_INFO |Clear all cloud data, including cloud ID information and data downloaded from the cloud (excluding the data modified or generated locally). |
## Config
Provides methods for configuring device-cloud synergy, including enabling and disabling cloud synchronization, clearing data, and notifying data changes.
### enableCloud
static enableCloud(accountId: string, switches: {[bundleName: string]: boolean}, callback: AsyncCallback&lt;void&gt;):void
Enables device-cloud synergy. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| accountId | string | Yes | ID of the target cloud. |
| switches | {[bundleName: string]: boolean} | Yes | Device-cloud synergy switches for applications. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let account = 'test_id';
let switches = { 'test_bundleName1': true, 'test_bundleName2': false };
try {
cloudData.Config.enableCloud(account, switches, function (err) {
if (err === undefined) {
console.info('Succeeded in enabling cloud');
} else {
console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`);
}
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### enableCloud
static enableCloud(accountId: string, switches: {[bundleName: string]: boolean}): Promise&lt;void&gt;
Enables device-cloud synergy. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| accountId | string | Yes | ID of the target cloud. |
| switches | {[bundleName: string]: boolean} | Yes | Device-cloud synergy switches for applications. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let account = 'test_id';
let switches = { 'test_bundleName1': true, 'test_bundleName2': false };
try {
cloudData.Config.enableCloud(account, switches).then(() => {
console.info('Succeeded in enabling cloud');
}).catch((err) => {
console.error(`Failed to enable.Code: ${err.code}, message: ${err.message}`);
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### disableCloud
static disableCloud(accountId: string, callback: AsyncCallback&lt;void&gt;):void
Disables device-cloud synergy. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------- | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let account = 'test_id';
try {
cloudData.Config.disableCloud(account, function (err) {
if (err === undefined) {
console.info('Succeeded in disabling cloud');
} else {
console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`);
}
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### disableCloud
static disableCloud(accountId: string): Promise&lt;void&gt;
Disables device-cloud synergy. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let account = 'test_id';
try {
cloudData.Config.disableCloud(account).then(() => {
console.info('Succeeded in disabling cloud');
}).catch((err) => {
console.error(`Failed to disableCloud. Code: ${err.code}, message: ${err.message}`);
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### changeAppCloudSwitch
static changeAppCloudSwitch(accountId: string,bundleName:string,status:boolean, callback: AsyncCallback&lt;void&gt;):void
Changes the device-cloud synergy switch for an application. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ---------------------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName| string | Yes | Name of the target application.|
| status | boolean | Yes | Setting of the device-cloud synergy switch for the application. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let account = 'test_id';
let bundleName = 'test_bundleName';
try {
cloudData.Config.changeAppCloudSwitch(account, bundleName, true, function (err) {
if (err === undefined) {
console.info('Succeeded in changing App cloud switch');
} else {
console.error(`Failed to change App cloud switch. Code: ${err.code}, message: ${err.message}`);
}
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### changeAppCloudSwitch
static changeAppCloudSwitch(accountId: string,bundleName:string,status:boolean): Promise&lt;void&gt;
Changes the device-cloud synergy switch for an application. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Config
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------------------- | ---- | ---------------------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName| string | Yes | Name of the target application.|
| status | boolean | Yes | Setting of the device-cloud synergy switch for the application. The value **true** means to enable the device-cloud synergy; the value **false** means the opposite.|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let account = 'test_id';
let bundleName = 'test_bundleName';
try {
cloudData.Config.changeAppCloudSwitch(account, bundleName, true).then(() => {
console.info('Succeeded in changing App cloud switch');
}).catch((err) => {
console.error(`Failed to change App cloud switch. Code is ${err.code}, message is ${err.message}`);
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### notifyDataChange
static notifyDataChange(accountId: string,bundleName:string, callback: AsyncCallback&lt;void&gt;):void
Notifies the data changes in the cloud. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------- | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName | string | Yes | Name of the target application. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let account = 'test_id';
let bundleName = 'test_bundleName';
try {
cloudData.Config.notifyDataChange(account, bundleName, function (err) {
if (err === undefined) {
console.info('Succeeded in notifying the change of data');
} else {
console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`);
}
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
### notifyDataChange
static notifyDataChange(accountId: string,bundleName:string): Promise&lt;void&gt;
Notifies the data changes in the cloud. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.CLOUDDATA_CONFIG
**System capability**: SystemCapability.DistributedDataManager.CloudSync.Server
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ---------------- |
| accountId | string | Yes | ID of the target cloud.|
| bundleName | string | Yes | Name of the target application. |
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let account = 'test_id';
let bundleName = 'test_bundleName';
try {
cloudData.Config.notifyDataChange(account, bundleName).then(() => {
console.info('Succeeded in notifying the change of data');
}).catch((err) => {
console.error(`Failed to notify the change of data. Code: ${err.code}, message: ${err.message}`);
});
} catch (error) {
console.error(`An unexpected error occurred. Code: ${error.code}, message: ${error.message}`);
}
```
# @ohos.data.dataSharePredicates (DataShare Predicates)
# @ohos.data.dataSharePredicates (Data Share Predicates)
You can use **DataSharePredicates** to specify conditions for [updating](js-apis-data-dataShare.md#update), [deleting](js-apis-data-dataShare.md#delete), and [querying](js-apis-data-dataShare.md#query) data when **DataShare** is used to manage data.
......@@ -18,13 +18,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
```
## DataSharePredicates
Provides methods for setting different **DataSharePredicates** objects.
Provides methods for setting different **DataSharePredicates** objects. This type is not multi-thread safe. If a **DataSharePredicates** instance is operated by multiple threads at the same time in an application, use a lock for the instance.
### equalTo
equalTo(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is equal to the specified value.
Sets a **DataSharePredicates** object to match the data that is equal to the specified value.
Currently, only the relational database (RDB) and key-value database (KVDB, schema) support this **DataSharePredicates** object.
......@@ -54,10 +54,11 @@ predicates.equalTo("NAME", "Rose")
notEqualTo(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is not equal to the specified value.
Sets a **DataSharePredicates** object to match the data that is not equal to the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -88,6 +89,7 @@ Adds a left parenthesis to this **DataSharePredicates**.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
......@@ -116,6 +118,7 @@ Adds a right parenthesis to this **DataSharePredicates** object.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
......@@ -144,6 +147,7 @@ Adds the OR condition to this **DataSharePredicates** object.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
......@@ -190,10 +194,11 @@ predicates.equalTo("NAME", "lisi")
contains(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that contains the specified value.
Sets a **DataSharePredicates** object to match the data that contains the specified value.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -220,10 +225,11 @@ predicates.contains("NAME", "os")
beginsWith(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that begins with the specified value.
Sets a **DataSharePredicates** object to match the data that begins with the specified value.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -250,10 +256,11 @@ predicates.beginsWith("NAME", "os")
endsWith(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that ends with the specified value.
Sets a **DataSharePredicates** object to match the data that ends with the specified value.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -280,10 +287,11 @@ predicates.endsWith("NAME", "os")
isNull(field: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data whose value is null.
Sets a **DataSharePredicates** object to match the data whose value is null.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -309,10 +317,11 @@ predicates.isNull("NAME")
isNotNull(field: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data whose value is not null.
Sets a **DataSharePredicates** object to match the data whose value is not null.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -338,10 +347,11 @@ predicates.isNotNull("NAME")
like(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that matches the specified wildcard expression.
Sets a **DataSharePredicates** object to match the data that matches the specified wildcard expression.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -368,10 +378,11 @@ predicates.like("NAME", "%os%")
unlike(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that does not match the specified wildcard expression.
Sets a **DataSharePredicates** object to match the data that does not match the specified wildcard expression.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -398,10 +409,11 @@ predicates.unlike("NAME", "%os%")
glob(field: string, value: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that matches the specified wildcard expression.
Sets a **DataSharePredicates** object to match the data that matches the specified wildcard expression.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -428,10 +440,11 @@ predicates.glob("NAME", "?h*g")
between(field: string, low: ValueType, high: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is within the specified range, including the start and end values.
Sets a **DataSharePredicates** object to match the data that is within the specified range, including the start and end values.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -459,10 +472,11 @@ predicates.between("AGE", 10, 50)
notBetween(field: string, low: ValueType, high: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is out of the specified range, excluding the start and end values.
Sets a **DataSharePredicates** object to match the data that is out of the specified range, excluding the start and end values.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -490,10 +504,11 @@ predicates.notBetween("AGE", 10, 50)
greaterThan(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is greater than the specified value.
Sets a **DataSharePredicates** object to match the data that is greater than the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -520,10 +535,11 @@ predicates.greaterThan("AGE", 10)
lessThan(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is less than the specified value.
Sets a **DataSharePredicates** object to match the data that is less than the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -550,10 +566,11 @@ predicates.lessThan("AGE", 50)
greaterThanOrEqualTo(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is greater than or equal to the specified value.
Sets a **DataSharePredicates** object to match the data that is greater than or equal to the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -580,10 +597,11 @@ predicates.greaterThanOrEqualTo("AGE", 10)
lessThanOrEqualTo(field: string, value: ValueType): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is less than or equal to the specified value.
Sets a **DataSharePredicates** object to match the data that is less than or equal to the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -672,6 +690,7 @@ Sets a **DataSharePredicates** object to filter out duplicate data records.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
......@@ -725,6 +744,7 @@ Sets a **DataSharePredicates** object group the records according to the specifi
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -754,6 +774,7 @@ Sets a **DataSharePredicates** object to list data by the specified index.
Currently, only the RDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -779,7 +800,7 @@ predicates.indexedBy("SALARY_INDEX")
in(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is within the specified value.
Sets a **DataSharePredicates** object to match the data that is within the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
......@@ -809,10 +830,11 @@ predicates.in("AGE", [18, 20])
notIn(field: string, value: Array&lt;ValueType&gt;): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data that is not in the specified value.
Sets a **DataSharePredicates** object to match the data that is not in the specified value.
Currently, only the RDB and KVDB (schema) support this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -839,10 +861,11 @@ predicates.notIn("NAME", ["Lisa", "Rose"])
prefixKey(prefix: string): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data with the specified key prefix.
Sets a **DataSharePredicates** object to match the data with the specified key prefix.
Currently, only the KVDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......@@ -868,10 +891,11 @@ predicates.prefixKey("NAME")
inKeys(keys: Array&lt;string&gt;): DataSharePredicates
Sets a **DataSharePredicates** object to search for the data whose keys are within the given range.
Sets a **DataSharePredicates** object to match the data whose keys are within the given range.
Currently, only the KVDB supports this **DataSharePredicates** object.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
......
......@@ -23,10 +23,10 @@ Creates a distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| source | object | Yes| Attributes of the distributed data object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| source | object | Yes| Attributes of the distributed data object.|
**Return value**
......@@ -75,9 +75,9 @@ Creates a random session ID.
**Return value**
| Type| Description|
| -------- | -------- |
| string | Session ID created.|
| Type| Description|
| -------- | -------- |
| string | Session ID created.|
**Example**
......@@ -124,18 +124,18 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | Yes| ID of a distributed data object on a trusted network.|
| callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback invoked when the session ID is successfully set.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | Yes| ID of a distributed data object on a trusted network.|
| callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback invoked when the session ID is successfully set.|
**Error codes**
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| ID| Error Message|
| -------- | -------- |
| 15400001 | Create table failed.|
**Example**
......@@ -158,17 +158,17 @@ Exits all joined sessions.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Asynchronous callback invoked when the distributed data object exits all joined sessions.|
**Error codes**
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| ID| Error Message|
| -------- | -------- |
| 15400001 | Create table failed.|
**Example**
......@@ -195,9 +195,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
**Return value**
......@@ -209,9 +209,9 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
| 15400001 | Failed to create the in-memory database.|
| ID| Error Message|
| -------- | -------- |
| 15400001 | Create table failed.|
**Example**
......@@ -240,10 +240,10 @@ Subscribes to data changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
......@@ -269,10 +269,10 @@ Unsubscribes from the data changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
......@@ -294,10 +294,10 @@ Subscribes to status changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
**Example**
......@@ -318,10 +318,10 @@ Unsubscribes from the status change of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.|
| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.|
**Example**
......@@ -354,10 +354,10 @@ The saved data will be released in the following cases:
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.|
| callback | AsyncCallback&lt;[SaveSuccessResponse](#savesuccessresponse9)&gt; | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| ID of the device where data is stored. The value **local** indicates the local device.|
| callback | AsyncCallback&lt;[SaveSuccessResponse](#savesuccessresponse9)&gt; | Yes| Callback invoked to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
**Example**
......@@ -394,15 +394,15 @@ The saved data will be released in the following cases:
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| deviceId | string | Yes| ID of the device where the data is saved. The default value is **local**, which indicates the local device. |
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[SaveSuccessResponse](#savesuccessresponse9)&gt; | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
| Type| Description|
| -------- | -------- |
| Promise&lt;[SaveSuccessResponse](#savesuccessresponse9)&gt; | Promise used to return **SaveSuccessResponse**, which contains information such as session ID, version, and device ID.|
**Example**
......@@ -423,7 +423,7 @@ g_object.save("local").then((result) => {
revokeSave(callback: AsyncCallback&lt;RevokeSaveSuccessResponse&gt;): void
Revokes the saving operation of this distributed data object. This API uses an asynchronous callback to return the result.
Revokes the data of this distributed data object saved. This API uses an asynchronous callback to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted.
......@@ -432,9 +432,9 @@ If the object is stored on another device, the data on the local device will be
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)&gt; | Yes| Callback invoked to return **RevokeSaveSuccessResponse**, which contains the session ID.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)&gt; | Yes| Callback invoked to return **RevokeSaveSuccessResponse**, which contains the session ID.|
**Example**
......@@ -468,7 +468,7 @@ g_object.revokeSave((err, result) => {
revokeSave(): Promise&lt;RevokeSaveSuccessResponse&gt;
Revokes the saving operation of this distributed data object. This API uses a promise to return the result.
Revokes the data of this distributed data object saved. This API uses a promise to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted.
......@@ -477,9 +477,9 @@ If the object is stored on another device, the data on the local device will be
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)&gt; | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.|
| Type| Description|
| -------- | -------- |
| Promise&lt;[RevokeSaveSuccessResponse](#revokesavesuccessresponse9)&gt; | Promise used to return **RevokeSaveSuccessResponse**, which contains the session ID.|
**Example**
......@@ -520,9 +520,9 @@ Creates a distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | object | Yes| Attributes of the distributed data object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | object | Yes| Attributes of the distributed data object.|
**Return value**
......@@ -558,15 +558,15 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the session ID is set successfully;<br>returns **false** otherwise. |
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the session ID is set successfully;<br>returns **false** otherwise. |
**Example**
......@@ -593,10 +593,10 @@ Subscribes to data changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | Yes| Callback invoked to return the changes of the distributed data object.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
......@@ -628,10 +628,10 @@ Unsubscribes from the data changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
| callback | Callback<{ sessionId: string, fields: Array&lt;string&gt; }> | No| Callback for data changes. If this parameter is not specified, all data change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**fields** indicates the changed attributes of the distributed data object.|
**Example**
......@@ -659,10 +659,10 @@ Subscribes to status changes of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback invoked to return the status change.<br>**sessionId** indicates the session ID of the distributed data object.<br>**networkId** indicates the object device ID, that is, **deviceId**.<br>**status** indicates the object status, which can be online or offline.|
**Example**
......@@ -689,8 +689,8 @@ Unsubscribes from the status change of this distributed data object.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object.|
| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unregistered.<br>**sessionId** indicates the session ID of the distributed data object.<br>**deviceId** indicates the device ID of the distributed data object.<br>**status** indicates the object status, which can be online or offline.|
......
......@@ -185,7 +185,7 @@ For details about the error codes, see [User Preference Error Codes](../errorcod
| ID| Error Message |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |
| 15500010 | Failed to delete preferences file. |
**Example**
......@@ -197,7 +197,7 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
try {
data_preferences.deletePreferences(context, 'mystore', function (err, val) {
data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
return;
......@@ -217,7 +217,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
try {
data_preferences.deletePreferences(this.context, 'mystore', function (err, val) {
data_preferences.deletePreferences(this.context, 'mystore', function (err) {
if (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
return;
......@@ -262,7 +262,7 @@ For details about the error codes, see [User Preference Error Codes](../errorcod
| ID| Error Message |
| -------- | ------------------------------|
| 15500010 | Failed to delete the preferences. |
| 15500010 | Failed to delete preferences file. |
**Example**
......@@ -334,7 +334,7 @@ import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
try {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
return;
......@@ -354,7 +354,7 @@ import UIAbility from '@ohos.app.ability.UIAbility';
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
try {
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err, val) {
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) {
if (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
return;
......
# @ohos.data.ValuesBucket (Value Bucket)
# @ohos.data.ValuesBucket (Data Set)
The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to insert data into a database.
......@@ -6,7 +6,6 @@ The **ValueBucket** module holds data in key-value (KV) pairs. You can use it to
>
> 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
......@@ -30,7 +29,7 @@ Enumerates the value types allowed by the database.
## ValuesBucket
Defines the types of the key and value in a KV pair.
Defines the types of the key and value in a KV pair. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use a lock for the instance.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
......
......@@ -62,12 +62,14 @@ Obtains distributed account information. This API uses an asynchronous callback
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try {
accountAbility.getOsAccountDistributedInfo((err, data) => {
console.log("getOsAccountDistributedInfo err: " + JSON.stringify(err));
console.log('Query account info name: ' + data.name);
console.log('Query account info id: ' + data.id);
if (err) {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else {
console.log('distributed information: ' + JSON.stringify(data));
}
});
} catch (e) {
console.log("getOsAccountDistributedInfo exception: " + JSON.stringify(e));
} catch (err) {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}
```
......@@ -98,15 +100,96 @@ Obtains distributed account information. This API uses a promise to return the r
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try {
accountAbility.getOsAccountDistributedInfo().then((data) => {
console.log('Query account info name: ' + data.name);
console.log('Query account info id: ' + data.id);
console.log('distributed information: ' + JSON.stringify(data));
}).catch((err) => {
console.log("getOsAccountDistributedInfo err: " + JSON.stringify(err));
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
});
} catch (e) {
console.log("getOsAccountDistributedInfo exception: " + JSON.stringify(e));
} catch (err) {
console.log('getOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}
```
### getOsAccountDistributedInfoByLocalId<sup>10+</sup>
getOsAccountDistributedInfoByLocalId(localId: number, callback: AsyncCallback&lt;DistributedInfo&gt;): void
Obtains distributed information about an OS account. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| localId | number | Yes| ID of the target OS account.|
| callback | AsyncCallback&lt;[DistributedInfo](#distributedinfo)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the distributed account information obtained. Otherwise, **err** is an error object.|
**Error codes**
| ID| Error Message|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300003 | Account not found. |
**Example**
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try {
accountAbility.getOsAccountDistributedInfoByLocalId(100, (err, data) => {
if (err) {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
} else {
console.log('distributed information: ' + JSON.stringify(data));
}
});
} catch (err) {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}
```
### getOsAccountDistributedInfoByLocalId<sup>10+</sup>
getOsAccountDistributedInfoByLocalId(localId: number): Promise&lt;DistributedInfo&gt;
Obtains distributed information about an OS account. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[DistributedInfo](#distributedinfo)&gt; | Promise used to return the distributed account information obtained.|
**Error codes**
| ID| Error Message|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300003 | Account not found. |
**Example**
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
try {
accountAbility.getOsAccountDistributedInfoByLocalId(100).then((data) => {
console.log('distributed information: ' + JSON.stringify(data));
}).catch((err) => {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
});
} catch (err) {
console.log('getOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}
```
### queryOsAccountDistributedInfo<sup>(deprecated)</sup>
queryOsAccountDistributedInfo(callback: AsyncCallback&lt;DistributedInfo&gt;): void
......@@ -130,9 +213,11 @@ Obtains distributed account information. This API uses an asynchronous callback
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
accountAbility.queryOsAccountDistributedInfo((err, data) => {
console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err));
console.log('Query account info name: ' + data.name);
console.log('Query account info id: ' + data.id);
if (err) {
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else {
console.log('distributed information: ' + JSON.stringify(data));
}
});
```
......@@ -160,10 +245,9 @@ Obtains distributed account information. This API uses a promise to return the r
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
accountAbility.queryOsAccountDistributedInfo().then((data) => {
console.log('Query account info name: ' + data.name);
console.log('Query account info id: ' + data.id);
console.log('distributed information: ' + JSON.stringify(data));
}).catch((err) => {
console.log("queryOsAccountDistributedInfoerr: " + JSON.stringify(err));
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
});
```
......@@ -198,10 +282,14 @@ Sets the distributed account information. This API uses an asynchronous callback
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try {
accountAbility.setOsAccountDistributedInfo(accountInfo, (err) => {
console.log("setOsAccountDistributedInfo err: " + JSON.stringify(err));
if (err) {
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else {
console.log('setOsAccountDistributedInfo successfully');
}
});
} catch (e) {
console.log("setOsAccountDistributedInfo exception: " + JSON.stringify(e));
} catch (err) {
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}
```
......@@ -241,14 +329,109 @@ Sets the distributed account information. This API uses a promise to return the
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try {
accountAbility.setOsAccountDistributedInfo(accountInfo).then(() => {
console.log('setOsAccountDistributedInfo Success');
console.log('setOsAccountDistributedInfo successfully');
}).catch((err) => {
console.log("setOsAccountDistributedInfo err: " + JSON.stringify(err));
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
});
} catch (e) {
console.log("setOsAccountDistributedInfo exception: " + JSON.stringify(e));
} catch (err) {
console.log('setOsAccountDistributedInfo exception: ' + JSON.stringify(err));
}
```
### setOsAccountDistributedInfoByLocalId<sup>10+</sup>
setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo, callback: AsyncCallback&lt;void&gt;): void
Sets the distributed information for an OS account. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| localId | number | Yes| ID of the target OS account.|
| accountInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information to set.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result. If the distributed information is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
| ID| Error Message|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid distributedInfo. |
| 12300003 | Account identified by localId or by distributedInfo not found. |
| 12300008 | Restricted OS account. |
**Example**
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try {
accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo, (err) => {
if (err) {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
} else {
console.log('setOsAccountDistributedInfoByLocalId successfully');
}
});
} catch (err) {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}
```
### setOsAccountDistributedInfoByLocalId<sup>10+</sup>
setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo): Promise&lt;void&gt;
Sets the distributed information for an OS account. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| localId | number | Yes| ID of the target OS account.|
| distributedInfo | [DistributedInfo](#distributedinfo) | Yes| Distributed account information to set.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
| ID| Error Message|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid distributedInfo. |
| 12300003 | Account identified by localId or by distributedInfo not found. |
| 12300008 | Restricted OS account. |
**Example**
```js
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
try {
accountAbility.setOsAccountDistributedInfoByLocalId(100, accountInfo).then(() => {
console.log('setOsAccountDistributedInfoByLocalId successfully');
}).catch((err) => {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
});
} catch (err) {
console.log('setOsAccountDistributedInfoByLocalId exception: ' + JSON.stringify(err));
}
```
### updateOsAccountDistributedInfo<sup>(deprecated)</sup>
updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback&lt;void&gt;): void
......@@ -275,7 +458,11 @@ Updates the distributed account information. This API uses an asynchronous callb
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
accountAbility.updateOsAccountDistributedInfo(accountInfo, (err) => {
console.log("queryOsAccountDistributedInfo err: " + JSON.stringify(err));
if (err) {
console.log('queryOsAccountDistributedInfo exception: ' + JSON.stringify(err));
} else {
console.log('queryOsAccountDistributedInfo successfully');
}
});
```
......@@ -308,22 +495,34 @@ Updates the distributed account information. This API uses a promise to return t
const accountAbility = account_distributedAccount.getDistributedAccountAbility();
let accountInfo = {id: '12345', name: 'ZhangSan', event: 'Ohos.account.event.LOGIN'};
accountAbility.updateOsAccountDistributedInfo(accountInfo).then(() => {
console.log('updateOsAccountDistributedInfo Success');
console.log('updateOsAccountDistributedInfo successfully');
}).catch((err) => {
console.log("updateOsAccountDistributedInfo err: " + JSON.stringify(err));
console.log('updateOsAccountDistributedInfo exception: ' + JSON.stringify(err));
});
```
## DistributedInfo
Defines distributed OS account information.
Defines the distributed information about an OS account.
**System capability**: SystemCapability.Account.OsAccount
| Name| Type| Read-only| Mandatory| Description|
| -------- | -------- | -------- |-------- | -------- |
| name | string | No|Yes| Name of the distributed account. It must be a non-null string.|
| id | string | No|Yes| UID of the distributed account. It must be a non-null string.|
| event | string | No|Yes| Login state of the distributed account. The state can be login, logout, token invalid, or logoff, which correspond to the following strings respectively:<br>-&nbsp;Ohos.account.event.LOGIN<br>-&nbsp;Ohos.account.event.LOGOUT<br>-&nbsp;Ohos.account.event.TOKEN_INVALID<br>-&nbsp;Ohos.account.event.LOGOFF |
| nickname<sup>9+</sup> | string | No|No| Nickname of the distributed account. By default, no value is passed.|
| avatar<sup>9+</sup> | string | No|No| Avatar of the distributed account. By default, no value is passed.|
| status<sup>10+</sup> | [DistributedAccountStatus](#distributedaccountstatus10) | Yes|No| Status of the distributed account. The value is of the enumerated type. The default status is unlogged.|
| scalableData<sup>8+</sup> | object | No|No| Extended information about the distributed account, passed in key-value (KV) pairs based on service requirements. By default, no value is passed.|
## DistributedAccountStatus<sup>10+</sup>
Enumerates the statuses of a distributed account.
**System capability**: SystemCapability.Account.OsAccount
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the distributed account. It must be a non-null string.|
| id | string | Yes| UID of the distributed account. It must be a non-null string.|
| event | string | Yes| Login state of the distributed account. The state can be login, logout, token invalid, or logoff, which correspond to the following strings respectively:<br>-&nbsp;Ohos.account.event.LOGIN<br>-&nbsp;Ohos.account.event.LOGOUT<br>-&nbsp;Ohos.account.event.TOKEN_INVALID<br>-&nbsp;Ohos.account.event.LOGOFF |
| nickname<sup>9+</sup> | string | No| Nickname of the distributed account. It must be a non-null string.|
| avatar<sup>9+</sup> | string | No| Avatar of the distributed account. It must be a non-null string.|
| scalableData<sup>8+</sup> | object | No| Extended information about the distributed account, passed in key-value (KV) pairs.<br>**NOTE**<br>This parameter is reserved and not used in the setters and getters.|
| Name | Value| Description |
| ---- | ------ | ----------- |
| NOT_LOGGED_IN | 0 | The account has not logged in.|
| LOGGED_IN | 1 | The account has logged in.|
......@@ -3768,7 +3768,7 @@ sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
Synchronizes the KV store manually.
> **NOTE**
>
> The value of **deviceIds** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
> **deviceIds** is the **networkId** in [DeviceInfo](js-apis-device-manager.md#deviceinfo), which is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
......@@ -3778,9 +3778,9 @@ Synchronizes the KV store manually.
| Name | Type | Mandatory| Description |
| --------- | --------------------- | ---- | ---------------------------------------------- |
| deviceIds | string[] | Yes | List of IDs of the devices in the same networking environment to be synchronized.|
| deviceIds | string[] | Yes | List of **networkId**s of the devices in the same networking environment to be synchronized.|
| mode | [SyncMode](#syncmode) | Yes | Synchronization mode. |
| delayMs | number | No | Allowed synchronization delay time, in ms. |
| delayMs | number | No | Delay time allowed, in milliseconds. The default value is **0**. |
**Example**
......@@ -3799,7 +3799,7 @@ deviceManager.createDeviceManager('bundleName', (err, value) => {
if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync();
for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId;
deviceIds[i] = devices[i].networkId;
}
}
try {
......@@ -5246,7 +5246,7 @@ Synchronizes the KV store manually.
> **NOTE**
>
> The value of **deviceIds** is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
> **deviceIds** is the **networkId** in [DeviceInfo](js-apis-device-manager.md#deviceinfo), which is obtained by [deviceManager.getTrustedDeviceListSync](js-apis-device-manager.md#gettrusteddevicelistsync). The APIs of the **deviceManager** module are system interfaces and available only to system applications.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
......@@ -5256,7 +5256,7 @@ Synchronizes the KV store manually.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| deviceIds |string[] | Yes |IDs of the devices to be synchronized.|
| deviceIds |string[] | Yes |**networkId**s of the devices to be synchronized.|
| mode |[SyncMode](#syncmode) | Yes |Synchronization mode. |
| delayMs |number | No |Allowed synchronization delay time, in ms. The default value is **0**. |
......@@ -5277,7 +5277,7 @@ deviceManager.createDeviceManager('bundleName', (err, value) => {
if (devManager != null) {
var devices = devManager.getTrustedDeviceListSync();
for (var i = 0; i < devices.length; i++) {
deviceIds[i] = devices[i].deviceId;
deviceIds[i] = devices[i].networkId;
}
}
try {
......
......@@ -368,8 +368,8 @@ Continues a mission on a remote device. This API uses an asynchronous callback t
| Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueDeviceInfo](#js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes**
......@@ -426,8 +426,8 @@ Continues a mission on a remote device. This API uses a promise to return the re
| Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueDeviceInfo](#js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](#js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
**Return value**
......
......@@ -176,7 +176,7 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
......
......@@ -2433,7 +2433,7 @@ Unsubscribes from the OS account activation states, including the states of the
| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
| type | 'activate' \| 'activating' | Yes | Type of the event to unsubscribe from. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated.|
| name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.|
| callback | Callback&lt;number&gt; | No | Callback to unregister. By default, **0** is returned. |
| callback | Callback&lt;number&gt; | No | Callback for the OS account activation state events. By default, no value is passed, which unsubscribes from all the callbacks for the OS account activation state events. |
**Error codes**
......@@ -5649,7 +5649,7 @@ Obtains authentication information of the specified type. This API uses a promis
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------- | ---- | -------- |
| authType | [AuthType](#authtype8) | No | Authentication credential type.|
| authType | [AuthType](#authtype8) | No | Authentication type. By default, no value is passed, which means to obtain information about all authentication types.|
**Return value**
......@@ -5929,12 +5929,14 @@ Defines the executor property.
**System capability**: SystemCapability.Account.OsAccount
| Name | Type | Mandatory | Description |
| ------------ | ---------------------------------------- | ----- | ----------------- |
| result | number | Yes | Result. |
| authSubType | [AuthSubType](#authsubtype8) | Yes | Authentication credential subtype.|
| remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. |
| Name | Type | Readable| Writable| Description |
| ------------ | ---------------------------- | ----- | -----|----------------- |
| result | number | Yes | Yes | Result. |
| authSubType | [AuthSubType](#authsubtype8) | Yes | Yes | Authentication credential subtype.|
| remainTimes | number | Yes | Yes | Number of remaining authentication times. |
| freezingTime | number | Yes | Yes | Freezing time. |
| enrollmentProgress<sup>10+</sup> | string | Yes | Yes | Enrollment progress. By default, no value is passed.|
| sensorInfo<sup>10+</sup> | string | Yes | Yes | Sensor information. By default, no value is passed.|
## AuthResult<sup>8+</sup>
......@@ -5946,9 +5948,9 @@ Defines the authentication result information.
| Name | Type | Mandatory | Description |
| ------------ | ----------- | ----- | ----------------- |
| token | Uint8Array | No | Authentication token. |
| remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. |
| token | Uint8Array | No | Authentication token. By default, no value is passed. |
| remainTimes | number | No | Number of remaining authentication times. By default, no value is passed. |
| freezingTime | number | No | Freezing time. By default, no value is passed. |
## CredentialInfo<sup>8+</sup>
......@@ -5974,7 +5976,7 @@ Defines the request result information.
| Name | Type | Mandatory | Description |
| ------------ | ----------- | ----- | ----------------- |
| credentialId | Uint8Array | No | Credential ID. |
| credentialId | Uint8Array | No | Credential ID. By default, no value is passed. |
## EnrolledCredInfo<sup>8+</sup>
......@@ -6004,6 +6006,8 @@ Enumerates the types of properties to obtain.
| AUTH_SUB_TYPE | 1 | Authentication credential subtype.|
| REMAIN_TIMES | 2 | Remaining time. |
| FREEZING_TIME | 3 | Freezing time. |
| ENROLLMENT_PROGRESS<sup>10+</sup> | 4 | Enrollment progress. |
| SENSOR_INFO<sup>10+</sup> | 5 | Sensor information. |
## SetPropertyType<sup>8+</sup>
......@@ -6047,6 +6051,9 @@ Enumerates the authentication credential subtypes.
| PIN_MIXED | 10002 | Custom mixed credentials.|
| FACE_2D | 20000 | 2D face credential. |
| FACE_3D | 20001 | 3D face credential. |
| FINGERPRINT_CAPACITIVE<sup>10+</sup> | 30000 | Capacitive fingerprint. |
| FINGERPRINT_OPTICAL<sup>10+</sup> | 30001 | Optical fingerprint. |
| FINGERPRINT_ULTRASONIC<sup>10+</sup> | 30002 | Ultrasonic fingerprint. |
| DOMAIN_MIXED<sup>9+</sup> | 10240001 | Mixed domain authentication credentials. |
## AuthTrustLevel<sup>8+</sup>
......@@ -6136,6 +6143,8 @@ Enumerates the tip codes for fingerprint authentication.
| FINGERPRINT_TIP_PARTIAL | 3 | Only part of the fingerprint image is detected. |
| FINGERPRINT_TIP_TOO_FAST | 4 | The fingerprint image is incomplete due to quick motion. |
| FINGERPRINT_TIP_TOO_SLOW | 5 | Failed to read the fingerprint image due to lack of motion. |
| FINGERPRINT_TIP_FINGER_DOWN<sup>10+</sup> | 6 | Press your finger. |
| FINGERPRINT_TIP_FINGER_UP<sup>10+</sup> | 7 | Lift your finger. |
## OsAccountInfo
......@@ -6148,16 +6157,16 @@ Defines the OS account information.
| localId | number | Yes | ID of the target OS account. |
| localName | string | Yes | OS account name. |
| type | [OsAccountType](#osaccounttype) | Yes | OS account type. |
| constraints | Array&lt;string&gt; | No | [Constraints](#constraints) on the OS account.|
| constraints | Array&lt;string&gt; | No | OS account [Constraints](#constraints). By default, no value is passed.|
| isVerified<sup>8+</sup> | boolean | Yes | Whether to verify the OS account. |
| photo<sup>8+</sup> | string | No | Profile photo of the OS account. |
| photo<sup>8+</sup> | string | No | OS account avatar. By default, no value is passed. |
| createTime<sup>8+</sup> | number | Yes | Time when the OS account was created. |
| lastLoginTime<sup>8+</sup> | number | No | Last login time of the OS account. |
| lastLoginTime<sup>8+</sup> | number | No | Last login time of the OS account. By default, no value is passed. |
| serialNumber<sup>8+</sup> | number | Yes | SN of the OS account. |
| isActived<sup>8+</sup> | boolean | Yes | Whether the OS account is activated. |
| isCreateCompleted<sup>8+</sup> | boolean | Yes | Whether the OS account information is complete. |
| distributedInfo | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | No | Distributed account information. |
| domainInfo<sup>8+</sup> | [DomainAccountInfo](#domainaccountinfo8) | No | Domain account information. |
| distributedInfo | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | No | Distributed account information. By default, no value is passed. |
| domainInfo<sup>8+</sup> | [DomainAccountInfo](#domainaccountinfo8) | No | Domain account information. By default, no value is passed. |
## DomainAccountInfo<sup>8+</sup>
......@@ -6169,7 +6178,7 @@ Defines the domain account information.
| ----------- | ------ | ---- | ---------- |
| domain | string | Yes | Domain name. |
| accountName | string | Yes | Domain account name.|
| accountId<sup>10+</sup> | string | No | Domain account ID.<br>**System API**: This is a system API.|
| accountId<sup>10+</sup> | string | No | Domain account ID.<br>**System API**: It is a system API and is left blank by default.|
## Constraints
......
......@@ -59,7 +59,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0).then(() => {
privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.PERMISSION_USED_STATS', 1, 0).then(() => {
console.log('addPermissionUsedRecord success');
}).catch((err) => {
console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
......@@ -88,7 +88,7 @@ The permission usage record includes the application identity (token ID) of the
| permissionName | Permissions | Yes | Name of the permission.|
| successCount | number | Yes | Number of successful accesses.|
| failCount | number | Yes | Number of failed accesses.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If a usage record is added successfully, **err** is **undefine**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If a usage record is added successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
......@@ -109,7 +109,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED_STATS", 1, 0, (err, data) => {
privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.PERMISSION_USED_STATS', 1, 0, (err, data) => {
if (err) {
console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
} else {
......@@ -161,14 +161,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import privacyManager from '@ohos.privacyManager';
let request = {
"tokenId": 1,
"isRemote": false,
"deviceId": "device",
"bundleName": "bundle",
"permissionNames": [],
"beginTime": 0,
"endTime": 1,
"flag":privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
'tokenId': 1,
'isRemote': false,
'deviceId': 'device',
'bundleName': 'bundle',
'permissionNames': [],
'beginTime': 0,
'endTime': 1,
'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
};
try {
privacyManager.getPermissionUsedRecord(request).then((data) => {
......@@ -196,7 +196,7 @@ Obtains historical permission usage records. This API uses an asynchronous callb
| Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ |
| request | [PermissionUsedRequest](#permissionusedrequest) | Yes| Request for querying permission usage records.|
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the result. If the query is successful, **err** is **undefine** and **data** is the permission usage record. Otherwise, **err** is an error object.|
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the result. If the query is successful, **err** is **undefined** and **data** is the permission usage record. Otherwise, **err** is an error object.|
**Error codes**
......@@ -216,14 +216,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
import privacyManager from '@ohos.privacyManager';
let request = {
"tokenId": 1,
"isRemote": false,
"deviceId": "device",
"bundleName": "bundle",
"permissionNames": [],
"beginTime": 0,
"endTime": 1,
"flag":privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
'tokenId': 1,
'isRemote': false,
'deviceId': 'device',
'bundleName': 'bundle',
'permissionNames': [],
'beginTime': 0,
'endTime': 1,
'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
};
try {
privacyManager.getPermissionUsedRecord(request, (err, data) => {
......@@ -281,7 +281,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.startUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS").then(() => {
privacyManager.startUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS').then(() => {
console.log('startUsingPermission success');
}).catch((err) => {
console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
......@@ -307,7 +307,7 @@ Starts to use a permission and flushes the permission usage record. This API is
| -------------- | --------------------- | ---- | ------------------------------------ |
| tokenID | number | Yes | Application token ID of the invoker. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md).|
| permissionName | Permissions | Yes | Permission to use. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the permission is successfully used, **err** is **undefine**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the permission is successfully used, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
......@@ -329,7 +329,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.startUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err, data) => {
privacyManager.startUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS', (err, data) => {
if (err) {
console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -384,7 +384,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.stopUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS").then(() => {
privacyManager.stopUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS').then(() => {
console.log('stopUsingPermission success');
}).catch((err) => {
console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
......@@ -410,7 +410,7 @@ Stops using a permission. This API is called by a system application and uses a
| -------------- | --------------------- | ---- | ------------------------------------ |
| tokenID | number | Yes | Application token ID of the invoker. The value can be obtained from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md).|
| permissionName | Permissions | Yes | Permission to use. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefine**. Otherwise, **err** is an error object.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
......@@ -432,7 +432,7 @@ import privacyManager from '@ohos.privacyManager';
let tokenID = 0; // You can use getApplicationInfo to obtain the access token ID.
try {
privacyManager.stopUsingPermission(tokenID, "ohos.permission.PERMISSION_USED_STATS", (err, data) => {
privacyManager.stopUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS', (err, data) => {
if (err) {
console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
} else {
......@@ -482,7 +482,7 @@ import privacyManager from '@ohos.privacyManager';
let permissionList = [];
try {
privacyManager.on('activeStateChange', permissionList, (data) => {
console.debug("receive permission state change, data:" + JSON.stringify(data));
console.debug('receive permission state change, data:' + JSON.stringify(data));
});
} catch(err) {
console.log(`catch err->${JSON.stringify(err)}`);
......@@ -514,7 +514,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| -------- | -------- |
| 12100001 | The permissionNames in the list are all invalid, or the list size exceeds 1024 bytes. |
| 12100004 | The interface is not used together with "on()".|
| 12100004 | The interface is not used together with 'on'.|
| 12100007 | Service is abnormal. |
| 12100008 | Out of memory. |
......@@ -550,14 +550,14 @@ Represents the request for querying permission usage records.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| tokenId | number | No | Token ID of the application (invoker). |
| isRemote | boolean | No | Whether the token ID belongs to the application on a remote device. The default value is **false**.|
| deviceId | string | No | ID of the device hosting the target application. |
| bundleName | string | No | Bundle name of the target application.|
| permissionNames | Array&lt;Permissions&gt; | No | Permissions to query. |
| beginTime | number | No | Start time of the query, in ms. The default value is **0**, indicating that no start time is set.|
| endTime | number | No | End time of the query, in ms. The default value is **0**, indicating that no end time is set.|
| flag | [PermissionUsageFlag](#permissionusageflag) | Yes | Query mode. The default value is **FLAG_PERMISSION_USAGE_SUMMARY**.|
| tokenId | number | No | Token ID of the application (invoker).<br>By default, all applications are queried. |
| isRemote | boolean | No | Whether to query the permission usage records of the remote device.<br> The default value is **false**, which means the permission usage records of the local device are queried by default.|
| deviceId | string | No | ID of the device hosting the target application.<br> The default value is the local device ID. |
| bundleName | string | No | Bundle name of the target application.<br>By default, all applications are queried.|
| permissionNames | Array&lt;Permissions&gt; | No | Permissions to query.<br>By default, the usage records of all permissions are queried. |
| beginTime | number | No | Start time of the query, in ms.<br>The default value is **0**, which means the start time is not set.|
| endTime | number | No | End time of the query, in ms.<br>The default value is **0**, which means the end time is not set.|
| flag | [PermissionUsageFlag](#permissionusageflag) | Yes | Query mode.|
## PermissionUsedResponse
......@@ -567,9 +567,9 @@ Represents the permission usage records of all applications.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| beginTime | number | No | Start time of the query, in ms.|
| endTime | number | No | End time of the query, in ms.|
| bundleRecords | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt; | No | Permission usage records. |
| beginTime | number | Yes | Start time of the query, in ms.|
| endTime | number | Yes | End time of the query, in ms.|
| bundleRecords | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt; | Yes | Permission usage records. |
## BundleUsedRecord
......@@ -579,11 +579,11 @@ Represents the permission access records of an application.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| tokenId | number | No | Token ID of the application (invoker). |
| isRemote | boolean | No | Whether the token ID belongs to the application on a remote device. The default value is **false**.|
| deviceId | string | No | ID of the device hosting the target application. |
| bundleName | string | No | Bundle name of the target application.|
| permissionRecords | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt; | No | Permission usage records of the target application. |
| tokenId | number | Yes | Token ID of the application (invoker). |
| isRemote | boolean | Yes | Whether the token ID belongs to the application on a remote device. The default value is **false**.|
| deviceId | string | Yes | ID of the device hosting the target application. |
| bundleName | string | Yes | Bundle name of the target application.|
| permissionRecords | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt; | Yes | Permission usage records of the target application. |
## PermissionUsedRecord
......@@ -593,14 +593,14 @@ Represents the usage records of a permission.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| permissionName | Permissions | No | Name of the permission. |
| accessCount | number | No | Total number of times that the permission is accessed.|
| rejectCount | number | No | Total number of times that the access to the permission is rejected.|
| lastAccessTime | number | No | Last time when the permission was accessed, accurate to ms.|
| lastRejectTime | number | No | Last time when the access to the permission was rejected, accurate to ms.|
| lastAccessDuration | number | No | Last access duration, in ms.|
| accessRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | No | Successful access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
| rejectRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | No | Rejected access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
| permissionName | Permissions | Yes | Name of the permission. |
| accessCount | number | Yes | Total number of times that the permission is accessed.|
| rejectCount | number | Yes | Total number of times that the access to the permission is rejected.|
| lastAccessTime | number | Yes | Last time when the permission was accessed, accurate to ms.|
| lastRejectTime | number | Yes | Last time when the access to the permission was rejected, accurate to ms.|
| lastAccessDuration | number | Yes | Last access duration, in ms.|
| accessRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | Yes | Successful access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
| rejectRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | Yes | Rejected access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
## UsedRecordDetail
......@@ -610,9 +610,9 @@ Represents the details of a single access record.
| Name | Type | Mandatory | Description |
| -------- | -------------- | ---- | ---------------------------------------- |
| status | number | No | Access status. |
| timestamp | number | No | Access timestamp, in ms.|
| accessDuration | number | No | Access duration, in ms. |
| status | number | Yes | Access status. |
| timestamp | number | Yes | Access timestamp, in ms.|
| accessDuration | number | Yes | Access duration, in ms. |
## PermissionActiveStatus
......
......@@ -4,11 +4,29 @@
>
> This topic describes only module-specific error codes. For details about universal error codes, see [Universal Error Codes](errorcode-universal.md).
## 14800000 Internal Error
**Error Message**
Inner error.
**Description**
An error occurs at the underlying database.
**Possible Causes**
Invalid SQL statement is passed in.
**Solution**
Determine the cause of the error based on the log information.
## 14800010 Invalid RDB Name
**Error Message**
Invalid database name.
Failed to open or delete database by invalid database path.
**Description**
......@@ -16,17 +34,17 @@ The RDB store name is invalid.
**Possible Causes**
The RDB store name is empty or exceeds 1024 bytes.
The RDB store path is invalid.
**Solution**
Check that the RDB store name is not empty and does not exceed 1024 bytes.
Check the RDB store path.
## 14800011 Database File Corrupted
**Error Message**
Database corrupted.
Failed to open database by database corrupted.
**Description**
......
......@@ -7,7 +7,7 @@
## 15500010 Failed to Delete the User Preference Persistence File
**Error Message**
Failed to delete preferences.
Failed to delete preferences file.
**Description**
......
......@@ -258,4 +258,4 @@ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
}
```
![GIF](figures/GIF.gif)
![floating_button](figures/floating_button.gif)
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册