• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.privacyManager (Privacy Management) (System API)
2
3<!--Kit: Ability Kit-->
4<!--Subsystem: Security-->
5<!--Owner: @xia-bubai-->
6<!--SE: @linshuqing; @hehehe-li-->
7<!--TSE: @leiyuqian-->
8
9The **privacyManager** module provides APIs for privacy management, such as management of permission usage records.
10
11> **NOTE**
12>
13> - 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.
14> - The APIs provided by this module are system APIs.
15
16## Modules to Import
17
18```ts
19import { privacyManager } from '@kit.AbilityKit';
20```
21
22
23## privacyManager.addPermissionUsedRecord
24
25addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, options?: AddPermissionUsedRecordOptions): Promise&lt;void&gt;
26
27Adds 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.
28The permission usage record includes the application identity (token ID) of the caller, name of the permission used, and number of successful and failed accesses to the target application.
29
30**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
31
32**System capability**: SystemCapability.Security.AccessToken
33
34**Parameters**
35
36| Name  | Type                | Mandatory| Description                                      |
37| -------- | -------------------  | ---- | ------------------------------------------ |
38| tokenID   |  number   | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
39| permissionName | Permissions | Yes  | Name of the permission.|
40| successCount | number | Yes  | Number of successful accesses.|
41| failCount | number | Yes  | Number of failed accesses.|
42| options<sup>12+</sup> | [AddPermissionUsedRecordOptions](#addpermissionusedrecordoptions12) | No  | Options for adding a permission usage record. The default value is **NORMAL_TYPE**. This parameter is supported since API version 12.|
43
44**Return value**
45
46| Type         | Description                               |
47| :------------ | :---------------------------------- |
48| Promise&lt;void&gt; | Promise that returns no value.|
49
50**Error codes**
51
52For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
53
54| ID| Error Message|
55| -------- | -------- |
56| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
57| 202 | Not system app. Interface caller is not a system app. |
58| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
59| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, the count value is invalid, or usedType in [AddPermissionUsedRecordOptions](#addpermissionusedrecordoptions12) is invalid. |
60| 12100002 | The specified tokenID does not exist or refer to an application process. |
61| 12100003 | The specified permission does not exist or is not a user_grant permission. |
62| 12100007 | The service is abnormal. |
63| 12100008 | Out of memory. |
64
65**Example**
66
67```ts
68import { privacyManager } from '@kit.AbilityKit';
69import { BusinessError } from '@kit.BasicServicesKit';
70
71let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
72privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0).then(() => {
73  console.log('addPermissionUsedRecord success');
74}).catch((err: BusinessError) => {
75  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
76});
77// with options param
78let options: privacyManager.AddPermissionUsedRecordOptions = {
79  usedType: privacyManager.PermissionUsedType.PICKER_TYPE
80};
81privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, options).then(() => {
82  console.log('addPermissionUsedRecord success');
83}).catch((err: BusinessError) => {
84  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
85});
86```
87
88## privacyManager.addPermissionUsedRecord
89
90addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, callback: AsyncCallback&lt;void&gt;): void
91
92Adds 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.
93The permission usage record includes the application identity (token ID) of the caller, name of the permission used, and number of successful and failed accesses to the target application.
94
95**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
96
97**System capability**: SystemCapability.Security.AccessToken
98
99**Parameters**
100
101| Name  | Type                | Mandatory| Description                                      |
102| -------- | -------------------  | ---- | ------------------------------------------ |
103| tokenID   |  number   | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
104| permissionName | Permissions | Yes  | Permission name. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
105| successCount | number | Yes  | Number of successful accesses.|
106| failCount | number | Yes  | Number of failed accesses.|
107| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
108
109**Error codes**
110
111For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
112
113| ID| Error Message|
114| -------- | -------- |
115| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
116| 202 | Not system app. Interface caller is not a system app. |
117| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
118| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
119| 12100002 | The specified tokenID does not exist or refer to an application process. |
120| 12100003 | The specified permission does not exist or is not a user_grant permission. |
121| 12100007 | The service is abnormal. |
122| 12100008 | Out of memory. |
123
124**Example**
125
126```ts
127import { privacyManager } from '@kit.AbilityKit';
128import { BusinessError } from '@kit.BasicServicesKit';
129
130let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
131privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, (err: BusinessError, data: void) => {
132  if (err) {
133    console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
134  } else {
135    console.log('addPermissionUsedRecord success');
136  }
137});
138```
139
140## privacyManager.getPermissionUsedRecord
141
142getPermissionUsedRecord(request: PermissionUsedRequest): Promise&lt;PermissionUsedResponse&gt;
143
144Obtains historical permission usage records. This API uses a promise to return the result.
145
146**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
147
148**System capability**: SystemCapability.Security.AccessToken
149
150**Parameters**
151
152| Name  | Type                | Mandatory| Description                                      |
153| -------- | -------------------  | ---- | ------------------------------------------ |
154| request   |  [PermissionUsedRequest](#permissionusedrequest)   | Yes  | Request for querying permission usage records.             |
155
156**Return value**
157
158| Type         | Description                               |
159| :------------ | :---------------------------------- |
160| Promise<[PermissionUsedResponse](#permissionusedresponse)> | Promise used to return the permission usage records.|
161
162**Error codes**
163
164For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
165
166| ID| Error Message|
167| -------- | -------- |
168| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
169| 202 | Not system app. Interface caller is not a system app. |
170| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
171| 12100001 | Invalid parameter. The value of flag, begin, or end in request is invalid. |
172| 12100002 | The specified tokenID does not exist or refer to an application process. |
173| 12100003 | The specified permission does not exist or is not a user_grant permission. |
174| 12100007 | The service is abnormal. |
175| 12100008 | Out of memory. |
176
177**Example**
178
179```ts
180import { privacyManager } from '@kit.AbilityKit';
181import { BusinessError } from '@kit.BasicServicesKit';
182
183let request: privacyManager.PermissionUsedRequest = {
184    'tokenId': 1,
185    'isRemote': false,
186    'deviceId': 'device',
187    'bundleName': 'bundle',
188    'permissionNames': [],
189    'beginTime': 0,
190    'endTime': 1,
191    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
192};
193
194privacyManager.getPermissionUsedRecord(request).then((data) => {
195  console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
196}).catch((err: BusinessError) => {
197  console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
198});
199```
200
201## privacyManager.getPermissionUsedRecord
202
203getPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback&lt;PermissionUsedResponse&gt;): void
204
205Obtains historical permission usage records. This API uses an asynchronous callback to return the result.
206
207**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
208
209**System capability**: SystemCapability.Security.AccessToken
210
211**Parameters**
212
213| Name  | Type                | Mandatory| Description                                      |
214| -------- | -------------------  | ---- | ------------------------------------------ |
215| request | [PermissionUsedRequest](#permissionusedrequest) | Yes| Request for querying permission usage records.|
216| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | Yes| Callback used 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.|
217
218**Error codes**
219
220For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
221
222| ID| Error Message|
223| -------- | -------- |
224| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
225| 202 | Not system app. Interface caller is not a system app. |
226| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
227| 12100001 | Invalid parameter. The value of flag, begin, or end in request is invalid. |
228| 12100002 | The specified tokenID does not exist or refer to an application process. |
229| 12100003 | The specified permission does not exist or is not a user_grant permission. |
230| 12100007 | The service is abnormal. |
231| 12100008 | Out of memory. |
232
233**Example**
234
235```ts
236import { privacyManager } from '@kit.AbilityKit';
237import { BusinessError } from '@kit.BasicServicesKit';
238
239let request: privacyManager.PermissionUsedRequest = {
240    'tokenId': 1,
241    'isRemote': false,
242    'deviceId': 'device',
243    'bundleName': 'bundle',
244    'permissionNames': [],
245    'beginTime': 0,
246    'endTime': 1,
247    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
248};
249
250privacyManager.getPermissionUsedRecord(request, (err: BusinessError, data: privacyManager.PermissionUsedResponse) => {
251  if (err) {
252    console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
253  } else {
254    console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
255  }
256});
257```
258
259## privacyManager.setPermissionUsedRecordToggleStatus<sup>18+</sup>
260
261setPermissionUsedRecordToggleStatus(status: boolean): Promise&lt;void&gt;
262
263Sets whether to record the permission usage of this user. This API uses a promise to return the result.
264
265If **status** is **true**, [addPermissionUsedRecord](#privacymanageraddpermissionusedrecord) can be called to add permission usage records. If **status** is set **false**, [addPermissionUsedRecord](#privacymanageraddpermissionusedrecord) does not add permission usage records. Instead, it deletes the historical records of the user.
266
267**Required permissions**: ohos.permission.PERMISSION_RECORD_TOGGLE (available only to system applications)
268
269**System capability**: SystemCapability.Security.AccessToken
270
271**Parameters**
272
273| Name         | Type  | Mandatory| Description                                 |
274| -------------- | ------ | ---- | ------------------------------------ |
275| status        | boolean | Yes  | Setting of the permission usage record switch. The value **true** means the switch is toggled on; the value **false** means the opposite.|
276
277**Return value**
278
279| Type         | Description                                   |
280| ------------- | --------------------------------------- |
281| Promise&lt;void&gt; | Promise that returns no value.|
282
283**Error codes**
284
285For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
286
287| ID| Error Message|
288| -------- | -------- |
289| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_RECORD_TOGGLE". |
290| 202 | Not system app. Interface caller is not a system app. |
291| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
292| 12100007 | The service is abnormal. |
293| 12100009 | Common inner error. |
294
295**Example**
296
297```ts
298import { privacyManager } from '@kit.AbilityKit';
299import { BusinessError } from '@kit.BasicServicesKit';
300
301privacyManager.setPermissionUsedRecordToggleStatus(true).then(() => {
302  console.log('setPermissionUsedRecordToggleStatus success');
303}).catch((err: BusinessError) => {
304  console.error(`setPermissionUsedRecordToggleStatus fail, err->${JSON.stringify(err)}`);
305});
306```
307
308## privacyManager.getPermissionUsedRecordToggleStatus<sup>18+</sup>
309
310getPermissionUsedRecordToggleStatus(): Promise&lt;boolean&gt;
311
312Obtains the settings of the permission usage record switch for this user. This API uses a promise to return the result.
313
314**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
315
316**System capability**: SystemCapability.Security.AccessToken
317
318**Return value**
319
320| Type         | Description                                   |
321| ------------- | --------------------------------------- |
322| Promise&lt;boolean&gt; | Promise used to return the switch settings. **true** to enable, **false** otherwise.|
323
324**Error codes**
325
326For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
327
328| ID| Error Message|
329| -------- | -------- |
330| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
331| 202 | Not system app. Interface caller is not a system app. |
332| 12100007 | The service is abnormal. |
333
334**Example**
335
336```ts
337import { privacyManager } from '@kit.AbilityKit';
338import { BusinessError } from '@kit.BasicServicesKit';
339
340privacyManager.getPermissionUsedRecordToggleStatus().then((res) => {
341  console.log('getPermissionUsedRecordToggleStatus success');
342  if (res == true) {
343    console.log('get status is TRUE');
344  } else {
345    console.log('get status is FALSE');
346  }
347}).catch((err: BusinessError) => {
348  console.error(`getPermissionUsedRecordToggleStatus fail, err->${JSON.stringify(err)}`);
349});
350```
351
352## privacyManager.startUsingPermission
353
354startUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
355
356Starts using a permission. This API is called by a system application to report the permission usage of an application in the foreground and background, allowing the privacy service to respond based on the application lifecycle. This API uses a promise to return the result.
357
358When an application starts to use a permission, the privacy service notifies the privacy indicator that the application is using the permission. Upon the application's exit, the privacy service notifies the privacy indicator that the application has stopped using the permission and clears the corresponding cache.
359
360**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
361
362**System capability**: SystemCapability.Security.AccessToken
363
364**Parameters**
365
366| Name         | Type  | Mandatory| Description                                 |
367| -------------- | ------ | ---- | ------------------------------------ |
368| tokenID        | number | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
369| permissionName | Permissions | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
370
371**Return value**
372
373| Type         | Description                                   |
374| ------------- | --------------------------------------- |
375| Promise&lt;void&gt; | Promise that returns no value.|
376
377**Error codes**
378
379For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
380
381| ID| Error Message|
382| -------- | -------- |
383| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
384| 202 | Not system app. Interface caller is not a system app. |
385| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
386| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the type of the specified tokenID is not of the application type. |
387| 12100002 | The specified tokenID does not exist or refer to an application process. |
388| 12100003 | The specified permission does not exist or is not a user_grant permission. |
389| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
390| 12100007 | The service is abnormal. |
391| 12100008 | Out of memory. |
392
393**Example**
394
395```ts
396import { privacyManager } from '@kit.AbilityKit';
397import { BusinessError } from '@kit.BasicServicesKit';
398
399let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
400privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
401  console.log('startUsingPermission success');
402}).catch((err: BusinessError) => {
403  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
404});
405```
406
407## privacyManager.startUsingPermission<sup>18+</sup>
408
409startUsingPermission(tokenID: number, permissionName: Permissions, pid?: number, usedType?: PermissionUsedType): Promise&lt;void&gt;
410
411Starts using a permission. This API is called by a system application to report the permission usage of an application in the foreground and background, allowing the privacy service to respond based on the application lifecycle. This API uses a promise to return the result.
412
413When an application starts to use a permission, the privacy service notifies the privacy indicator that the application is using the permission. Upon the application's exit, the privacy service notifies the privacy indicator that the application has stopped using the permission and clears the corresponding cache.
414
415For a multi-process application, you can specify the process ID (PID) of the application when reporting the permission usage. If no PID is specified, the privacy service responds by application. When the application exits, the privacy service notifies the privacy indicator and clears the cache.
416
417If a PID is specified, the privacy service responds by process. when the process exits, the privacy service notifies the privacy indicator and clears the cache. In this case, the PID must be that of the application corresponding to the token ID.
418
419**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
420
421**System capability**: SystemCapability.Security.AccessToken
422
423**Parameters**
424
425| Name         | Type  | Mandatory| Description                                 |
426| -------------- | ------ | ---- | ------------------------------------ |
427| tokenID        | number | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
428| permissionName | Permissions | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
429| pid            | number | No  | PID of the caller. The default value is **-1**, which indicates that the privacy service does not respond based on the process lifecycle.|
430| usedType       | [PermissionUsedType](#permissionusedtype12) | No| Sensitive permission access mode. The default value is **NORMAL_TYPE**.|
431
432**Return value**
433
434| Type         | Description                                   |
435| ------------- | --------------------------------------- |
436| Promise&lt;void&gt; | Promise that returns no value.|
437
438**Error codes**
439
440For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
441
442| ID| Error Message|
443| -------- | -------- |
444| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
445| 202 | Not system app. Interface caller is not a system app. |
446| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
447| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, the type of the specified tokenID is not of the application type, or usedType is invalid. |
448| 12100002 | The specified tokenID does not exist or refer to an application process. |
449| 12100003 | The specified permission does not exist or is not a user_grant permission. |
450| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
451| 12100007 | The service is abnormal. |
452| 12100008 | Out of memory. |
453
454**Example**
455
456```ts
457import { privacyManager } from '@kit.AbilityKit';
458import { BusinessError } from '@kit.BasicServicesKit';
459import { rpc } from '@kit.IPCKit'
460
461let tokenID: number = rpc.IPCSkeleton.getCallingTokenId(); // accessTokenId can also be obtained by using bundleManager.getBundleInfoForSelfSync.
462let pid: number = rpc.IPCSkeleton.getCallingPid();
463let usedType: privacyManager.PermissionUsedType = privacyManager.PermissionUsedType.PICKER_TYPE;
464
465// without pid and usedType
466privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
467  console.log('startUsingPermission success');
468}).catch((err: BusinessError) => {
469  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
470});
471// with pid
472privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid).then(() => {
473  console.log('startUsingPermission success');
474}).catch((err: BusinessError) => {
475  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
476});
477// with usedType
478privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', -1, usedType).then(() => {
479  console.log('startUsingPermission success');
480}).catch((err: BusinessError) => {
481  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
482});
483// with pid and usedType
484privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid, usedType).then(() => {
485  console.log('startUsingPermission success');
486}).catch((err: BusinessError) => {
487  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
488});
489```
490
491## privacyManager.startUsingPermission
492
493startUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
494
495Starts using a permission. This API is called by a system application to report the permission usage of an application in the foreground and background, allowing the privacy service to respond based on the application lifecycle. This API uses an asynchronous callback to return the result.
496
497When an application starts to use a permission, the privacy service notifies the privacy indicator that the application is using the permission. Upon the application's exit, the privacy service notifies the privacy indicator that the application has stopped using the permission and clears the corresponding cache.
498
499**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
500
501**System capability**: SystemCapability.Security.AccessToken
502
503**Parameters**
504
505| Name         | Type                 | Mandatory| Description                                 |
506| -------------- | --------------------- | ---- | ------------------------------------ |
507| tokenID        | number                | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
508| permissionName | Permissions                | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
509| callback       | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
510
511**Error codes**
512
513For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
514
515| ID| Error Message|
516| -------- | -------- |
517| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
518| 202 | Not system app. Interface caller is not a system app. |
519| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
520| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the type of the specified tokenID is not of the application type. |
521| 12100002 | The specified tokenID does not exist or refer to an application process. |
522| 12100003 | The specified permission does not exist or is not a user_grant permission. |
523| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
524| 12100007 | The service is abnormal. |
525| 12100008 | Out of memory. |
526
527**Example**
528
529```ts
530import { privacyManager } from '@kit.AbilityKit';
531import { BusinessError } from '@kit.BasicServicesKit';
532
533let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
534privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
535  if (err) {
536    console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
537  } else {
538    console.log('startUsingPermission success');
539  }
540});
541```
542
543## privacyManager.stopUsingPermission
544
545stopUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
546
547Stops using a permission. This API must be called by a system application, and used with **startUsingPermission** in pairs. This API uses a promise to return the result.
548
549**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
550
551**System capability**: SystemCapability.Security.AccessToken
552
553**Parameters**
554
555| Name         | Type  | Mandatory| Description                                 |
556| -------------- | ------ | ---- | ------------------------------------ |
557| tokenID        | number | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
558| permissionName | Permissions | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
559
560**Return value**
561
562| Type         | Description                                   |
563| ------------- | --------------------------------------- |
564| Promise&lt;void&gt; | Promise that returns no value.|
565
566**Error codes**
567
568For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
569
570| ID| Error Message|
571| -------- | -------- |
572| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
573| 202 | Not system app. Interface caller is not a system app. |
574| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
575| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the type of the specified tokenID is not of the application type. |
576| 12100002 | The specified tokenID does not exist or refer to an application process. |
577| 12100003 | The specified permission does not exist or is not a user_grant permission. |
578| 12100004 | The API is not used in pair with 'startUsingPermission'. |
579| 12100007 | The service is abnormal. |
580| 12100008 | Out of memory. |
581
582**Example**
583
584```ts
585import { privacyManager } from '@kit.AbilityKit';
586import { BusinessError } from '@kit.BasicServicesKit';
587
588let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
589privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
590  console.log('stopUsingPermission success');
591}).catch((err: BusinessError) => {
592  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
593});
594```
595
596## privacyManager.stopUsingPermission<sup>18+</sup>
597
598stopUsingPermission(tokenID: number, permissionName: Permissions, pid?: number): Promise&lt;void&gt;
599
600Stops using a permission. This API must be called by a system application, and used with **startUsingPermission** in pairs. This API uses a promise to return the result.
601
602The value of **pid** must match that used in **startUsingPermission**.
603
604**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
605
606**System capability**: SystemCapability.Security.AccessToken
607
608**Parameters**
609
610| Name         | Type  | Mandatory| Description                                 |
611| -------------- | ------ | ---- | ------------------------------------ |
612| tokenID        | number | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
613| permissionName | Permissions | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
614| pid            | number | No  | PID of the application. The value must match that used in **startUsingPermission**. The default value is **-1**.|
615
616**Return value**
617
618| Type         | Description                                   |
619| ------------- | --------------------------------------- |
620| Promise&lt;void&gt; | Promise that returns no value.|
621
622**Error codes**
623
624For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
625
626| ID| Error Message|
627| -------- | -------- |
628| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
629| 202 | Not system app. Interface caller is not a system app. |
630| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
631| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the type of the specified tokenID is not of the application type. |
632| 12100002 | The specified tokenID does not exist or refer to an application process. |
633| 12100003 | The specified permission does not exist or is not a user_grant permission. |
634| 12100004 | The API is not used in pair with 'startUsingPermission'. |
635| 12100007 | The service is abnormal. |
636| 12100008 | Out of memory. |
637
638**Example**
639
640```ts
641import { privacyManager } from '@kit.AbilityKit';
642import { BusinessError } from '@kit.BasicServicesKit';
643import { rpc } from '@kit.IPCKit'
644
645let tokenID: number = rpc.IPCSkeleton.getCallingTokenId(); // accessTokenId can also be obtained by using bundleManager.getBundleInfoForSelfSync.
646let pid: number = rpc.IPCSkeleton.getCallingPid();
647
648// without pid
649privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
650  console.log('stopUsingPermission success');
651}).catch((err: BusinessError) => {
652  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
653});
654
655// with pid
656privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid).then(() => {
657  console.log('stopUsingPermission success');
658}).catch((err: BusinessError) => {
659  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
660});
661```
662
663## privacyManager.stopUsingPermission
664
665stopUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
666
667Stops using a permission. This API must be called by a system application, and used with **startUsingPermission** in pairs. This API uses an asynchronous callback to return the result.
668
669**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
670
671**System capability**: SystemCapability.Security.AccessToken
672
673**Parameters**
674
675| Name         | Type                 | Mandatory| Description                                 |
676| -------------- | --------------------- | ---- | ------------------------------------ |
677| tokenID        | number                | Yes  | Token ID of the caller, which is the value of **accessTokenId** in [ApplicationInfo](js-apis-bundleManager-applicationInfo.md).|
678| permissionName | Permissions                | Yes  | Permission to use. For details, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
679| callback       | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
680
681**Error codes**
682
683For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
684
685| ID| Error Message|
686| -------- | -------- |
687| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
688| 202 | Not system app. Interface caller is not a system app. |
689| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
690| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the type of the specified tokenID is not of the application type. |
691| 12100002 | The specified tokenID does not exist or refer to an application process. |
692| 12100003 | The specified permission does not exist or is not a user_grant permission. |
693| 12100004 | The API is not used in pair with 'startUsingPermission'. |
694| 12100007 | The service is abnormal. |
695| 12100008 | Out of memory. |
696
697**Example**
698
699```ts
700import { privacyManager } from '@kit.AbilityKit';
701import { BusinessError } from '@kit.BasicServicesKit';
702
703let tokenID: number = 0; // You can use getApplicationInfo to obtain accessTokenId.
704privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
705  if (err) {
706    console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
707  } else {
708    console.log('stopUsingPermission success');
709  }
710});
711```
712
713## privacyManager.on
714
715on(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void
716
717Subscribes to changes in the permission usage status of the specified permissions.
718
719Multiple callbacks can be registered for the same **permissionList**.
720
721The same callback cannot be registered for the **permissionList**s with overlapping values.
722
723**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
724
725**System capability**: SystemCapability.Security.AccessToken
726
727**Parameters**
728
729| Name            | Type                  | Mandatory| Description                                                         |
730| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
731| type               | string                | Yes  | Event type. The value is **'activeStateChange'**, which indicates the permission usage change.  |
732| permissionList | Array&lt;Permissions&gt;   | Yes  | List of target permissions. If this parameter is not specified, this API will subscribe to usage changes of all permissions. For details about the permissions, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
733| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | Yes| Callback used to return the permission usage change.|
734
735**Error codes**
736
737For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
738
739| ID| Error Message|
740| -------- | -------- |
741| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
742| 202 | Not system app. Interface caller is not a system app. |
743| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
744| 12100001 | Invalid parameter. The permissionList exceeds the size limit, or the permissionNames in the list are all invalid. |
745| 12100004 | The API is used repeatedly with the same input. |
746| 12100005 | The registration time has exceeded the limit. |
747| 12100007 | The service is abnormal. |
748| 12100008 | Out of memory. |
749
750**Example**
751
752```ts
753import { privacyManager, Permissions } from '@kit.AbilityKit';
754import { BusinessError } from '@kit.BasicServicesKit';
755
756let permissionList: Array<Permissions> = [];
757try {
758    privacyManager.on('activeStateChange', permissionList, (data: privacyManager.ActiveChangeResponse) => {
759        console.debug('receive permission state change, data:' + JSON.stringify(data));
760    });
761} catch(err) {
762    console.error(`catch err->${JSON.stringify(err)}`);
763}
764```
765
766## privacyManager.off
767
768off(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void
769
770Unsubscribes from changes in the permission usage of the specified permissions.
771
772If **callback** is not specified, this API will unregister all callbacks for **permissionList**.
773
774**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
775
776**System capability**: SystemCapability.Security.AccessToken
777
778**Parameters**
779
780| Name            | Type                  | Mandatory| Description                                                         |
781| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
782| type               | string                | Yes  | Event type. The value is **'activeStateChange'**, which indicates the permission usage change.  |
783| permissionList | Array&lt;Permissions&gt;   | Yes  | List of target permissions. The value must be the same as that in **on()**. If this parameter is not specified, this API will unsubscribe from usage changes for all permissions. For details about the permissions, see [Application Permissions](../../security/AccessToken/app-permissions.md).|
784| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | No| Callback to unregister.|
785
786**Error codes**
787
788For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
789
790| ID| Error Message|
791| -------- | -------- |
792| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
793| 202 | Not system app. Interface caller is not a system app. |
794| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
795| 12100001 | Invalid parameter. The permissionList is not in the listening list. |
796| 12100004 | The API is not used in pair with 'on'. |
797| 12100007 | The service is abnormal. |
798| 12100008 | Out of memory. |
799
800**Example**
801
802```ts
803import { privacyManager, Permissions } from '@kit.AbilityKit';
804
805let permissionList: Array<Permissions> = [];
806try {
807    privacyManager.off('activeStateChange', permissionList);
808} catch(err) {
809    console.error(`catch err->${JSON.stringify(err)}`);
810}
811```
812
813## privacyManager.getPermissionUsedTypeInfos<sup>12+</sup>
814
815getPermissionUsedTypeInfos(tokenId?: number, permissionName?: Permissions): Promise&lt;Array&lt;PermissionUsedTypeInfo&gt;&gt;
816
817Obtains information about how a sensitive permission is used by an application.
818
819**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
820
821**System capability**: SystemCapability.Security.AccessToken
822
823**Parameters**
824
825| Name            | Type                  | Mandatory| Description                                                         |
826| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
827| tokenId            | number                | No  | ID of the application that uses the sensitive permission. If this parameter is **0**, this API obtains the sensitive permission access information of all applications.  |
828| 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.  |
829
830**Return value**
831
832| Type         | Description                                   |
833| ------------- | --------------------------------------- |
834| Promise&lt;Array&lt;[PermissionUsedTypeInfo](#permissionusedtypeinfo12)&gt;&gt; | Promise used to return the information obtained.|
835
836**Error codes**
837
838For details about the error codes, see [Access Control Error Codes](errorcode-access-token.md).
839
840| ID| Error Message|
841| -------- | -------- |
842| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
843| 202 | Not system app. Interface caller is not a system app. |
844| 401 | Parameter error. Possible causes: 1.Incorrect parameter types. |
845| 12100001 | Invalid parameter. PermissionName exceeds 256 characters. |
846| 12100002 | The input tokenId does not exist. |
847| 12100003 | The input permissionName does not exist. |
848
849**Example**
850
851```ts
852import { privacyManager, Permissions } from '@kit.AbilityKit';
853import { BusinessError } from '@kit.BasicServicesKit';
854
855let tokenId: number = 0; // You can use bundleManager.getApplicationInfo to obtain accessTokenId.
856let permissionName: Permissions = 'ohos.permission.CAMERA';
857// Without any parameter.
858privacyManager.getPermissionUsedTypeInfos().then(() => {
859  console.log('getPermissionUsedTypeInfos success');
860}).catch((err: BusinessError) => {
861  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
862});
863// Pass in tokenId only.
864privacyManager.getPermissionUsedTypeInfos(tokenId).then(() => {
865  console.log('getPermissionUsedTypeInfos success');
866}).catch((err: BusinessError) => {
867  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
868});
869// Pass in permissionName only.
870privacyManager.getPermissionUsedTypeInfos(null, permissionName).then(() => {
871  console.log('getPermissionUsedTypeInfos success');
872}).catch((err: BusinessError) => {
873  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
874});
875// Pass in tokenId and permissionName.
876privacyManager.getPermissionUsedTypeInfos(tokenId, permissionName).then(() => {
877  console.log('getPermissionUsedTypeInfos success');
878}).catch((err: BusinessError) => {
879  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
880});
881```
882
883## PermissionUsageFlag
884
885Enumerates the modes for querying the permission usage records.
886
887**System capability**: SystemCapability.Security.AccessToken
888
889| Name                   | Value| Description                  |
890| ----------------------- | ------ | ---------------------- |
891| FLAG_PERMISSION_USAGE_SUMMARY             | 0    | Query the permission usage summary.|
892| FLAG_PERMISSION_USAGE_DETAIL         | 1    | Query detailed permission usage records.        |
893
894## PermissionUsedRequest
895
896Represents the request for querying permission usage records.
897
898**System capability**: SystemCapability.Security.AccessToken
899
900| Name      | Type            | Read-Only| Optional| Description                                      |
901| -------- | -------------- | ---- | ---- | ---------------------------------------- |
902| tokenId  | number         | No   | Yes   | Token ID of the application (caller).<br> The default value is **0**, indicating that all applications are queried.        |
903| isRemote | boolean         | No   | Yes   | Whether to query the permission usage records of the remote device.<br> **false** (default) to query the local device; **true** to query the remote device.|
904| deviceId  | string         | No   | Yes   | ID of the device hosting the target application.<br> The default value is the local device ID.  |
905| bundleName | string         | No   | Yes   | Bundle name of the target application.<br> By default, all applications are queried.|
906| permissionNames  | Array&lt;Permissions&gt;         | No   | Yes   | Permissions to query.<br> By default, the usage records of all permissions are queried.              |
907| beginTime | number         | No   | Yes   | Start time of the query, in ms.<br>The default value is **0**, which means the start time is not set.|
908| endTime | number         | No   | Yes   | End time of the query, in ms.<br>The default value is **0**, which means the end time is not set.|
909| flag | [PermissionUsageFlag](#permissionusageflag)         | No   | No   | Query mode.|
910
911## PermissionUsedResponse
912
913Represents the permission usage records of all applications.
914
915**System capability**: SystemCapability.Security.AccessToken
916
917| Name      | Type            | Read-Only| Optional| Description                                      |
918| --------- | -------------- | ---- | ---- | ---------------------------------------- |
919| beginTime | number         | No   | No   | Start time of the query, in ms.|
920| endTime   | number         | No   | No   | End time of the query, in ms.|
921| bundleRecords  | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt;         | No   | No   | Permission usage records.                                |
922
923## BundleUsedRecord
924
925Represents the permission access records of an application.
926
927**System capability**: SystemCapability.Security.AccessToken
928
929| Name      | Type            | Read-Only| Optional| Description                                      |
930| -------- | -------------- | ---- | ---- | ---------------------------------------- |
931| tokenId  | number         | No   | No   | Token ID of the application (caller).                                |
932| isRemote | boolean         | No   | No   | Whether it is a distributed device. **false** (default) means non-distributed devices; **true** means distributed devices.|
933| deviceId  | string         | No   | No   | ID of the device hosting the target application.                                |
934| bundleName | string         | No   | No   | Bundle name of the target application.|
935| permissionRecords  | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt;         | No   | No   | Permission usage records of the target application.                                |
936
937## PermissionUsedRecord
938
939Represents the usage records of a permission.
940
941**System capability**: SystemCapability.Security.AccessToken
942
943| Name      | Type            | Read-Only| Optional| Description                                      |
944| -------- | -------------- | ---- | ---- | ---------------------------------------- |
945| permissionName  | Permissions         | No   | No   | Name of the permission.                                |
946| accessCount | number         | No   | No   | Total number of times that the permission is accessed.|
947| rejectCount | number         | No   | No   | Total number of times that the access to the permission is rejected.|
948| lastAccessTime | number         | No   | No   | Last time when the permission was accessed, accurate to ms.|
949| lastRejectTime | number         | No   | No   | Last time when the access to the permission was rejected, accurate to ms.|
950| lastAccessDuration | number         | No   | No   | Last access duration, in ms.|
951| accessRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | No   | No   | Successful access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_DETAIL**. By default, 10 records are provided.                                |
952| rejectRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | No   | No   | Rejected access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_DETAIL**. By default, 10 records are provided.                                |
953
954## UsedRecordDetail
955
956Represents the details of a single access record.
957
958**System capability**: SystemCapability.Security.AccessToken
959
960| Name      | Type            | Read-Only| Optional| Description                                      |
961| -------- | -------------- | ---- | ---- | ---------------------------------------- |
962| status  | number         | No   | No   | Access status.                                |
963| lockScreenStatus<sup>11+</sup>  | number         | No   | Yes   | 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.                                |
964| timestamp | number         | No   | No   | Access timestamp, in ms.|
965| accessDuration  | number         | No   | No   | Access duration, in ms.                                |
966| count<sup>11+</sup> | number | No| Yes   | Number of successful or failed accesses.
967| usedType<sup>12+</sup> | [PermissionUsedType](#permissionusedtype12) | No| Yes   | Means for using the sensitive permission.|
968
969## PermissionActiveStatus
970
971Enumerates the permission usage statuses.
972
973**System capability**: SystemCapability.Security.AccessToken
974
975| Name                     | Value    | Description             |
976| ------------------------- | ------ | ---------------- |
977| PERM_INACTIVE             | 0      | The permission is not used.  |
978| PERM_ACTIVE_IN_FOREGROUND | 1      | The permission is being used by an application running in the foreground.|
979| PERM_ACTIVE_IN_BACKGROUND | 2      | The permission is being used by an application running in the background.|
980
981## ActiveChangeResponse
982
983Defines the detailed permission usage information.
984
985 **System capability**: SystemCapability.Security.AccessToken
986
987| Name          | Type                   | Read-Only| Optional| Description                  |
988| -------------- | ---------------------- | ---- | ---- | --------------------- |
989| callingTokenId<sup>18+</sup> | number   | No  | Yes  | Token ID of the caller. This parameter is invalid when **activeStatus** is **INACTIVE**.|
990| tokenId        | number                 | No  | No  | Token ID of the application whose permission usage changes are subscribed to.   |
991| permissionName | Permissions            | No  | No  | Permissions whose usage status changes.|
992| deviceId       | string                 | No  | No  | Device ID.                |
993| activeStatus   | [PermissionActiveStatus](#permissionactivestatus) | No  | No  | Permission usage status.       |
994| usedType<sup>18+</sup> | [PermissionUsedType](#permissionusedtype12) | No  | Yes  | Sensitive permission access mode. This parameter is invalid when **activeStatus** is **INACTIVE**.|
995
996## PermissionUsedType<sup>12+</sup>
997
998Enumerates the means for using a sensitive permission.
999
1000**System capability**: SystemCapability.Security.AccessToken
1001
1002| Name                   | Value| Description             |
1003| ----------------------- | -- | ---------------- |
1004| NORMAL_TYPE             | 0  | The sensitive permission is used after authorization through a dialog box or a system settings page.  |
1005| PICKER_TYPE             | 1  | The sensitive permission is used through a system picker. This access mode does not grant the permissions to the application.|
1006| SECURITY_COMPONENT_TYPE | 2  | The sensitive permission is used through a security component, which comes with the authorization.|
1007
1008## PermissionUsedTypeInfo<sup>12+</sup>
1009
1010Represents detailed information about the use of a permission.
1011
1012 **System capability**: SystemCapability.Security.AccessToken
1013
1014| Name          | Type                   | Read-Only| Optional| Description                  |
1015| -------------- | ---------------------- | ---- | ---- | --------------------- |
1016| tokenId        | number                 | No  | No  | Token ID of the application that uses the sensitive permission.|
1017| permissionName | Permissions            | No  | No  | Name of the sensitive permission.|
1018| usedType | [PermissionUsedType](#permissionusedtype12) | No| No   | Access mode of the sensitive permission.|
1019
1020## AddPermissionUsedRecordOptions<sup>12+</sup>
1021
1022Represents the options for adding a permission usage record.
1023
1024 **System capability**: SystemCapability.Security.AccessToken
1025
1026| Name          | Type                   | Read-Only| Optional| Description                  |
1027| -------------- | ---------------------- | ---- | ---- | --------------------- |
1028| usedType | [PermissionUsedType](#permissionusedtype12) | No| Yes   | Access mode of the sensitive permission.|
1029