提交 dcfd1e19 编写于 作者: A Annie_wang
上级 9f15c720
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
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.
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -34,7 +35,7 @@ let atManager = abilityAccessCtrl.createAtManager(); ...@@ -34,7 +35,7 @@ let atManager = abilityAccessCtrl.createAtManager();
## AtManager ## AtManager
Implements ability access control. Provides APIs for application access control.
### checkAccessToken<sup>9+</sup> ### checkAccessToken<sup>9+</sup>
...@@ -59,11 +60,11 @@ Checks whether a permission is granted to an application. This API uses a promis ...@@ -59,11 +60,11 @@ Checks whether a permission is granted to an application. This API uses a promis
**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. |
**Example** **Example**
...@@ -106,11 +107,11 @@ Verifies whether a permission is granted to an application. This API returns the ...@@ -106,11 +107,11 @@ Verifies whether a permission is granted to an application. This API returns the
**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. |
**Example** **Example**
...@@ -123,7 +124,7 @@ console.log(`data->${JSON.stringify(data)}`); ...@@ -123,7 +124,7 @@ console.log(`data->${JSON.stringify(data)}`);
### grantUserGrantedPermission ### grantUserGrantedPermission
grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlag: number): Promise&lt;void&gt; grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number): Promise&lt;void&gt;
Grants a user_grant permission to an application. This API uses a promise to return the result. Grants a user_grant permission to an application. This API uses a promise to return the result.
...@@ -139,7 +140,7 @@ Grants a user_grant permission to an application. This API uses a promise to ret ...@@ -139,7 +140,7 @@ Grants a user_grant permission to an application. This API uses a promise to ret
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| 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';
let atManager = abilityAccessCtrl.createAtManager(); 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 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 permissionFlag = 1; let permissionFlags = 1;
try { try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag).then(() => { atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
console.log('grantUserGrantedPermission success'); console.log('grantUserGrantedPermission success');
}).catch((err) => { }).catch((err) => {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`); console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
...@@ -180,7 +181,7 @@ try { ...@@ -180,7 +181,7 @@ try {
### grantUserGrantedPermission ### grantUserGrantedPermission
grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlag: number, callback: AsyncCallback&lt;void&gt;): void grantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number, callback: AsyncCallback&lt;void&gt;): void
Grants a user_grant permission to an application. This API uses an asynchronous callback to return the result. Grants a user_grant permission to an application. This API uses an asynchronous callback to return the result.
...@@ -196,16 +197,16 @@ Grants a user_grant permission to an application. This API uses an asynchronous ...@@ -196,16 +197,16 @@ Grants a user_grant permission to an application. This API uses an asynchronous
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;void&gt; | Yes| Callback used to return the result. If the permission is granted successfully, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | 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';
let atManager = abilityAccessCtrl.createAtManager(); 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 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 permissionFlag = 1; let permissionFlags = 1;
try { try {
atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag, (err, data) => { atManager.grantUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
if (err) { if (err) {
console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`); console.log(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else { } else {
...@@ -234,7 +235,7 @@ try { ...@@ -234,7 +235,7 @@ try {
### revokeUserGrantedPermission ### revokeUserGrantedPermission
revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlag: number): Promise&lt;void&gt; revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number): Promise&lt;void&gt;
Revokes a user_grant permission from an application. This API uses a promise to return the result. Revokes a user_grant permission from an application. This API uses a promise to return the result.
...@@ -250,7 +251,7 @@ Revokes a user_grant permission from an application. This API uses a promise to ...@@ -250,7 +251,7 @@ Revokes a user_grant permission from an application. This API uses a promise to
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| 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';
let atManager = abilityAccessCtrl.createAtManager(); 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 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 permissionFlag = 1; let permissionFlags = 1;
try { try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag).then(() => { atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags).then(() => {
console.log('revokeUserGrantedPermission success'); console.log('revokeUserGrantedPermission success');
}).catch((err) => { }).catch((err) => {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`); console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
...@@ -291,7 +292,7 @@ try { ...@@ -291,7 +292,7 @@ try {
### revokeUserGrantedPermission ### revokeUserGrantedPermission
revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlag: number, callback: AsyncCallback&lt;void&gt;): void revokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number, callback: AsyncCallback&lt;void&gt;): void
Revokes a user_grant permission from an application. This API uses an asynchronous callback to return the result. Revokes a user_grant permission from an application. This API uses an asynchronous callback to return the result.
...@@ -307,16 +308,16 @@ Revokes a user_grant permission from an application. This API uses an asynchrono ...@@ -307,16 +308,16 @@ Revokes a user_grant permission from an application. This API uses an asynchrono
| --------- | ------------------- | ---- | ------------------------------------------------------------ | | --------- | ------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;void&gt; | Yes| Callback used to return the result. If the permission is revoked successfully, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;void&gt; | 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';
let atManager = abilityAccessCtrl.createAtManager(); 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 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 permissionFlag = 1; let permissionFlags = 1;
try { try {
atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlag, (err, data) => { atManager.revokeUserGrantedPermission(tokenID, "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", permissionFlags, (err, data) => {
if (err) { if (err) {
console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`); console.log(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`);
} else { } else {
...@@ -347,7 +348,7 @@ try { ...@@ -347,7 +348,7 @@ try {
getPermissionFlags(tokenID: number, permissionName: Permissions): Promise&lt;number&gt; getPermissionFlags(tokenID: number, permissionName: Permissions): Promise&lt;number&gt;
Obtains the flags of the specified permission of an application. This API uses a promise to return the result. Obtains the permission flag of an application. This API uses a promise to return the result.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -366,15 +367,15 @@ Obtains the flags of the specified permission of an application. This API uses a ...@@ -366,15 +367,15 @@ Obtains the flags of the specified permission of an application. This API uses a
| Type | Description | | Type | Description |
| :------------ | :---------------------------------- | | :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result.| | Promise&lt;number&gt; | Promise used to return the permission flag obtained. |
**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 operation is not allowed. Either the application is a sandbox or the tokenID is from a remote device. | | 12100006 | The operation is not allowed. Either the application is a sandbox or the tokenID is from a remote device. |
...@@ -426,9 +427,9 @@ promise.then(data => { ...@@ -426,9 +427,9 @@ promise.then(data => {
### on<sup>9+</sup> ### on<sup>9+</sup>
on(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionNameList: Array&lt;Permissions&gt;, callback: Callback&lt;PermissionStateChangeInfo&gt;): void; on(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;PermissionStateChangeInfo&gt;): void;
Subscribes to permission grant state changes of the specified applications and permissions. Subscribes to permission state changes of the specified applications and permissions.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -440,18 +441,18 @@ Subscribes to permission grant state changes of the specified applications and p ...@@ -440,18 +441,18 @@ Subscribes to permission grant state changes of the specified applications and p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | | ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;number&gt; | Yes | List of token IDs. If this parameter is left empty, the permission grant state changes of all applications are subscribed to. | | 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. |
| permissionNameList | Array&lt;Permissions&gt; | Yes | List of permission names. If this parameter is left empty, the permission grant state changes of all permissions are subscribed to. | | permissionList | Array&lt;Permissions&gt; | Yes | Permissions to observe. If this parameter is left empty, the grant state changes of all permissions are observed. |
| callback | Callback&lt;[PermissionStateChangeInfo](#permissionstatechangeinfo9)&gt; | Yes| Callback used to return the permission grant state change information.| | callback | Callback&lt;[PermissionStateChangeInfo](#permissionstatechangeinfo9)&gt; | 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
```js ```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100); let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId]; let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"]; let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try { try {
atManager.on('permissionStateChange', tokenIDList, permissionNameList, (data) => { 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) { } catch(err) {
...@@ -477,9 +479,9 @@ try { ...@@ -477,9 +479,9 @@ try {
### off<sup>9+</sup> ### off<sup>9+</sup>
off(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionNameList: Array&lt;Permissions&gt;, callback?: Callback&lt;PermissionStateChangeInfo&gt;): void; off(type: 'permissionStateChange', tokenIDList: Array&lt;number&gt;, permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;PermissionStateChangeInfo&gt;): void;
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
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | | ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;number&gt; | 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&lt;number&gt; | 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&lt;Permissions&gt; | 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&lt;Permissions&gt; | 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&lt;[PermissionStateChangeInfo](#permissionstatechangeinfo9)&gt; | No| Callback used to return the permission grant state change information.| | callback | Callback&lt;[PermissionStateChangeInfo](#permissionstatechangeinfo9)&gt; | 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 tokenIDs in the list are 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
```js ```js
import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl'; import abilityAccessCtrl, {Permissions} from '@ohos.abilityAccessCtrl';
import bundle from '@ohos.bundle.bundleManager';
let atManager = abilityAccessCtrl.createAtManager(); let atManager = abilityAccessCtrl.createAtManager();
let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100); let appInfo = bundle.getApplicationInfoSync('com.example.myapplication', 0, 100);
let tokenIDList: Array<number> = [appInfo.accessTokenId]; let tokenIDList: Array<number> = [appInfo.accessTokenId];
let permissionNameList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"]; let permissionList: Array<Permissions> = ["ohos.permission.DISTRIBUTED_DATASYNC"];
try { try {
atManager.off('permissionStateChange', tokenIDList, permissionNameList); atManager.off('permissionStateChange', tokenIDList, permissionList);
} catch(err) { } catch(err) {
console.log(`catch err->${JSON.stringify(err)}`); console.log(`catch err->${JSON.stringify(err)}`);
} }
...@@ -538,7 +541,7 @@ Verifies whether a permission is granted to an application. This API uses a prom ...@@ -538,7 +541,7 @@ Verifies whether a permission is granted to an application. This API uses a prom
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------- | ---- | ------------------------------------------ | | -------- | ------------------- | ---- | ------------------------------------------ |
| 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). |
**Return value** **Return value**
...@@ -561,9 +564,9 @@ promise.then(data => { ...@@ -561,9 +564,9 @@ promise.then(data => {
### requestPermissionsFromUser<sup>9+</sup> ### requestPermissionsFromUser<sup>9+</sup>
requestPermissionsFromUser(context: Context, permissions: Array&lt;Permissions&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void; requestPermissionsFromUser(context: Context, permissionList: Array&lt;Permissions&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;
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&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).| | permissionList | Array&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
| callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback invoked to return the result.| | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | 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. |
**Example** **Example**
...@@ -602,9 +605,9 @@ try { ...@@ -602,9 +605,9 @@ try {
### requestPermissionsFromUser<sup>9+</sup> ### requestPermissionsFromUser<sup>9+</sup>
requestPermissionsFromUser(context: Context, permissions: Array&lt;Permissions&gt;) : Promise&lt;PermissionRequestResult&gt;; requestPermissionsFromUser(context: Context, permissionList: Array&lt;Permissions&gt;) : Promise&lt;PermissionRequestResult&gt;;
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&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).| | permissionList | Array&lt;Permissions&gt; | 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.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| -------------- | ------------------------- | ---- | ---- | ------------------ | | -------------- | ------------------------- | ---- | ---- | ------------------ |
| 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). |
...@@ -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
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| permissions | Array&lt;string&gt; | Yes| No| Permissions requested.| | permissions | Array&lt;string&gt; | Yes| No| Permissions requested.|
| authResults | Array&lt;number&gt; | 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&lt;number&gt; | 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).|
## Usage ## Usage
......
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
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. |
| 12100004 | The interface is not used with | | 12100004 | The interface is not used with |
...@@ -445,7 +446,7 @@ try { ...@@ -445,7 +446,7 @@ try {
## privacyManager.on ## privacyManager.on
on(type: 'activeStateChange', permissionNameList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void on(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void
Subscribes to the permission usage status changes of the specified permissions. Subscribes to the permission usage status changes of the specified permissions.
...@@ -458,7 +459,7 @@ Subscribes to the permission usage status changes of the specified permissions. ...@@ -458,7 +459,7 @@ Subscribes to the permission usage status changes of the specified permissions.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | | ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;Permissions&gt; | Yes | List of permissions to be observed. If this parameter is left empty, the usage changes of all permissions are observed. | | permissionList | Array&lt;Permissions&gt; | Yes | List of permissions to be observed. If this parameter is left empty, the usage changes of all permissions are observed. |
| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | Yes| Callback invoked to return a change in the permission usage.| | callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | 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
```js ```js
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let permissionNameList = []; let permissionList = [];
try { try {
privacyManager.on('activeStateChange', permissionNameList, (data) => { 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) { } catch(err) {
...@@ -490,7 +491,7 @@ try { ...@@ -490,7 +491,7 @@ try {
## privacyManager.off ## privacyManager.off
off(type: 'activeStateChange', permissionNameList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void; off(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void;
Unsubscribes from the permission usage status changes of the specified permissions. Unsubscribes from the permission usage status changes of the specified permissions.
...@@ -503,7 +504,7 @@ Unsubscribes from the permission usage status changes of the specified permissio ...@@ -503,7 +504,7 @@ Unsubscribes from the permission usage status changes of the specified permissio
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | | ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
| 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&lt;Permissions&gt; | 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&lt;Permissions&gt; | 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&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | No| Callback for the permission usage change event.| | callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | No| Callback for the permission usage change event.|
**Error codes** **Error codes**
...@@ -512,8 +513,8 @@ For details about the error codes, see [Ability Access Control Error Codes](../e ...@@ -512,8 +513,8 @@ 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 permission names in the list are 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
```js ```js
import privacyManager from '@ohos.privacyManager'; import privacyManager from '@ohos.privacyManager';
let permissionNameList = []; let permissionList = [];
try { try {
privacyManager.off('activeStateChange', permissionNameList); privacyManager.off('activeStateChange', permissionList);
}catch(err) { }catch(err) {
console.log(`catch err->${JSON.stringify(err)}`); console.log(`catch err->${JSON.stringify(err)}`);
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
- [zlib Error Codes](errorcode-zlib.md) - [zlib Error Codes](errorcode-zlib.md)
- Common Event and Notification - Common Event and Notification
- [Event Error Codes](errorcode-CommonEventService.md) - [Event Error Codes](errorcode-CommonEventService.md)
- [Notification Error Codes](errorcode-notification.md)
- [DistributedNotificationService Error Codes](errorcode-DistributedNotificationService.md) - [DistributedNotificationService Error Codes](errorcode-DistributedNotificationService.md)
- UI Page - UI Page
- [Animator Error Codes](errorcode-animator.md) - [Animator Error Codes](errorcode-animator.md)
...@@ -27,13 +26,13 @@ ...@@ -27,13 +26,13 @@
- Resource Management - Resource Management
- [I18N Error Codes](errorcode-i18n.md) - [I18N Error Codes](errorcode-i18n.md)
- [Resource Manager Error Codes](errorcode-resource-manager.md) - [Resource Manager Error Codes](errorcode-resource-manager.md)
- Background Task - Resource Scheduling
- [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md) - [backgroundTaskManager Error Codes](errorcode-backgroundTaskMgr.md)
- [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md) - [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md)
- [reminderAgentManager Error Codes](errorcode-reminderAgentManager.md) - [reminderAgentManager Error Codes](errorcode-reminderAgentManager.md)
- [workScheduler Error Codes](errorcode-workScheduler.md) - [workScheduler Error Codes](errorcode-workScheduler.md)
- Security - Security
- [Ability Access Control Error Codes](errorcode-access-token.md) - [Application Access Control Error Codes](errorcode-access-token.md)
- [HUKS Error Codes](errorcode-huks.md) - [HUKS Error Codes](errorcode-huks.md)
- [Crypto Framework Error Codes](errorcode-crypto-framework.md) - [Crypto Framework Error Codes](errorcode-crypto-framework.md)
- [Certificate Error Codes](errorcode-cert.md) - [Certificate Error Codes](errorcode-cert.md)
...@@ -51,6 +50,7 @@ ...@@ -51,6 +50,7 @@
- Connectivity - Connectivity
- [NFC Error Codes](errorcode-nfc.md) - [NFC Error Codes](errorcode-nfc.md)
- [RPC Error Codes](errorcode-rpc.md) - [RPC Error Codes](errorcode-rpc.md)
- [Wi-Fi Error Codes](errorcode-wifi.md)
- Basic Features - Basic Features
- [Accessibility Error Codes](errorcode-accessibility.md) - [Accessibility Error Codes](errorcode-accessibility.md)
- [FaultLogger Error Codes](errorcode-faultlogger.md) - [FaultLogger Error Codes](errorcode-faultlogger.md)
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
- [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md) - [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md)
- [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) - [Input Method Framework Error Codes](errorcode-inputmethod-framework.md)
- [Pasteboard Error Codes](errorcode-pasteboard.md) - [Pasteboard Error Codes](errorcode-pasteboard.md)
- [Screen Lock Management Error Codes](errorcode-screenlock.md)
- [Time and Time Zone Service Error Codes](errorcode-time.md) - [Time and Time Zone Service Error Codes](errorcode-time.md)
- [Webview Error Codes](errorcode-webview.md) - [Webview Error Codes](errorcode-webview.md)
- Account Management - Account Management
......
# Ability Access Control Error Codes # Application Access Control Error Codes
## 12100001 Invalid Parameters ## 12100001 Invalid Parameters
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册