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