1# @ohos.resourceschedule.usageStatistics (设备使用信息统计)(系统接口) 2 3本模块提供设备使用信息统计能力,包括查询应用是否为常用应用、优先级分组、使用时长、系统事件(休眠、唤醒、解锁、锁屏)信息、应用事件(前台、后台、长时任务开始和结束)信息、通知次数等不同类型信息。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口为系统接口。 10 11## 导入模块 12 13``` 14import { usageStatistics } from '@kit.BackgroundTasksKit' 15``` 16 17## usageStatistics.isIdleState 18 19isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void 20 21查询指定的应用是否为常用应用(GroupType值≤30),使用Callback形式返回。 22 23**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 24 25**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 26 27**参数**: 28 29| 参数名 | 类型 | 必填 | 说明 | 30| ---------- | ---------------------------- | ---- | ---------------------------------------- | 31| bundleName | string | 是 | 应用的bundleName。 | 32| callback | AsyncCallback<boolean> | 是 | 回调函数。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 33 34**错误码**: 35 36以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 37 38| 错误码ID | 错误信息 | 39| ---- | --------------------- | 40| 201 | Permission denied. | 41| 202 | Not System App. | 42| 401 | Parameter error. | 43| 801 | Capability not supported.| 44| 10000001 | Memory operation failed. | 45| 10000002 | Parcel operation failed. | 46| 10000003 | System service operation failed. | 47| 10000004 | IPC failed. | 48| 10000006 | Failed to get the application information. | 49 50**示例**: 51```ts 52import { BusinessError } from '@kit.BasicServicesKit'; 53 54usageStatistics.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => { 55 if (err) { 56 console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message); 57 } else { 58 console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res)); 59 } 60}); 61``` 62 63## usageStatistics.isIdleState 64 65isIdleState(bundleName: string): Promise<boolean> 66 67查询指定的应用是否为常用应用(GroupType值≤30),使用Promise异步回调。 68 69**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 70 71**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 72 73**参数**: 74 75| 参数名 | 类型 | 必填 | 说明 | 76| ---------- | ------ | ---- | -------------- | 77| bundleName | string | 是 | 应用的bundleName。 | 78 79**返回值**: 80 81| 类型 | 说明 | 82| ---------------------- | ---------------------------------------- | 83| Promise<boolean> | Promise对象。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 84 85**错误码**: 86 87以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 88 89| 错误码ID | 错误信息 | 90| ---- | --------------------- | 91| 201 | Permission denied. | 92| 202 | Not System App. | 93| 401 | Parameter error. | 94| 801 | Capability not supported.| 95| 10000001 | Memory operation failed. | 96| 10000002 | Parcel operation failed. | 97| 10000003 | System service operation failed. | 98| 10000004 | IPC failed. | 99| 10000006 | Failed to get the application information. | 100 101**示例**: 102 103```ts 104import { BusinessError } from '@kit.BasicServicesKit'; 105 106usageStatistics.isIdleState("com.ohos.camera").then((res: boolean) => { 107 console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); 108}).catch((err: BusinessError) => { 109 console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message); 110}); 111``` 112## usageStatistics.isIdleStateSync<sup>10+<sup> 113 114isIdleStateSync(bundleName: string): boolean 115 116查询指定的应用是否为常用应用(GroupType值≤30),使用同步方式返回。 117 118**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 119 120**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 121 122**参数**: 123 124| 参数名 | 类型 | 必填 | 说明 | 125| ---------- | ---------------------------- | ---- | ---------------------------------------- | 126| bundleName | string | 是 | 应用的bundleName。 | 127 128**返回值**: 129 130| 类型 | 说明 | 131| ---------------------- | ---------------------------------------- | 132| boolean | 若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 133 134**错误码**: 135 136以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 137 138| 错误码ID | 错误信息 | 139| ---- | --------------------- | 140| 201 | Permission denied. | 141| 202 | Not System App. | 142| 401 | Parameter error. | 143| 801 | Capability not supported.| 144| 10000001 | Memory operation failed. | 145| 10000002 | Parcel operation failed. | 146| 10000003 | System service operation failed. | 147| 10000004 | IPC failed. | 148| 10000006 | Failed to get the application information. | 149 150**示例**: 151```ts 152let isIdleState: boolean = usageStatistics.isIdleStateSync("com.ohos.camera"); 153``` 154 155## usageStatistics.queryAppGroup 156 157queryAppGroup(): Promise<number> 158 159查询当前应用的优先级分组,使用Promise异步回调。 160 161**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 162 163**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 164 165**返回值**: 166 167| 类型 | 说明 | 168| --------------- | --------------------------- | 169| Promise<number> | Promise对象。返回当前应用优先级分组结果,值越小,优先级越高。 | 170 171**错误码**: 172 173以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 174 175| 错误码ID | 错误信息 | 176| ---- | --------------------- | 177| 201 | Permission denied. | 178| 202 | Not System App. | 179| 401 | Parameter error. | 180| 801 | Capability not supported.| 181| 10000001 | Memory operation failed. | 182| 10000002 | Parcel operation failed. | 183| 10000003 | System service operation failed. | 184| 10000004 | IPC failed. | 185| 10000005 | Application is not installed. | 186| 10000006 | Failed to get the application information. | 187| 10100002 | Failed to get the application group information. | 188 189**示例**: 190 191```ts 192import { BusinessError } from '@kit.BasicServicesKit'; 193 194usageStatistics.queryAppGroup().then((res: number) => { 195 console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 196}).catch((err: BusinessError) => { 197 console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 198}); 199``` 200 201## usageStatistics.queryAppGroup 202 203queryAppGroup(callback: AsyncCallback<number>): void 204 205查询当前应用的优先级分组,使用Callback异步回调。 206 207**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 208 209**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 210 211**参数**: 212 213| 参数名 | 类型 | 必填 | 说明 | 214| -------- | --------------------- | ---- | -------------------------- | 215| callback | AsyncCallback<number> | 是 | 回调函数,返回当前应用优先级分组结果,值越小,优先级越高。 | 216 217**错误码**: 218 219以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 220 221| 错误码ID | 错误信息 | 222| ---- | --------------------- | 223| 201 | Permission denied. | 224| 202 | Not System App. | 225| 401 | Parameter error. | 226| 801 | Capability not supported.| 227| 10000001 | Memory operation failed. | 228| 10000002 | Parcel operation failed. | 229| 10000003 | System service operation failed. | 230| 10000004 | IPC failed. | 231| 10000005 | Application is not installed. | 232| 10000006 | Failed to get the application information. | 233| 10100002 | Failed to get the application group information. | 234 235**示例**: 236 237```ts 238import { BusinessError } from '@kit.BasicServicesKit'; 239 240usageStatistics.queryAppGroup((err: BusinessError, res: number) => { 241 if(err) { 242 console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 243 } else { 244 console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 245 } 246}); 247``` 248 249## usageStatistics.queryAppGroupSync<sup>10+<sup> 250 251queryAppGroupSync(): number 252 253查询当前应用的优先级分组,使用同步方式返回。 254 255**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 256 257**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 258 259**返回值**: 260 261| 类型 | 说明 | 262| --------------- | --------------------------- | 263| number | 返回当前应用优先级分组结果,值越小,优先级越高。 | 264 265**错误码**: 266 267以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 268 269| 错误码ID | 错误信息 | 270| ---- | --------------------- | 271| 201 | Permission denied. | 272| 202 | Not System App. | 273| 401 | Parameter error. | 274| 801 | Capability not supported.| 275| 10000001 | Memory operation failed. | 276| 10000002 | Parcel operation failed. | 277| 10000003 | System service operation failed. | 278| 10000004 | IPC failed. | 279| 10000005 | Application is not installed. | 280| 10000006 | Failed to get the application information. | 281| 10100002 | Failed to get the application group information. | 282 283**示例**: 284 285```ts 286let priorityGroup: number = usageStatistics.queryAppGroupSync(); 287``` 288 289## usageStatistics.queryAppGroup 290 291queryAppGroup(bundleName : string): Promise<number> 292 293查询指定bundleName应用的优先级分组,使用Promise异步回调。 294 295**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 296 297**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 298 299**参数**: 300 301| 参数名 | 类型 | 必填 | 说明 | 302| ---------- | ------ | ---- | ---------------------------------------- | 303| bundleName | string | 是 | 应用的bundleName。 | 304 305**返回值**: 306 307| 类型 | 说明 | 308| --------------- | --------------------------- | 309| Promise<number> | Promise对象。返回指定应用的优先级分组结果,值越小,优先级越高。 | 310 311**错误码**: 312 313以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 314 315| 错误码ID | 错误信息 | 316| ---- | --------------------- | 317| 201 | Permission denied. | 318| 202 | Not System App. | 319| 401 | Parameter error. | 320| 801 | Capability not supported.| 321| 10000001 | Memory operation failed. | 322| 10000002 | Parcel operation failed. | 323| 10000003 | System service operation failed. | 324| 10000004 | IPC failed. | 325| 10000005 | Application is not installed. | 326| 10000006 | Failed to get the application information. | 327| 10100002 | Failed to get the application group information. | 328 329**示例**: 330 331```javascript 332//有bundleName的promise 333import { BusinessError } from '@kit.BasicServicesKit'; 334 335let bundleName: string = "com.ohos.camera"; 336usageStatistics.queryAppGroup(bundleName).then((res: number) => { 337 console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 338}).catch((err: BusinessError) => { 339 console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 340}); 341``` 342 343## usageStatistics.queryAppGroup 344 345queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void 346 347查询指定bundleName应用的优先级分组,使用Callback异步回调。 348 349**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 350 351**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 352 353**参数**: 354 355| 参数名 | 类型 | 必填 | 说明 | 356| ---------- | --------------------- | ---- | ---------------------------------------- | 357| bundleName | string | 是 | 应用的bundleName。 | 358| callback | AsyncCallback<number> | 是 | 回调函数,返回指定应用的优先级分组结果,值越小,优先级越高。| 359 360**错误码**: 361 362以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 363 364| 错误码ID | 错误信息 | 365| ---- | --------------------- | 366| 201 | Permission denied. | 367| 202 | Not System App. | 368| 401 | Parameter error. | 369| 801 | Capability not supported.| 370| 10000001 | Memory operation failed. | 371| 10000002 | Parcel operation failed. | 372| 10000003 | System service operation failed. | 373| 10000004 | IPC failed. | 374| 10000005 | Application is not installed. | 375| 10000006 | Failed to get the application information. | 376| 10100002 | Failed to get the application group information. | 377 378**示例**: 379 380```ts 381import { BusinessError } from '@kit.BasicServicesKit'; 382 383let bundleName: string = "com.ohos.camera"; 384usageStatistics.queryAppGroup(bundleName, (err: BusinessError, res: number) => { 385 if(err) { 386 console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 387 } else { 388 console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 389 } 390}); 391``` 392 393## usageStatistics.queryAppGroupSync<sup>10+<sup> 394 395queryAppGroupSync(bundleName: string): number 396 397查询指定bundleName应用的优先级分组,使用同步方式返回。 398 399**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 400 401**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 402 403**参数**: 404 405| 参数名 | 类型 | 必填 | 说明 | 406| ---------- | ---------------------------- | ---- | ---------------------------------------- | 407| bundleName | string | 是 | 应用的bundleName。 | 408 409**返回值**: 410 411| 类型 | 说明 | 412| --------------- | --------------------------- | 413| number | 返回应用的优先级分组结果,值越小,优先级越高。 | 414 415**错误码**: 416 417以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 418 419| 错误码ID | 错误信息 | 420| ---- | --------------------- | 421| 201 | Permission denied. | 422| 202 | Not System App. | 423| 401 | Parameter error. | 424| 801 | Capability not supported.| 425| 10000001 | Memory operation failed. | 426| 10000002 | Parcel operation failed. | 427| 10000003 | System service operation failed. | 428| 10000004 | IPC failed. | 429| 10000005 | Application is not installed. | 430| 10000006 | Failed to get the application information. | 431| 10100002 | Failed to get the application group information. | 432 433**示例**: 434 435```ts 436let priorityGroup: number = usageStatistics.queryAppGroupSync("com.ohos.camera"); 437``` 438 439## usageStatistics.setAppGroup 440 441setAppGroup(bundleName: string, newGroup: GroupType): Promise<void> 442 443将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用Promise异步回调。 444 445**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 446 447**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 448 449**参数**: 450 451| 参数名 | 类型 | 必填 | 说明 | 452| ---------- | --------- | ---- | ---- | 453| bundleName | string | 是 | 应用的bundleName。 | 454| newGroup | [GroupType](#grouptype) | 是 | 应用分组类型。 | 455 456**返回值**: 457 458| 类型 | 说明 | 459| ------------- | ------------------------- | 460| Promise<void> | 无返回结果的Promise对象。 | 461 462**错误码**: 463 464以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 465 466| 错误码ID | 错误信息 | 467| ---- | --------------------- | 468| 201 | Permission denied. | 469| 202 | Not System App. | 470| 401 | Parameter error. | 471| 801 | Capability not supported.| 472| 10000001 | Memory operation failed. | 473| 10000002 | Parcel operation failed. | 474| 10000003 | System service operation failed. | 475| 10000004 | IPC failed. | 476| 10000006 | Failed to get the application information. | 477| 10100001 | Repeated operation on the application group. | 478 479**示例**: 480 481```ts 482import { BusinessError } from '@kit.BasicServicesKit'; 483 484let bundleName: string = "com.example.deviceUsageStatistics"; 485let newGroup = usageStatistics.GroupType.DAILY_GROUP; 486 487usageStatistics.setAppGroup(bundleName, newGroup).then( () => { 488 console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.'); 489}).catch((err: BusinessError) => { 490 console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 491}); 492``` 493 494## usageStatistics.setAppGroup 495 496setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void 497 498将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用CallBack异步回调。 499 500**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 501 502**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 503 504**参数**: 505 506| 参数名 | 类型 | 必填 | 说明 | 507| ---------- | ------------------- | ---- | ------------------------- | 508| bundleName | string | 是 | 应用的bundleName。 | 509| newGroup | [GroupType](#grouptype) | 是 | 应用分组类型。 | 510| callback | AsyncCallback<void> | 是 | 回调函数,返回是否设置成功。 | 511 512**错误码**: 513 514以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 515 516| 错误码ID | 错误信息 | 517| ---- | --------------------- | 518| 201 | Permission denied. | 519| 202 | Not System App. | 520| 401 | Parameter error. | 521| 801 | Capability not supported.| 522| 10000001 | Memory operation failed. | 523| 10000002 | Parcel operation failed. | 524| 10000003 | System service operation failed. | 525| 10000004 | IPC failed. | 526| 10000006 | Failed to get the application information. | 527| 10100001 | Repeated operation on the application group. | 528 529**示例**: 530 531```ts 532import { BusinessError } from '@kit.BasicServicesKit'; 533 534let bundleName: string = "com.example.deviceUsageStatistics"; 535let newGroup = usageStatistics.GroupType.DAILY_GROUP; 536 537usageStatistics.setAppGroup(bundleName, newGroup, (err: BusinessError) => { 538 if(err) { 539 console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 540 } else { 541 console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.'); 542 } 543}); 544``` 545 546## usageStatistics.queryBundleStatsInfos 547 548queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void 549 550通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Callback异步回调。 551 552**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 553 554**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 555 556**参数**: 557 558| 参数名 | 类型 | 必填 | 说明 | 559| -------- | ---------------------------------------- | ---- | --------------------------------------- | 560| begin | number | 是 | 起始时间,以毫秒为单位。 | 561| end | number | 是 | 结束时间,以毫秒为单位。 | 562| callback | AsyncCallback<[BundleStatsMap](#bundlestatsmap)> | 是 | 回调函数,返回指定时间段内应用使用时长的具体信息。 | 563 564**错误码**: 565 566以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 567 568| 错误码ID | 错误信息 | 569| ---- | --------------------- | 570| 201 | Permission denied. | 571| 202 | Not System App. | 572| 401 | Parameter error. | 573| 801 | Capability not supported.| 574| 10000001 | Memory operation failed. | 575| 10000002 | Parcel operation failed. | 576| 10000003 | System service operation failed. | 577| 10000004 | IPC failed. | 578| 10000006 | Failed to get the application information. | 579| 10000007 | Failed to get the system time. | 580 581**示例**: 582 583```ts 584import { BusinessError } from '@kit.BasicServicesKit'; 585 586usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err: BusinessError, res:usageStatistics.BundleStatsMap) => { 587 if (err) { 588 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message); 589 } else { 590 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.'); 591 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res)); 592 } 593}); 594``` 595 596## usageStatistics.queryBundleStatsInfos 597 598queryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap> 599 600通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Promise异步回调。 601 602**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 603 604**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 605 606**参数**: 607 608| 参数名 | 类型 | 必填 | 说明 | 609| ----- | ------ | ---- | ----- | 610| begin | number | 是 | 起始时间,以毫秒为单位。 | 611| end | number | 是 | 结束时间,以毫秒为单位。 | 612 613**返回值**: 614 615| 类型 | 说明 | 616| ---------------------------------------- | -------------------------------------- | 617| Promise<[BundleStatsMap](#bundlestatsmap)> | Promise对象。返回指定时间段内应用使用时长的具体信息。 | 618 619**错误码**: 620 621以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 622 623| 错误码ID | 错误信息 | 624| ---- | --------------------- | 625| 201 | Permission denied. | 626| 202 | Not System App. | 627| 401 | Parameter error. | 628| 801 | Capability not supported.| 629| 10000001 | Memory operation failed. | 630| 10000002 | Parcel operation failed. | 631| 10000003 | System service operation failed. | 632| 10000004 | IPC failed. | 633| 10000006 | Failed to get the application information. | 634| 10000007 | Failed to get the system time. | 635 636**示例**: 637 638```ts 639import { BusinessError } from '@kit.BasicServicesKit'; 640 641usageStatistics.queryBundleStatsInfos(0, 20000000000000).then((res:usageStatistics.BundleStatsMap) => { 642 console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.'); 643 console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res)); 644}).catch((err: BusinessError) => { 645 console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message); 646}); 647``` 648 649## usageStatistics.queryAppStatsInfos<sup>15+</sup> 650 651queryAppStatsInfos(begin: number, end: number): Promise<AppStatsMap> 652 653通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Promise异步回调。 654 655**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 656 657**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 658 659**参数**: 660 661| 参数名 | 类型 | 必填 | 说明 | 662| ----- | ------ | ---- | ----- | 663| begin | number | 是 | 起始时间,以毫秒为单位。 | 664| end | number | 是 | 结束时间,以毫秒为单位。 | 665 666**返回值**: 667 668| 类型 | 说明 | 669| ---------------------------------------- | -------------------------------------- | 670| Promise<[AppStatsMap](#appstatsmap15)> | Promise对象。返回指定时间段内应用使用的具体信息。 | 671 672**错误码**: 673 674以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 675 676| 错误码ID | 错误信息 | 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**示例**: 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 706通过指定bundleName和应用的index,查询应用使用具体信息,统计的最小颗粒度是天,使用Promise异步回调。 707 708**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 709 710**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 711 712**参数**: 713 714| 参数名 | 类型 | 必填 | 说明 | 715| ----- | ------ | ---- | ----- | 716| appInfo | Record<string, Array<number>> | 是 | 参数为map结构,key是bundleName,value是查询应用的index(可以有多个,通过Array传入)。 | 717 718**返回值**: 719 720| 类型 | 说明 | 721| ---------------------------------------- | -------------------------------------- | 722| Promise<[AppStatsMap](#appstatsmap15)> | Promise对象。返回指定bundleName和index应用使用的具体信息。 | 723 724**错误码**: 725 726以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 727 728| 错误码ID | 错误信息 | 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**示例**: 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 758通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Callback异步回调。 759 760**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 761 762**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 763 764**参数**: 765 766| 参数名 | 类型 | 必填 | 说明 | 767| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 768| byInterval | [IntervalType](#intervaltype) | 是 | 查询类型。 | 769| begin | number | 是 | 起始时间,以毫秒为单位。 | 770| end | number | 是 | 结束时间,以毫秒为单位。 | 771| callback | AsyncCallback<Array<[BundleStatsInfo](#bundlestatsinfo)>> | 是 | 回调函数,返回指定时间段间隔内,应用使用时长的统计信息。 | 772 773**错误码**: 774 775以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 776 777| 错误码ID | 错误信息 | 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**示例**: 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 812通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Promise异步回调。 813 814**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 815 816**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 817 818**参数**: 819 820| 参数名 | 类型 | 必填 | 说明 | 821| ---------- | ----------------------------- | ---- | ----- | 822| byInterval | [IntervalType](#intervaltype) | 是 | 查询类型。 | 823| begin | number | 是 | 起始时间,以毫秒为单位。 | 824| end | number | 是 | 结束时间,以毫秒为单位。 | 825 826**返回值**: 827 828| 类型 | 说明 | 829| ---------------------------------------- | ---------------------------------------- | 830| Promise<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Promise对象。返回指定时间段间隔内,应用使用时长的统计信息。 | 831 832**错误码**: 833 834以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 835 836| 错误码ID | 错误信息 | 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**示例**: 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 869通过指定起始和结束时间,查询所有应用的事件集合,使用Callback异步回调。 870 871**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 872 873**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 874 875**参数**: 876 877| 参数名 | 类型 | 必填 | 说明 | 878| -------- | ---------------------------------------- | ---- | --------------------------------------- | 879| begin | number | 是 | 起始时间,以毫秒为单位。 | 880| end | number | 是 | 结束时间,以毫秒为单位。 | 881| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | 是 | 回调函数,返回起始和结束时间段内,所有应用的事件集合。 | 882 883**错误码**: 884 885以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 886 887| 错误码ID | 错误信息 | 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**示例**: 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 922通过指定起始和结束时间,查询所有应用的事件集合,使用Promise异步回调。 923 924**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 925 926**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 927 928**参数**: 929 930| 参数名 | 类型 | 必填 | 说明 | 931| ----- | ------ | ---- | ----- | 932| begin | number | 是 | 起始时间,以毫秒为单位。 | 933| end | number | 是 | 结束时间,以毫秒为单位。 | 934 935**返回值**: 936 937| 类型 | 说明 | 938| ---------------------------------------- | -------------------------------------- | 939| Promise<Array<[BundleEvents](#bundleevents)>> | Promise对象。返回起始和结束时间段内,所有应用的事件集合。 | 940 941**错误码**: 942 943以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 944 945| 错误码ID | 错误信息 | 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**示例**: 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 978通过指定起始和结束时间,查询当前应用的事件集合,使用Callback异步回调。 979 980**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 981 982**参数**: 983 984| 参数名 | 类型 | 必填 | 说明 | 985| -------- | ---------------------------------------- | ---- | --------------------------------------- | 986| begin | number | 是 | 起始时间,以毫秒为单位。 | 987| end | number | 是 | 结束时间,以毫秒为单位。 | 988| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | 是 | 回调函数,返回指定起始和结束时间段内,当前应用的事件集合。 | 989 990**错误码**: 991 992以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 993 994| 错误码ID | 错误信息 | 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**示例**: 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 1028通过指定起始和结束时间段内,查询当前应用的事件集合,使用Promise异步回调。 1029 1030**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1031 1032**参数**: 1033 1034| 参数名 | 类型 | 必填 | 说明 | 1035| ----- | ------ | ---- | ----- | 1036| begin | number | 是 | 起始时间,以毫秒为单位。 | 1037| end | number | 是 | 结束时间,以毫秒为单位。 | 1038 1039**返回值**: 1040 1041| 类型 | 说明 | 1042| ---------------------------------------- | -------------------------------------- | 1043| Promise<Array<[BundleEvents](#bundleevents)>> | Promise对象。返回指定起始和结束时间段内,当前应用的事件集合。 | 1044 1045**错误码**: 1046 1047以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1048 1049| 错误码ID | 错误信息 | 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**示例**: 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 1081通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Promise异步回调。 1082 1083**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1084 1085**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1086 1087**参数**: 1088 1089| 参数名 | 类型 | 必填 | 说明 | 1090| ----- | ------ | ---- | ----- | 1091| begin | number | 是 | 起始时间,以毫秒为单位。 | 1092| end | number | 是 | 结束时间,以毫秒为单位。 | 1093 1094**返回值**: 1095 1096| 类型 | 说明 | 1097| ---------------------------------------- | ---------------------------------------- | 1098| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise对象。返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 | 1099 1100**错误码**: 1101 1102以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1103 1104| 错误码ID | 错误信息 | 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**示例**: 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 1134通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Callback异步回调。 1135 1136**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1137 1138**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1139 1140**参数**: 1141 1142| 参数名 | 类型 | 必填 | 说明 | 1143| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1144| begin | number | 是 | 起始时间,以毫秒为单位。 | 1145| end | number | 是 | 结束时间,以毫秒为单位。 | 1146| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | 是 | 回调函数,返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 | 1147 1148**错误码**: 1149 1150以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1151 1152| 错误码ID | 错误信息 | 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**示例**: 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 1184通过指定起始和结束时间,查询所有应用的通知次数,使用Promise异步回调。 1185 1186**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1187 1188**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1189 1190**参数**: 1191 1192| 参数名 | 类型 | 必填 | 说明 | 1193| ----- | ------ | ---- | ----- | 1194| begin | number | 是 | 起始时间,以毫秒为单位。 | 1195| end | number | 是 | 结束时间,以毫秒为单位。 | 1196 1197**返回值**: 1198 1199| 类型 | 说明 | 1200| ---------------------------------------- | ---------------------------------------- | 1201| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise对象。返回指定起始和结束时间段内,所有应用的通知次数。 | 1202 1203**错误码**: 1204 1205以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1206 1207| 错误码ID | 错误信息 | 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**示例**: 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 1237通过指定起始和结束时间,查询所有应用的通知次数,使用Callback异步回调。 1238 1239**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1240 1241**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1242 1243**参数**: 1244 1245| 参数名 | 类型 | 必填 | 说明 | 1246| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1247| begin | number | 是 | 起始时间,以毫秒为单位。 | 1248| end | number | 是 | 结束时间,以毫秒为单位。 | 1249| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | 是 | 回调函数,返回指定起始和结束时间段内,所有应用的通知次数。 | 1250 1251**错误码**: 1252 1253以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1254 1255| 错误码ID | 错误信息 | 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**示例**: 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 1287查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。 1288 1289使用Promise形式返回不超过1000条FA使用记录,FA使用记录由近及远排序。 1290 1291**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1292 1293**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1294 1295**返回值**: 1296 1297| 类型 | 说明 | 1298| ---------------------------------------- | ---------------------------------- | 1299| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise对象。返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 | 1300 1301**错误码**: 1302 1303以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1304 1305| 错误码ID | 错误信息 | 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**示例**: 1319 1320```ts 1321// 无maxNum参数调用方式 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 1339查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用CallBack异步回调。 1340 1341**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1342 1343**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1344 1345**参数**: 1346 1347| 参数名 | 类型 | 必填 | 说明 | 1348| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1349| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | 是 | 回调函数,返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 | 1350 1351**错误码**: 1352 1353以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1354 1355| 错误码ID | 错误信息 | 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**示例**: 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 1386根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。 1387 1388**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1389 1390**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1391 1392**参数**: 1393 1394| 参数名 | 类型 | 必填 | 说明 | 1395| ------ | ------ | ---- | ---------------------------------- | 1396| maxNum | number | 是 | 使用记录的条数,取值范围为[1,1000]。 | 1397 1398**返回值**: 1399 1400| 类型 | 说明 | 1401| ---------------------------------------- | ---------------------------------- | 1402| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise对象,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 | 1403 1404**错误码**: 1405 1406以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1407 1408| 错误码ID | 错误信息 | 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**示例**: 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 1441根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Callback异步回调。 1442 1443**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1444 1445**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1446 1447**参数**: 1448 1449| 参数名 | 类型 | 必填 | 说明 | 1450| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1451| maxNum | number | 是 | 使用记录的条数,取值范围为[1,1000]。 | 1452| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | 是 | 回调方法,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 | 1453 1454**错误码**: 1455 1456以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1457 1458| 错误码ID | 错误信息 | 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**示例**: 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 1493注册应用分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Promise异步回调。 1494 1495**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1496 1497**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1498 1499**参数**: 1500 1501| 参数名 | 类型 | 必填 | 说明 | 1502| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 1503| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | 是 | 返回的应用分组变化信息。 | 1504 1505**返回值**: 1506 1507| 类型 | 说明 | 1508| ------------- | ----------------------- | 1509| Promise<void> | 无返回结果的Promise对象。 | 1510 1511**错误码**: 1512 1513以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1514 1515| 错误码ID | 错误信息 | 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**示例**: 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 1552应用注册分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Callback异步回调。 1553 1554**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1555 1556**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1557 1558**参数**: 1559 1560| 参数名 | 类型 | 必填 | 说明 | 1561| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- | 1562| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | 是 | 返回的应用分组变化信息。 | 1563| callback | AsyncCallback<void> | 是 | 回调函数,返回注册监听是否成功。 | 1564 1565**错误码**: 1566 1567以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1568 1569| 错误码ID | 错误信息 | 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**示例**: 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 1608应用解除分组变化监听。使用Promise异步回调。 1609 1610**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1611 1612**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1613 1614**返回值**: 1615 1616| 类型 | 说明 | 1617| ------------- | ------------------------ | 1618| Promise<void> | 无返回结果的Promise对象。 | 1619 1620**错误码**: 1621 1622以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1623 1624| 错误码ID | 错误信息 | 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**示例**: 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 1652应用解除分组变化监听。使用callback异步回调。 1653 1654**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1655 1656**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1657 1658**参数**: 1659 1660| 参数名 | 类型 | 必填 | 说明 | 1661| -------- | ------------------- | ---- | -------------- | 1662| callback | AsyncCallback<void> | 是 | 回调函数,返回是否成功解除监听。 | 1663 1664**错误码**: 1665 1666以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1667 1668| 错误码ID | 错误信息 | 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**示例**: 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 1696FA模型的使用信息属性集合。 1697 1698**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1699 1700| 名称 | 类型 | 必填 | 说明 | 1701| -------------------- | ---------------------------------------- | ---- | ----------------------------- | 1702| deviceId | string | 否 | 设备Id。 | 1703| bundleName | string | 是 | 应用名称。 | 1704| moduleName | string | 是 | FA所属module名。 | 1705| abilityName | string | 否 | FA的MainAbility名。 | 1706| appLabelId | number | 否 | FA的应用labelId。 | 1707| labelId | number | 否 | FA所属module的labelId。 | 1708| descriptionId | number | 否 | FA所属的应用descriptionId。 | 1709| abilityLableId | number | 否 | FA的MainAbility labelId。 | 1710| abilityDescriptionId | number | 否 | FA的MainAbility descriptionId。 | 1711| abilityIconId | number | 否 | FA的MainAbility iconId。 | 1712| launchedCount | number | 是 | FA的启动次数。 | 1713| lastModuleUsedTime | number | 是 | FA的上一次使用时间。 | 1714| formRecords | Array<[HapFormInfo](#hapforminfo)> | 是 | FA中卡片的使用记录。 | 1715 1716## HapFormInfo 1717 1718FA卡片的使用信息属性集合。 1719 1720**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1721 1722| 名称 | 类型 | 必填 | 说明 | 1723| ---------------- | ------ | ---- | ----------- | 1724| formName | string | 是 | 卡片名称。 | 1725| formDimension | number | 是 | 卡片尺寸。 | 1726| formId | number | 是 | 卡片Id。 | 1727| formLastUsedTime | number | 是 | 卡片的上一次点击时间。 | 1728| count | number | 是 | 卡片的点击次数。 | 1729 1730## AppGroupCallbackInfo 1731 1732应用分组变化回调返回的属性集合 1733 1734**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1735 1736| 名称 | 类型 | 必填 | 说明 | 1737| ---------------- | ------ | ---- | ---------------- | 1738| appOldGroup | number | 是 | 变化前的应用分组。 | 1739| appNewGroup | number | 是 | 变化后的应用分组。| 1740| userId | number | 是 | 用户id。 | 1741| changeReason | number | 是 | 分组变化原因。<br>- 256:使用记录初创建时,默认匹配的原因。<br>- 512:计算优先级分组时异常。<br>- 768:使用时长变化。 <br>- 1024:有其他应用为当前应用强制设置优先级分组。| 1742| bundleName | string | 是 | 应用名称。 | 1743 1744## BundleStatsInfo 1745 1746应用使用时长的具体信息。 1747 1748**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1749 1750| 名称 | 类型 | 必填 | 说明 | 1751| ------------------------ | ------ | ---- | ---------------------------------------- | 1752| bundleName | string | 否 | 应用包名。 | 1753| abilityPrevAccessTime | number | 否 | 应用最后一次使用的时间。 | 1754| abilityInFgTotalTime | number | 否 | 应用在前台使用的总时间。 | 1755| id | number | 是 | 用户id。 | 1756| abilityPrevSeenTime | number | 否 | 应用最后一次在前台可见的时间。 | 1757| abilitySeenTotalTime | number | 否 | 应用在前台可见的总时间。 | 1758| fgAbilityAccessTotalTime | number | 否 | 应用访问前台的总时间。 | 1759| fgAbilityPrevAccessTime | number | 否 | 应用最后一次访问前台的时间。| 1760| infosBeginTime | number | 否 | BundleActiveInfo对象中第一条应用使用统计的记录时间。 | 1761| infosEndTime | number | 否 | BundleActiveInfo对象中最后一条应用使用统计的记录时间。 | 1762| appIndex<sup>15+</sup> | number | 否 | 应用程序的索引。 | 1763 1764## BundleEvents 1765 1766应用事件的具体信息。 1767 1768**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1769 1770| 名称 | 类型 | 必填 | 说明 | 1771| --------------------- | ------ | ---- | ---------------------------------------- | 1772| bundleName | string | 否 | 应用包名。 | 1773| eventId | number | 否 | 应用事件类型。 | 1774| eventOccurredTime | number | 否 | 应用事件发生的时间戳。 | 1775| appGroup | number | 否 | 应用程序的使用优先级组。| 1776| indexOfLink | string | 否 | 快捷方式id。| 1777| nameOfClass | string | 否 | 类名。| 1778 1779## BundleStatsMap 1780 1781应用使用时长的具体信息。 1782 1783**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1784 1785|名称 | 描述 | 1786| ------------------------------ | ---------------------------------------- | 1787| Record<string, [BundleStatsInfo](#bundlestatsinfo)> | 不同应用的使用时长统计信息 | 1788 1789## AppStatsMap<sup>15+</sup> 1790 1791应用使用的具体信息(包含分身应用)。 1792 1793**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1794 1795|名称 | 描述 | 1796| ------------------------------ | ---------------------------------------- | 1797| Record<string, Array<[BundleStatsInfo](#bundlestatsinfo)>> | 不同应用的使用统计信息(包含分身应用)。 | 1798 1799## DeviceEventStats 1800 1801提供通知、系统事件的统计信息。 1802 1803**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1804 1805| 名称 | 类型 | 必填 | 说明 | 1806| ------- | ------ | ---- | ----------------- | 1807| name | string | 是 | 通知应用包名或者系统事件名。 | 1808| eventId | number | 是 | 通知、系统事件类型。 | 1809| count | number | 是 | 应用通知次数或者系统事件触发次数。 | 1810 1811## IntervalType 1812 1813应用使用时长的查询类型。 1814 1815**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1816 1817| 名称 | 值 | 说明 | 1818| ------------ | ---- | ---------------------------------------- | 1819| BY_OPTIMIZED | 0 | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 | 1820| BY_DAILY | 1 | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。 | 1821| BY_WEEKLY | 2 | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。 | 1822| BY_MONTHLY | 3 | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。 | 1823| BY_ANNUALLY | 4 | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。 | 1824 1825## GroupType 1826 1827应用分组的设置类型。 1828 1829**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1830 1831| 名称 | 值 | 说明 | 1832| ------------------ | ---- | ----------------- | 1833| ALIVE_GROUP | 10 | 活跃分组。 | 1834| DAILY_GROUP | 20 | 经常使用,但当前并未在活跃态。 | 1835| FIXED_GROUP | 30 | 常用分组,定期使用,但不是每天使用。 | 1836| RARE_GROUP | 40 | 极少使用分组,不经常使用。 | 1837| LIMITED_GROUP | 50 | 受限使用分组。 | 1838| NEVER_GROUP | 60 | 从未使用分组,安装但是从未运行过。 |