• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.privacyManager (隐私管理)(系统接口)
2
3<!--Kit: Ability Kit-->
4<!--Subsystem: Security-->
5<!--Owner: @xia-bubai-->
6<!--Designer: @linshuqing; @hehehe-li-->
7<!--Tester: @leiyuqian-->
8<!--Adviser: @zengyawen-->
9
10本模块主要提供权限使用记录等隐私管理接口。
11
12> **说明:**
13>
14> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
15> - 本模块为系统接口。
16
17## 导入模块
18
19```ts
20import { privacyManager } from '@kit.AbilityKit';
21```
22
23
24## privacyManager.addPermissionUsedRecord
25
26addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, options?: AddPermissionUsedRecordOptions): Promise&lt;void&gt;
27
28受应用权限保护的应用在被其他服务、应用调用时,可以使用该接口增加一条权限使用记录。使用Promise异步回调。
29权限使用记录包括:调用方的应用身份标识、使用的应用权限名称,和其访问本应用成功、失败的次数。
30
31**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
32
33**系统能力:** SystemCapability.Security.AccessToken
34
35**参数:**
36
37| 参数名   | 类型                 | 必填 | 说明                                       |
38| -------- | -------------------  | ---- | ------------------------------------------ |
39| tokenID   |  number   | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
40| permissionName | Permissions | 是   | 应用权限名称。 |
41| successCount | number | 是   | 访问成功的次数。 |
42| failCount | number | 是   | 访问失败的次数。 |
43| options<sup>12+</sup> | [AddPermissionUsedRecordOptions](#addpermissionusedrecordoptions12) | 否   | 添加权限使用记录可选参数,默认值为NORMAL_TYPE,从API version 12开始支持。 |
44
45**返回值:**
46
47| 类型          | 说明                                |
48| :------------ | :---------------------------------- |
49| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
50
51**错误码:**
52
53以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
54
55| 错误码ID | 错误信息 |
56| -------- | -------- |
57| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
58| 202 | Not system app. Interface caller is not a system app. |
59| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
60| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, the count value is invalid, or usedType in [AddPermissionUsedRecordOptions](#addpermissionusedrecordoptions12) is invalid. |
61| 12100002 | The specified tokenID does not exist or refer to an application process. |
62| 12100003 | The specified permission does not exist or is not a user_grant permission. |
63| 12100007 | The service is abnormal. |
64| 12100008 | Out of memory. |
65
66**示例:**
67
68```ts
69import { privacyManager } from '@kit.AbilityKit';
70import { BusinessError } from '@kit.BasicServicesKit';
71
72let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
73privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0).then(() => {
74  console.info('addPermissionUsedRecord success');
75}).catch((err: BusinessError) => {
76  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
77});
78// with options param
79let options: privacyManager.AddPermissionUsedRecordOptions = {
80  usedType: privacyManager.PermissionUsedType.PICKER_TYPE
81};
82privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, options).then(() => {
83  console.info('addPermissionUsedRecord success');
84}).catch((err: BusinessError) => {
85  console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
86});
87```
88
89## privacyManager.addPermissionUsedRecord
90
91addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, callback: AsyncCallback&lt;void&gt;): void
92
93受应用权限保护的应用在被其他服务、应用调用时,可以使用该接口增加一条权限使用记录。使用callback异步回调。
94权限使用记录包括:调用方的应用身份标识、使用的应用权限名称,和其访问本应用成功、失败的次数。
95
96**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
97
98**系统能力:** SystemCapability.Security.AccessToken
99
100**参数:**
101
102| 参数名   | 类型                 | 必填 | 说明                                       |
103| -------- | -------------------  | ---- | ------------------------------------------ |
104| tokenID   |  number   | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
105| permissionName | Permissions | 是   | 应用权限名称,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。 |
106| successCount | number | 是   | 访问成功的次数。 |
107| failCount | number | 是   | 访问失败的次数。 |
108| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数。当添加使用记录成功时,err为undefined;否则为错误对象。 |
109
110**错误码:**
111
112以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
113
114| 错误码ID | 错误信息 |
115| -------- | -------- |
116| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
117| 202 | Not system app. Interface caller is not a system app. |
118| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
119| 12100001 | Invalid parameter. The tokenID is 0, the permissionName exceeds 256 characters, or the count value is invalid. |
120| 12100002 | The specified tokenID does not exist or refer to an application process. |
121| 12100003 | The specified permission does not exist or is not a user_grant permission. |
122| 12100007 | The service is abnormal. |
123| 12100008 | Out of memory. |
124
125**示例:**
126
127```ts
128import { privacyManager } from '@kit.AbilityKit';
129import { BusinessError } from '@kit.BasicServicesKit';
130
131let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
132privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.READ_AUDIO', 1, 0, (err: BusinessError, data: void) => {
133  if (err) {
134    console.error(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
135  } else {
136    console.info('addPermissionUsedRecord success');
137  }
138});
139```
140
141## privacyManager.getPermissionUsedRecord
142
143getPermissionUsedRecord(request: PermissionUsedRequest): Promise&lt;PermissionUsedResponse&gt;
144
145获取历史权限使用记录。使用Promise异步回调。
146
147**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
148
149**系统能力:** SystemCapability.Security.AccessToken
150
151**参数:**
152
153| 参数名   | 类型                 | 必填 | 说明                                       |
154| -------- | -------------------  | ---- | ------------------------------------------ |
155| request   |  [PermissionUsedRequest](#permissionusedrequest)   | 是   | 查询权限使用记录的请求。              |
156
157**返回值:**
158
159| 类型          | 说明                                |
160| :------------ | :---------------------------------- |
161| Promise<[PermissionUsedResponse](#permissionusedresponse)> | Promise对象。返回查询的权限使用记录。|
162
163**错误码:**
164
165以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
166
167| 错误码ID | 错误信息 |
168| -------- | -------- |
169| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
170| 202 | Not system app. Interface caller is not a system app. |
171| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
172| 12100001 | Invalid parameter. The value of flag, begin, or end in request is invalid. |
173| 12100002 | The specified tokenID does not exist or refer to an application process. |
174| 12100003 | The specified permission does not exist or is not a user_grant permission. |
175| 12100007 | The service is abnormal. |
176| 12100008 | Out of memory. |
177
178**示例:**
179
180```ts
181import { privacyManager } from '@kit.AbilityKit';
182import { BusinessError } from '@kit.BasicServicesKit';
183
184let request: privacyManager.PermissionUsedRequest = {
185    'tokenId': 1,
186    'isRemote': false,
187    'deviceId': 'device',
188    'bundleName': 'bundle',
189    'permissionNames': [],
190    'beginTime': 0,
191    'endTime': 1,
192    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
193};
194
195privacyManager.getPermissionUsedRecord(request).then((data) => {
196  console.info(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
197}).catch((err: BusinessError) => {
198  console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
199});
200```
201
202## privacyManager.getPermissionUsedRecord
203
204getPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback&lt;PermissionUsedResponse&gt;): void
205
206获取历史权限使用记录。使用callback异步回调。
207
208**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
209
210**系统能力:** SystemCapability.Security.AccessToken
211
212**参数:**
213
214| 参数名   | 类型                 | 必填 | 说明                                       |
215| -------- | -------------------  | ---- | ------------------------------------------ |
216| request | [PermissionUsedRequest](#permissionusedrequest) | 是 | 查询权限使用记录的请求。 |
217| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | 是 | 回调函数。当查询记录成功时,err为undefined,data为查询到的权限使用记录;否则为错误对象。 |
218
219**错误码:**
220
221以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
222
223| 错误码ID | 错误信息 |
224| -------- | -------- |
225| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
226| 202 | Not system app. Interface caller is not a system app. |
227| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
228| 12100001 | Invalid parameter. The value of flag, begin, or end in request is invalid. |
229| 12100002 | The specified tokenID does not exist or refer to an application process. |
230| 12100003 | The specified permission does not exist or is not a user_grant permission. |
231| 12100007 | The service is abnormal. |
232| 12100008 | Out of memory. |
233
234**示例:**
235
236```ts
237import { privacyManager } from '@kit.AbilityKit';
238import { BusinessError } from '@kit.BasicServicesKit';
239
240let request: privacyManager.PermissionUsedRequest = {
241    'tokenId': 1,
242    'isRemote': false,
243    'deviceId': 'device',
244    'bundleName': 'bundle',
245    'permissionNames': [],
246    'beginTime': 0,
247    'endTime': 1,
248    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
249};
250
251privacyManager.getPermissionUsedRecord(request, (err: BusinessError, data: privacyManager.PermissionUsedResponse) => {
252  if (err) {
253    console.error(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
254  } else {
255    console.info(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
256  }
257});
258```
259
260## privacyManager.setPermissionUsedRecordToggleStatus<sup>18+</sup>
261
262setPermissionUsedRecordToggleStatus(status: boolean): Promise&lt;void&gt;
263
264设置是否记录当前用户的权限使用情况。系统应用调用此接口,可以设置当前用户的权限使用记录开关状态,使用Promise异步回调。
265
266status为true时,[addPermissionUsedRecord](#privacymanageraddpermissionusedrecord)接口可以正常添加使用记录;status为false时,[addPermissionUsedRecord](#privacymanageraddpermissionusedrecord)接口不记录权限使用记录,并且删除当前用户的历史记录。
267
268**需要权限:** ohos.permission.PERMISSION_RECORD_TOGGLE,仅系统应用可用。
269
270**系统能力:** SystemCapability.Security.AccessToken
271
272**参数:**
273
274| 参数名          | 类型   | 必填 | 说明                                  |
275| -------------- | ------ | ---- | ------------------------------------ |
276| status        | boolean | 是   | 权限使用记录开关状态。true为开,false为关。|
277
278**返回值:**
279
280| 类型          | 说明                                    |
281| ------------- | --------------------------------------- |
282| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
283
284**错误码:**
285
286以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
287
288| 错误码ID | 错误信息 |
289| -------- | -------- |
290| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_RECORD_TOGGLE". |
291| 202 | Not system app. Interface caller is not a system app. |
292| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
293| 12100007 | The service is abnormal. |
294| 12100009 | Common inner error. |
295
296**示例:**
297
298```ts
299import { privacyManager } from '@kit.AbilityKit';
300import { BusinessError } from '@kit.BasicServicesKit';
301
302privacyManager.setPermissionUsedRecordToggleStatus(true).then(() => {
303  console.info('setPermissionUsedRecordToggleStatus success');
304}).catch((err: BusinessError) => {
305  console.error(`setPermissionUsedRecordToggleStatus fail, err->${JSON.stringify(err)}`);
306});
307```
308
309## privacyManager.getPermissionUsedRecordToggleStatus<sup>18+</sup>
310
311getPermissionUsedRecordToggleStatus(): Promise&lt;boolean&gt;
312
313系统应用调用此接口,可以获取当前用户的权限使用记录开关状态,使用Promise异步回调。
314
315**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
316
317**系统能力:** SystemCapability.Security.AccessToken
318
319**返回值:**
320
321| 类型          | 说明                                    |
322| ------------- | --------------------------------------- |
323| Promise&lt;boolean&gt; | Promise对象,返回当前用户的开关状态值。true表示开启,false表示关闭。|
324
325**错误码:**
326
327以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
328
329| 错误码ID | 错误信息 |
330| -------- | -------- |
331| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
332| 202 | Not system app. Interface caller is not a system app. |
333| 12100007 | The service is abnormal. |
334
335**示例:**
336
337```ts
338import { privacyManager } from '@kit.AbilityKit';
339import { BusinessError } from '@kit.BasicServicesKit';
340
341privacyManager.getPermissionUsedRecordToggleStatus().then((res) => {
342  console.info('getPermissionUsedRecordToggleStatus success');
343  if (res == true) {
344    console.info('get status is TRUE');
345  } else {
346    console.info('get status is FALSE');
347  }
348}).catch((err: BusinessError) => {
349  console.error(`getPermissionUsedRecordToggleStatus fail, err->${JSON.stringify(err)}`);
350});
351```
352
353## privacyManager.startUsingPermission
354
355startUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
356
357系统应用调用此接口,能够传递应用在前后台的权限使用情况,并依据应用的生命周期做出相应的响应。使用Promise异步回调。
358
359当应用开始使用某项权限时,隐私服务将通知隐私指示器该应用正在使用该权限;当应用退出时,隐私服务将通知隐私指示器该应用已停止使用该权限,并清除相应的缓存。
360
361**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
362
363**系统能力:** SystemCapability.Security.AccessToken
364
365**参数:**
366
367| 参数名          | 类型   | 必填 | 说明                                  |
368| -------------- | ------ | ---- | ------------------------------------ |
369| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
370| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
371
372**返回值:**
373
374| 类型          | 说明                                    |
375| ------------- | --------------------------------------- |
376| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
377
378**错误码:**
379
380以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
381
382| 错误码ID | 错误信息 |
383| -------- | -------- |
384| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
385| 202 | Not system app. Interface caller is not a system app. |
386| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
387| 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. |
388| 12100002 | The specified tokenID does not exist or refer to an application process. |
389| 12100003 | The specified permission does not exist or is not a user_grant permission. |
390| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
391| 12100007 | The service is abnormal. |
392| 12100008 | Out of memory. |
393
394**示例:**
395
396```ts
397import { privacyManager } from '@kit.AbilityKit';
398import { BusinessError } from '@kit.BasicServicesKit';
399
400let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
401privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
402  console.info('startUsingPermission success');
403}).catch((err: BusinessError) => {
404  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
405});
406```
407
408## privacyManager.startUsingPermission<sup>18+</sup>
409
410startUsingPermission(tokenID: number, permissionName: Permissions, pid?: number, usedType?: PermissionUsedType): Promise&lt;void&gt;
411
412系统应用调用此接口,能够传递应用在前后台的权限使用情况,并依据应用的生命周期做出相应的响应。使用Promise异步回调。
413
414当应用按照某种权限授予方式使用权限时,隐私服务将通知隐私指示器该应用正在使用该权限;当应用退出时,隐私服务将通知隐私指示器该应用已停止使用该权限,并清除相应的缓存。
415
416在传递多进程应用的权限使用情况时,可以指定应用进程的pid。若未指定pid,默认按应用响应,在应用退出时,隐私服务通知隐私指示器并清除缓存。
417
418若指定了pid,当该进程退出时,隐私服务通知隐私指示器并清除缓存,此时pid必须为tokenID对应应用的进程pid,不能为其他应用的pid。
419
420**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
421
422**系统能力:** SystemCapability.Security.AccessToken
423
424**参数:**
425
426| 参数名          | 类型   | 必填 | 说明                                  |
427| -------------- | ------ | ---- | ------------------------------------ |
428| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
429| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
430| pid            | number | 否   | 调用方的进程pid,默认-1,-1表示不根据进程生命周期响应。|
431| usedType       | [PermissionUsedType](#permissionusedtype12) | 否 | 敏感权限访问方式,默认NORMAL_TYPE。 |
432
433**返回值:**
434
435| 类型          | 说明                                    |
436| ------------- | --------------------------------------- |
437| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
438
439**错误码:**
440
441以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
442
443| 错误码ID | 错误信息 |
444| -------- | -------- |
445| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
446| 202 | Not system app. Interface caller is not a system app. |
447| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
448| 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. |
449| 12100002 | The specified tokenID does not exist or refer to an application process. |
450| 12100003 | The specified permission does not exist or is not a user_grant permission. |
451| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
452| 12100007 | The service is abnormal. |
453| 12100008 | Out of memory. |
454
455**示例:**
456
457```ts
458import { privacyManager } from '@kit.AbilityKit';
459import { BusinessError } from '@kit.BasicServicesKit';
460import { rpc } from '@kit.IPCKit'
461
462let tokenID: number = rpc.IPCSkeleton.getCallingTokenId(); // 可以通过getApplicationInfo获取accessTokenId。
463let pid: number = rpc.IPCSkeleton.getCallingPid();
464let usedType: privacyManager.PermissionUsedType = privacyManager.PermissionUsedType.PICKER_TYPE;
465
466// without pid and usedType
467privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
468  console.info('startUsingPermission success');
469}).catch((err: BusinessError) => {
470  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
471});
472// with pid
473privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid).then(() => {
474  console.info('startUsingPermission success');
475}).catch((err: BusinessError) => {
476  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
477});
478// with usedType
479privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', -1, usedType).then(() => {
480  console.info('startUsingPermission success');
481}).catch((err: BusinessError) => {
482  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
483});
484// with pid and usedType
485privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid, usedType).then(() => {
486  console.info('startUsingPermission success');
487}).catch((err: BusinessError) => {
488  console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
489});
490```
491
492## privacyManager.startUsingPermission
493
494startUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
495
496系统应用调用此接口,能够传递应用在前后台的权限使用情况,并依据应用的生命周期做出相应的响应。使用callback异步回调。
497
498当应用开始使用某项权限时,隐私服务将通知隐私指示器该应用正在使用该权限;当应用退出时,隐私服务将通知隐私指示器该应用已停止使用该权限,并清除相应的缓存。
499
500**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
501
502**系统能力:** SystemCapability.Security.AccessToken
503
504**参数:**
505
506| 参数名          | 类型                  | 必填 | 说明                                  |
507| -------------- | --------------------- | ---- | ------------------------------------ |
508| tokenID        | number                | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
509| permissionName | Permissions                | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
510| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。当开始使用权限成功时,err为undefined;否则为错误对象。 |
511
512**错误码:**
513
514以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
515
516| 错误码ID | 错误信息 |
517| -------- | -------- |
518| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
519| 202 | Not system app. Interface caller is not a system app. |
520| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
521| 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. |
522| 12100002 | The specified tokenID does not exist or refer to an application process. |
523| 12100003 | The specified permission does not exist or is not a user_grant permission. |
524| 12100004 | The API is used repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
525| 12100007 | The service is abnormal. |
526| 12100008 | Out of memory. |
527
528**示例:**
529
530```ts
531import { privacyManager } from '@kit.AbilityKit';
532import { BusinessError } from '@kit.BasicServicesKit';
533
534let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
535privacyManager.startUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
536  if (err) {
537    console.error(`startUsingPermission fail, err->${JSON.stringify(err)}`);
538  } else {
539    console.info('startUsingPermission success');
540  }
541});
542```
543
544## privacyManager.stopUsingPermission
545
546stopUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
547
548应用停止使用某项权限,与Start对应,由系统服务调用。使用Promise异步回调。
549
550**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
551
552**系统能力:** SystemCapability.Security.AccessToken
553
554**参数:**
555
556| 参数名          | 类型   | 必填 | 说明                                  |
557| -------------- | ------ | ---- | ------------------------------------ |
558| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
559| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
560
561**返回值:**
562
563| 类型          | 说明                                    |
564| ------------- | --------------------------------------- |
565| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
566
567**错误码:**
568
569以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
570
571| 错误码ID | 错误信息 |
572| -------- | -------- |
573| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
574| 202 | Not system app. Interface caller is not a system app. |
575| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
576| 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. |
577| 12100002 | The specified tokenID does not exist or refer to an application process. |
578| 12100003 | The specified permission does not exist or is not a user_grant permission. |
579| 12100004 | The API is not used in pair with 'startUsingPermission'. |
580| 12100007 | The service is abnormal. |
581| 12100008 | Out of memory. |
582
583**示例:**
584
585```ts
586import { privacyManager } from '@kit.AbilityKit';
587import { BusinessError } from '@kit.BasicServicesKit';
588
589let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
590privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
591  console.info('stopUsingPermission success');
592}).catch((err: BusinessError) => {
593  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
594});
595```
596
597## privacyManager.stopUsingPermission<sup>18+</sup>
598
599stopUsingPermission(tokenID: number, permissionName: Permissions, pid?: number): Promise&lt;void&gt;
600
601应用停止使用某项权限,与Start对应,由系统服务调用。使用Promise异步回调。
602
603pid需要与startUsingPermission传入的pid相同。
604
605**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
606
607**系统能力:** SystemCapability.Security.AccessToken
608
609**参数:**
610
611| 参数名          | 类型   | 必填 | 说明                                  |
612| -------------- | ------ | ---- | ------------------------------------ |
613| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
614| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
615| pid            | number | 否   | 与startUsingPermission传入的pid相同,默认-1。|
616
617**返回值:**
618
619| 类型          | 说明                                    |
620| ------------- | --------------------------------------- |
621| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
622
623**错误码:**
624
625以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
626
627| 错误码ID | 错误信息 |
628| -------- | -------- |
629| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
630| 202 | Not system app. Interface caller is not a system app. |
631| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
632| 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. |
633| 12100002 | The specified tokenID does not exist or refer to an application process. |
634| 12100003 | The specified permission does not exist or is not a user_grant permission. |
635| 12100004 | The API is not used in pair with 'startUsingPermission'. |
636| 12100007 | The service is abnormal. |
637| 12100008 | Out of memory. |
638
639**示例:**
640
641```ts
642import { privacyManager } from '@kit.AbilityKit';
643import { BusinessError } from '@kit.BasicServicesKit';
644import { rpc } from '@kit.IPCKit'
645
646let tokenID: number = rpc.IPCSkeleton.getCallingTokenId(); // 也可以通过getApplicationInfo获取accessTokenId。
647let pid: number = rpc.IPCSkeleton.getCallingPid();
648
649// without pid
650privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO').then(() => {
651  console.info('stopUsingPermission success');
652}).catch((err: BusinessError) => {
653  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
654});
655
656// with pid
657privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', pid).then(() => {
658  console.info('stopUsingPermission success');
659}).catch((err: BusinessError) => {
660  console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
661});
662```
663
664## privacyManager.stopUsingPermission
665
666stopUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
667
668应用停止使用某项权限,与Start对应,由系统服务调用。使用callback异步回调。
669
670**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
671
672**系统能力:** SystemCapability.Security.AccessToken
673
674**参数:**
675
676| 参数名          | 类型                  | 必填 | 说明                                  |
677| -------------- | --------------------- | ---- | ------------------------------------ |
678| tokenID        | number                | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundleManager-applicationInfo.md)的accessTokenId字段获得。|
679| permissionName | Permissions                | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
680| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。当停止使用权限成功时,err为undefined;否则为错误对象。 |
681
682**错误码:**
683
684以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
685
686| 错误码ID | 错误信息 |
687| -------- | -------- |
688| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
689| 202 | Not system app. Interface caller is not a system app. |
690| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
691| 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. |
692| 12100002 | The specified tokenID does not exist or refer to an application process. |
693| 12100003 | The specified permission does not exist or is not a user_grant permission. |
694| 12100004 | The API is not used in pair with 'startUsingPermission'. |
695| 12100007 | The service is abnormal. |
696| 12100008 | Out of memory. |
697
698**示例:**
699
700```ts
701import { privacyManager } from '@kit.AbilityKit';
702import { BusinessError } from '@kit.BasicServicesKit';
703
704let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId。
705privacyManager.stopUsingPermission(tokenID, 'ohos.permission.READ_AUDIO', (err: BusinessError, data: void) => {
706  if (err) {
707    console.error(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
708  } else {
709    console.info('stopUsingPermission success');
710  }
711});
712```
713
714## privacyManager.on
715
716on(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void
717
718订阅指定权限列表的权限使用状态变更事件。
719
720允许相同permissionList订阅多个callback。
721
722不允许存在交集的permissionList订阅相同callback。
723
724**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
725
726**系统能力:** SystemCapability.Security.AccessToken
727
728**参数:**
729
730| 参数名             | 类型                   | 必填 | 说明                                                          |
731| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
732| type               | string                | 是   | 订阅事件类型,固定为'activeStateChange',权限使用状态变更事件。   |
733| permissionList | Array&lt;Permissions&gt;   | 是   | 订阅的权限名列表,为空时表示订阅所有的权限使用状态变化,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
734| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | 是 | 订阅指定权限使用状态变更事件的回调。 |
735
736**错误码:**
737
738以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
739
740| 错误码ID | 错误信息 |
741| -------- | -------- |
742| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
743| 202 | Not system app. Interface caller is not a system app. |
744| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
745| 12100001 | Invalid parameter. The permissionList exceeds the size limit, or the permissionNames in the list are all invalid. |
746| 12100004 | The API is used repeatedly with the same input. |
747| 12100005 | The registration time has exceeded the limit. |
748| 12100007 | The service is abnormal. |
749| 12100008 | Out of memory. |
750
751**示例:**
752
753```ts
754import { privacyManager, Permissions } from '@kit.AbilityKit';
755import { BusinessError } from '@kit.BasicServicesKit';
756
757let permissionList: Array<Permissions> = [];
758try {
759    privacyManager.on('activeStateChange', permissionList, (data: privacyManager.ActiveChangeResponse) => {
760        console.debug('receive permission state change, data:' + JSON.stringify(data));
761    });
762} catch(err) {
763    console.error(`catch err->${JSON.stringify(err)}`);
764}
765```
766
767## privacyManager.off
768
769off(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void
770
771取消订阅指定权限列表的权限使用状态变更事件。
772
773取消订阅时,若不传入callback,则批量删除permissionList下的所有callback。
774
775**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
776
777**系统能力:** SystemCapability.Security.AccessToken
778
779**参数:**
780
781| 参数名             | 类型                   | 必填 | 说明                                                          |
782| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
783| type               | string                | 是   | 取消订阅事件类型,固定为'activeStateChange',权限使用状态变更事件。   |
784| permissionList | Array&lt;Permissions&gt;   | 是   | 取消订阅的权限名列表,为空时表示订阅所有的权限状态变化,必须与on的输入一致,合法的权限名取值可在[应用权限列表](../../security/AccessToken/app-permissions.md)中查询。|
785| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | 否 | 取消订阅指定tokenId与指定权限名状态变更事件的回调。|
786
787**错误码:**
788
789以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
790
791| 错误码ID | 错误信息 |
792| -------- | -------- |
793| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
794| 202 | Not system app. Interface caller is not a system app. |
795| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
796| 12100001 | Invalid parameter. The permissionList is not in the listening list. |
797| 12100004 | The API is not used in pair with 'on'. |
798| 12100007 | The service is abnormal. |
799| 12100008 | Out of memory. |
800
801**示例:**
802
803```ts
804import { privacyManager, Permissions } from '@kit.AbilityKit';
805
806let permissionList: Array<Permissions> = [];
807try {
808    privacyManager.off('activeStateChange', permissionList);
809} catch(err) {
810    console.error(`catch err->${JSON.stringify(err)}`);
811}
812```
813
814## privacyManager.getPermissionUsedTypeInfos<sup>12+</sup>
815
816getPermissionUsedTypeInfos(tokenId?: number | null, permissionName?: Permissions): Promise&lt;Array&lt;PermissionUsedTypeInfo&gt;&gt;
817
818查询设备上指定应用访问敏感权限时的信息(包括敏感权限名称、敏感权限访问方式)。
819
820**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
821
822**系统能力:** SystemCapability.Security.AccessToken
823
824**参数:**
825
826| 参数名             | 类型                   | 必填 | 说明                                                          |
827| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
828| tokenId            | number \| null                | 否   | 访问敏感权限的应用身份标识,为0时表示查询所有应用的敏感权限访问类型信息。从API20,新增支持null类型。   |
829| permissionName     | Permissions           | 否   | 被访问的敏感权限名称,为空时标识查询所有敏感权限的访问类型信息。   |
830
831**返回值:**
832
833| 类型          | 说明                                    |
834| ------------- | --------------------------------------- |
835| Promise&lt;Array&lt;[PermissionUsedTypeInfo](#permissionusedtypeinfo12)&gt;&gt; | Promise对象。返回权限访问类型信息列表的Promise对象。|
836
837**错误码:**
838
839以下错误码的详细介绍请参见[访问控制错误码](errorcode-access-token.md)。
840
841| 错误码ID | 错误信息 |
842| -------- | -------- |
843| 201 | Permission denied. Interface caller does not have permission "ohos.permission.PERMISSION_USED_STATS". |
844| 202 | Not system app. Interface caller is not a system app. |
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**示例:**
850
851```ts
852import { privacyManager, Permissions } from '@kit.AbilityKit';
853import { BusinessError } from '@kit.BasicServicesKit';
854
855let tokenId: number = 0; // 可以通过bundleManager.getApplicationInfo获取accessTokenId。
856let permissionName: Permissions = 'ohos.permission.CAMERA';
857// without any param
858privacyManager.getPermissionUsedTypeInfos().then(() => {
859  console.info('getPermissionUsedTypeInfos success');
860}).catch((err: BusinessError) => {
861  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
862});
863// only tokenId
864privacyManager.getPermissionUsedTypeInfos(tokenId).then(() => {
865  console.info('getPermissionUsedTypeInfos success');
866}).catch((err: BusinessError) => {
867  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
868});
869// only permissionName
870privacyManager.getPermissionUsedTypeInfos(null, permissionName).then(() => {
871  console.info('getPermissionUsedTypeInfos success');
872}).catch((err: BusinessError) => {
873  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
874});
875// tokenId and permissionName
876privacyManager.getPermissionUsedTypeInfos(tokenId, permissionName).then(() => {
877  console.info('getPermissionUsedTypeInfos success');
878}).catch((err: BusinessError) => {
879  console.error(`getPermissionUsedTypeInfos fail, err->${JSON.stringify(err)}`);
880});
881```
882
883## PermissionUsageFlag
884
885表示使用记录的查询方式的枚举。
886
887**系统能力:** SystemCapability.Security.AccessToken
888
889| 名称                    | 值 | 说明                   |
890| ----------------------- | ------ | ---------------------- |
891| FLAG_PERMISSION_USAGE_SUMMARY             | 0    | 表示查询总览数据。 |
892| FLAG_PERMISSION_USAGE_DETAIL         | 1    | 表示查询详细数据。         |
893
894## PermissionUsedRequest
895
896表示使用记录的查询请求。
897
898**系统能力:** SystemCapability.Security.AccessToken
899
900| 名称       | 类型             | 只读 | 可选 | 说明                                       |
901| -------- | -------------- | ---- | ---- | ---------------------------------------- |
902| tokenId  | number         | 否    | 是    | 目标应用的身份标识。<br/> 默认值为0,查询所有应用。         |
903| isRemote | boolean         | 否    | 是    | 指定是否查询远端设备。<br/> 默认值false,表示查询本端设备,true表示查询远端设备。 |
904| deviceId  | string         | 否    | 是    | 目标应用所在设备的ID。<br/> 默认设备ID为本端设备ID。   |
905| bundleName | string         | 否    | 是    | 目标应用的包名。<br/> 默认查询所有应用。 |
906| permissionNames  | Array&lt;Permissions&gt;         | 否    | 是    | 需要查询的权限集合。<br/> 默认查询所有权限的使用记录。               |
907| beginTime | number         | 否    | 是    | 查询的起始时间,单位:ms。<br/>默认值0,不设定起始时间。 |
908| endTime | number         | 否    | 是    | 查询的终止时间,单位:ms。<br/>默认值0,不设定终止时间。 |
909| flag | [PermissionUsageFlag](#permissionusageflag)         | 否    | 否    | 指定查询方式。 |
910
911## PermissionUsedResponse
912
913表示所有应用的访问记录。
914
915**系统能力:** SystemCapability.Security.AccessToken
916
917| 名称       | 类型             | 只读 | 可选 | 说明                                       |
918| --------- | -------------- | ---- | ---- | ---------------------------------------- |
919| beginTime | number         | 否    | 否    | 查询记录的起始时间,单位:ms。 |
920| endTime   | number         | 否    | 否    | 查询记录的终止时间,单位:ms。 |
921| bundleRecords  | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt;         | 否    | 否    | 应用的权限使用记录集合。                                 |
922
923## BundleUsedRecord
924
925某个应用的访问记录。
926
927**系统能力:** SystemCapability.Security.AccessToken
928
929| 名称       | 类型             | 只读 | 可选 | 说明                                       |
930| -------- | -------------- | ---- | ---- | ---------------------------------------- |
931| tokenId  | number         | 否    | 否    | 目标应用的身份标识。                                 |
932| isRemote | boolean         | 否    | 否    | 是否是分布式设备。默认值为false,表示不是分布式设备,true表示是分布式设备。 |
933| deviceId  | string         | 否    | 否    | 目标应用所在设备的ID。                                 |
934| bundleName | string         | 否    | 否    | 目标应用的包名。 |
935| permissionRecords  | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt;         | 否    | 否    | 每个应用的权限使用记录集合。                                 |
936
937## PermissionUsedRecord
938
939某个权限的访问记录。
940
941**系统能力:** SystemCapability.Security.AccessToken
942
943| 名称       | 类型             | 只读 | 可选 | 说明                                       |
944| -------- | -------------- | ---- | ---- | ---------------------------------------- |
945| permissionName  | Permissions         | 否    | 否    | 权限名。                                 |
946| accessCount | number         | 否    | 否    | 该权限访问总次数。 |
947| rejectCount | number         | 否    | 否    | 该权限拒绝总次数。 |
948| lastAccessTime | number         | 否    | 否    | 最后一次访问时间,单位:ms。 |
949| lastRejectTime | number         | 否    | 否    | 最后一次拒绝时间,单位:ms。 |
950| lastAccessDuration | number         | 否    | 否    | 最后一次访问时长,单位:ms。 |
951| accessRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | 否    | 否    | 访问记录集合,当flag为FLAG_PERMISSION_USAGE_DETAIL时生效,默认查询10条记录。                                 |
952| rejectRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | 否    | 否    | 拒绝记录集合,当flag为FLAG_PERMISSION_USAGE_DETAIL时生效,默认查询10条记录。                                 |
953
954## UsedRecordDetail
955
956单次访问记录详情。
957
958**系统能力:** SystemCapability.Security.AccessToken
959
960| 名称       | 类型             | 只读 | 可选 | 说明                                       |
961| -------- | -------------- | ---- | ---- | ---------------------------------------- |
962| status  | number         | 否    | 否    | 访问状态。                                 |
963| lockScreenStatus<sup>11+</sup>  | number         | 否    | 是    | 访问时的锁屏状态。<br> - 1,表示非锁屏场景使用权限。<br> - 2,表示锁屏场景使用权限。                                 |
964| timestamp | number         | 否    | 否    | 访问时的时间戳,单位:ms。 |
965| accessDuration  | number         | 否    | 否    | 访问时长,单位:ms。                                 |
966| count<sup>11+</sup> | number | 否 | 是    | 成功或失败次数。
967| usedType<sup>12+</sup> | [PermissionUsedType](#permissionusedtype12) | 否 | 是    | 敏感权限访问方式。 |
968
969## PermissionActiveStatus
970
971表示权限使用状态变化类型的枚举。
972
973**系统能力:** SystemCapability.Security.AccessToken
974
975| 名称                      | 值     | 说明              |
976| ------------------------- | ------ | ---------------- |
977| PERM_INACTIVE             | 0      | 表示未使用权限。   |
978| PERM_ACTIVE_IN_FOREGROUND | 1      | 表示前台使用权限。 |
979| PERM_ACTIVE_IN_BACKGROUND | 2      | 表示后台使用权限。 |
980
981## ActiveChangeResponse
982
983表示某次权限使用状态变化的详情。
984
985 **系统能力:** SystemCapability.Security.AccessToken
986
987| 名称           | 类型                    | 只读 | 可选 | 说明                   |
988| -------------- | ---------------------- | ---- | ---- | --------------------- |
989| callingTokenId<sup>18+</sup> | number   | 否   | 是   | 接口调用方的应用身份标识,当activeStatus为INACTIVE时该值无效。 |
990| tokenId        | number                 | 否   | 否   | 被订阅的应用身份标识。    |
991| permissionName | Permissions            | 否   | 否   | 权限使用状态发生变化的权限名。 |
992| deviceId       | string                 | 否   | 否   | 设备号。                 |
993| activeStatus   | [PermissionActiveStatus](#permissionactivestatus) | 否   | 否   | 权限使用状态变化类型。        |
994| usedType<sup>18+</sup> | [PermissionUsedType](#permissionusedtype12) | 否   | 是   | 敏感权限使用类型,当activeStatus为INACTIVE时该值无效。 |
995
996## PermissionUsedType<sup>12+</sup>
997
998表示通过何种方式使用敏感权限的枚举。
999
1000**系统能力:** SystemCapability.Security.AccessToken
1001
1002| 名称                    | 值 | 说明              |
1003| ----------------------- | -- | ---------------- |
1004| NORMAL_TYPE             | 0  | 表示通过弹窗授权或设置授权来使用敏感权限。   |
1005| PICKER_TYPE             | 1  | 表示通过某个PICKER服务来使用敏感权限,但此方式未授予权限。 |
1006| SECURITY_COMPONENT_TYPE | 2  | 表示通过安全控件授权的方式来使用敏感权限。 |
1007
1008## PermissionUsedTypeInfo<sup>12+</sup>
1009
1010表示某次权限使用类型的详情。
1011
1012 **系统能力:** SystemCapability.Security.AccessToken
1013
1014| 名称           | 类型                    | 只读 | 可选 | 说明                   |
1015| -------------- | ---------------------- | ---- | ---- | --------------------- |
1016| tokenId        | number                 | 否   | 否   | 访问敏感权限的应用身份标识。 |
1017| permissionName | Permissions            | 否   | 否   | 被访问的敏感权限名称。 |
1018| usedType | [PermissionUsedType](#permissionusedtype12) | 否 | 否    | 敏感权限使用类型。 |
1019
1020## AddPermissionUsedRecordOptions<sup>12+</sup>
1021
1022添加权限使用记录可选参数集。
1023
1024 **系统能力:** SystemCapability.Security.AccessToken
1025
1026| 名称           | 类型                    | 只读 | 可选 | 说明                   |
1027| -------------- | ---------------------- | ---- | ---- | --------------------- |
1028| usedType | [PermissionUsedType](#permissionusedtype12) | 否 | 是    | 敏感权限使用类型。 |
1029