The **PrivacyManager** module provides APIs for privacy management, such as management of permission usage records.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module are system APIs and cannot be called by third-party applications.
...
...
@@ -16,7 +15,7 @@ import privacyManager from '@ohos.privacyManager';
Adds a permission usage record when an application protected by the permission is called by another service or application. This API uses a promise to return the result.
The permission usage record includes the application identity of the invoker, name of the permission used, and number of successful and failed accesses to the application.
...
...
@@ -29,7 +28,7 @@ The permission usage record includes the application identity of the invoker, na
| Promise<number> | Promise used to return the result. If **0** is returned, the record is added successfully. If **-1** is returned, the record fails to be added.|
| Promise<void> | Promise that returns no value.|
**Example**
```js
vartokenID=appInfo.accessTokenId;// accessTokenId can be obtained by using getApplicationInfo().
Adds a permission usage record when an application protected by the permission is called by another service or application. This API uses an asynchronous callback to return the result.
The permission usage record includes the application identity of the invoker, name of the permission used, and number of successful and failed accesses to the application.
...
...
@@ -64,19 +71,29 @@ The permission usage record includes the application identity of the invoker, na
| tokenID | number | Yes | Application token ID of the invoker. |
| tokenID | number | Yes | Application token ID of the invoker. You can obtain it from [ApplicationInfo](js-apis-bundle-ApplicationInfo.md). |
| permissionName | string | Yes | Name of the permission.|
| successCount | number | Yes | Number of successful accesses.|
| failCount | number | Yes | Number of failed accesses.|
| callback | AsyncCallback<number> | Yes | Callback used to return the result. If **0** is returned, the record is added successfully. If **-1** is returned, the record fails to be added.|
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.|
**Example**
```js
vartokenID=appInfo.accessTokenId;// accessTokenId can be obtained by using getApplicationInfo().
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback used to return the permission usage records obtained.|
| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the permission usage records obtained.|
Starts to record a permission usage event. This API is called by a system service and uses a promise to return the result. The permissions used by an app in the foreground and background can be observed, and the permission usage records can be saved.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
Starts to record a permission usage event. This API is called by a system service and uses an asynchronous callback to return the result. The permissions used by an app in the foreground and background can be observed and saved.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
Stops recording the permission usage event. This API is called by a system service and uses a promise to return the result. **startUsingPermission** and **stopUsingPermission** are used in pairs.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
Stops recording the permission usage event. This API is called by the system service and uses an asynchronous callback to return the result. **startUsingPermission** and **stopUsingPermission** are used in pairs.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
| type | string | Yes | Event type to subscribe to. The value is **activeStateChange**, which indicates permission usage change event. |
| permissionNameList | Array<string> | No | List of permissions to be observed. If this parameter is left empty, the usage changes of all permissions are observed. |
| callback | Callback<[ActiveChangeResponse](#activechangeresponse)> | Yes| Callback invoked to return a change in permission usage.|
| type | string | Yes | Event type to subscribe to. The value is **activeStateChange**, which indicates permission usage change event. |
| permissionNameList | Array<string> | No | List of permissions to be observed. If this parameter is left blank, the usage changes of all permissions are unsubscribed from. The value must be the same as that specified in **on()**.|
| callback | Callback<[ActiveChangeResponse](#activechangeresponse)> | No| Callback for the permission usage change event.|