1e41f4b71Sopenharmony_ci# @ohos.privacyManager (Privacy Management) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **privacyManager** module provides APIs for privacy management, such as management of permission usage records.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - 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.
8e41f4b71Sopenharmony_ci> - The APIs provided by this module are system APIs.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## privacyManager.addPermissionUsedRecord
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciaddPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, options?: AddPermissionUsedRecordOptions): Promise<void>
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciAdds a permission usage record when an application protected by the permission is called by another service or application. This API uses a promise to return the result.
22e41f4b71Sopenharmony_ciThe permission usage record includes the application identity (token ID) of the invoker, name of the permission used, and number of successful and failed accesses to the target application.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**Parameters**
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                      |
31e41f4b71Sopenharmony_ci| -------- | -------------------  | ---- | ------------------------------------------ |
32e41f4b71Sopenharmony_ci| tokenID   |  number   | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
33e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes  | Name of the permission.|
34e41f4b71Sopenharmony_ci| successCount | number | Yes  | Number of successful accesses.|
35e41f4b71Sopenharmony_ci| failCount | number | Yes  | Number of failed accesses.|
36e41f4b71Sopenharmony_ci| options<sup>12+</sup> | [AddPermissionUsedRecordOptions](#addpermissionusedrecordoptions12) | No  | Options for adding a permission usage record. This parameter is supported since API version 12.|
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Return value**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Type         | Description                               |
41e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- |
42e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Error codes**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci| ID| Error Message|
49e41f4b71Sopenharmony_ci| -------- | -------- |
50e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
51e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
52e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
53e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, the count value is invalid, or usedType in AddPermissionUsedRecordOptions is invalid. |
54e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
55e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
56e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
57e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci**Example**
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci```ts
62e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
63e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
66e41f4b71Sopenharmony_ciprivacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0).then(() => {
67e41f4b71Sopenharmony_ci  console.log('addPermissionUsedRecord success');
68e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
69e41f4b71Sopenharmony_ci  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
70e41f4b71Sopenharmony_ci});
71e41f4b71Sopenharmony_ci// with options param
72e41f4b71Sopenharmony_cilet options: privacyManager.AddPermissionUsedRecordOptions = {
73e41f4b71Sopenharmony_ci  usedType: privacyManager.PermissionUsedType.PICKER_TYPE
74e41f4b71Sopenharmony_ci};
75e41f4b71Sopenharmony_ciprivacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, options).then(() => {
76e41f4b71Sopenharmony_ci  console.log('addPermissionUsedRecord success');
77e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
78e41f4b71Sopenharmony_ci  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
79e41f4b71Sopenharmony_ci});
80e41f4b71Sopenharmony_ci```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci## privacyManager.addPermissionUsedRecord
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ciaddPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, callback: AsyncCallback&lt;void&gt;): void
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciAdds a permission usage record when an application protected by the permission is called by another service or application. This API uses an asynchronous callback to return the result.
87e41f4b71Sopenharmony_ciThe permission usage record includes the application identity (token ID) of the invoker, name of the permission used, and number of successful and failed accesses to the target application.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Parameters**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                      |
96e41f4b71Sopenharmony_ci| -------- | -------------------  | ---- | ------------------------------------------ |
97e41f4b71Sopenharmony_ci| tokenID   |  number   | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
98e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes  | Permission name. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
99e41f4b71Sopenharmony_ci| successCount | number | Yes  | Number of successful accesses.|
100e41f4b71Sopenharmony_ci| failCount | number | Yes  | Number of failed accesses.|
101e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Error codes**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci| ID| Error Message|
108e41f4b71Sopenharmony_ci| -------- | -------- |
109e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
110e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
111e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
112e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
113e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
114e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
115e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
116e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**Example**
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci```ts
121e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
122e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
125e41f4b71Sopenharmony_ciprivacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, (err: BusinessError, data: void) => {
126e41f4b71Sopenharmony_ci  if (err) {
127e41f4b71Sopenharmony_ci    console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
128e41f4b71Sopenharmony_ci  } else {
129e41f4b71Sopenharmony_ci    console.log('addPermissionUsedRecord success');
130e41f4b71Sopenharmony_ci  }
131e41f4b71Sopenharmony_ci});
132e41f4b71Sopenharmony_ci```
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci## privacyManager.getPermissionUsedRecord
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_cigetPermissionUsedRecord(request: PermissionUsedRequest): Promise&lt;PermissionUsedResponse&gt;
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ciObtains historical permission usage records. This API uses a promise to return the result.
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci**Parameters**
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                      |
147e41f4b71Sopenharmony_ci| -------- | -------------------  | ---- | ------------------------------------------ |
148e41f4b71Sopenharmony_ci| request   |  [PermissionUsedRequest](#permissionusedrequest)   | Yes  | Request for querying permission usage records.             |
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**Return value**
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci| Type         | Description                               |
153e41f4b71Sopenharmony_ci| :------------ | :---------------------------------- |
154e41f4b71Sopenharmony_ci| Promise<[PermissionUsedResponse](#permissionusedresponse)> | Promise used to return the permission usage records.|
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**Error codes**
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci| ID| Error Message|
161e41f4b71Sopenharmony_ci| -------- | -------- |
162e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
163e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
164e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
165e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The value of flag in request is invalid. |
166e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
167e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
168e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
169e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**Example**
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci```ts
174e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
175e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_cilet request: privacyManager.PermissionUsedRequest = {
178e41f4b71Sopenharmony_ci    'tokenId': 1,
179e41f4b71Sopenharmony_ci    'isRemote': false,
180e41f4b71Sopenharmony_ci    'deviceId': 'device',
181e41f4b71Sopenharmony_ci    'bundleName': 'bundle',
182e41f4b71Sopenharmony_ci    'permissionNames': [],
183e41f4b71Sopenharmony_ci    'beginTime': 0,
184e41f4b71Sopenharmony_ci    'endTime': 1,
185e41f4b71Sopenharmony_ci    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
186e41f4b71Sopenharmony_ci};
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedRecord(request).then((data) => {
189e41f4b71Sopenharmony_ci  console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
190e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
191e41f4b71Sopenharmony_ci  console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
192e41f4b71Sopenharmony_ci});
193e41f4b71Sopenharmony_ci```
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci## privacyManager.getPermissionUsedRecord
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_cigetPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback&lt;PermissionUsedResponse&gt;): void
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ciObtains historical permission usage records. This API uses an asynchronous callback to return the result.
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci**Parameters**
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                      |
208e41f4b71Sopenharmony_ci| -------- | -------------------  | ---- | ------------------------------------------ |
209e41f4b71Sopenharmony_ci| request | [PermissionUsedRequest](#permissionusedrequest) | Yes| Request for querying permission usage records.|
210e41f4b71Sopenharmony_ci| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the permission usage record obtained. Otherwise, **err** is an error object.|
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci**Error codes**
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci| ID| Error Message|
217e41f4b71Sopenharmony_ci| -------- | -------- |
218e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
219e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
220e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
221e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The value of flag in request is invalid. |
222e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
223e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
224e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
225e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci**Example**
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci```ts
230e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
231e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_cilet request: privacyManager.PermissionUsedRequest = {
234e41f4b71Sopenharmony_ci    'tokenId': 1,
235e41f4b71Sopenharmony_ci    'isRemote': false,
236e41f4b71Sopenharmony_ci    'deviceId': 'device',
237e41f4b71Sopenharmony_ci    'bundleName': 'bundle',
238e41f4b71Sopenharmony_ci    'permissionNames': [],
239e41f4b71Sopenharmony_ci    'beginTime': 0,
240e41f4b71Sopenharmony_ci    'endTime': 1,
241e41f4b71Sopenharmony_ci    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
242e41f4b71Sopenharmony_ci};
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedRecord(request, (err: BusinessError, data: privacyManager.PermissionUsedResponse) => {
245e41f4b71Sopenharmony_ci  if (err) {
246e41f4b71Sopenharmony_ci    console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
247e41f4b71Sopenharmony_ci  } else {
248e41f4b71Sopenharmony_ci    console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
249e41f4b71Sopenharmony_ci  }
250e41f4b71Sopenharmony_ci});
251e41f4b71Sopenharmony_ci```
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci## privacyManager.startUsingPermission
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_cistartUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ciStarts to use a permission and flushes the permission usage record. This API is called by a system application, either running in the foreground or background, and uses a promise to return the result. This API uses a promise to return the result.
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci**Parameters**
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory| Description                                 |
266e41f4b71Sopenharmony_ci| -------------- | ------ | ---- | ------------------------------------ |
267e41f4b71Sopenharmony_ci| tokenID        | number | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
268e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes  | Permission to use. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci**Return value**
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci| Type         | Description                                   |
273e41f4b71Sopenharmony_ci| ------------- | --------------------------------------- |
274e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**Error codes**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci| ID| Error Message|
281e41f4b71Sopenharmony_ci| -------- | -------- |
282e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
283e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
284e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
285e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
286e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
287e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
288e41f4b71Sopenharmony_ci| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
289e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
290e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci**Example**
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci```ts
295e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
296e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
299e41f4b71Sopenharmony_ciprivacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
300e41f4b71Sopenharmony_ci  console.log('startUsingPermission success');
301e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
302e41f4b71Sopenharmony_ci  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
303e41f4b71Sopenharmony_ci});
304e41f4b71Sopenharmony_ci```
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci## privacyManager.startUsingPermission
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_cistartUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ciStarts to use a permission and flushes the permission usage record. This API is called by a system application, either running in the foreground or background, and uses a promise to return the result. This API uses an asynchronous callback to return the result.
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci**Parameters**
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci| Name         | Type                 | Mandatory| Description                                 |
319e41f4b71Sopenharmony_ci| -------------- | --------------------- | ---- | ------------------------------------ |
320e41f4b71Sopenharmony_ci| tokenID        | number                | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
321e41f4b71Sopenharmony_ci| permissionName | Permissions                | Yes  | Permission to use. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
322e41f4b71Sopenharmony_ci| callback       | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci**Error codes**
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci| ID| Error Message|
329e41f4b71Sopenharmony_ci| -------- | -------- |
330e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
331e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
332e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
333e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
334e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
335e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
336e41f4b71Sopenharmony_ci| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
337e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
338e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci**Example**
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci```ts
343e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
344e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
347e41f4b71Sopenharmony_ciprivacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
348e41f4b71Sopenharmony_ci  if (err) {
349e41f4b71Sopenharmony_ci    console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
350e41f4b71Sopenharmony_ci  } else {
351e41f4b71Sopenharmony_ci    console.log('startUsingPermission success');
352e41f4b71Sopenharmony_ci  }
353e41f4b71Sopenharmony_ci});
354e41f4b71Sopenharmony_ci```
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_ci## privacyManager.stopUsingPermission
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_cistopUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ciStops using a permission. This API is called by a system application and uses a promise to return the result. **startUsingPermission** and **stopUsingPermission** are used in pairs. This API uses a promise to return the result.
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci**Parameters**
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci| Name         | Type  | Mandatory| Description                                 |
369e41f4b71Sopenharmony_ci| -------------- | ------ | ---- | ------------------------------------ |
370e41f4b71Sopenharmony_ci| tokenID        | number | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
371e41f4b71Sopenharmony_ci| permissionName | Permissions | Yes  | Permission to use. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**Return value**
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci| Type         | Description                                   |
376e41f4b71Sopenharmony_ci| ------------- | --------------------------------------- |
377e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise that returns no value.|
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_ci**Error codes**
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci| ID| Error Message|
384e41f4b71Sopenharmony_ci| -------- | -------- |
385e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
386e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
387e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
388e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
389e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
390e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
391e41f4b71Sopenharmony_ci| 12100004 | The API is not used in pair with 'startUsingPermission'. |
392e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
393e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
394e41f4b71Sopenharmony_ci
395e41f4b71Sopenharmony_ci**Example**
396e41f4b71Sopenharmony_ci
397e41f4b71Sopenharmony_ci```ts
398e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
399e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
402e41f4b71Sopenharmony_ciprivacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
403e41f4b71Sopenharmony_ci  console.log('stopUsingPermission success');
404e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
405e41f4b71Sopenharmony_ci  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
406e41f4b71Sopenharmony_ci});
407e41f4b71Sopenharmony_ci```
408e41f4b71Sopenharmony_ci
409e41f4b71Sopenharmony_ci## privacyManager.stopUsingPermission
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_cistopUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ciStops using a permission. This API is called by a system application and uses a promise to return the result. **startUsingPermission** and **stopUsingPermission** are used in pairs. This API uses an asynchronous callback to return the result.
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci**Parameters**
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci| Name         | Type                 | Mandatory| Description                                 |
422e41f4b71Sopenharmony_ci| -------------- | --------------------- | ---- | ------------------------------------ |
423e41f4b71Sopenharmony_ci| tokenID        | number                | Yes  | Application token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
424e41f4b71Sopenharmony_ci| permissionName | Permissions                | Yes  | Permission to use. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
425e41f4b71Sopenharmony_ci| callback       | AsyncCallback&lt;void&gt; | Yes  | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**Error codes**
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci| ID| Error Message|
432e41f4b71Sopenharmony_ci| -------- | -------- |
433e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
434e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
435e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
436e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
437e41f4b71Sopenharmony_ci| 12100002 | The specified tokenID does not exist or refer to an application process. |
438e41f4b71Sopenharmony_ci| 12100003 | The specified permission does not exist or is not an user_grant permission. |
439e41f4b71Sopenharmony_ci| 12100004 | The API is not used in pair with 'startUsingPermission'. |
440e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
441e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci**Example**
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci```ts
446e41f4b71Sopenharmony_ciimport { privacyManager } from '@kit.AbilityKit';
447e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_cilet tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
450e41f4b71Sopenharmony_ciprivacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
451e41f4b71Sopenharmony_ci  if (err) {
452e41f4b71Sopenharmony_ci    console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
453e41f4b71Sopenharmony_ci  } else {
454e41f4b71Sopenharmony_ci    console.log('stopUsingPermission success');
455e41f4b71Sopenharmony_ci  }
456e41f4b71Sopenharmony_ci});
457e41f4b71Sopenharmony_ci```
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci## privacyManager.on
460e41f4b71Sopenharmony_ci
461e41f4b71Sopenharmony_cion(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ciSubscribes to the permission usage status changes of the specified permissions.
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ciMultiple callbacks can be registered for the same **permissionList**.
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ciThe same callback cannot be registered for the **permissionList**s with common values.
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ci**Parameters**
474e41f4b71Sopenharmony_ci
475e41f4b71Sopenharmony_ci| Name            | Type                  | Mandatory| Description                                                         |
476e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
477e41f4b71Sopenharmony_ci| type               | string                | Yes  | Event type. The value is **'activeStateChange'**, which indicates the permission usage change.  |
478e41f4b71Sopenharmony_ci| permissionList | Array&lt;Permissions&gt;   | Yes  | Permissions to be observed. If this parameter is left empty, this API subscribes to usage status changes of all permissions. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
479e41f4b71Sopenharmony_ci| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | Yes| Callback invoked to return a change in the permission usage.|
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_ci**Error codes**
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci| ID| Error Message|
486e41f4b71Sopenharmony_ci| -------- | -------- |
487e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
488e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
489e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
490e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The tokenID is 0, or the permissionName exceeds 256 characters. |
491e41f4b71Sopenharmony_ci| 12100004 | The API is used repeatedly with the same input. |
492e41f4b71Sopenharmony_ci| 12100005 | The registration time has exceeded the limitation. |
493e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
494e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**Example**
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci```ts
499e41f4b71Sopenharmony_ciimport { privacyManager, Permissions } from '@kit.AbilityKit';
500e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_cilet permissionList: Array<Permissions> = [];
503e41f4b71Sopenharmony_citry {
504e41f4b71Sopenharmony_ci    privacyManager.on('activeStateChange', permissionList, (data: privacyManager.ActiveChangeResponse) => {
505e41f4b71Sopenharmony_ci        console.debug('receive permission state change, data:' + JSON.stringify(data));
506e41f4b71Sopenharmony_ci    });
507e41f4b71Sopenharmony_ci} catch(err) {
508e41f4b71Sopenharmony_ci    console.error(`catch err->${JSON.stringify(err)}`);
509e41f4b71Sopenharmony_ci}
510e41f4b71Sopenharmony_ci```
511e41f4b71Sopenharmony_ci
512e41f4b71Sopenharmony_ci## privacyManager.off
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_cioff(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ciUnsubscribes from the permission usage status changes of the specified permissions.
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ciIf no callback is passed in **privacyManager.off**, all callbacks of **permissionList** will be unregistered.
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**Parameters**
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci| Name            | Type                  | Mandatory| Description                                                         |
527e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
528e41f4b71Sopenharmony_ci| type               | string                | Yes  | Event type. The value is **'activeStateChange'**, which indicates the permission usage change.  |
529e41f4b71Sopenharmony_ci| permissionList | Array&lt;Permissions&gt;   | Yes  | List of permissions. The value must be the same as that of **on()**. If this parameter is left empty, this API unsubscribes from usage status changes of all permissions. For details about the permissions, see [Permissions for All Applications](../../security/AccessToken/permissions-for-all.md).|
530e41f4b71Sopenharmony_ci| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | No| Callback for the permission usage change event.|
531e41f4b71Sopenharmony_ci
532e41f4b71Sopenharmony_ci**Error codes**
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci| ID| Error Message|
537e41f4b71Sopenharmony_ci| -------- | -------- |
538e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
539e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
540e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
541e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. The permissionNames in the list are all invalid, or the list size exceeds 1024 bytes. |
542e41f4b71Sopenharmony_ci| 12100004 | The API is not used in pair with 'on'. |
543e41f4b71Sopenharmony_ci| 12100007 | The service is abnormal. |
544e41f4b71Sopenharmony_ci| 12100008 | Out of memory. |
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci**Example**
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci```ts
549e41f4b71Sopenharmony_ciimport { privacyManager, Permissions } from '@kit.AbilityKit';
550e41f4b71Sopenharmony_ci
551e41f4b71Sopenharmony_cilet permissionList: Array<Permissions> = [];
552e41f4b71Sopenharmony_citry {
553e41f4b71Sopenharmony_ci    privacyManager.off('activeStateChange', permissionList);
554e41f4b71Sopenharmony_ci} catch(err) {
555e41f4b71Sopenharmony_ci    console.error(`catch err->${JSON.stringify(err)}`);
556e41f4b71Sopenharmony_ci}
557e41f4b71Sopenharmony_ci```
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci## privacyManager.getPermissionUsedTypeInfos<sup>12+</sup>
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_cigetPermissionUsedTypeInfos(tokenId?: number, permissionName?: Permissions): Promise&lt;Array&lt;PermissionUsedTypeInfo&gt;&gt;
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ciObtains information about how a sensitive permission is used by an application.
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ci**Parameters**
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci| Name            | Type                  | Mandatory| Description                                                         |
572e41f4b71Sopenharmony_ci| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
573e41f4b71Sopenharmony_ci| tokenId            | number                | No  | ID of the application that uses the sensitive permission. If this parameter is left empty, this API obtains the sensitive permission access information of all applications.  |
574e41f4b71Sopenharmony_ci| permissionName     | Permissions           | No  | Name of the sensitive permission used. If this parameter is left blank, this API obtains the access information about all sensitive permissions.  |
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci**Return value**
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci| Type         | Description                                   |
579e41f4b71Sopenharmony_ci| ------------- | --------------------------------------- |
580e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;[PermissionUsedTypeInfo](#permissionusedtypeinfo12)&gt;&gt; | Promise used to return the information obtained.|
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci**Error codes**
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ciFor details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci| ID| Error Message|
587e41f4b71Sopenharmony_ci| -------- | -------- |
588e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. |
589e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. |
590e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. |
591e41f4b71Sopenharmony_ci| 12100001 | Invalid parameter. PermissionName exceeds 256 characters. |
592e41f4b71Sopenharmony_ci| 12100002 | The input tokenId does not exist. |
593e41f4b71Sopenharmony_ci| 12100003 | The input permissionName does not exist. |
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci**Example**
596e41f4b71Sopenharmony_ci
597e41f4b71Sopenharmony_ci```ts
598e41f4b71Sopenharmony_ciimport { privacyManager, Permissions } from '@kit.AbilityKit';
599e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_cilet tokenId: number = 0; // You can use bundleManager.getApplicationInfo to obtain accessTokenId.
602e41f4b71Sopenharmony_cilet permissionName: Permissions = 'ohos.permission.CAMERA';
603e41f4b71Sopenharmony_ci// Without any parameter.
604e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedTypeInfos().then(() => {
605e41f4b71Sopenharmony_ci  console.log('getPermissionUsedTypeInfos success');
606e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
607e41f4b71Sopenharmony_ci  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
608e41f4b71Sopenharmony_ci});
609e41f4b71Sopenharmony_ci// Pass in tokenId only.
610e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedTypeInfos(tokenId).then(() => {
611e41f4b71Sopenharmony_ci  console.log('getPermissionUsedTypeInfos success');
612e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
613e41f4b71Sopenharmony_ci  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
614e41f4b71Sopenharmony_ci});
615e41f4b71Sopenharmony_ci// Pass in permissionName only.
616e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedTypeInfos(null, permissionName).then(() => {
617e41f4b71Sopenharmony_ci  console.log('getPermissionUsedTypeInfos success');
618e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
619e41f4b71Sopenharmony_ci  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
620e41f4b71Sopenharmony_ci});
621e41f4b71Sopenharmony_ci// Pass in tokenId and permissionName.
622e41f4b71Sopenharmony_ciprivacyManager.getPermissionUsedTypeInfos(tokenId, permissionName).then(() => {
623e41f4b71Sopenharmony_ci  console.log('getPermissionUsedTypeInfos success');
624e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
625e41f4b71Sopenharmony_ci  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
626e41f4b71Sopenharmony_ci});
627e41f4b71Sopenharmony_ci```
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ci## PermissionUsageFlag
630e41f4b71Sopenharmony_ci
631e41f4b71Sopenharmony_ciEnumerates the modes for querying the permission usage records.
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_ci| Name                   | Value| Description                  |
636e41f4b71Sopenharmony_ci| ----------------------- | ------ | ---------------------- |
637e41f4b71Sopenharmony_ci| FLAG_PERMISSION_USAGE_SUMMARY             | 0    | Query the permission usage summary.|
638e41f4b71Sopenharmony_ci| FLAG_PERMISSION_USAGE_DETAIL         | 1    | Query detailed permission usage records.        |
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci## PermissionUsedRequest
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ciRepresents the request for querying permission usage records.
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ci| Name      | Type            | Mandatory  | Description                                      |
647e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---------------------------------------- |
648e41f4b71Sopenharmony_ci| tokenId  | number         | No   | Token ID of the application (invoker).<br> By default, all applications are queried.        |
649e41f4b71Sopenharmony_ci| isRemote | boolean         | No   | Whether to query the permission usage records of the remote device.<br> The default value is **false**, which means the permission usage records of the local device are queried by default.|
650e41f4b71Sopenharmony_ci| deviceId  | string         | No   | ID of the device hosting the target application.<br> The default value is the local device ID.  |
651e41f4b71Sopenharmony_ci| bundleName | string         | No   | Bundle name of the target application.<br> By default, all applications are queried.|
652e41f4b71Sopenharmony_ci| permissionNames  | Array&lt;Permissions&gt;         | No   | Permissions to query.<br> By default, the usage records of all permissions are queried.              |
653e41f4b71Sopenharmony_ci| beginTime | number         | No   | Start time of the query, in ms.<br>The default value is **0**, which means the start time is not set.|
654e41f4b71Sopenharmony_ci| endTime | number         | No   | End time of the query, in ms.<br>The default value is **0**, which means the end time is not set.|
655e41f4b71Sopenharmony_ci| flag | [PermissionUsageFlag](#permissionusageflag)         | Yes   | Query mode.|
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci## PermissionUsedResponse
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ciRepresents the permission usage records of all applications.
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci| Name      | Type            | Readable| Writable| Description                                      |
664e41f4b71Sopenharmony_ci| --------- | -------------- | ---- | ---- | ---------------------------------------- |
665e41f4b71Sopenharmony_ci| beginTime | number         | Yes   | No   | Start time of the query, in ms.|
666e41f4b71Sopenharmony_ci| endTime   | number         | Yes   | No   | End time of the query, in ms.|
667e41f4b71Sopenharmony_ci| bundleRecords  | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt;         | Yes   | No   | Permission usage records.                                |
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci## BundleUsedRecord
670e41f4b71Sopenharmony_ci
671e41f4b71Sopenharmony_ciRepresents the permission access records of an application.
672e41f4b71Sopenharmony_ci
673e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci| Name      | Type            | Readable| Writable| Description                                      |
676e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---- | ---------------------------------------- |
677e41f4b71Sopenharmony_ci| tokenId  | number         | Yes   | No   | Token ID of the application (invoker).                                |
678e41f4b71Sopenharmony_ci| isRemote | boolean         | Yes   | No   | Whether the token ID belongs to the application on a remote device. The default value is **false**.|
679e41f4b71Sopenharmony_ci| deviceId  | string         | Yes   | No   | ID of the device hosting the target application.                                |
680e41f4b71Sopenharmony_ci| bundleName | string         | Yes   | No   | Bundle name of the target application.|
681e41f4b71Sopenharmony_ci| permissionRecords  | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt;         | Yes   | No   | Permission usage records of the target application.                                |
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci## PermissionUsedRecord
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ciRepresents the usage records of a permission.
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci| Name      | Type            | Readable| Writable| Description                                      |
690e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---- | ---------------------------------------- |
691e41f4b71Sopenharmony_ci| permissionName  | Permissions         | Yes   | No   | Name of the permission.                                |
692e41f4b71Sopenharmony_ci| accessCount | number         | Yes   | No   | Total number of times that the permission is accessed.|
693e41f4b71Sopenharmony_ci| rejectCount | number         | Yes   | No   | Total number of times that the access to the permission is rejected.|
694e41f4b71Sopenharmony_ci| lastAccessTime | number         | Yes   | No   | Last time when the permission was accessed, accurate to ms.|
695e41f4b71Sopenharmony_ci| lastRejectTime | number         | Yes   | No   | Last time when the access to the permission was rejected, accurate to ms.|
696e41f4b71Sopenharmony_ci| lastAccessDuration | number         | Yes   | No   | Last access duration, in ms.|
697e41f4b71Sopenharmony_ci| accessRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | Yes   | No   | Successful access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_DETAIL**. By default, 10 records are provided.                                |
698e41f4b71Sopenharmony_ci| rejectRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | Yes   | No   | Rejected access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_DETAIL**. By default, 10 records are provided.                                |
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci## UsedRecordDetail
701e41f4b71Sopenharmony_ci
702e41f4b71Sopenharmony_ciRepresents the details of a single access record.
703e41f4b71Sopenharmony_ci
704e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ci| Name      | Type            | Readable| Writable| Description                                      |
707e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---- | ---------------------------------------- |
708e41f4b71Sopenharmony_ci| status  | number         | Yes   | No   | Access status.                                |
709e41f4b71Sopenharmony_ci| lockScreenStatus<sup>11+</sup>  | number         | Yes   | No   | Status of the screen during the access.<br> - **1**: The screen is not locked when the permission is used.<br> - **2**: The screen is locked when the permission is used.                                |
710e41f4b71Sopenharmony_ci| timestamp | number         | Yes   | No   | Access timestamp, in ms.|
711e41f4b71Sopenharmony_ci| accessDuration  | number         | Yes   | No   | Access duration, in ms.                                |
712e41f4b71Sopenharmony_ci| count<sup>11+</sup> | number | Yes| No   | Number of successful or failed accesses.
713e41f4b71Sopenharmony_ci| usedType<sup>12+</sup> | [PermissionUsedType](#permissionusedtype12) | Yes| No   | Means for using the sensitive permission.|
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci## PermissionActiveStatus
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ciEnumerates the permission usage statuses.
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci| Name                     | Value    | Description             |
722e41f4b71Sopenharmony_ci| ------------------------- | ------ | ---------------- |
723e41f4b71Sopenharmony_ci| PERM_INACTIVE             | 0      | The permission is not used.  |
724e41f4b71Sopenharmony_ci| PERM_ACTIVE_IN_FOREGROUND | 1      | The permission is being used by an application running in the foreground.|
725e41f4b71Sopenharmony_ci| PERM_ACTIVE_IN_BACKGROUND | 2      | The permission is being used by an application running in the background.|
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ci## ActiveChangeResponse
728e41f4b71Sopenharmony_ci
729e41f4b71Sopenharmony_ciDefines the detailed permission usage information.
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci **System capability**: SystemCapability.Security.AccessToken
732e41f4b71Sopenharmony_ci
733e41f4b71Sopenharmony_ci| Name          | Type                   | Readable| Writable| Description                  |
734e41f4b71Sopenharmony_ci| -------------- | ---------------------- | ---- | ---- | --------------------- |
735e41f4b71Sopenharmony_ci| tokenId        | number                 | Yes  | No  | Token ID of the application.   |
736e41f4b71Sopenharmony_ci| permissionName | Permissions            | Yes  | No  | Name of the permission.|
737e41f4b71Sopenharmony_ci| deviceId       | string                 | Yes  | No  | Device ID.                |
738e41f4b71Sopenharmony_ci| activeStatus   | [PermissionActiveStatus](#permissionactivestatus) | Yes  | No  | Permission usage status.       |
739e41f4b71Sopenharmony_ci
740e41f4b71Sopenharmony_ci## PermissionUsedType<sup>12+</sup>
741e41f4b71Sopenharmony_ci
742e41f4b71Sopenharmony_ciEnumerates the means for using a sensitive permission.
743e41f4b71Sopenharmony_ci
744e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Security.AccessToken
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci| Name                   | Value| Description             |
747e41f4b71Sopenharmony_ci| ----------------------- | -- | ---------------- |
748e41f4b71Sopenharmony_ci| NORMAL_TYPE             | 0  | The sensitive permission is used after authorization through a dialog box or a system settings page.  |
749e41f4b71Sopenharmony_ci| PICKER_TYPE             | 1  | The sensitive permission is used through a system picker. This access mode does not grant the permissions to the application.|
750e41f4b71Sopenharmony_ci| SECURITY_COMPONENT_TYPE | 2  | The sensitive permission is used through a security component, which comes with the authorization.|
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ci## PermissionUsedTypeInfo<sup>12+</sup>
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ciRepresents detailed information about the use of a permission.
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci **System capability**: SystemCapability.Security.AccessToken
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ci| Name          | Type                   | Readable| Writable| Description                  |
759e41f4b71Sopenharmony_ci| -------------- | ---------------------- | ---- | ---- | --------------------- |
760e41f4b71Sopenharmony_ci| tokenId        | number                 | Yes  | No  | ID of the application that uses the sensitive permission.|
761e41f4b71Sopenharmony_ci| permissionName | Permissions            | Yes  | No  | Name of the sensitive permission.|
762e41f4b71Sopenharmony_ci| usedType | [PermissionUsedType](#permissionusedtype12) | Yes| No   | Means for using the sensitive permission.|
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci## AddPermissionUsedRecordOptions<sup>12+</sup>
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ciRepresents the options for adding a permission usage record.
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci **System capability**: SystemCapability.Security.AccessToken
769e41f4b71Sopenharmony_ci
770e41f4b71Sopenharmony_ci| Name          | Type                   | Readable| Writable| Description                  |
771e41f4b71Sopenharmony_ci| -------------- | ---------------------- | ---- | ---- | --------------------- |
772e41f4b71Sopenharmony_ci| usedType | [PermissionUsedType](#permissionusedtype12) | Yes| No   | Means for using the sensitive permission.|
773