The **AbilityAccessCtrl** module provides APIs for application permission management, including authentication, authorization, and revocation.
The **AbilityAccessCtrl** module provides APIs for application permission management, including authentication, authorization, and revocation.
> **NOTE**
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
## Modules to Import
...
@@ -15,7 +16,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
...
@@ -15,7 +16,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
createAtManager(): AtManager
createAtManager(): AtManager
Creates an **AtManager** instance, which is used for ability access control.
Creates an **AtManager** instance, which is used for application access control.
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlags | number | Yes | Permission flag.<br>- **0**: The permission is not set by the user.<br>- **1**: A dialog box for user authorization will be displayed the next time if the user denies authorization for the permission.<br>- **2**: No dialog box will be displayed the next time if the user denies authorization for the permission. The permission must be granted by the user in **Settings**.<br>- **4**: The permission is authorized by the system and cannot be changed.|
**Return value**
**Return value**
...
@@ -149,11 +150,11 @@ Grants a user_grant permission to an application. This API uses a promise to ret
...
@@ -149,11 +150,11 @@ Grants a user_grant permission to an application. This API uses a promise to ret
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist. |
| 12100002 | The specified tokenID does not exist. |
| 12100003 | The specified permission 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. |
| 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. |
...
@@ -166,9 +167,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
...
@@ -166,9 +167,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
letatManager=abilityAccessCtrl.createAtManager();
letatManager=abilityAccessCtrl.createAtManager();
lettokenID=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.
lettokenID=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.
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlags | number | Yes | Permission flag.<br>- **0**: The permission is not set by the user.<br>- **1**: A dialog box for user authorization will be displayed the next time if the user denies authorization for the permission.<br>- **2**: No dialog box will be displayed the next time if the user denies authorization for the permission. The permission must be granted by the user in **Settings**.<br>- **4**: The permission is authorized by the system and cannot be changed.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is granted successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the permission is granted, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | TokenId does not exist. |
| 12100002 | TokenId does not exist. |
| 12100003 | Permission does not exist. |
| 12100003 | 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. |
| 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. |
...
@@ -218,9 +219,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
...
@@ -218,9 +219,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
letatManager=abilityAccessCtrl.createAtManager();
letatManager=abilityAccessCtrl.createAtManager();
lettokenID=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.
lettokenID=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.
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlags | number | Yes | Permission flag.<br>- **0**: The permission is not set by the user.<br>- **1**: A dialog box for user authorization will be displayed the next time if the user denies authorization for the permission.<br>- **2**: No dialog box will be displayed the next time if the user denies authorization for the permission. The permission must be granted by the user in **Settings**.<br>- **4**: The permission is authorized by the system and cannot be changed.|
**Return value**
**Return value**
...
@@ -260,11 +261,11 @@ Revokes a user_grant permission from an application. This API uses a promise to
...
@@ -260,11 +261,11 @@ Revokes a user_grant permission from an application. This API uses a promise to
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist. |
| 12100002 | The specified tokenID does not exist. |
| 12100003 | The specified permission does not exist. |
| 12100003 | The specified permission does not exist. |
| 12100006 | The application specified by the tokenID is not allowed to be revoked with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
| 12100006 | The application specified by the tokenID is not allowed to be revoked with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
...
@@ -277,9 +278,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
...
@@ -277,9 +278,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
letatManager=abilityAccessCtrl.createAtManager();
letatManager=abilityAccessCtrl.createAtManager();
lettokenID=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.
lettokenID=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.
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionFlag | number | Yes | Permission flag. The value **1** means that the permission request dialog box will still be displayed after the user grants or denies the permission. The value **2** means that no dialog box will be displayed after the user grants or denies the permission. The value **3** means a system permission that cannot be changed. |
| permissionFlags | number | Yes | Permission flag.<br>- **0**: The permission is not set by the user.<br>- **1**: A dialog box for user authorization will be displayed the next time if the user denies authorization for the permission.<br>- **2**: No dialog box will be displayed the next time if the user denies authorization for the permission. The permission must be granted by the user in **Settings**.<br>- **4**: The permission is authorized by the system and cannot be changed.|
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the permission is revoked successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the permission is revoked, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | TokenId does not exist. |
| 12100002 | TokenId does not exist. |
| 12100003 | Permission does not exist. |
| 12100003 | Permission does not exist. |
| 12100006 | The application specified by the tokenID is not allowed to be revoked with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
| 12100006 | The application specified by the tokenID is not allowed to be revoked with the specified permission. Either the application is a sandbox or the tokenID is from a remote device. |
...
@@ -329,9 +330,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
...
@@ -329,9 +330,9 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
letatManager=abilityAccessCtrl.createAtManager();
letatManager=abilityAccessCtrl.createAtManager();
lettokenID=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.
lettokenID=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.
| type | string | Yes | Event type. The value is fixed at **'permissionStateChange'**, indicating the permission grant state change event. |
| type | string | Yes | Event type to subscribe to. The value is **'permissionStateChange'**, which indicates the permission grant state change. |
| tokenIDList | Array<number> | Yes | List of token IDs. If this parameter is left empty, the permission grant state changes of all applications are subscribed to. |
| tokenIDList | Array<number> | Yes | Token IDs of the applications to observe. If this parameter is left empty, the permission grant state changes of all applications are observed. |
| permissionNameList | Array<Permissions> | Yes | List of permission names. If this parameter is left empty, the permission grant state changes of all permissions are subscribed to. |
| permissionList | Array<Permissions> | Yes | Permissions to observe. If this parameter is left empty, the grant state changes of all permissions are observed. |
| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | Yes| Callback used to return the permission grant state change information.|
| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | Yes| Callback invoked to return the permission grant state change.|
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100004 | The interface is called repeatedly with the same input. |
| 12100004 | The interface is called repeatedly with the same input. |
| 12100005 | The registration time has exceeded the limitation. |
| 12100005 | The registration time has exceeded the limitation. |
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
...
@@ -461,13 +462,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -461,13 +462,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
Unsubscribes from permission grant state changes of the specified applications and permissions. This API uses an asynchronous callback to return the result.
Unsubscribes from permission grant state changes of the specified applications and permissions. This API uses a callback to return the result.
**System API**: This is a system API.
**System API**: This is a system API.
...
@@ -491,19 +493,19 @@ Unsubscribes from permission grant state changes of the specified applications a
...
@@ -491,19 +493,19 @@ Unsubscribes from permission grant state changes of the specified applications a
| type | string | Yes | Event type. The value is fixed at **'permissionStateChange'**, indicating the permission grant state change event. |
| type | string | Yes | Event type to unsubscribe from. The value is **'permissionStateChange'**, which indicates the permission grant state change. |
| tokenIDList | Array<number> | Yes | List of token IDs. If this parameter is left empty, the permission grant state changes of all applications are unsubscribed from. The value must be the same as that passed in **on()**.|
| tokenIDList | Array<number> | Yes | Token IDs of the applications. If this parameter is left empty, the permission grant state changes of all applications are unsubscribed from. The value must be the same as that passed in **on()**. |
| permissionNameList | Array<Permissions> | Yes | List of permission names. If this parameter is left empty, the permission grant state changes of all permissions are unsubscribed from. The value must be the same as that passed in **on()**.|
| permissionList | Array<Permissions> | Yes | Permission names. If this parameter is left empty, the grant state changes of all permissions are unsubscribed from. The value must be the same as that passed in **on()**. |
| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | No| Callback used to return the permission grant state change information.|
| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | No| Callback for the permission grant state change. |
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID in list is all invalid |
| 12100001 | The parameter is invalid. The tokenID in list is all invalid. |
| 12100004 | The interface is not used with |
| 12100004 | The interface is not used together with "on". |
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
| 12100008 | Out of memory. |
| 12100008 | Out of memory. |
...
@@ -511,13 +513,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -511,13 +513,14 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| tokenID | number | Yes | Token ID of the application. The value can be obtained from [ApplicationInfo](js-apis-bundleManager-applicationInfo.md). |
| permissionName | Permissions | Yes | Permission to verify. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | Permission to verify. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
Requests user authorization in a dialog box. This API uses an asynchronous callback to return the result.
Requests permissions from the user in a dialog box. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the stage model.
**Model restriction**: This API can be used only in the stage model.
...
@@ -573,16 +576,16 @@ Requests user authorization in a dialog box. This API uses an asynchronous callb
...
@@ -573,16 +576,16 @@ Requests user authorization in a dialog box. This API uses an asynchronous callb
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Ability context of the application that requests the permission.|
| context | Context | Yes| Ability context of the application that requests the permissions. |
| permissions | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionList | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback invoked to return the result.|
| callback | AsyncCallback<[PermissionRequestResult](js-apis-permissionrequestresult.md)> | Yes| Callback invoked to return the result.|
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | Parameter invalid. |
| 12100001 | The parameter is invalid. The context is invalid when it does not belong to the application itself. |
Requests user authorization in a dialog box. This API uses a promise to return the result.
Requests permissions from the user in a dialog box. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the stage model.
**Model restriction**: This API can be used only in the stage model.
...
@@ -614,8 +617,8 @@ Requests user authorization in a dialog box. This API uses a promise to return
...
@@ -614,8 +617,8 @@ Requests user authorization in a dialog box. This API uses a promise to return
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Ability context of the application that requests the permission.|
| context | Context | Yes| Ability context of the application that requests the permissions. |
| permissions | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionList | Array<Permissions> | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md). |
**Return value**
**Return value**
...
@@ -625,10 +628,10 @@ Requests user authorization in a dialog box. This API uses a promise to return
...
@@ -625,10 +628,10 @@ Requests user authorization in a dialog box. This API uses a promise to return
**Error codes**
**Error codes**
For details about the error codes, see [Ability Access Control Error Codes](../errorcodes/errorcode-access-token.md).
For details about the error codes, see [Application Access Control Error Codes](../errorcodes/errorcode-access-token.md).
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | Parameter invalid. |
| 12100001 | The parameter is invalid. The context is invalid when it does not belong to the application itself. |
**Example**
**Example**
...
@@ -710,7 +713,7 @@ Enumerates the operations that trigger permission grant state changes.
...
@@ -710,7 +713,7 @@ Enumerates the operations that trigger permission grant state changes.
### PermissionStateChangeInfo<sup>9+</sup>
### PermissionStateChangeInfo<sup>9+</sup>
Defines the detailed permission grant state change information.
Defines detailed information about the permission grant state change.
**System API**: This is a system API.
**System API**: This is a system API.
...
@@ -719,5 +722,6 @@ Defines the detailed permission grant state change information.
...
@@ -719,5 +722,6 @@ Defines the detailed permission grant state change information.
| change | [PermissionStateChangeType](#permissionstatechangetype9) | Yes | No | Operation that triggers the permission grant state change. |
| change | [PermissionStateChangeType](#permissionstatechangetype9) | Yes | No | Operation that triggers the permission grant state change. |
| tokenID | number | Yes | No | Token ID of the application whose permission grant state changes are subscribed.|
| tokenID | number | Yes | No | Token ID of the application. |
| permissionName | Permissions | Yes | No | Permission whose authorization status changes. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| permissionName | Permissions | Yes | No | Permission whose grant state changes. For details about the permissions, see the [Application Permission List](../../security/permission-list.md). |
@@ -4,8 +4,8 @@ The **PermissionRequestResult** module defines the result of a permission reques
...
@@ -4,8 +4,8 @@ The **PermissionRequestResult** module defines the result of a permission reques
> **NOTE**
> **NOTE**
>
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model.
> - The APIs of this module can be used only in the stage model.
## Attributes
## Attributes
...
@@ -14,7 +14,7 @@ The **PermissionRequestResult** module defines the result of a permission reques
...
@@ -14,7 +14,7 @@ The **PermissionRequestResult** module defines the result of a permission reques
| authResults | Array<number> | Yes| No|Result of the permission Request.<br>**-1**: The permission has been set and no dialog box will be displayed. Users can modify the permission in **Settings**.<br>**0**: No operation is required.<br>**1**: Dynamic user authorization is required via a dialog window .<br>**2**: The request is invalid. Possible causes are as follows:<br>- The permission is not declared in the configuration file.<br>- The permission name is invalid.<br>- Special conditions for applying for the permission do not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).|
| authResults | Array<number> | Yes| No| Result of the permission request.<br>- **-1**: The permission is not authorized and must be set in **Settings** without displaying a dialog box.<br>- **0**: The permission is authorized.<br>- **2**: The permission is not authorized due to an invalid request. The possible causes are as follows:<br> - The permission is not declared in the configuration file.<br> - The permission name is invalid.<br> - Special conditions for applying for the permission are not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).|
The **privacyManager** module provides APIs for privacy management, such as management of permission usage records.
The **privacyManager** module provides APIs for privacy management, such as management of permission usage records.
> **NOTE**
> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module are system APIs.
> - The 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
## Modules to Import
...
@@ -45,7 +46,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -45,7 +46,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
...
@@ -95,7 +96,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -95,7 +96,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
...
@@ -266,7 +267,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -266,7 +267,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
...
@@ -314,7 +315,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -314,7 +315,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
...
@@ -369,7 +370,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -369,7 +370,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100004 | The interface is not used with |
| 12100004 | The interface is not used with |
...
@@ -417,7 +418,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -417,7 +418,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100002 | The specified tokenID does not exist or it does not refer to an application process. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| 12100003 | The specified permission does not exist or it is not an user_grant permission. |
| type | string | Yes | Event type to subscribe to. The value is **'activeStateChange'**, which indicates the permission usage change event. |
| type | string | Yes | Event type to subscribe to. The value is **'activeStateChange'**, which indicates the permission usage change event. |
| permissionNameList | Array<Permissions> | Yes | List of permissions to be observed. If this parameter is left empty, the usage changes of all permissions are observed. |
| permissionList | Array<Permissions> | Yes | 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 the permission usage.|
| callback | Callback<[ActiveChangeResponse](#activechangeresponse)> | Yes| Callback invoked to return a change in the permission usage.|
**Error codes**
**Error codes**
...
@@ -467,7 +468,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -467,7 +468,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID is 0 |
| 12100001 | The parameter is invalid. The tokenID is 0. |
| 12100004 | The interface is called repeatedly with the same input. |
| 12100004 | The interface is called repeatedly with the same input. |
| 12100005 | The registration time has exceeded the limitation. |
| 12100005 | The registration time has exceeded the limitation. |
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
...
@@ -478,9 +479,9 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -478,9 +479,9 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| type | string | Yes | Event type to subscribe to. The value is **'activeStateChange'**, which indicates the permission usage change event. |
| type | string | Yes | Event type to subscribe to. The value is **'activeStateChange'**, which indicates the permission usage change event. |
| permissionNameList | Array<Permissions> | Yes | 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()**.|
| permissionList | Array<Permissions> | Yes | 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.|
| callback | Callback<[ActiveChangeResponse](#activechangeresponse)> | No| Callback for the permission usage change event.|
**Error codes**
**Error codes**
...
@@ -513,7 +514,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -513,7 +514,7 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
| ID| Error Message|
| ID| Error Message|
| -------- | -------- |
| -------- | -------- |
| 12100001 | The parameter is invalid. The permissionName in list is all invalid or the list size is larger than 1024. |
| 12100001 | The parameter is invalid. The permissionName in list is all invalid or the list size is larger than 1024. |
| 12100004 | The interface is not used with |
| 12100004 | The interface is not used together with "on()".|
| 12100007 | Service is abnormal. |
| 12100007 | Service is abnormal. |
| 12100008 | Out of memory. |
| 12100008 | Out of memory. |
...
@@ -522,9 +523,9 @@ For details about the error codes, see [Ability Access Control Error Codes](../e
...
@@ -522,9 +523,9 @@ For details about the error codes, see [Ability Access Control Error Codes](../e