1# @ohos.resourceschedule.usageStatistics (Device Usage Statistics) (System API) 2 3The **usageStatistics** module provides APIs for collecting statistics on device usage. For example, you can use the APIs to query whether an application is commonly used and an application's priority group, usage duration, system events (hibernation, wakeup, unlocking, and screen locking), application events (foreground, background, and start and end of continuous tasks), and the number of notifications. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13``` 14import { usageStatistics } from '@kit.BackgroundTasksKit' 15``` 16 17## usageStatistics.isIdleState 18 19isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void 20 21Checks whether an application is commonly used (with the value of **GroupType** being less than or equal to 30). This API uses an asynchronous callback to return the result. 22 23**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 24 25**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 26 27**Parameters** 28 29| Name | Type | Mandatory | Description | 30| ---------- | ---------------------------- | ---- | ---------------------------------------- | 31| bundleName | string | Yes | Bundle name of the application. | 32| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.<br>If the application is commonly used, **true** is returned. If the application is not commonly used or **bundleName** is invalid, **false** is returned.| 33 34**Error codes** 35 36For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 37 38| ID | Error Message | 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**Example** 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<boolean> 66 67Checks whether an application is commonly used (with the value of **GroupType** being less than or equal to 30). This API uses a promise to return the result. 68 69**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 70 71**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 72 73**Parameters** 74 75| Name | Type | Mandatory | Description | 76| ---------- | ------ | ---- | -------------- | 77| bundleName | string | Yes | Bundle name of the application.| 78 79**Return value** 80 81| Type | Description | 82| ---------------------- | ---------------------------------------- | 83| Promise<boolean> | Promise used to return the result.<br>If the application is commonly used, **true** is returned. If the application is not commonly used or **bundleName** is invalid, **false** is returned.| 84 85**Error codes** 86 87For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 88 89| ID | Error Message | 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**Example** 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 116Checks whether an application is commonly used (with the value of **GroupType** being less than or equal to 30). This API returns the result synchronously. 117 118**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 119 120**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 121 122**Parameters** 123 124| Name | Type | Mandatory | Description | 125| ---------- | ---------------------------- | ---- | ---------------------------------------- | 126| bundleName | string | Yes | Bundle name of the application. | 127 128**Return value** 129 130| Type | Description | 131| ---------------------- | ---------------------------------------- | 132| boolean | If the application is commonly used, **true** is returned. If the application is not commonly used or **bundleName** is invalid, **false** is returned.| 133 134**Error codes** 135 136For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 137 138| ID | Error Message | 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**Example** 151```ts 152let isIdleState: boolean = usageStatistics.isIdleStateSync("com.ohos.camera"); 153``` 154 155## usageStatistics.queryAppGroup 156 157queryAppGroup(): Promise<number> 158 159Queries the priority group of this application. This API uses a promise to return the result. 160 161**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 162 163**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 164 165**Return value** 166 167| Type | Description | 168| --------------- | --------------------------- | 169| Promise<number> | Promise used to return the priority group. A smaller value indicates a higher priority.| 170 171**Error codes** 172 173For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 174 175| ID | Error Message | 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**Example** 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<number>): void 204 205Queries the priority group of this application. This API uses an asynchronous callback to return the result. 206 207**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 208 209**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 210 211**Parameters** 212 213| Name | Type | Mandatory | Description | 214| -------- | --------------------- | ---- | -------------------------- | 215| callback | AsyncCallback<number> | Yes | Callback used to return the priority group. A smaller value indicates a higher priority.| 216 217**Error codes** 218 219For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 220 221| ID | Error Message | 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**Example** 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 253Queries the priority group of this application. This API returns the result synchronously. 254 255**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 256 257**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 258 259**Return value** 260 261| Type | Description | 262| --------------- | --------------------------- | 263| number | Priority group. A smaller value indicates a higher priority.| 264 265**Error codes** 266 267For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 268 269| ID | Error Message | 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**Example** 284 285```ts 286let priorityGroup: number = usageStatistics.queryAppGroupSync(); 287``` 288 289## usageStatistics.queryAppGroup 290 291queryAppGroup(bundleName : string): Promise<number> 292 293Queries the priority group of the application specified by **bundleName**. This API uses a promise to return the result. 294 295**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 296 297**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 298 299**Parameters** 300 301| Name | Type | Mandatory | Description | 302| ---------- | ------ | ---- | ---------------------------------------- | 303| bundleName | string | Yes | Bundle name of the application.| 304 305**Return value** 306 307| Type | Description | 308| --------------- | --------------------------- | 309| Promise<number> | Promise used to return the priority group. A smaller value indicates a higher priority.| 310 311**Error codes** 312 313For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 314 315| ID | Error Message | 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**Example** 330 331```javascript 332// Promise mode when bundleName is specified 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<number>): void 346 347Queries the priority group of the application specified by **bundleName**. This API uses an asynchronous callback to return the result. 348 349**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 350 351**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 352 353**Parameters** 354 355| Name | Type | Mandatory | Description | 356| ---------- | --------------------- | ---- | ---------------------------------------- | 357| bundleName | string | Yes | Bundle name of the application.| 358| callback | AsyncCallback<number> | Yes | Callback used to return the priority group. A smaller value indicates a higher priority.| 359 360**Error codes** 361 362For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 363 364| ID | Error Message | 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**Example** 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 397Queries the priority group of the application specified by **bundleName**. This API returns the result synchronously. 398 399**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 400 401**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 402 403**Parameters** 404 405| Name | Type | Mandatory | Description | 406| ---------- | ---------------------------- | ---- | ---------------------------------------- | 407| bundleName | string | Yes | Bundle name of the application. | 408 409**Return value** 410 411| Type | Description | 412| --------------- | --------------------------- | 413| number | Priority group. A smaller value indicates a higher priority.| 414 415**Error codes** 416 417For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 418 419| ID | Error Message | 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**Example** 434 435```ts 436let priorityGroup: number = usageStatistics.queryAppGroupSync("com.ohos.camera"); 437``` 438 439## usageStatistics.setAppGroup 440 441setAppGroup(bundleName: string, newGroup: GroupType): Promise<void> 442 443Sets a new group for the application specified by **bundleName**. This API uses a promise to return the result. It can be called only by the current application. 444 445**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 446 447**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 448 449**Parameters** 450 451| Name | Type | Mandatory | Description | 452| ---------- | --------- | ---- | ---- | 453| bundleName | string | Yes | Bundle name of the application.| 454| newGroup | [GroupType](#grouptype) | Yes | Type of the new group. | 455 456**Return value** 457 458| Type | Description | 459| ------------- | ------------------------- | 460| Promise<void> | Promise that returns no value.| 461 462**Error codes** 463 464For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 465 466| ID | Error Message | 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**Example** 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<void>): void 497 498Sets a new group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result. It can be called only by the current application. 499 500**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 501 502**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 503 504**Parameters** 505 506| Name | Type | Mandatory | Description | 507| ---------- | ------------------- | ---- | ------------------------- | 508| bundleName | string | Yes | Bundle name of the application. | 509| newGroup | [GroupType](#grouptype) | Yes | Type of the new group. | 510| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 511 512**Error codes** 513 514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 515 516| ID | Error Message | 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**Example** 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<BundleStatsMap>): void 549 550Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses an asynchronous callback to return the result. 551 552**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 553 554**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 555 556**Parameters** 557 558| Name | Type | Mandatory | Description | 559| -------- | ---------------------------------------- | ---- | --------------------------------------- | 560| begin | number | Yes | Start time, in milliseconds. | 561| end | number | Yes | End time, in milliseconds. | 562| callback | AsyncCallback<[BundleStatsMap](#bundlestatsmap)> | Yes | Callback used to return the application usage duration statistics.| 563 564**Error codes** 565 566For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 567 568| ID | Error Message | 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**Example** 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<BundleStatsMap> 599 600Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses a promise to return the result. 601 602**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 603 604**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 605 606**Parameters** 607 608| Name | Type | Mandatory | Description | 609| ----- | ------ | ---- | ----- | 610| begin | number | Yes | Start time, in milliseconds.| 611| end | number | Yes | End time, in milliseconds.| 612 613**Return value** 614 615| Type | Description | 616| ---------------------------------------- | -------------------------------------- | 617| Promise<[BundleStatsMap](#bundlestatsmap)> | Promise used to return the application usage duration statistics.| 618 619**Error codes** 620 621For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 622 623| ID | Error Message | 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**Example** 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.queryAppStatsInfos<sup>15+</sup> 650 651queryAppStatsInfos(begin: number, end: number): Promise<AppStatsMap> 652 653Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses a promise to return the result. 654 655**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 656 657**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 658 659**Parameters** 660 661| Name | Type | Mandatory | Description | 662| ----- | ------ | ---- | ----- | 663| begin | number | Yes | Start time, in milliseconds.| 664| end | number | Yes | End time, in milliseconds.| 665 666**Return value** 667 668| Type | Description | 669| ---------------------------------------- | -------------------------------------- | 670| Promise<[AppStatsMap](#appstatsmap15)> | Promise used to return the application usage details in a specified period.| 671 672**Error codes** 673 674For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 675 676| ID | Error Message | 677| ---- | --------------------- | 678| 201 | Permission denied. | 679| 202 | Not System App. | 680| 401 | Parameter error. | 681| 801 | Capability not supported.| 682| 10000001 | Memory operation failed. | 683| 10000002 | Parcel operation failed. | 684| 10000003 | System service operation failed. | 685| 10000004 | IPC failed. | 686| 10000006 | Failed to get the application information. | 687| 10000007 | Failed to get the system time. | 688 689**Example** 690 691```ts 692import { BusinessError } from '@kit.BasicServicesKit'; 693 694usageStatistics.queryAppStatsInfos(0, 20000000000000).then((res:usageStatistics.AppStatsMap) => { 695 console.log('queryAppStatsInfos promise success.'); 696 console.log('queryAppStatsInfos promise result ' + JSON.stringify(res)); 697}).catch((err: BusinessError) => { 698 console.log('queryAppStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message); 699}); 700``` 701 702## usageStatistics.queryLastUseTime<sup>15+</sup> 703 704queryLastUseTime(appInfo: Record<string, Array<number>>): Promise<AppStatsMap> 705 706Queries application usage details based on the specified bundle name and application index. The minimum granularity is day. This API uses a promise to return the result. 707 708**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 709 710**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 711 712**Parameters** 713 714| Name | Type | Mandatory | Description | 715| ----- | ------ | ---- | ----- | 716| appInfo | Record<string, Array<number>> | Yes | The parameter is in the map structure. The key is the bundle name, and the value is the index of the queried application. Multiple indexes can be transferred through the array.| 717 718**Return value** 719 720| Type | Description | 721| ---------------------------------------- | -------------------------------------- | 722| Promise<[AppStatsMap](#appstatsmap15)> | Promise used to return the detailed information about the application with the specified bundle name and index.| 723 724**Error codes** 725 726For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 727 728| ID | Error Message | 729| ---- | --------------------- | 730| 201 | Permission denied. | 731| 202 | Not System App. | 732| 401 | Parameter error. | 733| 801 | Capability not supported.| 734| 10000001 | Memory operation failed. | 735| 10000002 | Parcel operation failed. | 736| 10000003 | System service operation failed. | 737| 10000004 | IPC failed. | 738| 10000006 | Failed to get the application information. | 739| 10000007 | Failed to get the system time. | 740 741**Example** 742 743```ts 744import { BusinessError } from '@kit.BasicServicesKit'; 745 746usageStatistics.queryLastUseTime({"com.huawei.hmos.ailife": [0]}).then((res:usageStatistics.AppStatsMap) => { 747 console.log('queryLastUseTime promise success.'); 748 console.log('queryLastUseTime promise result ' + JSON.stringify(res)); 749}).catch((err: BusinessError) => { 750 console.log('queryLastUseTime promise failed. code is: ' + err.code + ',message is: ' + err.message); 751}); 752``` 753 754## usageStatistics.queryBundleStatsInfoByInterval 755 756queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void 757 758Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses an asynchronous callback to return the result. 759 760**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 761 762**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 763 764**Parameters** 765 766| Name | Type | Mandatory | Description | 767| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 768| byInterval | [IntervalType](#intervaltype) | Yes | Type of information to be queried. | 769| begin | number | Yes | Start time, in milliseconds. | 770| end | number | Yes | End time, in milliseconds. | 771| callback | AsyncCallback<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Yes | Callback used to return the application usage duration statistics.| 772 773**Error codes** 774 775For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 776 777| ID | Error Message | 778| ---- | --------------------- | 779| 201 | Permission denied. | 780| 202 | Not System App. | 781| 401 | Parameter error. | 782| 801 | Capability not supported.| 783| 10000001 | Memory operation failed. | 784| 10000002 | Parcel operation failed. | 785| 10000003 | System service operation failed. | 786| 10000004 | IPC failed. | 787| 10000006 | Failed to get the application information. | 788| 10000007 | Failed to get the system time. | 789 790**Example** 791 792```ts 793import { BusinessError } from '@kit.BasicServicesKit'; 794 795usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleStatsInfo>) => { 796 if (err) { 797 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message); 798 } else { 799 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.'); 800 for (let i = 0; i < res.length; i++) { 801 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1)); 802 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i])); 803 } 804 } 805}); 806``` 807 808## usageStatistics.queryBundleStatsInfoByInterval 809 810queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStatsInfo>> 811 812Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses a promise to return the result. 813 814**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 815 816**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 817 818**Parameters** 819 820| Name | Type | Mandatory | Description | 821| ---------- | ----------------------------- | ---- | ----- | 822| byInterval | [IntervalType](#intervaltype) | Yes | Type of information to be queried.| 823| begin | number | Yes | Start time, in milliseconds.| 824| end | number | Yes | End time, in milliseconds.| 825 826**Return value** 827 828| Type | Description | 829| ---------------------------------------- | ---------------------------------------- | 830| Promise<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Promise used to return the application usage duration statistics.| 831 832**Error codes** 833 834For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 835 836| ID | Error Message | 837| ---- | --------------------- | 838| 201 | Permission denied. | 839| 202 | Not System App. | 840| 401 | Parameter error. | 841| 801 | Capability not supported.| 842| 10000001 | Memory operation failed. | 843| 10000002 | Parcel operation failed. | 844| 10000003 | System service operation failed. | 845| 10000004 | IPC failed. | 846| 10000006 | Failed to get the application information. | 847| 10000007 | Failed to get the system time. | 848 849**Example** 850 851```ts 852import { BusinessError } from '@kit.BasicServicesKit'; 853 854usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then((res: Array<usageStatistics.BundleStatsInfo>) => { 855 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.'); 856 for (let i = 0; i < res.length; i++) { 857 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1)); 858 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i])); 859 } 860}).catch((err: BusinessError) => { 861 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message); 862}); 863``` 864 865## usageStatistics.queryBundleEvents 866 867queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 868 869Queries events of all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result. 870 871**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 872 873**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 874 875**Parameters** 876 877| Name | Type | Mandatory | Description | 878| -------- | ---------------------------------------- | ---- | --------------------------------------- | 879| begin | number | Yes | Start time, in milliseconds. | 880| end | number | Yes | End time, in milliseconds. | 881| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | Yes | Callback used to return the events.| 882 883**Error codes** 884 885For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 886 887| ID | Error Message | 888| ---- | --------------------- | 889| 201 | Permission denied. | 890| 202 | Not System App. | 891| 401 | Parameter error. | 892| 801 | Capability not supported.| 893| 10000001 | Memory operation failed. | 894| 10000002 | Parcel operation failed. | 895| 10000003 | System service operation failed. | 896| 10000004 | IPC failed. | 897| 10000006 | Failed to get the application information. | 898| 10000007 | Failed to get the system time. | 899 900**Example** 901 902```ts 903import { BusinessError } from '@kit.BasicServicesKit'; 904 905usageStatistics.queryBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 906 if (err) { 907 console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 908 } else { 909 console.log('BUNDLE_ACTIVE queryBundleEvents callback success.'); 910 for (let i = 0; i < res.length; i++) { 911 console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1)); 912 console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i])); 913 } 914 } 915}); 916``` 917 918## usageStatistics.queryBundleEvents 919 920queryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 921 922Queries events of all applications based on the specified start time and end time. This API uses a promise to return the result. 923 924**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 925 926**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 927 928**Parameters** 929 930| Name | Type | Mandatory | Description | 931| ----- | ------ | ---- | ----- | 932| begin | number | Yes | Start time, in milliseconds.| 933| end | number | Yes | End time, in milliseconds.| 934 935**Return value** 936 937| Type | Description | 938| ---------------------------------------- | -------------------------------------- | 939| Promise<Array<[BundleEvents](#bundleevents)>> | Promise used to return the events obtained.| 940 941**Error codes** 942 943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 944 945| ID | Error Message | 946| ---- | --------------------- | 947| 201 | Permission denied. | 948| 202 | Not System App. | 949| 401 | Parameter error. | 950| 801 | Capability not supported.| 951| 10000001 | Memory operation failed. | 952| 10000002 | Parcel operation failed. | 953| 10000003 | System service operation failed. | 954| 10000004 | IPC failed. | 955| 10000006 | Failed to get the application information. | 956| 10000007 | Failed to get the system time. | 957 958**Example** 959 960```ts 961import { BusinessError } from '@kit.BasicServicesKit'; 962 963usageStatistics.queryBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 964 console.log('BUNDLE_ACTIVE queryBundleEvents promise success.'); 965 for (let i = 0; i < res.length; i++) { 966 console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1)); 967 console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i])); 968 } 969}).catch((err: BusinessError) => { 970 console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 971}); 972``` 973 974## usageStatistics.queryCurrentBundleEvents 975 976queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 977 978Queries events of this application based on the specified start time and end time. This API uses an asynchronous callback to return the result. 979 980**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 981 982**Parameters** 983 984| Name | Type | Mandatory | Description | 985| -------- | ---------------------------------------- | ---- | --------------------------------------- | 986| begin | number | Yes | Start time, in milliseconds. | 987| end | number | Yes | End time, in milliseconds. | 988| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | Yes | Callback used to return the events.| 989 990**Error codes** 991 992For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 993 994| ID | Error Message | 995| ---- | --------------------- | 996| 202 | Not System App. | 997| 401 | Parameter error. | 998| 801 | Capability not supported.| 999| 10000001 | Memory operation failed. | 1000| 10000002 | Parcel operation failed. | 1001| 10000003 | System service operation failed. | 1002| 10000004 | IPC failed. | 1003| 10000006 | Failed to get the application information. | 1004| 10000007 | Failed to get the system time. | 1005 1006**Example** 1007 1008```ts 1009import { BusinessError } from '@kit.BasicServicesKit'; 1010 1011usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 1012 if (err) { 1013 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 1014 } else { 1015 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.'); 1016 for (let i = 0; i < res.length; i++) { 1017 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1)); 1018 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i])); 1019 } 1020 } 1021}); 1022``` 1023 1024## usageStatistics.queryCurrentBundleEvents 1025 1026queryCurrentBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 1027 1028Queries events of this application based on the specified start time and end time. This API uses a promise to return the result. 1029 1030**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1031 1032**Parameters** 1033 1034| Name | Type | Mandatory | Description | 1035| ----- | ------ | ---- | ----- | 1036| begin | number | Yes | Start time, in milliseconds.| 1037| end | number | Yes | End time, in milliseconds.| 1038 1039**Return value** 1040 1041| Type | Description | 1042| ---------------------------------------- | -------------------------------------- | 1043| Promise<Array<[BundleEvents](#bundleevents)>> | Promise used to return the events obtained.| 1044 1045**Error codes** 1046 1047For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1048 1049| ID | Error Message | 1050| ---- | --------------------- | 1051| 202 | Not System App. | 1052| 401 | Parameter error. | 1053| 801 | Capability not supported.| 1054| 10000001 | Memory operation failed. | 1055| 10000002 | Parcel operation failed. | 1056| 10000003 | System service operation failed. | 1057| 10000004 | IPC failed. | 1058| 10000006 | Failed to get the application information. | 1059| 10000007 | Failed to get the system time. | 1060 1061**Example** 1062 1063```ts 1064import { BusinessError } from '@kit.BasicServicesKit'; 1065 1066usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 1067 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.'); 1068 for (let i = 0; i < res.length; i++) { 1069 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1)); 1070 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i])); 1071 } 1072}).catch((err: BusinessError) => { 1073 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 1074}); 1075``` 1076 1077## usageStatistics.queryDeviceEventStats 1078 1079queryDeviceEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 1080 1081Queries statistics about system events (hibernation, wakeup, unlocking, and locking) that occur between the specified start time and end time. This API uses a promise to return the result. 1082 1083**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1084 1085**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1086 1087**Parameters** 1088 1089| Name | Type | Mandatory | Description | 1090| ----- | ------ | ---- | ----- | 1091| begin | number | Yes | Start time, in milliseconds.| 1092| end | number | Yes | End time, in milliseconds.| 1093 1094**Return value** 1095 1096| Type | Description | 1097| ---------------------------------------- | ---------------------------------------- | 1098| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise used to return the statistics about system events.| 1099 1100**Error codes** 1101 1102For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1103 1104| ID | Error Message | 1105| ---- | --------------------- | 1106| 201 | Permission denied. | 1107| 202 | Not System App. | 1108| 401 | Parameter error. | 1109| 801 | Capability not supported.| 1110| 10000001 | Memory operation failed. | 1111| 10000002 | Parcel operation failed. | 1112| 10000003 | System service operation failed. | 1113| 10000004 | IPC failed. | 1114| 10000006 | Failed to get the application information. | 1115| 10000007 | Failed to get the system time. | 1116 1117**Example** 1118 1119```ts 1120import { BusinessError } from '@kit.BasicServicesKit'; 1121 1122usageStatistics.queryDeviceEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1123 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.'); 1124 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res)); 1125}).catch((err: BusinessError) => { 1126 console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1127}); 1128``` 1129 1130## usageStatistics.queryDeviceEventStats 1131 1132queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1133 1134Queries statistics about system events (hibernation, wakeup, unlocking, and locking) that occur between the specified start time and end time. This API uses an asynchronous callback to return the result. 1135 1136**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1137 1138**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1139 1140**Parameters** 1141 1142| Name | Type | Mandatory | Description | 1143| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1144| begin | number | Yes | Start time, in milliseconds. | 1145| end | number | Yes | End time, in milliseconds. | 1146| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | Yes | Callback used to return the statistics about system events.| 1147 1148**Error codes** 1149 1150For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1151 1152| ID | Error Message | 1153| ---- | --------------------- | 1154| 201 | Permission denied. | 1155| 202 | Not System App. | 1156| 401 | Parameter error. | 1157| 801 | Capability not supported.| 1158| 10000001 | Memory operation failed. | 1159| 10000002 | Parcel operation failed. | 1160| 10000003 | System service operation failed. | 1161| 10000004 | IPC failed. | 1162| 10000006 | Failed to get the application information. | 1163| 10000007 | Failed to get the system time. | 1164 1165**Example** 1166 1167```ts 1168import { BusinessError } from '@kit.BasicServicesKit'; 1169 1170usageStatistics.queryDeviceEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1171 if(err) { 1172 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1173 } else { 1174 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.'); 1175 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res)); 1176 } 1177}); 1178``` 1179 1180## usageStatistics.queryNotificationEventStats 1181 1182queryNotificationEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 1183 1184Queries the number of notifications from all applications based on the specified start time and end time. This API uses a promise to return the result. 1185 1186**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1187 1188**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1189 1190**Parameters** 1191 1192| Name | Type | Mandatory | Description | 1193| ----- | ------ | ---- | ----- | 1194| begin | number | Yes | Start time, in milliseconds.| 1195| end | number | Yes | End time, in milliseconds.| 1196 1197**Return value** 1198 1199| Type | Description | 1200| ---------------------------------------- | ---------------------------------------- | 1201| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise used to return the number of notifications.| 1202 1203**Error codes** 1204 1205For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1206 1207| ID | Error Message | 1208| ---- | --------------------- | 1209| 201 | Permission denied. | 1210| 202 | Not System App. | 1211| 401 | Parameter error. | 1212| 801 | Capability not supported.| 1213| 10000001 | Memory operation failed. | 1214| 10000002 | Parcel operation failed. | 1215| 10000003 | System service operation failed. | 1216| 10000004 | IPC failed. | 1217| 10000006 | Failed to get the application information. | 1218| 10000007 | Failed to get the system time. | 1219 1220**Example** 1221 1222```ts 1223import { BusinessError } from '@kit.BasicServicesKit'; 1224 1225usageStatistics.queryNotificationEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1226 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.'); 1227 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res)); 1228}).catch((err: BusinessError) => { 1229 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1230}); 1231``` 1232 1233## usageStatistics.queryNotificationEventStats 1234 1235queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1236 1237Queries the number of notifications from all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result. 1238 1239**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1240 1241**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1242 1243**Parameters** 1244 1245| Name | Type | Mandatory | Description | 1246| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1247| begin | number | Yes | Start time, in milliseconds. | 1248| end | number | Yes | End time, in milliseconds. | 1249| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | Yes | Callback used to return the number of notifications.| 1250 1251**Error codes** 1252 1253For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1254 1255| ID | Error Message | 1256| ---- | --------------------- | 1257| 201 | Permission denied. | 1258| 202 | Not System App. | 1259| 401 | Parameter error. | 1260| 801 | Capability not supported.| 1261| 10000001 | Memory operation failed. | 1262| 10000002 | Parcel operation failed. | 1263| 10000003 | System service operation failed. | 1264| 10000004 | IPC failed. | 1265| 10000006 | Failed to get the application information. | 1266| 10000007 | Failed to get the system time. | 1267 1268**Example** 1269 1270```ts 1271import { BusinessError } from '@kit.BasicServicesKit'; 1272 1273usageStatistics.queryNotificationEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1274 if(err) { 1275 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1276 } else { 1277 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.'); 1278 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res)); 1279 } 1280}); 1281``` 1282 1283## usageStatistics.queryModuleUsageRecords 1284 1285queryModuleUsageRecords(): Promise<Array<HapModuleInfo>> 1286 1287Queries the usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses a promise to return the result. 1288 1289Queries FA usage records. This API uses a promise to return a maximum of 1000 FA usage records sorted by time (most recent first). 1290 1291**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1292 1293**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1294 1295**Return value** 1296 1297| Type | Description | 1298| ---------------------------------------- | ---------------------------------- | 1299| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise used to return the result. A maximum of 1000 usage records can be returned.| 1300 1301**Error codes** 1302 1303For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1304 1305| ID | Error Message | 1306| ---- | --------------------- | 1307| 201 | Permission denied. | 1308| 202 | Not System App. | 1309| 401 | Parameter error. | 1310| 801 | Capability not supported.| 1311| 10000001 | Memory operation failed. | 1312| 10000002 | Parcel operation failed. | 1313| 10000003 | System service operation failed. | 1314| 10000004 | IPC failed. | 1315| 10000006 | Failed to get the application information. | 1316| 10000007 | Failed to get the system time. | 1317 1318**Example** 1319 1320```ts 1321// Invocation when maxNum is not passed 1322import { BusinessError } from '@kit.BasicServicesKit'; 1323 1324usageStatistics.queryModuleUsageRecords().then((res: Array<usageStatistics.HapModuleInfo>) => { 1325 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1326 for (let i = 0; i < res.length; i++) { 1327 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1328 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1329 } 1330}).catch((err: BusinessError) => { 1331 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1332}); 1333``` 1334 1335## usageStatistics.queryModuleUsageRecords 1336 1337queryModuleUsageRecords(callback: AsyncCallback<Array<HapModuleInfo>>): void 1338 1339Queries the usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses an asynchronous callback to return the result. 1340 1341**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1342 1343**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1344 1345**Parameters** 1346 1347| Name | Type | Mandatory | Description | 1348| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1349| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | Yes | Callback used to return the result. A maximum of 1000 usage records can be returned.| 1350 1351**Error codes** 1352 1353For details about the error codes, see [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1354 1355| ID | Error Message | 1356| ---------- | ---------------------------- | 1357| 10000001 | Memory operation failed. | 1358| 10000002 | Parcel operation failed. | 1359| 10000003 | System service operation failed. | 1360| 10000004 | IPC failed. | 1361| 10000006 | Failed to get the application information. | 1362| 10000007 | Failed to get the system time. | 1363 1364**Example** 1365 1366```ts 1367import { BusinessError } from '@kit.BasicServicesKit'; 1368 1369usageStatistics.queryModuleUsageRecords((err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1370 if(err) { 1371 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1372 } else { 1373 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1374 for (let i = 0; i < res.length; i++) { 1375 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1376 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1377 } 1378 } 1379}); 1380``` 1381 1382## usageStatistics.queryModuleUsageRecords 1383 1384queryModuleUsageRecords(maxNum: number): Promise<Array<HapModuleInfo>> 1385 1386Queries a given number of usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses a promise to return the result. 1387 1388**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1389 1390**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1391 1392**Parameters** 1393 1394| Name | Type | Mandatory | Description | 1395| ------ | ------ | ---- | ---------------------------------- | 1396| maxNum | number | Yes | Number of usage records, in the range [1, 1000].| 1397 1398**Return value** 1399 1400| Type | Description | 1401| ---------------------------------------- | ---------------------------------- | 1402| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise used to return the result. The usage records returned does not exceed the value of **maxNum**.| 1403 1404**Error codes** 1405 1406For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1407 1408| ID | Error Message | 1409| ---- | --------------------- | 1410| 201 | Permission denied. | 1411| 202 | Not System App. | 1412| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1413| 801 | Capability not supported.| 1414| 10000001 | Memory operation failed. | 1415| 10000002 | Parcel operation failed. | 1416| 10000003 | System service operation failed. | 1417| 10000004 | IPC failed. | 1418| 10000006 | Failed to get the application information. | 1419| 10000007 | Failed to get the system time. | 1420 1421**Example** 1422 1423```ts 1424import { BusinessError } from '@kit.BasicServicesKit'; 1425 1426usageStatistics.queryModuleUsageRecords(1000).then((res: Array<usageStatistics.HapModuleInfo>) => { 1427 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1428 for (let i = 0; i < res.length; i++) { 1429 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1430 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1431 } 1432}).catch((err: BusinessError) => { 1433 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1434}); 1435``` 1436 1437## usageStatistics.queryModuleUsageRecords 1438 1439queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapModuleInfo>>): void 1440 1441Queries a given number of usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses an asynchronous callback to return the result. 1442 1443**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1444 1445**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1446 1447**Parameters** 1448 1449| Name | Type | Mandatory | Description | 1450| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1451| maxNum | number | Yes | Number of usage records, in the range [1, 1000].| 1452| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | Yes | Callback used to return the result. The usage records returned does not exceed the value of **maxNum**.| 1453 1454**Error codes** 1455 1456For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1457 1458| ID | Error Message | 1459| ---- | --------------------- | 1460| 201 | Permission denied. | 1461| 202 | Not System App. | 1462| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1463| 801 | Capability not supported.| 1464| 10000001 | Memory operation failed. | 1465| 10000002 | Parcel operation failed. | 1466| 10000003 | System service operation failed. | 1467| 10000004 | IPC failed. | 1468| 10000006 | Failed to get the application information. | 1469| 10000007 | Failed to get the system time. | 1470 1471**Example** 1472 1473```ts 1474import { BusinessError } from '@kit.BasicServicesKit'; 1475 1476usageStatistics.queryModuleUsageRecords(1000, (err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1477 if(err) { 1478 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1479 } else { 1480 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1481 for (let i = 0; i < res.length; i++) { 1482 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1483 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1484 } 1485 } 1486}); 1487``` 1488 1489## usageStatistics.registerAppGroupCallBack 1490 1491registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): Promise<void> 1492 1493Registers a callback for application group changes. When an application group of the user changes, an [AppGroupCallbackInfo](#appgroupcallbackinfo) instance is returned to all applications that have registered the callback. This API uses a promise to return the result. 1494 1495**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1496 1497**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1498 1499**Parameters** 1500 1501| Name | Type | Mandatory| Description | 1502| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 1503| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | Yes | Application group change information.| 1504 1505**Return value** 1506 1507| Type | Description | 1508| ------------- | ----------------------- | 1509| Promise<void> | Promise that returns no value.| 1510 1511**Error codes** 1512 1513For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1514 1515| ID | Error Message | 1516| ---- | --------------------- | 1517| 201 | Permission denied. | 1518| 202 | Not System App. | 1519| 401 | Parameter error. | 1520| 801 | Capability not supported.| 1521| 10000001 | Memory operation failed. | 1522| 10000002 | Parcel operation failed. | 1523| 10000003 | System service operation failed. | 1524| 10000004 | IPC failed. | 1525| 10100001 | Repeated operation on the application group. | 1526 1527 1528**Example** 1529 1530```ts 1531import { BusinessError } from '@kit.BasicServicesKit'; 1532 1533function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1534 console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.'); 1535 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1536 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1537 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1538 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1539 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1540}; 1541usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => { 1542 console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.'); 1543}).catch((err: BusinessError) => { 1544 console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1545}); 1546``` 1547 1548## usageStatistics.registerAppGroupCallBack 1549 1550registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void 1551 1552Registers a callback for application group changes. When an application group of the user changes, an [AppGroupCallbackInfo](#appgroupcallbackinfo) instance is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result. 1553 1554**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1555 1556**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1557 1558**Parameters** 1559 1560| Name | Type | Mandatory| Description | 1561| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- | 1562| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | Yes | Application group change information. | 1563| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1564 1565**Error codes** 1566 1567For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1568 1569| ID | Error Message | 1570| ---- | --------------------- | 1571| 201 | Permission denied. | 1572| 202 | Not System App. | 1573| 401 | Parameter error. | 1574| 801 | Capability not supported.| 1575| 10000001 | Memory operation failed. | 1576| 10000002 | Parcel operation failed. | 1577| 10000003 | System service operation failed. | 1578| 10000004 | IPC failed. | 1579| 10100001 | Repeated operation on the application group. | 1580 1581 1582**Example** 1583 1584```ts 1585import { BusinessError } from '@kit.BasicServicesKit'; 1586 1587function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1588 console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); 1589 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1590 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1591 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1592 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1593 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1594}; 1595usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err: BusinessError) => { 1596 if(err) { 1597 console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1598 } else { 1599 console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.'); 1600 } 1601}); 1602``` 1603 1604## usageStatistics.unregisterAppGroupCallBack 1605 1606unregisterAppGroupCallBack(): Promise<void> 1607 1608Unregisters the callback for application group changes. This API uses a promise to return the result. 1609 1610**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1611 1612**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1613 1614**Return value** 1615 1616| Type | Description | 1617| ------------- | ------------------------ | 1618| Promise<void> | Promise that returns no value.| 1619 1620**Error codes** 1621 1622For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1623 1624| ID | Error Message | 1625| ---- | --------------------- | 1626| 201 | Permission denied. | 1627| 202 | Not System App. | 1628| 401 | Parameter error. | 1629| 801 | Capability not supported.| 1630| 10000001 | Memory operation failed. | 1631| 10000002 | Parcel operation failed. | 1632| 10000003 | System service operation failed. | 1633| 10000004 | IPC failed. | 1634| 10100001 | Repeated operation on the application group. | 1635 1636**Example** 1637 1638```ts 1639import { BusinessError } from '@kit.BasicServicesKit'; 1640 1641usageStatistics.unregisterAppGroupCallBack().then( () => { 1642 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.'); 1643}).catch((err: BusinessError) => { 1644 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1645}); 1646``` 1647 1648## usageStatistics.unregisterAppGroupCallBack 1649 1650unregisterAppGroupCallBack(callback: AsyncCallback<void>): void; 1651 1652Unregisters the callback for application group changes. This API uses an asynchronous callback to return the result. 1653 1654**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1655 1656**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1657 1658**Parameters** 1659 1660| Name | Type | Mandatory | Description | 1661| -------- | ------------------- | ---- | -------------- | 1662| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1663 1664**Error codes** 1665 1666For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1667 1668| ID | Error Message | 1669| ---- | --------------------- | 1670| 201 | Permission denied. | 1671| 202 | Not System App. | 1672| 401 | Parameter error. | 1673| 801 | Capability not supported.| 1674| 10000001 | Memory operation failed. | 1675| 10000002 | Parcel operation failed. | 1676| 10000003 | System service operation failed. | 1677| 10000004 | IPC failed. | 1678| 10100001 | Repeated operation on the application group. | 1679 1680**Example** 1681 1682```ts 1683import { BusinessError } from '@kit.BasicServicesKit'; 1684 1685usageStatistics.unregisterAppGroupCallBack((err: BusinessError) => { 1686 if(err) { 1687 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1688 } else { 1689 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.'); 1690 } 1691}); 1692``` 1693 1694## HapModuleInfo 1695 1696Defines the information about the usage record in the FA model. 1697 1698**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1699 1700| Name | Type | Mandatory | Description | 1701| -------------------- | ---------------------------------------- | ---- | ----------------------------- | 1702| deviceId | string | No | Device ID. | 1703| bundleName | string | Yes | Bundle name. | 1704| moduleName | string | Yes | Name of the module to which the FA belongs. | 1705| abilityName | string | No | **MainAbility** name of the FA. | 1706| appLabelId | number | No | Application label ID of the FA. | 1707| labelId | number | No | Label ID of the module to which the FA belongs. | 1708| descriptionId | number | No | Description ID of the application to which the FA belongs. | 1709| abilityLableId | number | No | **MainAbility** label ID of the FA. | 1710| abilityDescriptionId | number | No | **MainAbility** description ID of the FA.| 1711| abilityIconId | number | No | **MainAbility** icon ID of the FA. | 1712| launchedCount | number | Yes | Number of FA startup times. | 1713| lastModuleUsedTime | number | Yes | Last time when the FA was used. | 1714| formRecords | Array<[HapFormInfo](#hapforminfo)> | Yes | Array of widget usage records in the FA. | 1715 1716## HapFormInfo 1717 1718Defines the information about the usage record of FA widgets. 1719 1720**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1721 1722| Name | Type | Mandatory | Description | 1723| ---------------- | ------ | ---- | ----------- | 1724| formName | string | Yes | Widget name. | 1725| formDimension | number | Yes | Widget dimensions. | 1726| formId | number | Yes | Widget ID. | 1727| formLastUsedTime | number | Yes | Last time when the widget was clicked.| 1728| count | number | Yes | Number of clicks on the widget. | 1729 1730## AppGroupCallbackInfo 1731 1732Provides the application group changes returned through a callback. 1733 1734**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1735 1736| Name | Type | Mandatory| Description | 1737| ---------------- | ------ | ---- | ---------------- | 1738| appOldGroup | number | Yes | Application group before the change.| 1739| appNewGroup | number | Yes | Application group after the change.| 1740| userId | number | Yes | User ID. | 1741| changeReason | number | Yes | Reason for the group change.<br>- 256 (default): A record is initially created.<br>- 512: An exception occurs when the priority group is calculated.<br>- 768: The usage duration changes.<br>- 1024: Another application forcibly sets a priority group for the current application.| 1742| bundleName | string | Yes | Bundle name. | 1743 1744## BundleStatsInfo 1745 1746Provides the usage duration information of an application. 1747 1748**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1749 1750| Name | Type | Mandatory | Description | 1751| ------------------------ | ------ | ---- | ---------------------------------------- | 1752| bundleName | string | No | Bundle name of the application. | 1753| abilityPrevAccessTime | number | No | Last time when the application was used. | 1754| abilityInFgTotalTime | number | No | Total time that the application runs in the foreground. | 1755| id | number | Yes | User ID.| 1756| abilityPrevSeenTime | number | No | Last time when the application was visible in the foreground.| 1757| abilitySeenTotalTime | number | No | Total time that the application is visible in the foreground.| 1758| fgAbilityAccessTotalTime | number | No | Total time that the application accesses the foreground.| 1759| fgAbilityPrevAccessTime | number | No | Last time when the application accessed the foreground.| 1760| infosBeginTime | number | No | Time logged in the first application usage record in the **BundleActiveInfo** object.| 1761| infosEndTime | number | No | Time logged in the last application usage record in the **BundleActiveInfo** object.| 1762| appIndex<sup>15+</sup> | number | No | Application index.| 1763 1764## BundleEvents 1765 1766Provides information about an application event. 1767 1768**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1769 1770| Name | Type | Mandatory | Description | 1771| --------------------- | ------ | ---- | ---------------------------------------- | 1772| bundleName | string | No | Bundle name of the application. | 1773| eventId | number | No | Application event type. | 1774| eventOccurredTime | number | No | Timestamp when the application event occurs. | 1775| appGroup | number | No | Group of the application by usage priority.| 1776| indexOfLink | string | No | Shortcut ID.| 1777| nameOfClass | string | No | Class name.| 1778 1779## BundleStatsMap 1780 1781Provides the usage duration information of an application. 1782 1783**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1784 1785|Name | Description | 1786| ------------------------------ | ---------------------------------------- | 1787| Record<string, [BundleStatsInfo](#bundlestatsinfo)> | Usage duration information by application.| 1788 1789## AppStatsMap<sup>15+</sup> 1790 1791Provides the detailed usage information of an application (including application clones). 1792 1793**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1794 1795|Name | Description | 1796| ------------------------------ | ---------------------------------------- | 1797| Record<string, Array<[BundleStatsInfo](#bundlestatsinfo)>> | Usage information by application (including application clones).| 1798 1799## DeviceEventStats 1800 1801Provides statistics about notifications and system events. 1802 1803**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1804 1805| Name | Type | Mandatory | Description | 1806| ------- | ------ | ---- | ----------------- | 1807| name | string | Yes | Bundle name of the notification sending application or system event name. | 1808| eventId | number | Yes | Type of the notification or system event. | 1809| count | number | Yes | Number of application notifications or system event triggering times.| 1810 1811## IntervalType 1812 1813Enumerates the interval types for querying the application usage duration. 1814 1815**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1816 1817| Name | Value | Description | 1818| ------------ | ---- | ---------------------------------------- | 1819| BY_OPTIMIZED | 0 | The system queries the application usage duration statistics in the specified time frame at the interval the system deems appropriate.| 1820| BY_DAILY | 1 | The system queries the application usage duration statistics in the specified time frame on a daily basis. | 1821| BY_WEEKLY | 2 | The system queries the application usage duration statistics in the specified time frame on a weekly basis. | 1822| BY_MONTHLY | 3 | The system queries the application usage duration statistics in the specified time frame on a monthly basis. | 1823| BY_ANNUALLY | 4 | The system queries the application usage duration statistics in the specified time frame on an annual basis. | 1824 1825## GroupType 1826 1827Enumerates the application group types. 1828 1829**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1830 1831| Name | Value | Description | 1832| ------------------ | ---- | ----------------- | 1833| ALIVE_GROUP | 10 | Group of active applications. | 1834| DAILY_GROUP | 20 | Group of frequently used applications that are not in the active state. | 1835| FIXED_GROUP | 30 | Group of applications that are used periodically but not every day.| 1836| RARE_GROUP | 40 | Group of rarely used applications. | 1837| LIMITED_GROUP | 50 | Group of restricted applications. | 1838| NEVER_GROUP | 60 | Group of applications that have been installed but never run. | 1839