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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 46| 10000003 | Failed to get system ability manager. | 47| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 97| 10000003 | Failed to get system ability manager. | 98| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 146| 10000003 | Failed to get system ability manager. | 147| 10000004 | Failed to access the device usage service. | 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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 183| 10000003 | Failed to get system ability manager. | 184| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 229| 10000003 | Failed to get system ability manager. | 230| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 277| 10000003 | Failed to get system ability manager. | 278| 10000004 | Failed to access the device usage service. | 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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 323| 10000003 | Failed to get system ability manager. | 324| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 372| 10000003 | Failed to get system ability manager. | 373| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 427| 10000003 | Failed to get system ability manager. | 428| 10000004 | Failed to access the device usage service. | 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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 474| 10000003 | Failed to get system ability manager. | 475| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 524| 10000003 | Failed to get system ability manager. | 525| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 576| 10000003 | Failed to get system ability manager. | 577| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 631| 10000003 | Failed to get system ability manager. | 632| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 684| 10000003 | Failed to get system ability manager. | 685| 10000004 | Failed to access the device usage service. | 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.error('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 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 736| 10000003 | Failed to get system ability manager. | 737| 10000004 | Failed to access the device usage service. | 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 746// Replace com.ohos.camera with the actual bundle name. 747usageStatistics.queryLastUseTime({"com.ohos.camera": [0]}).then((res:usageStatistics.AppStatsMap) => { 748 console.log('queryLastUseTime promise success.'); 749 console.log('queryLastUseTime promise result ' + JSON.stringify(res)); 750}).catch((err: BusinessError) => { 751 console.error('queryLastUseTime promise failed. code is: ' + err.code + ',message is: ' + err.message); 752}); 753``` 754 755## usageStatistics.queryBundleStatsInfoByInterval 756 757queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void 758 759Queries 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. 760 761**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 762 763**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 764 765**Parameters** 766 767| Name | Type | Mandatory | Description | 768| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 769| byInterval | [IntervalType](#intervaltype) | Yes | Type of information to be queried. | 770| begin | number | Yes | Start time, in milliseconds. | 771| end | number | Yes | End time, in milliseconds. | 772| callback | AsyncCallback<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Yes | Callback used to return the application usage duration statistics.| 773 774**Error codes** 775 776For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 777 778| ID | Error Message | 779| ---- | --------------------- | 780| 201 | Permission denied. | 781| 202 | Not System App. | 782| 401 | Parameter error. | 783| 801 | Capability not supported.| 784| 10000001 | Memory operation failed. | 785| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 786| 10000003 | Failed to get system ability manager. | 787| 10000004 | Failed to access the device usage service. | 788| 10000006 | Failed to get the application information. | 789| 10000007 | Failed to get the system time. | 790 791**Example** 792 793```ts 794import { BusinessError } from '@kit.BasicServicesKit'; 795 796usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleStatsInfo>) => { 797 if (err) { 798 console.error('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message); 799 } else { 800 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.'); 801 for (let i = 0; i < res.length; i++) { 802 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1)); 803 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i])); 804 } 805 } 806}); 807``` 808 809## usageStatistics.queryBundleStatsInfoByInterval 810 811queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStatsInfo>> 812 813Queries 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. 814 815**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 816 817**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 818 819**Parameters** 820 821| Name | Type | Mandatory | Description | 822| ---------- | ----------------------------- | ---- | ----- | 823| byInterval | [IntervalType](#intervaltype) | Yes | Type of information to be queried.| 824| begin | number | Yes | Start time, in milliseconds.| 825| end | number | Yes | End time, in milliseconds.| 826 827**Return value** 828 829| Type | Description | 830| ---------------------------------------- | ---------------------------------------- | 831| Promise<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Promise used to return the application usage duration statistics.| 832 833**Error codes** 834 835For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 836 837| ID | Error Message | 838| ---- | --------------------- | 839| 201 | Permission denied. | 840| 202 | Not System App. | 841| 401 | Parameter error. | 842| 801 | Capability not supported.| 843| 10000001 | Memory operation failed. | 844| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 845| 10000003 | Failed to get system ability manager. | 846| 10000004 | Failed to access the device usage service. | 847| 10000006 | Failed to get the application information. | 848| 10000007 | Failed to get the system time. | 849 850**Example** 851 852```ts 853import { BusinessError } from '@kit.BasicServicesKit'; 854 855usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then((res: Array<usageStatistics.BundleStatsInfo>) => { 856 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.'); 857 for (let i = 0; i < res.length; i++) { 858 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1)); 859 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i])); 860 } 861}).catch((err: BusinessError) => { 862 console.error('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message); 863}); 864``` 865 866## usageStatistics.queryBundleEvents 867 868queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 869 870Queries events of all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result. 871 872**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 873 874**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 875 876**Parameters** 877 878| Name | Type | Mandatory | Description | 879| -------- | ---------------------------------------- | ---- | --------------------------------------- | 880| begin | number | Yes | Start time, in milliseconds. | 881| end | number | Yes | End time, in milliseconds. | 882| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | Yes | Callback used to return the events.| 883 884**Error codes** 885 886For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 887 888| ID | Error Message | 889| ---- | --------------------- | 890| 201 | Permission denied. | 891| 202 | Not System App. | 892| 401 | Parameter error. | 893| 801 | Capability not supported.| 894| 10000001 | Memory operation failed. | 895| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 896| 10000003 | Failed to get system ability manager. | 897| 10000004 | Failed to access the device usage service. | 898| 10000006 | Failed to get the application information. | 899| 10000007 | Failed to get the system time. | 900 901**Example** 902 903```ts 904import { BusinessError } from '@kit.BasicServicesKit'; 905 906usageStatistics.queryBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 907 if (err) { 908 console.error('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 909 } else { 910 console.log('BUNDLE_ACTIVE queryBundleEvents callback success.'); 911 for (let i = 0; i < res.length; i++) { 912 console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1)); 913 console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i])); 914 } 915 } 916}); 917``` 918 919## usageStatistics.queryBundleEvents 920 921queryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 922 923Queries events of all applications based on the specified start time and end time. This API uses a promise to return the result. 924 925**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 926 927**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 928 929**Parameters** 930 931| Name | Type | Mandatory | Description | 932| ----- | ------ | ---- | ----- | 933| begin | number | Yes | Start time, in milliseconds.| 934| end | number | Yes | End time, in milliseconds.| 935 936**Return value** 937 938| Type | Description | 939| ---------------------------------------- | -------------------------------------- | 940| Promise<Array<[BundleEvents](#bundleevents)>> | Promise used to return the events obtained.| 941 942**Error codes** 943 944For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 945 946| ID | Error Message | 947| ---- | --------------------- | 948| 201 | Permission denied. | 949| 202 | Not System App. | 950| 401 | Parameter error. | 951| 801 | Capability not supported.| 952| 10000001 | Memory operation failed. | 953| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 954| 10000003 | Failed to get system ability manager. | 955| 10000004 | Failed to access the device usage service. | 956| 10000006 | Failed to get the application information. | 957| 10000007 | Failed to get the system time. | 958 959**Example** 960 961```ts 962import { BusinessError } from '@kit.BasicServicesKit'; 963 964usageStatistics.queryBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 965 console.log('BUNDLE_ACTIVE queryBundleEvents promise success.'); 966 for (let i = 0; i < res.length; i++) { 967 console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1)); 968 console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i])); 969 } 970}).catch((err: BusinessError) => { 971 console.error('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 972}); 973``` 974 975## usageStatistics.queryCurrentBundleEvents 976 977queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 978 979Queries events of this application based on the specified start time and end time. This API uses an asynchronous callback to return the result. 980 981**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 982 983**Parameters** 984 985| Name | Type | Mandatory | Description | 986| -------- | ---------------------------------------- | ---- | --------------------------------------- | 987| begin | number | Yes | Start time, in milliseconds. | 988| end | number | Yes | End time, in milliseconds. | 989| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | Yes | Callback used to return the events.| 990 991**Error codes** 992 993For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 994 995| ID | Error Message | 996| ---- | --------------------- | 997| 202 | Not System App. | 998| 401 | Parameter error. | 999| 801 | Capability not supported.| 1000| 10000001 | Memory operation failed. | 1001| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1002| 10000003 | Failed to get system ability manager. | 1003| 10000004 | Failed to access the device usage service. | 1004| 10000006 | Failed to get the application information. | 1005| 10000007 | Failed to get the system time. | 1006 1007**Example** 1008 1009```ts 1010import { BusinessError } from '@kit.BasicServicesKit'; 1011 1012usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 1013 if (err) { 1014 console.error('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 1015 } else { 1016 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.'); 1017 for (let i = 0; i < res.length; i++) { 1018 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1)); 1019 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i])); 1020 } 1021 } 1022}); 1023``` 1024 1025## usageStatistics.queryCurrentBundleEvents 1026 1027queryCurrentBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 1028 1029Queries events of this application based on the specified start time and end time. This API uses a promise to return the result. 1030 1031**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1032 1033**Parameters** 1034 1035| Name | Type | Mandatory | Description | 1036| ----- | ------ | ---- | ----- | 1037| begin | number | Yes | Start time, in milliseconds.| 1038| end | number | Yes | End time, in milliseconds.| 1039 1040**Return value** 1041 1042| Type | Description | 1043| ---------------------------------------- | -------------------------------------- | 1044| Promise<Array<[BundleEvents](#bundleevents)>> | Promise used to return the events obtained.| 1045 1046**Error codes** 1047 1048For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1049 1050| ID | Error Message | 1051| ---- | --------------------- | 1052| 202 | Not System App. | 1053| 401 | Parameter error. | 1054| 801 | Capability not supported.| 1055| 10000001 | Memory operation failed. | 1056| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1057| 10000003 | Failed to get system ability manager. | 1058| 10000004 | Failed to access the device usage service. | 1059| 10000006 | Failed to get the application information. | 1060| 10000007 | Failed to get the system time. | 1061 1062**Example** 1063 1064```ts 1065import { BusinessError } from '@kit.BasicServicesKit'; 1066 1067usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 1068 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.'); 1069 for (let i = 0; i < res.length; i++) { 1070 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1)); 1071 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i])); 1072 } 1073}).catch((err: BusinessError) => { 1074 console.error('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 1075}); 1076``` 1077 1078## usageStatistics.queryDeviceEventStats 1079 1080queryDeviceEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 1081 1082Queries 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. 1083 1084**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1085 1086**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1087 1088**Parameters** 1089 1090| Name | Type | Mandatory | Description | 1091| ----- | ------ | ---- | ----- | 1092| begin | number | Yes | Start time, in milliseconds.| 1093| end | number | Yes | End time, in milliseconds.| 1094 1095**Return value** 1096 1097| Type | Description | 1098| ---------------------------------------- | ---------------------------------------- | 1099| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise used to return the statistics about system events.| 1100 1101**Error codes** 1102 1103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1104 1105| ID | Error Message | 1106| ---- | --------------------- | 1107| 201 | Permission denied. | 1108| 202 | Not System App. | 1109| 401 | Parameter error. | 1110| 801 | Capability not supported.| 1111| 10000001 | Memory operation failed. | 1112| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1113| 10000003 | Failed to get system ability manager. | 1114| 10000004 | Failed to access the device usage service. | 1115| 10000006 | Failed to get the application information. | 1116| 10000007 | Failed to get the system time. | 1117 1118**Example** 1119 1120```ts 1121import { BusinessError } from '@kit.BasicServicesKit'; 1122 1123usageStatistics.queryDeviceEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1124 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.'); 1125 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res)); 1126}).catch((err: BusinessError) => { 1127 console.error('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1128}); 1129``` 1130 1131## usageStatistics.queryDeviceEventStats 1132 1133queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1134 1135Queries 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. 1136 1137**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1138 1139**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1140 1141**Parameters** 1142 1143| Name | Type | Mandatory | Description | 1144| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1145| begin | number | Yes | Start time, in milliseconds. | 1146| end | number | Yes | End time, in milliseconds. | 1147| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | Yes | Callback used to return the statistics about system events.| 1148 1149**Error codes** 1150 1151For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1152 1153| ID | Error Message | 1154| ---- | --------------------- | 1155| 201 | Permission denied. | 1156| 202 | Not System App. | 1157| 401 | Parameter error. | 1158| 801 | Capability not supported.| 1159| 10000001 | Memory operation failed. | 1160| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1161| 10000003 | Failed to get system ability manager. | 1162| 10000004 | Failed to access the device usage service. | 1163| 10000006 | Failed to get the application information. | 1164| 10000007 | Failed to get the system time. | 1165 1166**Example** 1167 1168```ts 1169import { BusinessError } from '@kit.BasicServicesKit'; 1170 1171usageStatistics.queryDeviceEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1172 if(err) { 1173 console.error('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1174 } else { 1175 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.'); 1176 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res)); 1177 } 1178}); 1179``` 1180 1181## usageStatistics.queryNotificationEventStats 1182 1183queryNotificationEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 1184 1185Queries 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. 1186 1187**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1188 1189**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1190 1191**Parameters** 1192 1193| Name | Type | Mandatory | Description | 1194| ----- | ------ | ---- | ----- | 1195| begin | number | Yes | Start time, in milliseconds.| 1196| end | number | Yes | End time, in milliseconds.| 1197 1198**Return value** 1199 1200| Type | Description | 1201| ---------------------------------------- | ---------------------------------------- | 1202| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise used to return the number of notifications.| 1203 1204**Error codes** 1205 1206For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1207 1208| ID | Error Message | 1209| ---- | --------------------- | 1210| 201 | Permission denied. | 1211| 202 | Not System App. | 1212| 401 | Parameter error. | 1213| 801 | Capability not supported.| 1214| 10000001 | Memory operation failed. | 1215| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1216| 10000003 | Failed to get system ability manager. | 1217| 10000004 | Failed to access the device usage service. | 1218| 10000006 | Failed to get the application information. | 1219| 10000007 | Failed to get the system time. | 1220 1221**Example** 1222 1223```ts 1224import { BusinessError } from '@kit.BasicServicesKit'; 1225 1226usageStatistics.queryNotificationEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1227 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.'); 1228 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res)); 1229}).catch((err: BusinessError) => { 1230 console.error('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1231}); 1232``` 1233 1234## usageStatistics.queryNotificationEventStats 1235 1236queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1237 1238Queries 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. 1239 1240**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1241 1242**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1243 1244**Parameters** 1245 1246| Name | Type | Mandatory | Description | 1247| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1248| begin | number | Yes | Start time, in milliseconds. | 1249| end | number | Yes | End time, in milliseconds. | 1250| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | Yes | Callback used to return the number of notifications.| 1251 1252**Error codes** 1253 1254For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1255 1256| ID | Error Message | 1257| ---- | --------------------- | 1258| 201 | Permission denied. | 1259| 202 | Not System App. | 1260| 401 | Parameter error. | 1261| 801 | Capability not supported.| 1262| 10000001 | Memory operation failed. | 1263| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1264| 10000003 | Failed to get system ability manager. | 1265| 10000004 | Failed to access the device usage service. | 1266| 10000006 | Failed to get the application information. | 1267| 10000007 | Failed to get the system time. | 1268 1269**Example** 1270 1271```ts 1272import { BusinessError } from '@kit.BasicServicesKit'; 1273 1274usageStatistics.queryNotificationEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1275 if(err) { 1276 console.error('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1277 } else { 1278 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.'); 1279 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res)); 1280 } 1281}); 1282``` 1283 1284## usageStatistics.queryModuleUsageRecords 1285 1286queryModuleUsageRecords(): Promise<Array<HapModuleInfo>> 1287 1288Queries 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. 1289 1290Queries FA usage records. This API uses a promise to return a maximum of 1000 FA usage records sorted by time (most recent first). 1291 1292**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1293 1294**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1295 1296**Return value** 1297 1298| Type | Description | 1299| ---------------------------------------- | ---------------------------------- | 1300| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise used to return the result. A maximum of 1000 usage records can be returned.| 1301 1302**Error codes** 1303 1304For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1305 1306| ID | Error Message | 1307| ---- | --------------------- | 1308| 201 | Permission denied. | 1309| 202 | Not System App. | 1310| 401 | Parameter error. | 1311| 801 | Capability not supported.| 1312| 10000001 | Memory operation failed. | 1313| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1314| 10000003 | Failed to get system ability manager. | 1315| 10000004 | Failed to access the device usage service. | 1316| 10000006 | Failed to get the application information. | 1317| 10000007 | Failed to get the system time. | 1318 1319**Example** 1320 1321```ts 1322// Invocation when maxNum is not passed 1323import { BusinessError } from '@kit.BasicServicesKit'; 1324 1325usageStatistics.queryModuleUsageRecords().then((res: Array<usageStatistics.HapModuleInfo>) => { 1326 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1327 for (let i = 0; i < res.length; i++) { 1328 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1329 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1330 } 1331}).catch((err: BusinessError) => { 1332 console.error('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1333}); 1334``` 1335 1336## usageStatistics.queryModuleUsageRecords 1337 1338queryModuleUsageRecords(callback: AsyncCallback<Array<HapModuleInfo>>): void 1339 1340Queries 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. 1341 1342**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1343 1344**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1345 1346**Parameters** 1347 1348| Name | Type | Mandatory | Description | 1349| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1350| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | Yes | Callback used to return the result. A maximum of 1000 usage records can be returned.| 1351 1352**Error codes** 1353 1354For details about the error codes, see [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1355 1356| ID | Error Message | 1357| ---------- | ---------------------------- | 1358| 10000001 | Memory operation failed. | 1359| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1360| 10000003 | Failed to get system ability manager. | 1361| 10000004 | Failed to access the device usage service. | 1362| 10000006 | Failed to get the application information. | 1363| 10000007 | Failed to get the system time. | 1364 1365**Example** 1366 1367```ts 1368import { BusinessError } from '@kit.BasicServicesKit'; 1369 1370usageStatistics.queryModuleUsageRecords((err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1371 if(err) { 1372 console.error('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1373 } else { 1374 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1375 for (let i = 0; i < res.length; i++) { 1376 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1377 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1378 } 1379 } 1380}); 1381``` 1382 1383## usageStatistics.queryModuleUsageRecords 1384 1385queryModuleUsageRecords(maxNum: number): Promise<Array<HapModuleInfo>> 1386 1387Queries 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. 1388 1389**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1390 1391**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1392 1393**Parameters** 1394 1395| Name | Type | Mandatory | Description | 1396| ------ | ------ | ---- | ---------------------------------- | 1397| maxNum | number | Yes | Number of usage records, in the range [1, 1000].| 1398 1399**Return value** 1400 1401| Type | Description | 1402| ---------------------------------------- | ---------------------------------- | 1403| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise used to return the result. The usage records returned does not exceed the value of **maxNum**.| 1404 1405**Error codes** 1406 1407For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1408 1409| ID | Error Message | 1410| ---- | --------------------- | 1411| 201 | Permission denied. | 1412| 202 | Not System App. | 1413| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1414| 801 | Capability not supported.| 1415| 10000001 | Memory operation failed. | 1416| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1417| 10000003 | Failed to get system ability manager. | 1418| 10000004 | Failed to access the device usage service. | 1419| 10000006 | Failed to get the application information. | 1420| 10000007 | Failed to get the system time. | 1421 1422**Example** 1423 1424```ts 1425import { BusinessError } from '@kit.BasicServicesKit'; 1426 1427usageStatistics.queryModuleUsageRecords(1000).then((res: Array<usageStatistics.HapModuleInfo>) => { 1428 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1429 for (let i = 0; i < res.length; i++) { 1430 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1431 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1432 } 1433}).catch((err: BusinessError) => { 1434 console.error('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1435}); 1436``` 1437 1438## usageStatistics.queryModuleUsageRecords 1439 1440queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapModuleInfo>>): void 1441 1442Queries 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. 1443 1444**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1445 1446**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1447 1448**Parameters** 1449 1450| Name | Type | Mandatory | Description | 1451| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1452| maxNum | number | Yes | Number of usage records, in the range [1, 1000].| 1453| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | Yes | Callback used to return the result. The usage records returned does not exceed the value of **maxNum**.| 1454 1455**Error codes** 1456 1457For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1458 1459| ID | Error Message | 1460| ---- | --------------------- | 1461| 201 | Permission denied. | 1462| 202 | Not System App. | 1463| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1464| 801 | Capability not supported.| 1465| 10000001 | Memory operation failed. | 1466| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1467| 10000003 | Failed to get system ability manager. | 1468| 10000004 | Failed to access the device usage service. | 1469| 10000006 | Failed to get the application information. | 1470| 10000007 | Failed to get the system time. | 1471 1472**Example** 1473 1474```ts 1475import { BusinessError } from '@kit.BasicServicesKit'; 1476 1477usageStatistics.queryModuleUsageRecords(1000, (err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1478 if(err) { 1479 console.error('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1480 } else { 1481 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1482 for (let i = 0; i < res.length; i++) { 1483 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1484 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1485 } 1486 } 1487}); 1488``` 1489 1490## usageStatistics.registerAppGroupCallBack 1491 1492registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): Promise<void> 1493 1494Registers 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. 1495 1496**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1497 1498**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1499 1500**Parameters** 1501 1502| Name | Type | Mandatory| Description | 1503| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 1504| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | Yes | Application group change information.| 1505 1506**Return value** 1507 1508| Type | Description | 1509| ------------- | ----------------------- | 1510| Promise<void> | Promise that returns no value.| 1511 1512**Error codes** 1513 1514For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1515 1516| ID | Error Message | 1517| ---- | --------------------- | 1518| 201 | Permission denied. | 1519| 202 | Not System App. | 1520| 401 | Parameter error. | 1521| 801 | Capability not supported.| 1522| 10000001 | Memory operation failed. | 1523| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1524| 10000003 | Failed to get system ability manager. | 1525| 10000004 | Failed to access the device usage service. | 1526| 10100001 | Repeated operation on the application group. | 1527 1528 1529**Example** 1530 1531```ts 1532import { BusinessError } from '@kit.BasicServicesKit'; 1533 1534function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1535 console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.'); 1536 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1537 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1538 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1539 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1540 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1541}; 1542usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => { 1543 console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.'); 1544}).catch((err: BusinessError) => { 1545 console.error('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1546}); 1547``` 1548 1549## usageStatistics.registerAppGroupCallBack 1550 1551registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void 1552 1553Registers 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. 1554 1555**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1556 1557**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1558 1559**Parameters** 1560 1561| Name | Type | Mandatory| Description | 1562| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- | 1563| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | Yes | Application group change information. | 1564| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1565 1566**Error codes** 1567 1568For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1569 1570| ID | Error Message | 1571| ---- | --------------------- | 1572| 201 | Permission denied. | 1573| 202 | Not System App. | 1574| 401 | Parameter error. | 1575| 801 | Capability not supported.| 1576| 10000001 | Memory operation failed. | 1577| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1578| 10000003 | Failed to get system ability manager. | 1579| 10000004 | Failed to access the device usage service. | 1580| 10100001 | Repeated operation on the application group. | 1581 1582 1583**Example** 1584 1585```ts 1586import { BusinessError } from '@kit.BasicServicesKit'; 1587 1588function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1589 console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); 1590 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1591 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1592 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1593 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1594 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1595}; 1596usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err: BusinessError) => { 1597 if(err) { 1598 console.error('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1599 } else { 1600 console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.'); 1601 } 1602}); 1603``` 1604 1605## usageStatistics.unregisterAppGroupCallBack 1606 1607unregisterAppGroupCallBack(): Promise<void> 1608 1609Unregisters the callback for application group changes. This API uses a promise to return the result. 1610 1611**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1612 1613**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1614 1615**Return value** 1616 1617| Type | Description | 1618| ------------- | ------------------------ | 1619| Promise<void> | Promise that returns no value.| 1620 1621**Error codes** 1622 1623For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1624 1625| ID | Error Message | 1626| ---- | --------------------- | 1627| 201 | Permission denied. | 1628| 202 | Not System App. | 1629| 401 | Parameter error. | 1630| 801 | Capability not supported.| 1631| 10000001 | Memory operation failed. | 1632| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1633| 10000003 | Failed to get system ability manager. | 1634| 10000004 | Failed to access the device usage service. | 1635| 10100001 | Repeated operation on the application group. | 1636 1637**Example** 1638 1639```ts 1640import { BusinessError } from '@kit.BasicServicesKit'; 1641 1642usageStatistics.unregisterAppGroupCallBack().then( () => { 1643 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.'); 1644}).catch((err: BusinessError) => { 1645 console.error('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1646}); 1647``` 1648 1649## usageStatistics.unregisterAppGroupCallBack 1650 1651unregisterAppGroupCallBack(callback: AsyncCallback<void>): void; 1652 1653Unregisters the callback for application group changes. This API uses an asynchronous callback to return the result. 1654 1655**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO 1656 1657**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1658 1659**Parameters** 1660 1661| Name | Type | Mandatory | Description | 1662| -------- | ------------------- | ---- | -------------- | 1663| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 1664 1665**Error codes** 1666 1667For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [DeviceUsageStatistics Error Codes](errorcode-DeviceUsageStatistics.md). 1668 1669| ID | Error Message | 1670| ---- | --------------------- | 1671| 201 | Permission denied. | 1672| 202 | Not System App. | 1673| 401 | Parameter error. | 1674| 801 | Capability not supported.| 1675| 10000001 | Memory operation failed. | 1676| 10000002 | Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory. | 1677| 10000003 | Failed to get system ability manager. | 1678| 10000004 | Failed to access the device usage service. | 1679| 10100001 | Repeated operation on the application group. | 1680 1681**Example** 1682 1683```ts 1684import { BusinessError } from '@kit.BasicServicesKit'; 1685 1686usageStatistics.unregisterAppGroupCallBack((err: BusinessError) => { 1687 if(err) { 1688 console.error('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1689 } else { 1690 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.'); 1691 } 1692}); 1693``` 1694 1695## HapModuleInfo 1696 1697Defines the information about the usage record in the FA model. 1698 1699**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1700 1701| Name | Type | Mandatory | Description | 1702| -------------------- | ---------------------------------------- | ---- | ----------------------------- | 1703| deviceId | string | No | Device ID. | 1704| bundleName | string | Yes | Bundle name. | 1705| moduleName | string | Yes | Name of the module to which the FA belongs. | 1706| abilityName | string | No | **MainAbility** name of the FA. | 1707| appLabelId | number | No | Application label ID of the FA. | 1708| labelId | number | No | Label ID of the module to which the FA belongs. | 1709| descriptionId | number | No | Description ID of the application to which the FA belongs. | 1710| abilityLableId | number | No | **MainAbility** label ID of the FA. | 1711| abilityDescriptionId | number | No | **MainAbility** description ID of the FA.| 1712| abilityIconId | number | No | **MainAbility** icon ID of the FA. | 1713| launchedCount | number | Yes | Number of FA startup times. | 1714| lastModuleUsedTime | number | Yes | Last time when the FA was used. | 1715| formRecords | Array<[HapFormInfo](#hapforminfo)> | Yes | Array of widget usage records in the FA. | 1716 1717## HapFormInfo 1718 1719Defines the information about the usage record of FA widgets. 1720 1721**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1722 1723| Name | Type | Mandatory | Description | 1724| ---------------- | ------ | ---- | ----------- | 1725| formName | string | Yes | Widget name. | 1726| formDimension | number | Yes | Widget dimensions. | 1727| formId | number | Yes | Widget ID. | 1728| formLastUsedTime | number | Yes | Last time when the widget was clicked.| 1729| count | number | Yes | Number of clicks on the widget. | 1730 1731## AppGroupCallbackInfo 1732 1733Provides the application group changes returned through a callback. 1734 1735**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1736 1737| Name | Type | Mandatory| Description | 1738| ---------------- | ------ | ---- | ---------------- | 1739| appOldGroup | number | Yes | Application group before the change.| 1740| appNewGroup | number | Yes | Application group after the change.| 1741| userId | number | Yes | User ID. | 1742| 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.| 1743| bundleName | string | Yes | Bundle name. | 1744 1745## BundleStatsInfo 1746 1747Provides the usage duration information of an application. 1748 1749**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1750 1751| Name | Type | Mandatory | Description | 1752| ------------------------ | ------ | ---- | ---------------------------------------- | 1753| bundleName | string | No | Bundle name of the application. | 1754| abilityPrevAccessTime | number | No | Last time when the application was used. | 1755| abilityInFgTotalTime | number | No | Total time that the application runs in the foreground. | 1756| id | number | Yes | User ID.| 1757| abilityPrevSeenTime | number | No | Last time when the application was visible in the foreground.| 1758| abilitySeenTotalTime | number | No | Total time that the application is visible in the foreground.| 1759| fgAbilityAccessTotalTime | number | No | Total time that the application accesses the foreground.| 1760| fgAbilityPrevAccessTime | number | No | Last time when the application accessed the foreground.| 1761| infosBeginTime | number | No | Time logged in the first application usage record in the **BundleActiveInfo** object.| 1762| infosEndTime | number | No | Time logged in the last application usage record in the **BundleActiveInfo** object.| 1763| appIndex<sup>15+</sup> | number | No | Application index.| 1764 1765## BundleEvents 1766 1767Provides information about an application event. 1768 1769**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1770 1771| Name | Type | Mandatory | Description | 1772| --------------------- | ------ | ---- | ---------------------------------------- | 1773| bundleName | string | No | Bundle name of the application. | 1774| eventId | number | No | Application event type. | 1775| eventOccurredTime | number | No | Timestamp when the application event occurs. | 1776| appGroup | number | No | Group of the application by usage priority.| 1777| indexOfLink | string | No | Shortcut ID.| 1778| nameOfClass | string | No | Class name.| 1779 1780## BundleStatsMap 1781 1782Provides the usage duration information of an application. 1783 1784**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1785 1786|Name | Description | 1787| ------------------------------ | ---------------------------------------- | 1788| Record<string, [BundleStatsInfo](#bundlestatsinfo)> | Usage duration information by application.| 1789 1790## AppStatsMap<sup>15+</sup> 1791 1792Provides the detailed usage information of an application (including application clones). 1793 1794**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1795 1796|Name | Description | 1797| ------------------------------ | ---------------------------------------- | 1798| Record<string, Array<[BundleStatsInfo](#bundlestatsinfo)>> | Usage information by application (including application clones).| 1799 1800## DeviceEventStats 1801 1802Provides statistics about notifications and system events. 1803 1804**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1805 1806| Name | Type | Mandatory | Description | 1807| ------- | ------ | ---- | ----------------- | 1808| name | string | Yes | Bundle name of the notification sending application or system event name. | 1809| eventId | number | Yes | Type of the notification or system event. | 1810| count | number | Yes | Number of application notifications or system event triggering times.| 1811 1812## IntervalType 1813 1814Enumerates the interval types for querying the application usage duration. 1815 1816**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App 1817 1818| Name | Value | Description | 1819| ------------ | ---- | ---------------------------------------- | 1820| BY_OPTIMIZED | 0 | The system queries the application usage duration statistics in the specified time frame at the interval the system deems appropriate.| 1821| BY_DAILY | 1 | The system queries the application usage duration statistics in the specified time frame on a daily basis. | 1822| BY_WEEKLY | 2 | The system queries the application usage duration statistics in the specified time frame on a weekly basis. | 1823| BY_MONTHLY | 3 | The system queries the application usage duration statistics in the specified time frame on a monthly basis. | 1824| BY_ANNUALLY | 4 | The system queries the application usage duration statistics in the specified time frame on an annual basis. | 1825 1826## GroupType 1827 1828Enumerates the application group types. 1829 1830**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1831 1832| Name | Value | Description | 1833| ------------------ | ---- | ----------------- | 1834| ALIVE_GROUP | 10 | Group of active applications. | 1835| DAILY_GROUP | 20 | Group of frequently used applications that are not in the active state. | 1836| FIXED_GROUP | 30 | Group of applications that are used periodically but not every day.| 1837| RARE_GROUP | 40 | Group of rarely used applications. | 1838| LIMITED_GROUP | 50 | Group of restricted applications. | 1839| NEVER_GROUP | 60 | Group of applications that have been installed but never run. | 1840