1e41f4b71Sopenharmony_ci# @ohos.abilityAccessCtrl (程序访问控制管理)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci程序访问控制提供程序的权限管理能力,包括鉴权、授权和取消授权等。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.abilityAccessCtrl (程序访问控制管理)](js-apis-abilityAccessCtrl.md)。 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 导入模块 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci```ts 13e41f4b71Sopenharmony_ciimport { abilityAccessCtrl } from '@kit.AbilityKit' 14e41f4b71Sopenharmony_ci``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## AtManager 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci管理访问控制模块的实例。 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci### grantUserGrantedPermission 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_cigrantUserGrantedPermission(tokenID: number, permissionName: Permissions, permissionFlags: number): Promise<void> 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci授予应用user_grant权限。使用Promise异步回调。 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GRANT_SENSITIVE_PERMISSIONS,仅系统应用可用。 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**参数:** 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 35e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 36e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 37e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 被授予的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 38e41f4b71Sopenharmony_ci| permissionFlags | number | 是 | 授权选项<br>- 1表示当次用户若选择禁止该权限,下次权限弹窗仍可以弹出申请用户授权。<br>- 2表示当次用户若选择禁止该权限,下次不会再弹出权限弹窗,需要用户在setting的权限管理中进行授权。<br>- 64表示当次用户若选择仅本次允许,权限仅本次授权,应用切换后台状态或退出后取消授权。 | 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**返回值:** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| 类型 | 说明 | 43e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 44e41f4b71Sopenharmony_ci| Promise<void> | Promise对象。无返回结果的Promise对象。 | 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci**错误码:** 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci授予应用user_grant权限。使用callback异步回调。 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GRANT_SENSITIVE_PERMISSIONS,仅系统应用可用。 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**参数:** 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 92e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 93e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 94e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 被授予的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 95e41f4b71Sopenharmony_ci| permissionFlags | number | 是 | 授权选项<br>- 1表示当次用户若选择禁止该权限,下次权限弹窗仍可以弹出申请用户授权。<br>- 2表示当次用户若选择禁止该权限,下次不会再弹出权限弹窗,需要用户在setting的权限管理中进行授权。<br>- 64表示当次用户若选择仅本次允许,权限仅本次授权,应用切换后台状态或退出后取消授权。 | 96e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 授予应用user_grant权限。当授予权限成功时,err为undefined;否则为错误对象。 | 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**错误码:** 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci撤销应用user_grant权限。使用Promise异步回调。 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.REVOKE_SENSITIVE_PERMISSIONS,仅系统应用可用。 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**参数:** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 146e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 147e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 148e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 被撤销的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 149e41f4b71Sopenharmony_ci| permissionFlags | number | 是 | 授权选项<br>- 1表示当次用户若选择禁止该权限,下次权限弹窗仍可以弹出申请用户授权。<br>- 2表示当次用户若选择禁止该权限,下次不会再弹出权限弹窗,需要用户在setting的权限管理中进行授权。<br>- 64表示当次用户若选择仅本次允许,权限仅本次授权,应用切换后台状态或退出后取消授权。 | 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**返回值:** 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci| 类型 | 说明 | 154e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 155e41f4b71Sopenharmony_ci| Promise<void> | Promise对象。无返回结果的Promise对象。 | 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci**错误码:** 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci撤销应用user_grant权限。使用callback异步回调。 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.REVOKE_SENSITIVE_PERMISSIONS,仅系统应用可用。 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**参数:** 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 203e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 204e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 205e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 被撤销的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 206e41f4b71Sopenharmony_ci| permissionFlags | number | 是 | 授权选项<br>- 1表示当次用户若选择禁止该权限,下次权限弹窗仍可以弹出申请用户授权。<br>- 2表示当次用户若选择禁止该权限,下次不会再弹出权限弹窗,需要用户在setting的权限管理中进行授权。<br>- 64表示当次用户若选择仅本次允许,权限仅本次授权,应用切换后台状态或退出后取消授权。 | 207e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 撤销应用user_grant权限。当撤销权限成功时,err为undefined;否则为错误对象。 | 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**错误码:** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci获取指定应用的指定权限的flag。使用Promise异步回调。 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_SENSITIVE_PERMISSIONS or ohos.permission.GRANT_SENSITIVE_PERMISSIONS or ohos.permission.REVOKE_SENSITIVE_PERMISSIONS,仅系统应用可用。 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**参数:** 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 257e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 258e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 259e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 查询的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**返回值:** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci| 类型 | 说明 | 264e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 265e41f4b71Sopenharmony_ci| Promise<number> | Promise对象。返回查询结果。 | 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**错误码:** 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci设置当前用户指定权限的弹窗开关状态。使用Promise异步回调。 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.DISABLE_PERMISSION_DIALOG。 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**参数:** 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 312e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 313e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 待设置弹窗开关状态的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 314e41f4b71Sopenharmony_ci| status | [PermissionRequestToggleStatus](#permissionrequesttogglestatus12) | 是 | 指定权限的弹窗开关状态值。 | 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**返回值:** 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci| 类型 | 说明 | 319e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 320e41f4b71Sopenharmony_ci| Promise<void> | Promise对象。无返回结果的Promise对象。 | 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**错误码:** 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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_ci获取当前用户指定权限的弹窗开关状态。使用Promise异步回调。 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_SENSITIVE_PERMISSIONS。 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**参数:** 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 366e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 367e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 待查询弹窗开关状态的权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**返回值:** 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci| 类型 | 说明 | 372e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 373e41f4b71Sopenharmony_ci| Promise<[PermissionRequestToggleStatus](#permissionrequesttogglestatus12)> | Promise对象。返回指定权限的弹窗开关状态值。 | 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci**错误码:** 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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_ci获取当前权限管理的数据版本。使用Promise异步回调。 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**返回值:** 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci| 类型 | 说明 | 421e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 422e41f4b71Sopenharmony_ci| Promise<number> | Promise对象。返回查询到的版本号。 | 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 425e41f4b71Sopenharmony_ci| -------- | -------- | 426e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**示例:** 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_ci获取指定应用权限状态列表。使用Promise异步回调。 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_SENSITIVE_PERMISSIONS,仅系统应用可用。 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 451e41f4b71Sopenharmony_ci 452e41f4b71Sopenharmony_ci**参数:** 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 455e41f4b71Sopenharmony_ci| --------- | ------------------- | ---- | ------------------------------------------------------------ | 456e41f4b71Sopenharmony_ci| tokenID | number | 是 | 目标应用的身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 457e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | 是 | 待获取权限状态的权限名列表,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci**返回值:** 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci| 类型 | 说明 | 462e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- | 463e41f4b71Sopenharmony_ci| Promise<Array<[PermissionStatus](#permissionstatus12)>> | Promise对象。返回查询到的权限状态列表。 | 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci**错误码:** 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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; // 系统应用可以通过bundleManager.getApplicationInfo获取,普通应用可以通过bundleManager.getBundleInfoForSelf获取 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_ci订阅指定tokenId列表与权限列表的权限状态变更事件。 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci允许指定tokenId列表与权限列表订阅多个callback。 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci不允许存在交集的tokenId列表与权限列表订阅相同callback。 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_SENSITIVE_PERMISSIONS,仅系统应用可用。 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci**参数:** 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 512e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | 513e41f4b71Sopenharmony_ci| type | string | 是 | 订阅事件类型,固定为'permissionStateChange',权限状态变更事件。 | 514e41f4b71Sopenharmony_ci| tokenIDList | Array<number> | 是 | 订阅的tokenId列表,为空时表示订阅所有的应用的权限状态变化。 | 515e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | 是 | 订阅的权限名列表,为空时表示订阅所有的权限状态变化,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。| 516e41f4b71Sopenharmony_ci| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | 是 | 订阅指定tokenId与指定权限名状态变更事件的回调。| 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**错误码:** 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 521e41f4b71Sopenharmony_ci 522e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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_ci取消订阅指定tokenId列表与权限列表的权限状态变更事件,使用callback回调异步返回结果。 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci取消订阅不传callback时,批量删除tokenIDList和permissionList下面的所有callback。 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**需要权限:** ohos.permission.GET_SENSITIVE_PERMISSIONS,仅系统应用可用。 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**参数:** 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 568e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ | 569e41f4b71Sopenharmony_ci| type | string | 是 | 订阅事件类型,固定为'permissionStateChange',权限状态变更事件。 | 570e41f4b71Sopenharmony_ci| tokenIDList | Array<number> | 是 | 订阅的tokenId列表,为空时表示订阅所有的应用的权限状态变化,必须与on的输入一致。 | 571e41f4b71Sopenharmony_ci| permissionList | Array<Permissions> | 是 | 订阅的权限名列表,为空时表示订阅所有的权限状态变化,必须与on的输入一致,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 572e41f4b71Sopenharmony_ci| callback | Callback<[PermissionStateChangeInfo](#permissionstatechangeinfo9)> | 否 | 取消订阅指定tokenId与指定权限名状态变更事件的回调。| 573e41f4b71Sopenharmony_ci 574e41f4b71Sopenharmony_ci**错误码:** 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 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_ci表示权限授权状态变化操作类型的枚举。 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 613e41f4b71Sopenharmony_ci| ----------------------- | ------ | ----------------- | 614e41f4b71Sopenharmony_ci| PERMISSION_REVOKED_OPER | 0 | 表示权限取消操作。 | 615e41f4b71Sopenharmony_ci| PERMISSION_GRANTED_OPER | 1 | 表示权限授予操作。 | 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci### PermissionRequestToggleStatus<sup>12+</sup> 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci表示指定权限对应的弹窗开关状态的枚举。 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 624e41f4b71Sopenharmony_ci| ------------------ | ----- | ----------- | 625e41f4b71Sopenharmony_ci| CLOSED | 0 | 表示关闭状态。 | 626e41f4b71Sopenharmony_ci| OPEN | 1 | 表示开启状态。 | 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci### PermissionStateChangeInfo<sup>9+</sup> 629e41f4b71Sopenharmony_ci 630e41f4b71Sopenharmony_ci表示某次权限授权状态变化的详情。 631e41f4b71Sopenharmony_ci 632e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 必填 | 说明 | 637e41f4b71Sopenharmony_ci| -------------- | ------------------------- | ---- | ---- | ------------------ | 638e41f4b71Sopenharmony_ci| change | [PermissionStateChangeType](#permissionstatechangetype9) | 是 | 是 | 权限授权状态变化类型。 | 639e41f4b71Sopenharmony_ci| tokenID | number | 是 | 是 | 被订阅的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。| 640e41f4b71Sopenharmony_ci| permissionName | Permissions | 是 | 是 | 当前授权状态发生变化的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/permissions-for-all.md)中查询。 | 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci### PermissionStatus<sup>12+</sup> 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci表示权限状态的枚举。 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**系统接口:** 此接口为系统接口。 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.Security.AccessToken 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 651e41f4b71Sopenharmony_ci| ------------------ | ----- | ----------- | 652e41f4b71Sopenharmony_ci| DENIED | -1 | 表示未授权。 | 653e41f4b71Sopenharmony_ci| GRANTED | 0 | 表示已授权。 | 654e41f4b71Sopenharmony_ci| NOT_DETERMINED | 1 | 表示未操作。 | 655e41f4b71Sopenharmony_ci| INVALID | 2 | 表示无效。 | 656e41f4b71Sopenharmony_ci| RESTRICTED | 3 | 表示受限。 | 657