1e41f4b71Sopenharmony_ci# @ohos.abilityAccessCtrl (Application Access Control) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **abilityAccessCtrl** module provides APIs for application permission management, including authentication, authorization, and revocation. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 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. 8e41f4b71Sopenharmony_ci> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.abilityAccessCtrl (Application Access Control)](js-apis-abilityAccessCtrl.md). 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Modules to Import 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit' 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## AtManager 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciProvides APIs for application access control. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci### grantUserGrantedPermission 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_cigrantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number): Promise<void> 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciGrants a user_grant permission to an application. This API uses a promise to return the result. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**System API**: This is a system API. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS (available only to system applications) 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**Parameters** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 35e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 36e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 37e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 38e41f4b71Sopenharmony_ci| permissionFlags | number | Yes | Permission flag.<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>- **64**: The permission is granted to the user only this time. The authorization is revoked after the application switches to the background or exits.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Return value** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| Type | Description | 43e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 44e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**Error codes** 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci| ID| Error Message| 51e41f4b71Sopenharmony_ci| -------- | -------- | 52e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 53e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 54e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 55e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters, or the flags value is invalid. | 56e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 57e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 58e41f4b71Sopenharmony_ci| 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. | 59e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**Example** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci```ts 64e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 65e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 68e41f4b71Sopenharmony_cilet tokenID: number = 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. 69e41f4b71Sopenharmony_cilet permissionFlags: number = 1; 70e41f4b71Sopenharmony_ciatManager.grantUserGrantedPermission(tokenID, 'ohos.permission.READ_AUDIO', permissionFlags).then(() => { 71e41f4b71Sopenharmony_ci console.log('grantUserGrantedPermission success'); 72e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 73e41f4b71Sopenharmony_ci console.error(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`); 74e41f4b71Sopenharmony_ci}); 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci### grantUserGrantedPermission 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_cigrantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number, callback: AsyncCallback<void>): void 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciGrants a user_grant permission to an application. This API uses an asynchronous callback to return the result. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**System API**: This is a system API. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GRANT_SENSITIVE_PERMISSIONS (available only to system applications) 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Parameters** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 92e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 93e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 94e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission to grant. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 95e41f4b71Sopenharmony_ci| permissionFlags | number | Yes | Permission flag.<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>- **64**: The permission is granted to the user only this time. The authorization is revoked after the application switches to the background or exits.| 96e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Grants a user_grant permission to an application. If the permission is granted, **err** is **undefined**. Otherwise, **err** is an error object.| 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**Error codes** 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci| ID| Error Message| 103e41f4b71Sopenharmony_ci| -------- | -------- | 104e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 105e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 106e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 107e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters, or the flags value is invalid. | 108e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 109e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 110e41f4b71Sopenharmony_ci| 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. | 111e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**Example** 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci```ts 116e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 117e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 120e41f4b71Sopenharmony_cilet tokenID: number = 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. 121e41f4b71Sopenharmony_cilet permissionFlags: number = 1; 122e41f4b71Sopenharmony_ciatManager.grantUserGrantedPermission(tokenID, 'ohos.permission.READ_AUDIO', permissionFlags, (err: BusinessError, data: void) => { 123e41f4b71Sopenharmony_ci if (err) { 124e41f4b71Sopenharmony_ci console.error(`grantUserGrantedPermission fail, err->${JSON.stringify(err)}`); 125e41f4b71Sopenharmony_ci } else { 126e41f4b71Sopenharmony_ci console.log('grantUserGrantedPermission success'); 127e41f4b71Sopenharmony_ci } 128e41f4b71Sopenharmony_ci}); 129e41f4b71Sopenharmony_ci``` 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci### revokeUserGrantedPermission 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_cirevokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number): Promise<void> 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ciRevokes a user_grant permission from an application. This API uses a promise to return the result. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**System API**: This is a system API. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS (available only to system applications) 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Parameters** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 146e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 147e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 148e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 149e41f4b71Sopenharmony_ci| permissionFlags | number | Yes | Permission flag.<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>- **64**: The permission is granted to the user only this time. The authorization is revoked after the application switches to the background or exits.| 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**Return value** 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci| Type | Description | 154e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 155e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**Error codes** 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci| ID| Error Message| 162e41f4b71Sopenharmony_ci| -------- | -------- | 163e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 164e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 165e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 166e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters, or the flags value is invalid. | 167e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 168e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 169e41f4b71Sopenharmony_ci| 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. | 170e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**Example** 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci```ts 175e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 176e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 179e41f4b71Sopenharmony_cilet tokenID: number = 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. 180e41f4b71Sopenharmony_cilet permissionFlags: number = 1; 181e41f4b71Sopenharmony_ciatManager.revokeUserGrantedPermission(tokenID, 'ohos.permission.READ_AUDIO', permissionFlags).then(() => { 182e41f4b71Sopenharmony_ci console.log('revokeUserGrantedPermission success'); 183e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 184e41f4b71Sopenharmony_ci console.error(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`); 185e41f4b71Sopenharmony_ci}); 186e41f4b71Sopenharmony_ci``` 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci### revokeUserGrantedPermission 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_cirevokeUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number, callback: AsyncCallback<void>): void 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ciRevokes a user_grant permission from an application. This API uses an asynchronous callback to return the result. 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**System API**: This is a system API. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.REVOKE_SENSITIVE_PERMISSIONS (available only to system applications) 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**Parameters** 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 203e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 204e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 205e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission to revoke. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 206e41f4b71Sopenharmony_ci| permissionFlags | number | Yes | Permission flag.<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>- **64**: The permission is granted to the user only this time. The authorization is revoked after the application switches to the background or exits.| 207e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the permission is revoked, **err** is **undefined**. Otherwise, **err** is an error object.| 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**Error codes** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci| ID| Error Message| 214e41f4b71Sopenharmony_ci| -------- | -------- | 215e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 216e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 217e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 218e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters, or the flags value is invalid. | 219e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 220e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 221e41f4b71Sopenharmony_ci| 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. | 222e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**Example** 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci```ts 227e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 228e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 231e41f4b71Sopenharmony_cilet tokenID: number = 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. 232e41f4b71Sopenharmony_cilet permissionFlags: number = 1; 233e41f4b71Sopenharmony_ciatManager.revokeUserGrantedPermission(tokenID, 'ohos.permission.READ_AUDIO', permissionFlags, (err: BusinessError, data: void) => { 234e41f4b71Sopenharmony_ci if (err) { 235e41f4b71Sopenharmony_ci console.error(`revokeUserGrantedPermission fail, err->${JSON.stringify(err)}`); 236e41f4b71Sopenharmony_ci } else { 237e41f4b71Sopenharmony_ci console.log('revokeUserGrantedPermission success'); 238e41f4b71Sopenharmony_ci } 239e41f4b71Sopenharmony_ci}); 240e41f4b71Sopenharmony_ci``` 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci### getPermissionFlags 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_cigetPermissionFlags(tokenID: number, permissionName: Permissions): Promise<number> 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ciObtains the flag of the specified permission of an application. This API uses a promise to return the result. 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**System API**: This is a system API. 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS, ohos.permission.GRANT_SENSITIVE_PERMISSIONS, or ohos.permission.REVOKE_SENSITIVE_PERMISSIONS (available only to system applications) 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**Parameters** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 257e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 258e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 259e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission whose flag is to be obtained. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**Return value** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci| Type | Description | 264e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 265e41f4b71Sopenharmony_ci| Promise<number> | Promise used to return the result.| 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**Error codes** 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| ID| Error Message| 272e41f4b71Sopenharmony_ci| -------- | -------- | 273e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 274e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 275e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 276e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters. | 277e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 278e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 279e41f4b71Sopenharmony_ci| 12100006 | The operation is not allowed. Either the application is a sandbox or the tokenID is from a remote device. | 280e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci**Example** 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci```ts 285e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 286e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 289e41f4b71Sopenharmony_cilet tokenID: number = 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. 290e41f4b71Sopenharmony_ciatManager.getPermissionFlags(tokenID, 'ohos.permission.GRANT_SENSITIVE_PERMISSIONS').then((data: number) => { 291e41f4b71Sopenharmony_ci console.log(`getPermissionFlags success, data->${JSON.stringify(data)}`); 292e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 293e41f4b71Sopenharmony_ci console.error(`getPermissionFlags fail, err->${JSON.stringify(err)}`); 294e41f4b71Sopenharmony_ci}); 295e41f4b71Sopenharmony_ci``` 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci### setPermissionRequestToggleStatus<sup>12+</sup> 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_cisetPermissionRequestToggleStatus(permissionName: Permissions, status: PermissionRequestToggleStatus): Promise<void> 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ciSets the toggle state of a permission. This API uses a promise to return the result. 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**System API**: This is a system API. 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DISABLE_PERMISSION_DIALOG 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**Parameters** 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 312e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 313e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission to be set with the toggle state. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 314e41f4b71Sopenharmony_ci| status | [PermissionRequestToggleStatus](#permissionrequesttogglestatus12) | Yes | Toggle state to set. | 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**Return value** 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci| Type | Description | 319e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 320e41f4b71Sopenharmony_ci| Promise<void> | Promise that returns no value.| 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**Error codes** 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| ID| Error Message| 327e41f4b71Sopenharmony_ci| -------- | -------- | 328e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 329e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 330e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 331e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The permissionName exceeds 256 characters, or the status value is invalid. | 332e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 333e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci**Example** 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci```ts 338e41f4b71Sopenharmony_ciimport { abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; 339e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_cilet atManager = abilityAccessCtrl.createAtManager(); 342e41f4b71Sopenharmony_cilet permission: Permissions = 'ohos.permission.CAMERA'; 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ciatManager.setPermissionRequestToggleStatus(permission, abilityAccessCtrl.PermissionRequestToggleStatus.CLOSED).then((err) => { 345e41f4b71Sopenharmony_ci console.info('toggle_status: Set closed successful'); 346e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 347e41f4b71Sopenharmony_ci console.error('toggle_status: Code is ${err.code}, message is ${err.message}'); 348e41f4b71Sopenharmony_ci}); 349e41f4b71Sopenharmony_ci``` 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci### getPermissionRequestToggleStatus<sup>12+</sup> 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_cigetPermissionRequestToggleStatus(permissionName: Permissions): Promise<PermissionRequestToggleStatus> 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ciObtains the toggle state of a permission. This API uses a promise to return the result. 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**System API**: This is a system API. 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**Parameters** 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 366e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 367e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Permission whose toggle state is to be obtained. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**Return value** 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci| Type | Description | 372e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 373e41f4b71Sopenharmony_ci| Promise<[PermissionRequestToggleStatus](#permissionrequesttogglestatus12)> | Promise used to return the toggle state obtained.| 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci**Error codes** 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| ID| Error Message| 380e41f4b71Sopenharmony_ci| -------- | -------- | 381e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 382e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 383e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 384e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The permissionName exceeds 256 characters. | 385e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist. | 386e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci**Example** 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_ci```ts 391e41f4b71Sopenharmony_ciimport { abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; 392e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_cilet atManager = abilityAccessCtrl.createAtManager(); 395e41f4b71Sopenharmony_cilet permission: Permissions = 'ohos.permission.CAMERA'; 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ciatManager.getPermissionRequestToggleStatus(permission).then((res) => { 398e41f4b71Sopenharmony_ci if (res == abilityAccessCtrl.PermissionRequestToggleStatus.CLOSED) { 399e41f4b71Sopenharmony_ci console.info('toggle_status: The toggle status is close'); 400e41f4b71Sopenharmony_ci } else { 401e41f4b71Sopenharmony_ci console.info('toggle_status: The toggle status is open'); 402e41f4b71Sopenharmony_ci } 403e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 404e41f4b71Sopenharmony_ciconsole.error('toggle_status: Code is ${err.code}, message is ${err.message}'); 405e41f4b71Sopenharmony_ci}); 406e41f4b71Sopenharmony_ci``` 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci### getVersion<sup>9+</sup> 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_cigetVersion(): Promise<number> 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ciObtains the data version of the permission management. This API uses a promise to return the result. 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci**System API**: This is a system API. 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**Return value** 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| Type | Description | 421e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 422e41f4b71Sopenharmony_ci| Promise<number> | Promise used to return the version obtained.| 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci| ID| Error Message| 425e41f4b71Sopenharmony_ci| -------- | -------- | 426e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**Example** 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci```ts 431e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 434e41f4b71Sopenharmony_cilet promise = atManager.getVersion(); 435e41f4b71Sopenharmony_cipromise.then((data: number) => { 436e41f4b71Sopenharmony_ci console.log(`promise: data->${JSON.stringify(data)}`); 437e41f4b71Sopenharmony_ci}); 438e41f4b71Sopenharmony_ci``` 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci### getPermissionsStatus<sup>12+</sup> 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_cigetPermissionsStatus(tokenID: number, permissionList: Array<Permissions>): Promise<Array<PermissionStatus>> 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ciObtains the status of the specified permissions. This API uses a promise to return the result. 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**System API**: This is a system API. 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS (available only to system applications) 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**Parameters** 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 455e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 456e41f4b71Sopenharmony_ci| tokenID | number | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 457e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | Yes | Permissions whose status is to be obtained. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**Return value** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci| Type | Description | 462e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 463e41f4b71Sopenharmony_ci| Promise<Array<[PermissionStatus](#permissionstatus12)>> | Promise used to return the permission status obtained.| 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci**Error codes** 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci| ID| Error Message| 470e41f4b71Sopenharmony_ci| -------- | -------- | 471e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 472e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 473e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 474e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters. | 475e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist. | 476e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci**Example** 479e41f4b71Sopenharmony_ci 480e41f4b71Sopenharmony_ci```ts 481e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit'; 482e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 485e41f4b71Sopenharmony_cilet tokenID: number = 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. 486e41f4b71Sopenharmony_ciatManager.getPermissionsStatus(tokenID, ['ohos.permission.CAMERA']).then((data: Array<abilityAccessCtrl.PermissionStatus>) => { 487e41f4b71Sopenharmony_ci console.log(`getPermissionsStatus success, data->${JSON.stringify(data)}`); 488e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 489e41f4b71Sopenharmony_ci console.error(`getPermissionsStatus fail, err->${JSON.stringify(err)}`); 490e41f4b71Sopenharmony_ci}); 491e41f4b71Sopenharmony_ci``` 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci### on<sup>9+</sup> 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_cion(type: 'permissionStateChange', tokenIDList: Array<number>, permissionList: Array<Permissions>, callback: Callback<PermissionStateChangeInfo>): void 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ciSubscribes to permission state changes of the specified applications and permissions. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciMultiple callbacks can be registered for the specified **tokenIDList** and **permissionList**. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ciIf **tokenIDList** and **permissionList** have common values with the **tokenIDList** and **permissionList** of a callback registered, **callback** must be different. 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**System API**: This is a system API. 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS (available only to system applications) 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci**Parameters** 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 512e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | 513e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is **'permissionStateChange'**, which indicates the permission grant state changes. | 514e41f4b71Sopenharmony_ci| tokenIDList | Array<number> | Yes | List of application token IDs. If this parameter is left empty, this API subscribes to the permission grant state changes of all applications.| 515e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | Yes | List of permissions to be subscribed to. If this parameter is left empty, this API subscribes to state changes of all permissions. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 516e41f4b71Sopenharmony_ci| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | Yes| Callback invoked to return the permission grant state change.| 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**Error codes** 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci| ID| Error Message| 523e41f4b71Sopenharmony_ci| -------- | -------- | 524e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 525e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 526e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 527e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters. | 528e41f4b71Sopenharmony_ci| 12100004 | The API is used repeatedly with the same input. | 529e41f4b71Sopenharmony_ci| 12100005 | The registration time has exceeded the limitation. | 530e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 531e41f4b71Sopenharmony_ci| 12100008 | Out of memory. | 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**Example** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci```ts 536e41f4b71Sopenharmony_ciimport { abilityAccessCtrl, Permissions, bundleManager } from '@kit.AbilityKit'; 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 539e41f4b71Sopenharmony_cilet appInfo: bundleManager.ApplicationInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100); 540e41f4b71Sopenharmony_cilet tokenIDList: Array<number> = [appInfo.accessTokenId]; 541e41f4b71Sopenharmony_cilet permissionList: Array<Permissions> = ['ohos.permission.DISTRIBUTED_DATASYNC']; 542e41f4b71Sopenharmony_citry { 543e41f4b71Sopenharmony_ci atManager.on('permissionStateChange', tokenIDList, permissionList, (data: abilityAccessCtrl.PermissionStateChangeInfo) => { 544e41f4b71Sopenharmony_ci console.debug('receive permission state change, data:' + JSON.stringify(data)); 545e41f4b71Sopenharmony_ci }); 546e41f4b71Sopenharmony_ci} catch(err) { 547e41f4b71Sopenharmony_ci console.error(`catch err->${JSON.stringify(err)}`); 548e41f4b71Sopenharmony_ci} 549e41f4b71Sopenharmony_ci``` 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci### off<sup>9+</sup> 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_cioff(type: 'permissionStateChange', tokenIDList: Array<number>, permissionList: Array<Permissions>, callback?: Callback<PermissionStateChangeInfo>): void 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ciUnsubscribes from permission grant state changes of the specified applications and permissions. This API uses a callback to return the result. 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ciIf no callback is passed in **atManager.off**, all callbacks for **tokenIDList** and **permissionList** will be unregistered. 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci**System API**: This is a system API. 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.GET_SENSITIVE_PERMISSIONS (available only to system applications) 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**Parameters** 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 568e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | 569e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The value is **'permissionStateChange'**, which indicates the permission grant state changes. | 570e41f4b71Sopenharmony_ci| tokenIDList | Array<number> | Yes | List of application token IDs. The value must be the same as that passed in **on()**. If this parameter is left empty, this API unsubscribes from the permission grant state changes of all applications.| 571e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | Yes | List of permissions. The value must be the same as that of **on()**. If this parameter is left empty, this API unsubscribes from state changes of all permissions. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 572e41f4b71Sopenharmony_ci| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | No| Callback for the permission grant state change.| 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**Error codes** 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md). 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci| ID| Error Message| 579e41f4b71Sopenharmony_ci| -------- | -------- | 580e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 581e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 582e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. | 583e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenIDs or permissionNames in the list are all invalid. | 584e41f4b71Sopenharmony_ci| 12100004 | The API is not used in pair with 'on'. | 585e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. | 586e41f4b71Sopenharmony_ci| 12100008 | Out of memory. | 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci**Example** 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci```ts 591e41f4b71Sopenharmony_ciimport { abilityAccessCtrl, Permissions, bundleManager } from '@kit.AbilityKit'; 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_cilet atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); 594e41f4b71Sopenharmony_cilet appInfo: bundleManager.ApplicationInfo = bundleManager.getApplicationInfoSync('com.example.myapplication', 0, 100); 595e41f4b71Sopenharmony_cilet tokenIDList: Array<number> = [appInfo.accessTokenId]; 596e41f4b71Sopenharmony_cilet permissionList: Array<Permissions> = ['ohos.permission.DISTRIBUTED_DATASYNC']; 597e41f4b71Sopenharmony_citry { 598e41f4b71Sopenharmony_ci atManager.off('permissionStateChange', tokenIDList, permissionList); 599e41f4b71Sopenharmony_ci} catch(err) { 600e41f4b71Sopenharmony_ci console.error(`catch err->${JSON.stringify(err)}`); 601e41f4b71Sopenharmony_ci} 602e41f4b71Sopenharmony_ci``` 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci### PermissionStateChangeType<sup>9+</sup> 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ciEnumerates the operations that trigger permission grant state changes. 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci**System API**: This is a system API. 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci| Name | Value| Description | 613e41f4b71Sopenharmony_ci| ----------------------- | ------ | ----------------- | 614e41f4b71Sopenharmony_ci| PERMISSION_REVOKED_OPER | 0 | Operation to revoke the permission.| 615e41f4b71Sopenharmony_ci| PERMISSION_GRANTED_OPER | 1 | Operation to grant the permission.| 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci### PermissionRequestToggleStatus<sup>12+</sup> 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ciEnumerates the permission toggle states. 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci| Name | Value| Description | 624e41f4b71Sopenharmony_ci| ------------------ | ----- | ----------- | 625e41f4b71Sopenharmony_ci| CLOSED | 0 | The permission request toggle is disabled.| 626e41f4b71Sopenharmony_ci| OPEN | 1 | The permission request toggle is enabled.| 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci### PermissionStateChangeInfo<sup>9+</sup> 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ciDefines detailed information about the permission grant state change. 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci**System API**: This is a system API. 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci| Name | Type | Read Only| Mandatory| Description | 637e41f4b71Sopenharmony_ci| -------------- | ------------------------- | ---- | ---- | ------------------ | 638e41f4b71Sopenharmony_ci| change | [PermissionStateChangeType](#permissionstatechangetype9) | Yes | Yes | Operation that triggers the permission grant state change. | 639e41f4b71Sopenharmony_ci| tokenID | number | Yes | Yes | Application token ID, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).| 640e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes | Yes | Permission whose grant state changes. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).| 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci### PermissionStatus<sup>12+</sup> 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ciEnumerates the permission states. 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**System API**: This is a system API. 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci| Name | Value| Description | 651e41f4b71Sopenharmony_ci| ------------------ | ----- | ----------- | 652e41f4b71Sopenharmony_ci| DENIED | -1 | The permission is not granted.| 653e41f4b71Sopenharmony_ci| GRANTED | 0 | The permission is granted.| 654e41f4b71Sopenharmony_ci| NOT_DETERMINED | 1 | The permission state is not determined.| 655e41f4b71Sopenharmony_ci| INVALID | 2 | The permission is invalid.| 656e41f4b71Sopenharmony_ci| RESTRICTED | 3 | The permission is restricted.| 657