1# @ohos.resourceschedule.usageStatistics (设备使用信息统计)(系统接口)
2
3本模块提供设备使用信息统计能力,包括查询应用是否为常用应用、优先级分组、使用时长、系统事件(休眠、唤醒、解锁、锁屏)信息、应用事件(前台、后台、长时任务开始和结束)信息、通知次数等不同类型信息。
4
5> **说明:**
6>
7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> 本模块接口为系统接口。
10
11## 导入模块
12
13```
14import { usageStatistics } from '@kit.BackgroundTasksKit'
15```
16
17## usageStatistics.isIdleState
18
19isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
20
21查询指定的应用是否为常用应用(GroupType值≤30),使用Callback形式返回。
22
23**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
24
25**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
26
27**参数**:
28
29| 参数名        | 类型                           | 必填   | 说明                                       |
30| ---------- | ---------------------------- | ---- | ---------------------------------------- |
31| bundleName | string                       | 是    | 应用的bundleName。                           |
32| callback   | AsyncCallback&lt;boolean&gt; | 是    | 回调函数。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 |
33
34**错误码**:
35
36以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
37
38| 错误码ID  | 错误信息             |
39| ---- | --------------------- |
40| 201  | Permission denied. |
41| 202  | Not System App. |
42| 401 | Parameter error. |
43| 801 | Capability not supported.|
44| 10000001   | Memory operation failed.         |
45| 10000002   | Parcel operation failed.         |
46| 10000003   | System service operation failed. |
47| 10000004   | IPC failed.        |
48| 10000006   | Failed to get the application information.    |
49
50**示例**:
51```ts
52import { BusinessError } from '@kit.BasicServicesKit';
53
54usageStatistics.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => {
55  if (err) {
56    console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message);
57  } else {
58    console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
59  }
60});
61```
62
63## usageStatistics.isIdleState
64
65isIdleState(bundleName: string): Promise&lt;boolean&gt;
66
67查询指定的应用是否为常用应用(GroupType值≤30),使用Promise异步回调。
68
69**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
70
71**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
72
73**参数**:
74
75| 参数名        | 类型     | 必填   | 说明             |
76| ---------- | ------ | ---- | -------------- |
77| bundleName | string | 是    | 应用的bundleName。 |
78
79**返回值**:
80
81| 类型                     | 说明                                       |
82| ---------------------- | ---------------------------------------- |
83| Promise&lt;boolean&gt; | Promise对象。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 |
84
85**错误码**:
86
87以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
88
89| 错误码ID  | 错误信息             |
90| ---- | --------------------- |
91| 201  | Permission denied. |
92| 202  | Not System App. |
93| 401 | Parameter error. |
94| 801 | Capability not supported.|
95| 10000001   | Memory operation failed.         |
96| 10000002   | Parcel operation failed.         |
97| 10000003   | System service operation failed. |
98| 10000004   | IPC failed.        |
99| 10000006   | Failed to get the application information.     |
100
101**示例**:
102
103```ts
104import { BusinessError } from '@kit.BasicServicesKit';
105
106usageStatistics.isIdleState("com.ohos.camera").then((res: boolean) => {
107  console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
108}).catch((err: BusinessError) => {
109  console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message);
110});
111```
112## usageStatistics.isIdleStateSync<sup>10+<sup>
113
114isIdleStateSync(bundleName: string): boolean
115
116查询指定的应用是否为常用应用(GroupType值≤30),使用同步方式返回。
117
118**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
119
120**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
121
122**参数**:
123
124| 参数名        | 类型                           | 必填   | 说明                                       |
125| ---------- | ---------------------------- | ---- | ---------------------------------------- |
126| bundleName | string                       | 是    | 应用的bundleName。                           |
127
128**返回值**:
129
130| 类型                     | 说明                                       |
131| ---------------------- | ---------------------------------------- |
132| boolean | 若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 |
133
134**错误码**:
135
136以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
137
138| 错误码ID  | 错误信息             |
139| ---- | --------------------- |
140| 201  | Permission denied. |
141| 202  | Not System App. |
142| 401 | Parameter error. |
143| 801 | Capability not supported.|
144| 10000001   | Memory operation failed.         |
145| 10000002   | Parcel operation failed.         |
146| 10000003   | System service operation failed. |
147| 10000004   | IPC failed.        |
148| 10000006   | Failed to get the application information.    |
149
150**示例**:
151```ts
152let isIdleState: boolean = usageStatistics.isIdleStateSync("com.ohos.camera");
153```
154
155## usageStatistics.queryAppGroup
156
157queryAppGroup(): Promise&lt;number&gt;
158
159查询当前应用的优先级分组,使用Promise异步回调。
160
161**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
162
163**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
164
165**返回值**:
166
167| 类型              | 说明                          |
168| --------------- | --------------------------- |
169| Promise&lt;number&gt; | Promise对象。返回当前应用优先级分组结果,值越小,优先级越高。 |
170
171**错误码**:
172
173以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
174
175| 错误码ID  | 错误信息             |
176| ---- | --------------------- |
177| 201  | Permission denied. |
178| 202  | Not System App. |
179| 401 | Parameter error. |
180| 801 | Capability not supported.|
181| 10000001   | Memory operation failed.           |
182| 10000002   | Parcel operation failed.           |
183| 10000003   | System service operation failed.   |
184| 10000004   | IPC failed.          |
185| 10000005   | Application is not installed.      |
186| 10000006   | Failed to get the application information.       |
187| 10100002   | Failed to get the application group information. |
188
189**示例**:
190
191```ts
192import { BusinessError } from '@kit.BasicServicesKit';
193
194usageStatistics.queryAppGroup().then((res: number) => {
195  console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
196}).catch((err: BusinessError) => {
197  console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
198});
199```
200
201## usageStatistics.queryAppGroup
202
203queryAppGroup(callback: AsyncCallback&lt;number&gt;): void
204
205查询当前应用的优先级分组,使用Callback异步回调。
206
207**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
208
209**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
210
211**参数**:
212
213| 参数名      | 类型                    | 必填   | 说明                         |
214| -------- | --------------------- | ---- | -------------------------- |
215| callback | AsyncCallback&lt;number&gt; | 是    | 回调函数,返回当前应用优先级分组结果,值越小,优先级越高。 |
216
217**错误码**:
218
219以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
220
221| 错误码ID  | 错误信息             |
222| ---- | --------------------- |
223| 201  | Permission denied. |
224| 202  | Not System App. |
225| 401 | Parameter error. |
226| 801 | Capability not supported.|
227| 10000001   | Memory operation failed.           |
228| 10000002   | Parcel operation failed.           |
229| 10000003   | System service operation failed.   |
230| 10000004   | IPC failed.          |
231| 10000005   | Application is not installed.      |
232| 10000006   | Failed to get the application information.       |
233| 10100002   | Failed to get the application group information. |
234
235**示例**:
236
237```ts
238import { BusinessError } from '@kit.BasicServicesKit';
239
240usageStatistics.queryAppGroup((err: BusinessError, res: number) => {
241  if(err) {
242    console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
243  } else {
244    console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
245  }
246});
247```
248
249## usageStatistics.queryAppGroupSync<sup>10+<sup>
250
251queryAppGroupSync(): number
252
253查询当前应用的优先级分组,使用同步方式返回。
254
255**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
256
257**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
258
259**返回值**:
260
261| 类型              | 说明                          |
262| --------------- | --------------------------- |
263| number | 返回当前应用优先级分组结果,值越小,优先级越高。 |
264
265**错误码**:
266
267以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
268
269| 错误码ID  | 错误信息             |
270| ---- | --------------------- |
271| 201  | Permission denied. |
272| 202  | Not System App. |
273| 401 | Parameter error. |
274| 801 | Capability not supported.|
275| 10000001   | Memory operation failed.           |
276| 10000002   | Parcel operation failed.           |
277| 10000003   | System service operation failed.   |
278| 10000004   | IPC failed.          |
279| 10000005   | Application is not installed.      |
280| 10000006   | Failed to get the application information.       |
281| 10100002   | Failed to get the application group information. |
282
283**示例**:
284
285```ts
286let priorityGroup: number = usageStatistics.queryAppGroupSync();
287```
288
289## usageStatistics.queryAppGroup
290
291queryAppGroup(bundleName : string): Promise&lt;number&gt;
292
293查询指定bundleName应用的优先级分组,使用Promise异步回调。
294
295**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
296
297**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
298
299**参数**:
300
301| 参数名        | 类型     | 必填   | 说明                                       |
302| ---------- | ------ | ---- | ---------------------------------------- |
303| bundleName | string | 是    | 应用的bundleName。 |
304
305**返回值**:
306
307| 类型              | 说明                          |
308| --------------- | --------------------------- |
309| Promise&lt;number&gt; | Promise对象。返回指定应用的优先级分组结果,值越小,优先级越高。 |
310
311**错误码**:
312
313以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
314
315| 错误码ID  | 错误信息             |
316| ---- | --------------------- |
317| 201  | Permission denied. |
318| 202  | Not System App. |
319| 401 | Parameter error. |
320| 801 | Capability not supported.|
321| 10000001   | Memory operation failed.           |
322| 10000002   | Parcel operation failed.           |
323| 10000003   | System service operation failed.   |
324| 10000004   | IPC failed.          |
325| 10000005   | Application is not installed.      |
326| 10000006   | Failed to get the application information.       |
327| 10100002   | Failed to get the application group information. |
328
329**示例**:
330
331```javascript
332//有bundleName的promise
333import { BusinessError } from '@kit.BasicServicesKit';
334
335let bundleName: string = "com.ohos.camera";
336usageStatistics.queryAppGroup(bundleName).then((res: number) => {
337  console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
338}).catch((err: BusinessError) => {
339  console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
340});
341```
342
343## usageStatistics.queryAppGroup
344
345queryAppGroup(bundleName : string, callback: AsyncCallback&lt;number&gt;): void
346
347查询指定bundleName应用的优先级分组,使用Callback异步回调。
348
349**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
350
351**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
352
353**参数**:
354
355| 参数名        | 类型                    | 必填   | 说明                                       |
356| ---------- | --------------------- | ---- | ---------------------------------------- |
357| bundleName | string                | 是    | 应用的bundleName。 |
358| callback   | AsyncCallback&lt;number&gt; | 是    | 回调函数,返回指定应用的优先级分组结果,值越小,优先级越高。|
359
360**错误码**:
361
362以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
363
364| 错误码ID  | 错误信息             |
365| ---- | --------------------- |
366| 201  | Permission denied. |
367| 202  | Not System App. |
368| 401 | Parameter error. |
369| 801 | Capability not supported.|
370| 10000001   | Memory operation failed.           |
371| 10000002   | Parcel operation failed.           |
372| 10000003   | System service operation failed.   |
373| 10000004   | IPC failed.          |
374| 10000005   | Application is not installed.      |
375| 10000006   | Failed to get the application information.       |
376| 10100002   | Failed to get the application group information. |
377
378**示例**:
379
380```ts
381import { BusinessError } from '@kit.BasicServicesKit';
382
383let bundleName: string = "com.ohos.camera";
384usageStatistics.queryAppGroup(bundleName, (err: BusinessError, res: number) => {
385  if(err) {
386    console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
387  } else {
388    console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
389  }
390});
391```
392
393## usageStatistics.queryAppGroupSync<sup>10+<sup>
394
395queryAppGroupSync(bundleName: string): number
396
397查询指定bundleName应用的优先级分组,使用同步方式返回。
398
399**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
400
401**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
402
403**参数**:
404
405| 参数名        | 类型                           | 必填   | 说明                                       |
406| ---------- | ---------------------------- | ---- | ---------------------------------------- |
407| bundleName | string                       | 是    | 应用的bundleName。                           |
408
409**返回值**:
410
411| 类型              | 说明                          |
412| --------------- | --------------------------- |
413| number | 返回应用的优先级分组结果,值越小,优先级越高。 |
414
415**错误码**:
416
417以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
418
419| 错误码ID  | 错误信息             |
420| ---- | --------------------- |
421| 201  | Permission denied. |
422| 202  | Not System App. |
423| 401 | Parameter error. |
424| 801 | Capability not supported.|
425| 10000001   | Memory operation failed.           |
426| 10000002   | Parcel operation failed.           |
427| 10000003   | System service operation failed.   |
428| 10000004   | IPC failed.          |
429| 10000005   | Application is not installed.      |
430| 10000006   | Failed to get the application information.       |
431| 10100002   | Failed to get the application group information. |
432
433**示例**:
434
435```ts
436let priorityGroup: number = usageStatistics.queryAppGroupSync("com.ohos.camera");
437```
438
439## usageStatistics.setAppGroup
440
441setAppGroup(bundleName: string, newGroup: GroupType): Promise&lt;void&gt;
442
443将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用Promise异步回调。
444
445**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
446
447**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
448
449**参数**:
450
451| 参数名        | 类型        | 必填   | 说明   |
452| ---------- | --------- | ---- | ---- |
453| bundleName | string    | 是    | 应用的bundleName。 |
454| newGroup   | [GroupType](#grouptype) | 是    | 应用分组类型。  |
455
456**返回值**:
457
458| 类型            | 说明                        |
459| ------------- | ------------------------- |
460| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
461
462**错误码**:
463
464以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
465
466| 错误码ID  | 错误信息             |
467| ---- | --------------------- |
468| 201  | Permission denied. |
469| 202  | Not System App. |
470| 401 | Parameter error. |
471| 801 | Capability not supported.|
472| 10000001   | Memory operation failed.              |
473| 10000002   | Parcel operation failed.              |
474| 10000003   | System service operation failed.      |
475| 10000004   | IPC failed.             |
476| 10000006   | Failed to get the application information.          |
477| 10100001   | Repeated operation on the application group. |
478
479**示例**:
480
481```ts
482import { BusinessError } from '@kit.BasicServicesKit';
483
484let bundleName: string = "com.example.deviceUsageStatistics";
485let newGroup = usageStatistics.GroupType.DAILY_GROUP;
486
487usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
488  console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
489}).catch((err: BusinessError) => {
490  console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
491});
492```
493
494## usageStatistics.setAppGroup
495
496setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback&lt;void&gt;): void
497
498将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用CallBack异步回调。
499
500**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
501
502**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
503
504**参数**:
505
506| 参数名        | 类型                  | 必填   | 说明                        |
507| ---------- | ------------------- | ---- | ------------------------- |
508| bundleName | string              | 是    | 应用的bundleName。                    |
509| newGroup   | [GroupType](#grouptype)           | 是    | 应用分组类型。                      |
510| callback   | AsyncCallback&lt;void&gt; | 是    | 回调函数,返回是否设置成功。 |
511
512**错误码**:
513
514以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
515
516| 错误码ID  | 错误信息             |
517| ---- | --------------------- |
518| 201  | Permission denied. |
519| 202  | Not System App. |
520| 401 | Parameter error. |
521| 801 | Capability not supported.|
522| 10000001   | Memory operation failed.              |
523| 10000002   | Parcel operation failed.              |
524| 10000003   | System service operation failed.      |
525| 10000004   | IPC failed.             |
526| 10000006   | Failed to get the application information.          |
527| 10100001   | Repeated operation on the application group. |
528
529**示例**:
530
531```ts
532import { BusinessError } from '@kit.BasicServicesKit';
533
534let bundleName: string = "com.example.deviceUsageStatistics";
535let newGroup = usageStatistics.GroupType.DAILY_GROUP;
536
537usageStatistics.setAppGroup(bundleName, newGroup, (err: BusinessError) => {
538  if(err) {
539    console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
540  } else {
541    console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
542  }
543});
544```
545
546## usageStatistics.queryBundleStatsInfos
547
548queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback&lt;BundleStatsMap&gt;): void
549
550通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Callback异步回调。
551
552**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
553
554**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
555
556**参数**:
557
558| 参数名      | 类型                                       | 必填   | 说明                                      |
559| -------- | ---------------------------------------- | ---- | --------------------------------------- |
560| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                   |
561| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
562| callback | AsyncCallback&lt;[BundleStatsMap](#bundlestatsmap)&gt; | 是    | 回调函数,返回指定时间段内应用使用时长的具体信息。 |
563
564**错误码**:
565
566以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
567
568| 错误码ID  | 错误信息             |
569| ---- | --------------------- |
570| 201  | Permission denied. |
571| 202  | Not System App. |
572| 401 | Parameter error. |
573| 801 | Capability not supported.|
574| 10000001   | Memory operation failed.           |
575| 10000002   | Parcel operation failed.           |
576| 10000003   | System service operation failed.   |
577| 10000004   | IPC failed.          |
578| 10000006   | Failed to get the application information.       |
579| 10000007   | Failed to get the system time.  |
580
581**示例**:
582
583```ts
584import { BusinessError } from '@kit.BasicServicesKit';
585
586usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err: BusinessError, res:usageStatistics.BundleStatsMap) => {
587  if (err) {
588    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
589  } else {
590    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.');
591    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res));
592  }
593});
594```
595
596## usageStatistics.queryBundleStatsInfos
597
598queryBundleStatsInfos(begin: number, end: number): Promise&lt;BundleStatsMap&gt;
599
600通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Promise异步回调。
601
602**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
603
604**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
605
606**参数**:
607
608| 参数名   | 类型     | 必填   | 说明    |
609| ----- | ------ | ---- | ----- |
610| begin | number | 是    | 起始时间,以毫秒为单位。 |
611| end   | number | 是    | 结束时间,以毫秒为单位。 |
612
613**返回值**:
614
615| 类型                                       | 说明                                     |
616| ---------------------------------------- | -------------------------------------- |
617| Promise&lt;[BundleStatsMap](#bundlestatsmap)&gt; | Promise对象。返回指定时间段内应用使用时长的具体信息。 |
618
619**错误码**:
620
621以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
622
623| 错误码ID  | 错误信息             |
624| ---- | --------------------- |
625| 201  | Permission denied. |
626| 202  | Not System App. |
627| 401 | Parameter error. |
628| 801 | Capability not supported.|
629| 10000001   | Memory operation failed.           |
630| 10000002   | Parcel operation failed.           |
631| 10000003   | System service operation failed.   |
632| 10000004   | IPC failed.          |
633| 10000006   | Failed to get the application information.       |
634| 10000007   | Failed to get the system time.  |
635
636**示例**:
637
638```ts
639import { BusinessError } from '@kit.BasicServicesKit';
640
641usageStatistics.queryBundleStatsInfos(0, 20000000000000).then((res:usageStatistics.BundleStatsMap) => {
642  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.');
643  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res));
644}).catch((err: BusinessError) => {
645  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
646});
647```
648
649## usageStatistics.queryBundleStatsInfoByInterval
650
651queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleStatsInfo&gt;&gt;): void
652
653通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Callback异步回调。
654
655**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
656
657**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
658
659**参数**:
660
661| 参数名        | 类型                                       | 必填   | 说明                                       |
662| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
663| byInterval | [IntervalType](#intervaltype)            | 是    | 查询类型。                                    |
664| begin      | number                                   | 是    | 起始时间,以毫秒为单位。                                    |
665| end        | number                                   | 是    | 结束时间,以毫秒为单位。                                    |
666| callback   | AsyncCallback&lt;Array&lt;[BundleStatsInfo](#bundlestatsinfo)&gt;&gt; | 是    | 回调函数,返回指定时间段间隔内,应用使用时长的统计信息。 |
667
668**错误码**:
669
670以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
671
672| 错误码ID  | 错误信息             |
673| ---- | --------------------- |
674| 201  | Permission denied. |
675| 202  | Not System App. |
676| 401 | Parameter error. |
677| 801 | Capability not supported.|
678| 10000001   | Memory operation failed.           |
679| 10000002   | Parcel operation failed.           |
680| 10000003   | System service operation failed.   |
681| 10000004   | IPC failed.          |
682| 10000006   | Failed to get the application information.       |
683| 10000007   | Failed to get the system time.  |
684
685**示例**:
686
687```ts
688import { BusinessError } from '@kit.BasicServicesKit';
689
690usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleStatsInfo>) => {
691  if (err) {
692    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
693  } else {
694    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.');
695    for (let i = 0; i < res.length; i++) {
696      console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1));
697      console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i]));
698    }
699  }
700});
701```
702
703## usageStatistics.queryBundleStatsInfoByInterval
704
705queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise&lt;Array&lt;BundleStatsInfo&gt;&gt;
706
707通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Promise异步回调。
708
709**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
710
711**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
712
713**参数**:
714
715| 参数名        | 类型                            | 必填   | 说明    |
716| ---------- | ----------------------------- | ---- | ----- |
717| byInterval | [IntervalType](#intervaltype) | 是    | 查询类型。 |
718| begin      | number                        | 是    | 起始时间,以毫秒为单位。 |
719| end        | number                        | 是    | 结束时间,以毫秒为单位。 |
720
721**返回值**:
722
723| 类型                                       | 说明                                       |
724| ---------------------------------------- | ---------------------------------------- |
725| Promise&lt;Array&lt;[BundleStatsInfo](#bundlestatsinfo)&gt;&gt; | Promise对象。返回指定时间段间隔内,应用使用时长的统计信息。 |
726
727**错误码**:
728
729以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
730
731| 错误码ID  | 错误信息             |
732| ---- | --------------------- |
733| 201  | Permission denied. |
734| 202  | Not System App. |
735| 401 | Parameter error. |
736| 801 | Capability not supported.|
737| 10000001   | Memory operation failed.           |
738| 10000002   | Parcel operation failed.           |
739| 10000003   | System service operation failed.   |
740| 10000004   | IPC failed.          |
741| 10000006   | Failed to get the application information.       |
742| 10000007   | Failed to get the system time.  |
743
744**示例**:
745
746```ts
747import { BusinessError } from '@kit.BasicServicesKit';
748
749usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then((res: Array<usageStatistics.BundleStatsInfo>) => {
750  console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.');
751  for (let i = 0; i < res.length; i++) {
752    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
753    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
754  }
755}).catch((err: BusinessError) => {
756  console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
757});
758```
759
760## usageStatistics.queryBundleEvents
761
762queryBundleEvents(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleEvents&gt;&gt;): void
763
764通过指定起始和结束时间,查询所有应用的事件集合,使用Callback异步回调。
765
766**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
767
768**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
769
770**参数**:
771
772| 参数名      | 类型                                       | 必填   | 说明                                      |
773| -------- | ---------------------------------------- | ---- | --------------------------------------- |
774| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                   |
775| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
776| callback | AsyncCallback&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 是    | 回调函数,返回起始和结束时间段内,所有应用的事件集合。 |
777
778**错误码**:
779
780以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
781
782| 错误码ID  | 错误信息             |
783| ---- | --------------------- |
784| 201  | Permission denied. |
785| 202  | Not System App. |
786| 401 | Parameter error. |
787| 801 | Capability not supported.|
788| 10000001   | Memory operation failed.           |
789| 10000002   | Parcel operation failed.           |
790| 10000003   | System service operation failed.   |
791| 10000004   | IPC failed.          |
792| 10000006   | Failed to get the application information.       |
793| 10000007   | Failed to get the system time.  |
794
795**示例**:
796
797```ts
798import { BusinessError } from '@kit.BasicServicesKit';
799
800usageStatistics.queryBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => {
801  if (err) {
802    console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
803  } else {
804    console.log('BUNDLE_ACTIVE queryBundleEvents callback success.');
805    for (let i = 0; i < res.length; i++) {
806      console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1));
807      console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i]));
808    }
809  }
810});
811```
812
813## usageStatistics.queryBundleEvents
814
815queryBundleEvents(begin: number, end: number): Promise&lt;Array&lt;BundleEvents&gt;&gt;
816
817通过指定起始和结束时间,查询所有应用的事件集合,使用Promise异步回调。
818
819**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
820
821**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
822
823**参数**:
824
825| 参数名   | 类型     | 必填   | 说明    |
826| ----- | ------ | ---- | ----- |
827| begin | number | 是    | 起始时间,以毫秒为单位。 |
828| end   | number | 是    | 结束时间,以毫秒为单位。 |
829
830**返回值**:
831
832| 类型                                       | 说明                                     |
833| ---------------------------------------- | -------------------------------------- |
834| Promise&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | Promise对象。返回起始和结束时间段内,所有应用的事件集合。 |
835
836**错误码**:
837
838以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
839
840| 错误码ID  | 错误信息             |
841| ---- | --------------------- |
842| 201  | Permission denied. |
843| 202  | Not System App. |
844| 401 | Parameter error. |
845| 801 | Capability not supported.|
846| 10000001   | Memory operation failed.           |
847| 10000002   | Parcel operation failed.           |
848| 10000003   | System service operation failed.   |
849| 10000004   | IPC failed.          |
850| 10000006   | Failed to get the application information.       |
851| 10000007   | Failed to get the system time.  |
852
853**示例**:
854
855```ts
856import { BusinessError } from '@kit.BasicServicesKit';
857
858usageStatistics.queryBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => {
859  console.log('BUNDLE_ACTIVE queryBundleEvents promise success.');
860  for (let i = 0; i < res.length; i++) {
861    console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
862    console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
863  }
864}).catch((err: BusinessError) => {
865  console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
866});
867```
868
869## usageStatistics.queryCurrentBundleEvents
870
871queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleEvents&gt;&gt;): void
872
873通过指定起始和结束时间,查询当前应用的事件集合,使用Callback异步回调。
874
875**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
876
877**参数**:
878
879| 参数名      | 类型                                       | 必填   | 说明                                      |
880| -------- | ---------------------------------------- | ---- | --------------------------------------- |
881| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                   |
882| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
883| callback | AsyncCallback&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 是    | 回调函数,返回指定起始和结束时间段内,当前应用的事件集合。 |
884
885**错误码**:
886
887以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
888
889| 错误码ID  | 错误信息             |
890| ---- | --------------------- |
891| 202  | Not System App. |
892| 401 | Parameter error. |
893| 801 | Capability not supported.|
894| 10000001   | Memory operation failed.           |
895| 10000002   | Parcel operation failed.           |
896| 10000003   | System service operation failed.   |
897| 10000004   | IPC failed.          |
898| 10000006   | Failed to get the application information.       |
899| 10000007   | Failed to get the system time.  |
900
901**示例**:
902
903```ts
904import { BusinessError } from '@kit.BasicServicesKit';
905
906usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => {
907  if (err) {
908    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
909  } else {
910    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.');
911    for (let i = 0; i < res.length; i++) {
912      console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1));
913      console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i]));
914    }
915  }
916});
917```
918
919## usageStatistics.queryCurrentBundleEvents
920
921queryCurrentBundleEvents(begin: number, end: number): Promise&lt;Array&lt;BundleEvents&gt;&gt;
922
923通过指定起始和结束时间段内,查询当前应用的事件集合,使用Promise异步回调。
924
925**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
926
927**参数**:
928
929| 参数名   | 类型     | 必填   | 说明    |
930| ----- | ------ | ---- | ----- |
931| begin | number | 是    | 起始时间,以毫秒为单位。 |
932| end   | number | 是    | 结束时间,以毫秒为单位。 |
933
934**返回值**:
935
936| 类型                                       | 说明                                     |
937| ---------------------------------------- | -------------------------------------- |
938| Promise&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | Promise对象。返回指定起始和结束时间段内,当前应用的事件集合。 |
939
940**错误码**:
941
942以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
943
944| 错误码ID  | 错误信息             |
945| ---- | --------------------- |
946| 202  | Not System App. |
947| 401 | Parameter error. |
948| 801 | Capability not supported.|
949| 10000001   | Memory operation failed.           |
950| 10000002   | Parcel operation failed.           |
951| 10000003   | System service operation failed.   |
952| 10000004   | IPC failed.          |
953| 10000006   | Failed to get the application information.      |
954| 10000007   | Failed to get the system time.  |
955
956**示例**:
957
958```ts
959import { BusinessError } from '@kit.BasicServicesKit';
960
961usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => {
962  console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.');
963  for (let i = 0; i < res.length; i++) {
964    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
965    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
966  }
967}).catch((err: BusinessError) => {
968  console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
969});
970```
971
972## usageStatistics.queryDeviceEventStats
973
974queryDeviceEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;
975
976通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Promise异步回调。
977
978**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
979
980**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
981
982**参数**:
983
984| 参数名   | 类型     | 必填   | 说明    |
985| ----- | ------ | ---- | ----- |
986| begin | number | 是    | 起始时间,以毫秒为单位。 |
987| end   | number | 是    | 结束时间,以毫秒为单位。 |
988
989**返回值**:
990
991| 类型                                       | 说明                                       |
992| ---------------------------------------- | ---------------------------------------- |
993| Promise&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | Promise对象。返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 |
994
995**错误码**:
996
997以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
998
999| 错误码ID  | 错误信息             |
1000| ---- | --------------------- |
1001| 201  | Permission denied. |
1002| 202  | Not System App. |
1003| 401 | Parameter error. |
1004| 801 | Capability not supported.|
1005| 10000001   | Memory operation failed.              |
1006| 10000002   | Parcel operation failed.              |
1007| 10000003   | System service operation failed.      |
1008| 10000004   | IPC failed.             |
1009| 10000006   | Failed to get the application information.          |
1010| 10000007   | Failed to get the system time.     |
1011
1012**示例**:
1013
1014```ts
1015import { BusinessError } from '@kit.BasicServicesKit';
1016
1017usageStatistics.queryDeviceEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => {
1018  console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.');
1019  console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res));
1020}).catch((err: BusinessError) => {
1021  console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1022});
1023```
1024
1025## usageStatistics.queryDeviceEventStats
1026
1027queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void
1028
1029通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Callback异步回调。
1030
1031**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1032
1033**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1034
1035**参数**:
1036
1037| 参数名      | 类型                                       | 必填   | 说明                                       |
1038| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1039| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                    |
1040| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                    |
1041| callback | AsyncCallback&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 是    | 回调函数,返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 |
1042
1043**错误码**:
1044
1045以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1046
1047| 错误码ID  | 错误信息             |
1048| ---- | --------------------- |
1049| 201  | Permission denied. |
1050| 202  | Not System App. |
1051| 401 | Parameter error. |
1052| 801 | Capability not supported.|
1053| 10000001   | Memory operation failed.              |
1054| 10000002   | Parcel operation failed.              |
1055| 10000003   | System service operation failed.      |
1056| 10000004   | IPC failed.             |
1057| 10000006   | Failed to get the application information.           |
1058| 10000007   | Failed to get the system time.     |
1059
1060**示例**:
1061
1062```ts
1063import { BusinessError } from '@kit.BasicServicesKit';
1064
1065usageStatistics.queryDeviceEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => {
1066  if(err) {
1067    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1068  } else {
1069    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
1070    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
1071  }
1072});
1073```
1074
1075## usageStatistics.queryNotificationEventStats
1076
1077queryNotificationEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;
1078
1079通过指定起始和结束时间,查询所有应用的通知次数,使用Promise异步回调。
1080
1081**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1082
1083**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1084
1085**参数**:
1086
1087| 参数名   | 类型     | 必填   | 说明    |
1088| ----- | ------ | ---- | ----- |
1089| begin | number | 是    | 起始时间,以毫秒为单位。 |
1090| end   | number | 是    | 结束时间,以毫秒为单位。 |
1091
1092**返回值**:
1093
1094| 类型                                       | 说明                                       |
1095| ---------------------------------------- | ---------------------------------------- |
1096| Promise&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | Promise对象。返回指定起始和结束时间段内,所有应用的通知次数。 |
1097
1098**错误码**:
1099
1100以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1101
1102| 错误码ID  | 错误信息             |
1103| ---- | --------------------- |
1104| 201  | Permission denied. |
1105| 202  | Not System App. |
1106| 401 | Parameter error. |
1107| 801 | Capability not supported.|
1108| 10000001   | Memory operation failed.              |
1109| 10000002   | Parcel operation failed.              |
1110| 10000003   | System service operation failed.      |
1111| 10000004   | IPC failed.             |
1112| 10000006   | Failed to get the application information.          |
1113| 10000007   | Failed to get the system time.     |
1114
1115**示例**:
1116
1117```ts
1118import { BusinessError } from '@kit.BasicServicesKit';
1119
1120usageStatistics.queryNotificationEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => {
1121  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.');
1122  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res));
1123}).catch((err: BusinessError) => {
1124  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1125});
1126```
1127
1128## usageStatistics.queryNotificationEventStats
1129
1130queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void
1131
1132通过指定起始和结束时间,查询所有应用的通知次数,使用Callback异步回调。
1133
1134**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1135
1136**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1137
1138**参数**:
1139
1140| 参数名      | 类型                                       | 必填   | 说明                                       |
1141| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1142| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                    |
1143| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                    |
1144| callback | AsyncCallback&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 是    | 回调函数,返回指定起始和结束时间段内,所有应用的通知次数。 |
1145
1146**错误码**:
1147
1148以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1149
1150| 错误码ID  | 错误信息             |
1151| ---- | --------------------- |
1152| 201  | Permission denied. |
1153| 202  | Not System App. |
1154| 401 | Parameter error. |
1155| 801 | Capability not supported.|
1156| 10000001   | Memory operation failed.              |
1157| 10000002   | Parcel operation failed.              |
1158| 10000003   | System service operation failed.      |
1159| 10000004   | IPC failed.             |
1160| 10000006   | Failed to get the application information.          |
1161| 10000007   | Failed to get the system time.     |
1162
1163**示例**:
1164
1165```ts
1166import { BusinessError } from '@kit.BasicServicesKit';
1167
1168usageStatistics.queryNotificationEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => {
1169  if(err) {
1170    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1171  } else {
1172    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
1173    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
1174  }
1175});
1176```
1177
1178## usageStatistics.queryModuleUsageRecords
1179
1180queryModuleUsageRecords(): Promise&lt;Array&lt;HapModuleInfo&gt;&gt;
1181
1182查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。
1183
1184使用Promise形式返回不超过1000条FA使用记录,FA使用记录由近及远排序。
1185
1186**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1187
1188**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1189
1190**返回值**:
1191
1192| 类型                                       | 说明                                 |
1193| ---------------------------------------- | ---------------------------------- |
1194| Promise&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | Promise对象。返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 |
1195
1196**错误码**:
1197
1198以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1199
1200| 错误码ID  | 错误信息             |
1201| ---- | --------------------- |
1202| 201  | Permission denied. |
1203| 202  | Not System App. |
1204| 401 | Parameter error. |
1205| 801 | Capability not supported.|
1206| 10000001   | Memory operation failed.           |
1207| 10000002   | Parcel operation failed.           |
1208| 10000003   | System service operation failed.   |
1209| 10000004   | IPC failed.          |
1210| 10000006   | Failed to get the application information.       |
1211| 10000007   | Failed to get the system time.  |
1212
1213**示例**:
1214
1215```ts
1216// 无maxNum参数调用方式
1217import { BusinessError } from '@kit.BasicServicesKit';
1218
1219usageStatistics.queryModuleUsageRecords().then((res: Array<usageStatistics.HapModuleInfo>) => {
1220  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
1221  for (let i = 0; i < res.length; i++) {
1222    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
1223    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
1224  }
1225}).catch((err: BusinessError) => {
1226  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
1227});
1228```
1229
1230## usageStatistics.queryModuleUsageRecords
1231
1232queryModuleUsageRecords(callback: AsyncCallback&lt;Array&lt;HapModuleInfo&gt;&gt;): void
1233
1234查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用CallBack异步回调。
1235
1236**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1237
1238**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1239
1240**参数**:
1241
1242| 参数名      | 类型                                       | 必填   | 说明                                  |
1243| -------- | ---------------------------------------- | ---- | ----------------------------------- |
1244| callback | AsyncCallback&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 是    | 回调函数,返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 |
1245
1246**错误码**:
1247
1248以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。
1249
1250| 错误码ID        | 错误信息                       |
1251| ---------- | ----------------------------       |
1252| 10000001   | Memory operation failed.           |
1253| 10000002   | Parcel operation failed.           |
1254| 10000003   | System service operation failed.   |
1255| 10000004   | IPC failed.          |
1256| 10000006   | Failed to get the application information.       |
1257| 10000007   | Failed to get the system time.  |
1258
1259**示例**:
1260
1261```ts
1262import { BusinessError } from '@kit.BasicServicesKit';
1263
1264usageStatistics.queryModuleUsageRecords((err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => {
1265  if(err) {
1266    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
1267  } else {
1268    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
1269    for (let i = 0; i < res.length; i++) {
1270      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
1271      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
1272    }
1273  }
1274});
1275```
1276
1277## usageStatistics.queryModuleUsageRecords
1278
1279queryModuleUsageRecords(maxNum: number): Promise&lt;Array&lt;HapModuleInfo&gt;&gt;
1280
1281根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。
1282
1283**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1284
1285**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1286
1287**参数**:
1288
1289| 参数名    | 类型     | 必填   | 说明                                 |
1290| ------ | ------ | ---- | ---------------------------------- |
1291| maxNum | number | 是    | 使用记录的条数,取值范围为[1,1000]。 |
1292
1293**返回值**:
1294
1295| 类型                                       | 说明                                 |
1296| ---------------------------------------- | ---------------------------------- |
1297| Promise&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | Promise对象,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 |
1298
1299**错误码**:
1300
1301以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1302
1303| 错误码ID  | 错误信息             |
1304| ---- | --------------------- |
1305| 201  | Permission denied. |
1306| 202  | Not System App. |
1307| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
1308| 801 | Capability not supported.|
1309| 10000001   | Memory operation failed.           |
1310| 10000002   | Parcel operation failed.           |
1311| 10000003   | System service operation failed.   |
1312| 10000004   | IPC failed.          |
1313| 10000006   | Failed to get the application information.       |
1314| 10000007   | Failed to get the system time.  |
1315
1316**示例**:
1317
1318```ts
1319import { BusinessError } from '@kit.BasicServicesKit';
1320
1321usageStatistics.queryModuleUsageRecords(1000).then((res: Array<usageStatistics.HapModuleInfo>) => {
1322  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
1323  for (let i = 0; i < res.length; i++) {
1324    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
1325    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
1326  }
1327}).catch((err: BusinessError) => {
1328  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
1329});
1330```
1331
1332## usageStatistics.queryModuleUsageRecords
1333
1334queryModuleUsageRecords(maxNum: number, callback: AsyncCallback&lt;Array&lt;HapModuleInfo&gt;&gt;): void
1335
1336根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Callback异步回调。
1337
1338**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1339
1340**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1341
1342**参数**:
1343
1344| 参数名      | 类型                                       | 必填   | 说明                                  |
1345| -------- | ---------------------------------------- | ---- | ----------------------------------- |
1346| maxNum   | number                                   | 是    |  使用记录的条数,取值范围为[1,1000]。 |
1347| callback | AsyncCallback&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 是    | 回调方法,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 |
1348
1349**错误码**:
1350
1351以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1352
1353| 错误码ID  | 错误信息             |
1354| ---- | --------------------- |
1355| 201  | Permission denied. |
1356| 202  | Not System App. |
1357| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
1358| 801 | Capability not supported.|
1359| 10000001   | Memory operation failed.           |
1360| 10000002   | Parcel operation failed.           |
1361| 10000003   | System service operation failed.   |
1362| 10000004   | IPC failed.          |
1363| 10000006   | Failed to get the application information.       |
1364| 10000007   | Failed to get the system time.  |
1365
1366**示例**:
1367
1368```ts
1369import { BusinessError } from '@kit.BasicServicesKit';
1370
1371usageStatistics.queryModuleUsageRecords(1000, (err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => {
1372  if(err) {
1373    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
1374  } else {
1375    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
1376    for (let i = 0; i < res.length; i++) {
1377      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
1378      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
1379    }
1380  }
1381});
1382```
1383
1384## usageStatistics.registerAppGroupCallBack
1385
1386registerAppGroupCallBack(groupCallback: Callback&lt;AppGroupCallbackInfo&gt;): Promise&lt;void&gt;
1387
1388注册应用分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Promise异步回调。
1389
1390**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1391
1392**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1393
1394**参数**:
1395
1396| 参数名   | 类型                                                         | 必填 | 说明                                       |
1397| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
1398| groupCallback | Callback&lt;[AppGroupCallbackInfo](#appgroupcallbackinfo)&gt; | 是   | 返回的应用分组变化信息。 |
1399
1400**返回值**:
1401
1402| 类型            | 说明                      |
1403| ------------- | ----------------------- |
1404| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1405
1406**错误码**:
1407
1408以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1409
1410| 错误码ID  | 错误信息             |
1411| ---- | --------------------- |
1412| 201  | Permission denied. |
1413| 202  | Not System App. |
1414| 401 | Parameter error. |
1415| 801 | Capability not supported.|
1416| 10000001   | Memory operation failed.              |
1417| 10000002   | Parcel operation failed.              |
1418| 10000003   | System service operation failed.      |
1419| 10000004   | IPC failed.             |
1420| 10100001   | Repeated operation on the application group. |
1421
1422
1423**示例**:
1424
1425```ts
1426import { BusinessError } from '@kit.BasicServicesKit';
1427
1428function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) {
1429  console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.');
1430  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
1431  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
1432  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
1433  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
1434  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
1435};
1436usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => {
1437  console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.');
1438}).catch((err: BusinessError) => {
1439  console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1440});
1441```
1442
1443## usageStatistics.registerAppGroupCallBack
1444
1445registerAppGroupCallBack(groupCallback: Callback&lt;AppGroupCallbackInfo&gt;, callback: AsyncCallback&lt;void&gt;): void
1446
1447应用注册分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Callback异步回调。
1448
1449**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1450
1451**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1452
1453**参数**:
1454
1455| 参数名   | 类型                                                         | 必填 | 说明                                         |
1456| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
1457| groupCallback | Callback&lt;[AppGroupCallbackInfo](#appgroupcallbackinfo)&gt; | 是   | 返回的应用分组变化信息。   |
1458| callback | AsyncCallback&lt;void&gt;                                    | 是   | 回调函数,返回注册监听是否成功。 |
1459
1460**错误码**:
1461
1462以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。和[通用错误码](../errorcode-universal.md)。
1463
1464| 错误码ID  | 错误信息             |
1465| ---- | --------------------- |
1466| 201  | Permission denied. |
1467| 202  | Not System App. |
1468| 401 | Parameter error. |
1469| 801 | Capability not supported.|
1470| 10000001   | Memory operation failed.              |
1471| 10000002   | Parcel operation failed.              |
1472| 10000003   | System service operation failed.      |
1473| 10000004   | IPC failed.             |
1474| 10100001   | Repeated operation on the application group. |
1475
1476
1477**示例**:
1478
1479```ts
1480import { BusinessError } from '@kit.BasicServicesKit';
1481
1482function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) {
1483  console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
1484  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
1485  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
1486  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
1487  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
1488  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
1489};
1490usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err: BusinessError) => {
1491  if(err) {
1492    console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
1493  } else {
1494    console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.');
1495  }
1496});
1497```
1498
1499## usageStatistics.unregisterAppGroupCallBack
1500
1501unregisterAppGroupCallBack(): Promise&lt;void&gt;
1502
1503应用解除分组变化监听。使用Promise异步回调。
1504
1505**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1506
1507**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1508
1509**返回值**:
1510
1511| 类型            | 说明                       |
1512| ------------- | ------------------------ |
1513| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
1514
1515**错误码**:
1516
1517以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1518
1519| 错误码ID  | 错误信息             |
1520| ---- | --------------------- |
1521| 201  | Permission denied. |
1522| 202  | Not System App. |
1523| 401 | Parameter error. |
1524| 801 | Capability not supported.|
1525| 10000001   | Memory operation failed.              |
1526| 10000002   | Parcel operation failed.              |
1527| 10000003   | System service operation failed.      |
1528| 10000004   | IPC failed.             |
1529| 10100001   | Repeated operation on the application group. |
1530
1531**示例**:
1532
1533```ts
1534import { BusinessError } from '@kit.BasicServicesKit';
1535
1536usageStatistics.unregisterAppGroupCallBack().then( () => {
1537  console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.');
1538}).catch((err: BusinessError) => {
1539  console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1540});
1541```
1542
1543## usageStatistics.unregisterAppGroupCallBack
1544
1545unregisterAppGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
1546
1547应用解除分组变化监听。使用callback异步回调。
1548
1549**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
1550
1551**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1552
1553**参数**:
1554
1555| 参数名      | 类型                  | 必填   | 说明             |
1556| -------- | ------------------- | ---- | -------------- |
1557| callback | AsyncCallback&lt;void&gt; | 是    | 回调函数,返回是否成功解除监听。 |
1558
1559**错误码**:
1560
1561以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。
1562
1563| 错误码ID  | 错误信息             |
1564| ---- | --------------------- |
1565| 201  | Permission denied. |
1566| 202  | Not System App. |
1567| 401 | Parameter error. |
1568| 801 | Capability not supported.|
1569| 10000001   | Memory operation failed.              |
1570| 10000002   | Parcel operation failed.              |
1571| 10000003   | System service operation failed.      |
1572| 10000004   | IPC failed.             |
1573| 10100001   | Repeated operation on the application group. |
1574
1575**示例**:
1576
1577```ts
1578import { BusinessError } from '@kit.BasicServicesKit';
1579
1580usageStatistics.unregisterAppGroupCallBack((err: BusinessError) => {
1581  if(err) {
1582    console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
1583  } else {
1584    console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.');
1585  }
1586});
1587```
1588
1589## HapModuleInfo
1590
1591FA模型的使用信息属性集合。
1592
1593**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1594
1595| 名称                  | 类型                                       | 必填   | 说明                            |
1596| -------------------- | ---------------------------------------- | ---- | ----------------------------- |
1597| deviceId             | string                                   | 否    | 设备Id。                 |
1598| bundleName           | string                                   | 是    | 应用名称。             |
1599| moduleName           | string                                   | 是    | FA所属module名。                  |
1600| abilityName          | string                                   | 否    | FA的MainAbility名。              |
1601| appLabelId           | number                                   | 否    | FA的应用labelId。                 |
1602| labelId              | number                                   | 否    | FA所属module的labelId。           |
1603| descriptionId        | number                                   | 否    | FA所属的应用descriptionId。         |
1604| abilityLableId       | number                                   | 否    | FA的MainAbility labelId。       |
1605| abilityDescriptionId | number                                   | 否    | FA的MainAbility descriptionId。 |
1606| abilityIconId        | number                                   | 否    | FA的MainAbility iconId。        |
1607| launchedCount        | number                                   | 是    | FA的启动次数。                      |
1608| lastModuleUsedTime   | number                                   | 是    | FA的上一次使用时间。                   |
1609| formRecords          | Array&lt;[HapFormInfo](#hapforminfo)&gt; | 是    | FA中卡片的使用记录。                   |
1610
1611## HapFormInfo
1612
1613FA卡片的使用信息属性集合。
1614
1615**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1616
1617| 名称              | 类型     | 必填   | 说明          |
1618| ---------------- | ------ | ---- | ----------- |
1619| formName         | string | 是    | 卡片名称。       |
1620| formDimension    | number | 是    | 卡片尺寸。       |
1621| formId           | number | 是    | 卡片Id。       |
1622| formLastUsedTime | number | 是    | 卡片的上一次点击时间。 |
1623| count            | number | 是    | 卡片的点击次数。    |
1624
1625## AppGroupCallbackInfo
1626
1627应用分组变化回调返回的属性集合
1628
1629**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1630
1631| 名称           | 类型   | 必填 | 说明             |
1632| ---------------- | ------ | ---- | ---------------- |
1633| appOldGroup | number | 是   | 变化前的应用分组。 |
1634| appNewGroup | number | 是   | 变化后的应用分组。|
1635| userId           | number | 是   | 用户id。           |
1636| changeReason     | number | 是   | 分组变化原因。<br>- 256:使用记录初创建时,默认匹配的原因。<br>- 512:计算优先级分组时异常。<br>- 768:使用时长变化。  <br>- 1024:有其他应用为当前应用强制设置优先级分组。|
1637| bundleName       | string | 是   | 应用名称。         |
1638
1639## BundleStatsInfo
1640
1641应用使用时长的具体信息。
1642
1643**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1644
1645| 名称                      | 类型     | 必填   | 说明                                       |
1646| ------------------------ | ------ | ---- | ---------------------------------------- |
1647| bundleName               | string | 否    | 应用包名。                                    |
1648| abilityPrevAccessTime    | number | 否    | 应用最后一次使用的时间。                             |
1649| abilityInFgTotalTime     | number | 否    | 应用在前台使用的总时间。                             |
1650| id                       | number | 是    | 用户id。 |
1651| abilityPrevSeenTime      | number | 否    | 应用最后一次在前台可见的时间。 |
1652| abilitySeenTotalTime     | number | 否    | 应用在前台可见的总时间。 |
1653| fgAbilityAccessTotalTime | number | 否    | 应用访问前台的总时间。 |
1654| fgAbilityPrevAccessTime  | number | 否    | 应用最后一次访问前台的时间。|
1655| infosBeginTime           | number | 否    | BundleActiveInfo对象中第一条应用使用统计的记录时间。 |
1656| infosEndTime             | number | 否    | BundleActiveInfo对象中最后一条应用使用统计的记录时间。 |
1657
1658## BundleEvents
1659
1660应用事件的具体信息。
1661
1662**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1663
1664| 名称                   | 类型     | 必填   | 说明                                       |
1665| --------------------- | ------ | ---- | ---------------------------------------- |
1666| bundleName            | string | 否    | 应用包名。                                    |
1667| eventId             | number | 否    | 应用事件类型。                                  |
1668| eventOccurredTime     | number | 否    | 应用事件发生的时间戳。                              |
1669| appGroup | number | 否    | 应用程序的使用优先级组。|
1670| indexOfLink           | string | 否    | 快捷方式id。|
1671| nameOfClass           | string | 否    | 类名。|
1672
1673## BundleStatsMap
1674
1675应用使用时长的具体信息。
1676
1677**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
1678
1679|名称                           | 描述                                       |
1680| ------------------------------ | ---------------------------------------- |
1681| Record<string, [BundleStatsInfo](#bundlestatsinfo)> | 不同应用的使用时长统计信息 |
1682
1683## DeviceEventStats
1684
1685提供通知、系统事件的统计信息。
1686
1687**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1688
1689| 名称     | 类型     | 必填   | 说明                |
1690| ------- | ------ | ---- | ----------------- |
1691| name    | string | 是    | 通知应用包名或者系统事件名。    |
1692| eventId | number | 是    | 通知、系统事件类型。        |
1693| count   | number | 是    | 应用通知次数或者系统事件触发次数。 |
1694
1695## IntervalType
1696
1697应用使用时长的查询类型。
1698
1699**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
1700
1701| 名称           | 值  | 说明                                       |
1702| ------------ | ---- | ---------------------------------------- |
1703| BY_OPTIMIZED | 0    | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 |
1704| BY_DAILY     | 1    | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。              |
1705| BY_WEEKLY    | 2    | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。              |
1706| BY_MONTHLY   | 3    | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。              |
1707| BY_ANNUALLY  | 4    | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。              |
1708
1709## GroupType
1710
1711应用分组的设置类型。
1712
1713**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1714
1715| 名称                 | 值  | 说明                |
1716| ------------------ | ---- | ----------------- |
1717| ALIVE_GROUP | 10   | 活跃分组。              |
1718| DAILY_GROUP | 20   | 经常使用,但当前并未在活跃态。    |
1719| FIXED_GROUP | 30   | 常用分组,定期使用,但不是每天使用。 |
1720| RARE_GROUP  | 40   | 极少使用分组,不经常使用。      |
1721| LIMITED_GROUP | 50   | 受限使用分组。            |
1722| NEVER_GROUP | 60   | 从未使用分组,安装但是从未运行过。  |