• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.privacyManager (隐私管理)
2
3本模块主要提供权限使用记录等隐私管理接口。
4
5> **说明:**
6> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
7> 本模块接口为系统接口。
8
9## 导入模块
10
11```ts
12import privacyManager from '@ohos.privacyManager';
13```
14
15
16## privacyManager.addPermissionUsedRecord
17
18addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number): Promise<void>
19
20受应用权限保护的应用在被其他服务、应用调用时,可以使用该接口增加一条权限使用记录。使用Promise异步回调。
21权限使用记录包括:调用方的应用身份标识、使用的应用权限名称,和其访问本应用成功、失败的次数。
22
23**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
24
25**系统能力:** SystemCapability.Security.AccessToken
26
27**参数:**
28
29| 参数名   | 类型                 | 必填 | 说明                                       |
30| -------- | -------------------  | ---- | ------------------------------------------ |
31| tokenID   |  number   | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。              |
32| permissionName | Permissions | 是   | 应用权限名称。 |
33| successCount | number | 是   | 访问成功的次数。 |
34| failCount | number | 是   | 访问失败的次数。 |
35
36**返回值:**
37
38| 类型          | 说明                                |
39| :------------ | :---------------------------------- |
40| Promise<void> | Promise对象。无返回结果的Promise对象。 |
41
42**错误码:**
43
44以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
45
46| 错误码ID | 错误信息 |
47| -------- | -------- |
48| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256, or the count value is invalid. |
49| 12100002 | The specified tokenID does not exist or refer to an application process. |
50| 12100003 | The specified permission does not exist or is not an user_grant permission. |
51| 12100007 | Service is abnormal. |
52| 12100008 | Out of memory. |
53
54**示例:**
55
56```ts
57import privacyManager from '@ohos.privacyManager';
58import { BusinessError } from '@ohos.base';
59
60let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
61try {
62    privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.PERMISSION_USED_STATS', 1, 0).then(() => {
63        console.log('addPermissionUsedRecord success');
64    }).catch((err: BusinessError) => {
65        console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
66    });
67} catch(err) {
68    console.log(`catch err->${JSON.stringify(err)}`);
69}
70```
71
72## privacyManager.addPermissionUsedRecord
73
74addPermissionUsedRecord(tokenID: number, permissionName: Permissions, successCount: number, failCount: number, callback: AsyncCallback<void>): void
75
76受应用权限保护的应用在被其他服务、应用调用时,可以使用该接口增加一条权限使用记录。使用callback异步回调。
77权限使用记录包括:调用方的应用身份标识、使用的应用权限名称,和其访问本应用成功、失败的次数。
78
79**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
80
81**系统能力:** SystemCapability.Security.AccessToken
82
83**参数:**
84
85| 参数名   | 类型                 | 必填 | 说明                                       |
86| -------- | -------------------  | ---- | ------------------------------------------ |
87| tokenID   |  number   | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。              |
88| permissionName | Permissions | 是   | 应用权限名称,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。 |
89| successCount | number | 是   | 访问成功的次数。 |
90| failCount | number | 是   | 访问失败的次数。 |
91| callback | AsyncCallback<void> | 是   | 回调函数。当添加使用记录成功时,err为undefined;否则为错误对象。 |
92
93**错误码:**
94
95以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
96
97| 错误码ID | 错误信息 |
98| -------- | -------- |
99| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256, or the count value is invalid. |
100| 12100002 | The specified tokenID does not exist or refer to an application process. |
101| 12100003 | The specified permission does not exist or is not an user_grant permission. |
102| 12100007 | Service is abnormal. |
103| 12100008 | Out of memory. |
104
105**示例:**
106
107```ts
108import privacyManager from '@ohos.privacyManager';
109import { BusinessError } from '@ohos.base';
110
111let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
112try {
113    privacyManager.addPermissionUsedRecord(tokenID, 'ohos.permission.PERMISSION_USED_STATS', 1, 0, (err: BusinessError, data: void) => {
114        if (err) {
115            console.log(`addPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
116        } else {
117            console.log('addPermissionUsedRecord success');
118        }
119    });
120} catch(err) {
121    console.log(`catch err->${JSON.stringify(err)}`);
122}
123```
124
125## privacyManager.getPermissionUsedRecord
126
127getPermissionUsedRecord(request: PermissionUsedRequest): Promise<PermissionUsedResponse>
128
129获取历史权限使用记录。使用Promise异步回调。
130
131**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
132
133**系统能力:** SystemCapability.Security.AccessToken
134
135**参数:**
136
137| 参数名   | 类型                 | 必填 | 说明                                       |
138| -------- | -------------------  | ---- | ------------------------------------------ |
139| request   |  [PermissionUsedRequest](#permissionusedrequest)   | 是   | 查询权限使用记录的请求。              |
140
141**返回值:**
142
143| 类型          | 说明                                |
144| :------------ | :---------------------------------- |
145| Promise<[PermissionUsedResponse](#permissionusedresponse)> | Promise对象。返回查询的权限使用记录。|
146
147**错误码:**
148
149以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
150
151| 错误码ID | 错误信息 |
152| -------- | -------- |
153| 12100001 | The parameter is invalid. the value of flag in request is invalid. |
154| 12100002 | The specified tokenID does not exist or refer to an application process. |
155| 12100003 | The specified permission does not exist or is not an user_grant permission. |
156| 12100007 | Service is abnormal. |
157| 12100008 | Out of memory. |
158
159**示例:**
160
161```ts
162import privacyManager from '@ohos.privacyManager';
163import { BusinessError } from '@ohos.base';
164
165let request: privacyManager.PermissionUsedRequest = {
166    'tokenId': 1,
167    'isRemote': false,
168    'deviceId': 'device',
169    'bundleName': 'bundle',
170    'permissionNames': [],
171    'beginTime': 0,
172    'endTime': 1,
173    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
174};
175try {
176    privacyManager.getPermissionUsedRecord(request).then((data) => {
177        console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
178    }).catch((err: BusinessError) => {
179        console.log(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
180    });
181} catch(err) {
182    console.log(`catch err->${JSON.stringify(err)}`);
183}
184```
185
186## privacyManager.getPermissionUsedRecord
187
188getPermissionUsedRecord(request: PermissionUsedRequest, callback: AsyncCallback&lt;PermissionUsedResponse&gt;): void
189
190获取历史权限使用记录。使用callback异步回调。
191
192**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
193
194**系统能力:** SystemCapability.Security.AccessToken
195
196**参数:**
197
198| 参数名   | 类型                 | 必填 | 说明                                       |
199| -------- | -------------------  | ---- | ------------------------------------------ |
200| request | [PermissionUsedRequest](#permissionusedrequest) | 是 | 查询权限使用记录的请求。 |
201| callback | AsyncCallback<[PermissionUsedResponse](#permissionusedresponse)> | 是 | 回调函数。当查询记录成功时,err为undefined,data为查询到的权限使用记录;否则为错误对象。 |
202
203**错误码:**
204
205以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
206
207| 错误码ID | 错误信息 |
208| -------- | -------- |
209| 12100001 | The parameter is invalid. the value of flag in request is invalid. |
210| 12100002 | The specified tokenID does not exist or refer to an application process. |
211| 12100003 | The specified permission does not exist or is not an user_grant permission. |
212| 12100007 | Service is abnormal. |
213| 12100008 | Out of memory. |
214
215**示例:**
216
217```ts
218import privacyManager from '@ohos.privacyManager';
219import { BusinessError } from '@ohos.base';
220
221let request: privacyManager.PermissionUsedRequest = {
222    'tokenId': 1,
223    'isRemote': false,
224    'deviceId': 'device',
225    'bundleName': 'bundle',
226    'permissionNames': [],
227    'beginTime': 0,
228    'endTime': 1,
229    'flag':privacyManager.PermissionUsageFlag.FLAG_PERMISSION_USAGE_DETAIL,
230};
231try {
232    privacyManager.getPermissionUsedRecord(request, (err: BusinessError, data: privacyManager.PermissionUsedResponse) => {
233        if (err) {
234            console.log(`getPermissionUsedRecord fail, err->${JSON.stringify(err)}`);
235        } else {
236            console.log(`getPermissionUsedRecord success, data->${JSON.stringify(data)}`);
237        }
238    });
239} catch(err) {
240    console.log(`catch err->${JSON.stringify(err)}`);
241}
242```
243
244## privacyManager.startUsingPermission
245
246startUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
247
248应用开始使用某项权限,可监听应用在前后台使用权限,并将使用权限的记录落盘,由系统服务调用。使用Promise异步回调。
249
250**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
251
252**系统能力:** SystemCapability.Security.AccessToken
253
254**参数:**
255
256| 参数名          | 类型   | 必填 | 说明                                  |
257| -------------- | ------ | ---- | ------------------------------------ |
258| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。 |
259| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
260
261**返回值:**
262
263| 类型          | 说明                                    |
264| ------------- | --------------------------------------- |
265| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
266
267**错误码:**
268
269以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
270
271| 错误码ID | 错误信息 |
272| -------- | -------- |
273| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
274| 12100002 | The specified tokenID does not exist or refer to an application process. |
275| 12100003 | The specified permission does not exist or is not an user_grant permission. |
276| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
277| 12100007 | Service is abnormal. |
278| 12100008 | Out of memory. |
279
280**示例:**
281
282```ts
283import privacyManager from '@ohos.privacyManager';
284import { BusinessError } from '@ohos.base';
285
286let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
287try {
288    privacyManager.startUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS').then(() => {
289        console.log('startUsingPermission success');
290    }).catch((err: BusinessError) => {
291        console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
292    });
293} catch(err) {
294    console.log(`catch err->${JSON.stringify(err)}`);
295}
296```
297
298## privacyManager.startUsingPermission
299
300startUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
301
302应用开始使用某项权限,可监听应用在前后台使用权限,并将使用权限的记录落盘,由系统服务调用。使用callback异步回调。
303
304**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
305
306**系统能力:** SystemCapability.Security.AccessToken
307
308**参数:**
309
310| 参数名          | 类型                  | 必填 | 说明                                  |
311| -------------- | --------------------- | ---- | ------------------------------------ |
312| tokenID        | number                | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。 |
313| permissionName | Permissions                | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
314| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。当开始使用权限成功时,err为undefined;否则为错误对象。 |
315
316**错误码:**
317
318以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
319
320| 错误码ID | 错误信息 |
321| -------- | -------- |
322| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
323| 12100002 | The specified tokenID does not exist or refer to an application process. |
324| 12100003 | The specified permission does not exist or is not an user_grant permission. |
325| 12100004 | The interface is called repeatedly with the same input. It means the application specified by the tokenID has been using the specified permission. |
326| 12100007 | Service is abnormal. |
327| 12100008 | Out of memory. |
328
329**示例:**
330
331```ts
332import privacyManager from '@ohos.privacyManager';
333import { BusinessError } from '@ohos.base';
334
335let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
336try {
337    privacyManager.startUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS', (err: BusinessError, data: void) => {
338        if (err) {
339            console.log(`startUsingPermission fail, err->${JSON.stringify(err)}`);
340        } else {
341            console.log('startUsingPermission success');
342        }
343    });
344} catch(err) {
345    console.log(`catch err->${JSON.stringify(err)}`);
346}
347```
348
349## privacyManager.stopUsingPermission
350
351stopUsingPermission(tokenID: number, permissionName: Permissions): Promise&lt;void&gt;
352
353应用停止使用某项权限,与Start对应,由系统服务调用。使用Promise异步回调。
354
355**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
356
357**系统能力:** SystemCapability.Security.AccessToken
358
359**参数:**
360
361| 参数名          | 类型   | 必填 | 说明                                  |
362| -------------- | ------ | ---- | ------------------------------------ |
363| tokenID        | number | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。 |
364| permissionName | Permissions | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
365
366**返回值:**
367
368| 类型          | 说明                                    |
369| ------------- | --------------------------------------- |
370| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。|
371
372**错误码:**
373
374以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
375
376| 错误码ID | 错误信息 |
377| -------- | -------- |
378| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
379| 12100002 | The specified tokenID does not exist or refer to an application process. |
380| 12100003 | The specified permission does not exist or is not an user_grant permission. |
381| 12100004 | The interface is not used with |
382| 12100007 | Service is abnormal. |
383| 12100008 | Out of memory. |
384
385**示例:**
386
387```ts
388import privacyManager from '@ohos.privacyManager';
389import { BusinessError } from '@ohos.base';
390
391let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
392try {
393    privacyManager.stopUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS').then(() => {
394        console.log('stopUsingPermission success');
395    }).catch((err: BusinessError) => {
396        console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
397    });
398} catch(err) {
399    console.log(`catch err->${JSON.stringify(err)}`);
400}
401```
402
403## privacyManager.stopUsingPermission
404
405stopUsingPermission(tokenID: number, permissionName: Permissions, callback: AsyncCallback&lt;void&gt;): void
406
407应用停止使用某项权限,与Start对应,由系统服务调用。使用callback异步回调。
408
409**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
410
411**系统能力:** SystemCapability.Security.AccessToken
412
413**参数:**
414
415| 参数名          | 类型                  | 必填 | 说明                                  |
416| -------------- | --------------------- | ---- | ------------------------------------ |
417| tokenID        | number                | 是   | 调用方的应用身份标识。可通过应用的[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)获得。 |
418| permissionName | Permissions                | 是   | 需要使用的权限名,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
419| callback       | AsyncCallback&lt;void&gt; | 是   | 回调函数。当停止使用权限成功时,err为undefined;否则为错误对象。 |
420
421**错误码:**
422
423以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
424
425| 错误码ID | 错误信息 |
426| -------- | -------- |
427| 12100001 | The tokenID is 0, permissionName is longer than 256 bytes, or the count value is invalid. |
428| 12100002 | The specified tokenID does not exist or refer to an application process. |
429| 12100003 | The specified permission does not exist or is not an user_grant permission. |
430| 12100004 | The interface is not used with |
431| 12100007 | Service is abnormal. |
432| 12100008 | Out of memory. |
433
434**示例:**
435
436```ts
437import privacyManager from '@ohos.privacyManager';
438import { BusinessError } from '@ohos.base';
439
440let tokenID: number = 0; // 可以通过getApplicationInfo获取accessTokenId
441try {
442    privacyManager.stopUsingPermission(tokenID, 'ohos.permission.PERMISSION_USED_STATS', (err: BusinessError, data: void) => {
443        if (err) {
444            console.log(`stopUsingPermission fail, err->${JSON.stringify(err)}`);
445        } else {
446            console.log('stopUsingPermission success');
447        }
448    });
449} catch(err) {
450    console.log(`catch err->${JSON.stringify(err)}`);
451}
452```
453
454## privacyManager.on
455
456on(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback: Callback&lt;ActiveChangeResponse&gt;): void
457
458订阅指定权限列表的权限使用状态变更事件。
459
460允许相同permissionList订阅多个callback。
461
462不允许存在交集的permissionList订阅相同callback。
463
464**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
465
466**系统能力:** SystemCapability.Security.AccessToken
467
468**参数:**
469
470| 参数名             | 类型                   | 必填 | 说明                                                          |
471| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
472| type               | string                | 是   | 订阅事件类型,固定为'activeStateChange',权限使用状态变更事件。   |
473| permissionList | Array&lt;Permissions&gt;   | 是   | 订阅的权限名列表,为空时表示订阅所有的权限使用状态变化,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
474| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | 是 | 订阅指定权限使用状态变更事件的回调。 |
475
476**错误码:**
477
478以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
479
480| 错误码ID | 错误信息 |
481| -------- | -------- |
482| 12100001 | The parameter is invalid. The tokenID is 0, or the string size of permissionName is larger than 256. |
483| 12100004 | The interface is called repeatedly with the same input. |
484| 12100005 | The registration time has exceeded the limitation. |
485| 12100007 | Service is abnormal. |
486| 12100008 | Out of memory. |
487
488**示例:**
489
490```ts
491import privacyManager, { Permissions } from '@ohos.privacyManager';
492import { BusinessError } from '@ohos.base';
493
494let permissionList: Array<Permissions> = [];
495try {
496    privacyManager.on('activeStateChange', permissionList, (data: privacyManager.ActiveChangeResponse) => {
497        console.debug('receive permission state change, data:' + JSON.stringify(data));
498    });
499} catch(err) {
500    console.log(`catch err->${JSON.stringify(err)}`);
501}
502```
503
504## privacyManager.off
505
506off(type: 'activeStateChange', permissionList: Array&lt;Permissions&gt;, callback?: Callback&lt;ActiveChangeResponse&gt;): void
507
508取消订阅指定权限列表的权限使用状态变更事件。
509
510取消订阅不传callback时,批量删除permissionList下面的所有callback。
511
512**需要权限:** ohos.permission.PERMISSION_USED_STATS,仅系统应用可用。
513
514**系统能力:** SystemCapability.Security.AccessToken
515
516**参数:**
517
518| 参数名             | 类型                   | 必填 | 说明                                                          |
519| ------------------ | --------------------- | ---- | ------------------------------------------------------------ |
520| type               | string                | 是   | 订阅事件类型,固定为'activeStateChange',权限使用状态变更事件。   |
521| permissionList | Array&lt;Permissions&gt;   | 是   | 订阅的权限名列表,为空时表示订阅所有的权限状态变化,必须与on的输入一致,合法的权限名取值可在[应用权限列表](../../security/permission-list.md)中查询。|
522| callback | Callback&lt;[ActiveChangeResponse](#activechangeresponse)&gt; | 否 | 取消订阅指定tokenId与指定权限名状态变更事件的回调。|
523
524**错误码:**
525
526以下错误码的详细介绍请参见[访问控制错误码](../errorcodes/errorcode-access-token.md)。
527
528| 错误码ID | 错误信息 |
529| -------- | -------- |
530| 12100001 | The permissionNames in the list are all invalid, or the list size exceeds 1024 bytes. |
531| 12100004 | The interface is not used together with 'on'|
532| 12100007 | Service is abnormal. |
533| 12100008 | Out of memory. |
534
535**示例:**
536
537```ts
538import privacyManager, { Permissions } from '@ohos.privacyManager';
539
540let permissionList: Array<Permissions> = [];
541try {
542    privacyManager.off('activeStateChange', permissionList);
543}catch(err) {
544    console.log(`catch err->${JSON.stringify(err)}`);
545}
546```
547
548## PermissionUsageFlag
549
550使用记录的查询方式的枚举。
551
552**系统能力:** SystemCapability.Security.AccessToken
553
554| 名称                    | 值 | 说明                   |
555| ----------------------- | ------ | ---------------------- |
556| FLAG_PERMISSION_USAGE_SUMMARY             | 0    | 表示查询总览数据。 |
557| FLAG_PERMISSION_USAGE_DETAIL         | 1    | 表示查询详细数据。         |
558
559## PermissionUsedRequest
560
561表示使用记录的查询请求。
562
563**系统能力:** SystemCapability.Security.AccessToken
564
565| 名称       | 类型             | 必填   | 说明                                       |
566| -------- | -------------- | ---- | ---------------------------------------- |
567| tokenId  | number         | 否    | 目标应用的身份标识。<br/> 默认查询所有应用。         |
568| isRemote | boolean         | 否    | 指定是否查询远端设备。<br/> 默认值:false,默认查询本端设备。 |
569| deviceId  | string         | 否    | 目标应用所在设备的ID。<br/> 默认设备ID为本端设备ID。   |
570| bundleName | string         | 否    | 目标应用的包名。<br/> 默认查询所有应用。 |
571| permissionNames  | Array&lt;Permissions&gt;         | 否    | 需要查询的权限集合。<br/> 默认查询所有权限的使用记录。               |
572| beginTime | number         | 否    | 查询的起始时间,单位:ms。<br/>默认值0,不设定起始时间。 |
573| endTime | number         | 否    | 查询的终止时间,单位:ms。<br/>默认值0,不设定终止时间。 |
574| flag | [PermissionUsageFlag](#permissionusageflag)         | 是    | 指定查询方式。 |
575
576## PermissionUsedResponse
577
578表示所有应用的访问记录。
579
580**系统能力:** SystemCapability.Security.AccessToken
581
582| 名称       | 类型             | 必填   | 说明                                       |
583| -------- | -------------- | ---- | ---------------------------------------- |
584| beginTime | number         | 是    | 查询记录的起始时间,单位:ms。 |
585| endTime | number         | 是    | 查询记录的终止时间,单位:ms。 |
586| bundleRecords  | Array&lt;[BundleUsedRecord](#bundleusedrecord)&gt;         | 是    | 应用的权限使用记录集合。                                 |
587
588## BundleUsedRecord
589
590某个应用的访问记录。
591
592**系统能力:** SystemCapability.Security.AccessToken
593
594| 名称       | 类型             | 必填   | 说明                                       |
595| -------- | -------------- | ---- | ---------------------------------------- |
596| tokenId  | number         | 是    | 目标应用的身份标识。                                 |
597| isRemote | boolean         | 是    | 默认值false。 |
598| deviceId  | string         | 是    | 目标应用所在设备的ID。                                 |
599| bundleName | string         | 是    | 目标应用的包名。 |
600| permissionRecords  | Array&lt;[PermissionUsedRecord](#permissionusedrecord)&gt;         | 是    | 每个应用的权限使用记录集合。                                 |
601
602## PermissionUsedRecord
603
604某个权限的访问记录。
605
606**系统能力:** SystemCapability.Security.AccessToken
607
608| 名称       | 类型             | 必填   | 说明                                       |
609| -------- | -------------- | ---- | ---------------------------------------- |
610| permissionName  | Permissions         | 是    | 权限名。                                 |
611| accessCount | number         | 是    | 该权限访问总次数。 |
612| rejectCount | number         | 是    | 该权限拒绝总次数。 |
613| lastAccessTime | number         | 是    | 最后一次访问时间,单位:ms。 |
614| lastRejectTime | number         | 是    | 最后一次拒绝时间,单位:ms。 |
615| lastAccessDuration | number         | 是    | 最后一次访问时长,单位:ms。 |
616| accessRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | 是    | 访问记录集合,当flag为FLAG_PERMISSION_USAGE_DETAIL时生效,默认查询10条。                                 |
617| rejectRecords  | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt;         | 是    | 拒绝记录集合,当flag为FLAG_PERMISSION_USAGE_DETAIL时生效,默认查询10条。                                 |
618
619## UsedRecordDetail
620
621单次访问记录详情。
622
623**系统能力:** SystemCapability.Security.AccessToken
624
625| 名称       | 类型             | 必填   | 说明                                       |
626| -------- | -------------- | ---- | ---------------------------------------- |
627| status  | number         | 是    | 访问状态。                                 |
628| timestamp | number         | 是    | 访问时的时间戳,单位:ms。 |
629| accessDuration  | number         | 是    | 访问时长,单位:ms。                                 |
630
631## PermissionActiveStatus
632
633表示权限使用状态变化类型的枚举。
634
635**系统能力:** SystemCapability.Security.AccessToken
636
637| 名称                      | 值     | 说明              |
638| ------------------------- | ------ | ---------------- |
639| PERM_INACTIVE             | 0      | 表示未使用权限。   |
640| PERM_ACTIVE_IN_FOREGROUND | 1      | 表示前台使用权限。 |
641| PERM_ACTIVE_IN_BACKGROUND | 2      | 表示后台使用权限。 |
642
643## ActiveChangeResponse
644
645表示某次权限使用状态变化的详情。
646
647 **系统能力:** SystemCapability.Security.AccessToken
648
649| 名称           | 类型                    | 可读 | 可写 | 说明                   |
650| -------------- | ---------------------- | ---- | ---- | --------------------- |
651| tokenId        | number                 | 是   | 否   | 被订阅的应用身份标识    |
652| permissionName | Permissions                 | 是   | 否   | 权限使用状态发生变化的权限名 |
653| deviceId       | string                 | 是   | 否   | 设备号                 |
654| activeStatus   | [PermissionActiveStatus](#permissionactivestatus) | 是   | 否   | 权限使用状态变化类型        |
655