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