js-apis-resourceschedule-deviceUsageStatistics.md 72.1 KB
Newer Older
Z
zengyawen 已提交
1
# @ohos.resourceschedule.usageStatistics (设备使用信息统计)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

本模块提供设备使用信息统计能力。

设备使用信息统计,系统应用可调用接口实现如下功能:

- 查询设备上各应用在不同时间段的使用时长、各应用的事件(前台、后台、长时任务开始、长时任务结束)信息及各应用的通知次数信息。
- 查询系统事件(休眠、唤醒、解锁、锁屏)统计信息。
- 查询应用分组信息(其他应用和自身应用)。
- 查询应用空闲状态(其他应用和自身应用)。
- 设置应用分组信息(其他应用)。
- 注册和解除注册应用分组变化监听。

三方应用可调用接口实现如下功能:

- 查询应用空闲状态(仅限自身应用)。
- 查询应用分组信息(仅限自身应用)。
- 查询应用事件(仅限自身应用)。

Y
yupeng74@huawei.com 已提交
20 21
> **说明:**
>
22
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Y
yupeng74@huawei.com 已提交
23
>
24 25 26 27 28 29 30 31 32 33 34 35 36 37


## 导入模块

```
import usageStatistics from '@ohos.resourceschedule.usageStatistics'
```

## usageStatistics.isIdleState

isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void

判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Callback形式返回。

38 39
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

40 41
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

42 43
**系统API**:此接口为系统接口。

44 45 46 47 48 49 50
**参数**

| 参数名        | 类型                           | 必填   | 说明                                       |
| ---------- | ---------------------------- | ---- | ---------------------------------------- |
| bundleName | string                       | 是    | 应用的bundleName。                           |
| callback   | AsyncCallback<boolean> | 是    | 指定的callback回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |

51 52
**错误码**

Z
zengyawen 已提交
53
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
54

55 56 57 58 59
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
| 10000001   | Memory operation failed.         | 
| 10000002   | Parcel operation failed.         | 
| 10000003   | System service operation failed. | 
60 61
| 10000004   | IPC failed.        |
| 10000006   | Failed to get the application information.    |
62

63
**示例**
Y
yupeng74@huawei.com 已提交
64
  ```js
65 66
    try{
        usageStatistics.isIdleState("com.ohos.camera", (err, res) => {
Y
yupeng74@huawei.com 已提交
67 68 69 70 71
            if (err) {
                console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
            }
72 73 74 75 76 77
        });
    } catch(error) {
        console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

Y
yupeng74@huawei.com 已提交
78
## usageStatistics.isIdleState
79 80 81 82 83

isIdleState(bundleName: string): Promise<boolean>

判断指定bundleName的应用当前是否是空闲状态,三方应用只能查询自身的空闲状态,使用Promise形式返回。

84 85
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

86 87
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

88 89
**系统API**:此接口为系统接口。

90 91 92 93 94 95 96 97 98 99 100 101
**参数**

| 参数名        | 类型     | 必填   | 说明             |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | 是    | 应用的bundleName。 |

**返回值**

| 类型                     | 说明                                       |
| ---------------------- | ---------------------------------------- |
| Promise<boolean> | 指定的Promise回调方法。如果指定的bundleName有效,则返回指定bundleName的应用当前是否是空闲状态;否则返回null。 |

102 103
**错误码**

Z
zengyawen 已提交
104
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
105

106 107 108 109 110
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
| 10000001   | Memory operation failed.         | 
| 10000002   | Parcel operation failed.         | 
| 10000003   | System service operation failed. | 
111 112
| 10000004   | IPC failed.        |
| 10000006   | Failed to get the application information.     |
113

114 115 116 117 118 119 120
**示例**

  ```js
    try{
        usageStatistics.isIdleState("com.ohos.camera").then( res => {
            console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
121
            console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryAppGroup

queryAppGroup(): Promise<number>

查询当前应用的优先级分组。使用Promise形式返回其应用分组。

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**返回值**

| 类型              | 说明                          |
| --------------- | --------------------------- |
| Promise<number> | 指定的Promise回调方法。返回查询的应用分组结果。 |

142 143
**错误码**

Z
zengyawen 已提交
144
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
145

146 147 148 149 150
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
151 152 153 154
| 10000004   | IPC failed.          |
| 10000005   | Application is not installed.      |
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
155

156 157 158 159 160 161 162
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup().then( res => {
            console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
        }).catch( err => {
163
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.queryAppGroup

queryAppGroup(callback: AsyncCallback<number>): void

查询当前应用的优先级分组。使用callback形式返回其应用分组。

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**参数**

| 参数名      | 类型                    | 必填   | 说明                         |
| -------- | --------------------- | ---- | -------------------------- |
| callback | AsyncCallback<number> | 是    | 指定的CallBack回调方法。返回查询的应用分组。 |

184 185
**错误码**

Z
zengyawen 已提交
186
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
187

188
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
189
| ---------- | ----------------------------       | 
190 191 192
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
193 194 195 196
| 10000004   | IPC failed.          |
| 10000005   | Application is not installed.      |
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
197

198 199 200 201 202
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup((err, res) => {
Y
yupeng74@huawei.com 已提交
203 204 205 206 207
            if(err) {
                console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
            }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.queryBundleStatsInfos

queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void

通过指定起始和结束时间查询应用使用时长统计信息,使用Callback形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
224
**系统API**:此接口为系统接口。
225 226 227 228 229

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
230 231
| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                   |
| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
232 233
| callback | AsyncCallback<[BundleStatsMap](#bundlestatsmap)> | 是    | 指定的callback回调方法。返回指定起始和结束时间内应用使用时长统计信息。 |

234 235
**错误码**

Z
zengyawen 已提交
236
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
237

238
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
239
| ---------- | ----------------------------       | 
240 241 242
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
243 244 245
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
246

247 248 249 250 251 252
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
253
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
254
            } else {
Y
yupeng74@huawei.com 已提交
255 256 257 258 259 260 261
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.');
                let i = 1;
                for(let key in res){
                    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback number : ' + i);
                    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res[key]));
                    i++;
                }
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleStatsInfos throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryBundleStatsInfos

queryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap>

通过指定起始和结束时间查询应用使用时长统计信息,使用Promise形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
279
**系统API**:此接口为系统接口。
280 281 282 283 284

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
285 286
| begin | number | 是    | 起始时间,以毫秒为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
287 288 289 290 291 292 293

**返回值**

| 类型                                       | 说明                                     |
| ---------------------------------------- | -------------------------------------- |
| Promise<[BundleStatsMap](#bundlestatsmap)> | 指定的Promise回调方法。返回指定起始和结束时间内应用使用时长统计信息。 |

294 295
**错误码**

Z
zengyawen 已提交
296
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
297

298
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
299
| ---------- | ----------------------------       | 
300 301 302
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
303 304 305
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
306

307 308 309 310 311 312 313 314
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfos(0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.');
            let i = 1;
            for(let key in res){
Y
yupeng74@huawei.com 已提交
315 316 317
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise number : ' + i);
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res[key]));
                i++;
318 319
            }
        }).catch( err => {
320
            console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleStatsInfos throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryBundleStatsInfoByInterval

queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息,使用Callback形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
337
**系统API**:此接口为系统接口。
338 339 340 341 342 343

**参数**

| 参数名        | 类型                                       | 必填   | 说明                                       |
| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
| byInterval | [IntervalType](#intervaltype)            | 是    | 查询类型。                                    |
344 345
| begin      | number                                   | 是    | 起始时间,以毫米为单位。                                    |
| end        | number                                   | 是    | 结束时间,以毫秒为单位。                                    |
346 347
| callback   | AsyncCallback<Array<[BundleStatsInfo](#bundlestatsinfo)>> | 是    | 指定的callback回调方法。返回指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 |

348 349
**错误码**

Z
zengyawen 已提交
350
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
351

352
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
353
| ---------- | ----------------------------       | 
354 355 356
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
357 358 359
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
360

361 362 363 364 365 366
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
367
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
368
            } else {
Y
yupeng74@huawei.com 已提交
369 370 371 372 373
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i]));
                }
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryBundleStatsInfoByInterval

queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise&lt;Array&lt;BundleStatsInfo&gt;&gt;

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息,使用Promise形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
391
**系统API**:此接口为系统接口。
392 393 394 395 396 397

**参数**

| 参数名        | 类型                            | 必填   | 说明    |
| ---------- | ----------------------------- | ---- | ----- |
| byInterval | [IntervalType](#intervaltype) | 是    | 查询类型。 |
398 399
| begin      | number                        | 是    | 起始时间,以毫秒为单位。 |
| end        | number                        | 是    | 结束时间,以毫秒为单位。 |
400 401 402 403 404 405 406

**返回值**

| 类型                                       | 说明                                       |
| ---------------------------------------- | ---------------------------------------- |
| Promise&lt;Array&lt;[BundleStatsInfo](#bundlestatsinfo)&gt;&gt; | 指定的Promise回调方法。返回指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 |

407 408
**错误码**

Z
zengyawen 已提交
409
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
410

411
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
412
| ---------- | ----------------------------       | 
413 414 415
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
416 417 418
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
419

420 421 422 423 424 425 426
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.');
            for (let i = 0; i < res.length; i++) {
Y
yupeng74@huawei.com 已提交
427 428
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
429 430
            }
        }).catch( err => {
431
            console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryBundleEvents

queryBundleEvents(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleEvents&gt;&gt;): void

通过指定起始和结束时间查询所有应用的事件集合,使用Callback形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
448
**系统API**:此接口为系统接口。
449 450 451 452 453

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
454 455
| begin    | number                                   | 是    | 起始时间,以毫米为单位。                                   |
| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
456 457
| callback | AsyncCallback&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 是    | 指定的callback回调方法。返回指定起始和结束时间查询所有应用的事件集合。 |

458 459
**错误码**

Z
zengyawen 已提交
460
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
461

462 463 464 465 466
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
467 468 469
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
470

471 472 473 474 475 476
**示例**

  ```js
    try{
        usageStatistics.queryBundleEvents(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
477
                console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
478
            } else {
Y
yupeng74@huawei.com 已提交
479 480 481 482 483
                console.log('BUNDLE_ACTIVE queryBundleEvents callback success.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i]));
                }
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleEvents throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryBundleEvents

queryBundleEvents(begin: number, end: number): Promise&lt;Array&lt;BundleEvents&gt;&gt;

通过指定起始和结束时间查询所有应用的事件集合,使用Promise形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
501
**系统API**:此接口为系统接口。
502 503 504 505 506

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
507 508
| begin | number | 是    | 起始时间,以毫秒为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
509 510 511 512 513 514 515

**返回值**

| 类型                                       | 说明                                     |
| ---------------------------------------- | -------------------------------------- |
| Promise&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 指定的Promise回调方法。返回指定起始和结束时间查询所有应用的事件集合。 |

516 517
**错误码**

Z
zengyawen 已提交
518
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
519

520 521 522 523 524
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
525 526 527
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
528

529 530 531 532 533 534 535
**示例**

  ```js
    try{
        usageStatistics.queryBundleEvents(0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryBundleEvents promise success.');
            for (let i = 0; i < res.length; i++) {
Y
yupeng74@huawei.com 已提交
536 537
                console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
538 539
            }
        }).catch( err => {
540
            console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryBundleEvents throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryCurrentBundleEvents

queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleEvents&gt;&gt;): void

通过指定起始和结束时间查询当前应用的事件集合,使用Callback形式返回。

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                      |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
559 560
| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                   |
| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                   |
561 562
| callback | AsyncCallback&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 是    | 指定的callback回调方法。返回指定起始和结束时间查询当前应用的事件集合。 |

563 564
**错误码**

Z
zengyawen 已提交
565
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
566

567
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
568
| ---------- | ----------------------------       | 
569 570 571
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
572 573 574
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
575

576 577 578 579 580 581
**示例**

  ```js
    try{
        usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
582
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
583
            } else {
Y
yupeng74@huawei.com 已提交
584 585 586 587 588
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i]));
                }
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryCurrentBundleEvents throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryCurrentBundleEvents

queryCurrentBundleEvents(begin: number, end: number): Promise&lt;Array&lt;BundleEvents&gt;&gt;

通过指定起始和结束时间查询当前应用的事件集合,使用Promise形式返回。

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
608 609
| begin | number | 是    | 起始时间,以毫米为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
610 611 612 613 614 615 616

**返回值**

| 类型                                       | 说明                                     |
| ---------------------------------------- | -------------------------------------- |
| Promise&lt;Array&lt;[BundleEvents](#bundleevents)&gt;&gt; | 指定的Promise回调方法。返回指定起始和结束时间查询当前应用的事件集合。 |

617 618
**错误码**

Z
zengyawen 已提交
619
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
620

621
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
622
| ---------- | ----------------------------       | 
623 624 625
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
626 627 628
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.      |
| 10000007   | Failed to get the system time.  |
629

630 631 632 633 634 635 636
**示例**

  ```js
    try{
        usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.');
            for (let i = 0; i < res.length; i++) {
Y
yupeng74@huawei.com 已提交
637 638
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
639 640
            }
        }).catch( err => {
641
            console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryCurrentBundleEvents throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(): Promise&lt;Array&lt;HapModuleInfo&gt;&gt;

使用Promise形式返回不超过1000条FA使用记录,FA使用记录由近及远排序。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
658
**系统API**:此接口为系统接口。
659 660 661 662 663

**返回值**

| 类型                                       | 说明                                 |
| ---------------------------------------- | ---------------------------------- |
664
| Promise&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 指定的Promise回调方法。返回不超过1000条FA使用记录。 |
665

666 667
**错误码**

Z
zengyawen 已提交
668
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
669

670
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
671
| ---------- | ----------------------------       | 
672 673 674
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
675 676 677
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
678

679 680 681 682 683 684 685 686 687 688 689 690
**示例**

  ```js
    // 无maxNum参数调用方式
    try{
        usageStatistics.queryModuleUsageRecords().then( res => {
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
            for (let i = 0; i < res.length; i++) {
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
            }
        }).catch( err=> {
691
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(callback: AsyncCallback&lt;Array&lt;HapModuleInfo&gt;&gt;): void

查询FA使用记录。使用CallBack形式返回数量不超过1000条FA使用记录(FA记录按时间由近及远排序)。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
708
**系统API**:此接口为系统接口。
709 710 711 712 713

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                  |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
714
| callback | AsyncCallback&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 是    | 指定的CallBack回调方法。返回不超过maxNum条FA使用记录。 |
715

716 717
**错误码**

Z
zengyawen 已提交
718
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
719

720
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
721
| ---------- | ----------------------------       | 
722 723 724
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
725 726 727
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
728

729 730 731 732 733 734
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords((err, res) => {
        if(err) {
735
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
        } else {
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
            for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
            }
        }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(maxNum: number): Promise&lt;Array&lt;HapModuleInfo&gt;&gt;

据maxNum,查询FA使用记录,使用Promise形式返回不超过maxNum条FA使用记录,FA使用记录由近及远排序,maxNum最大为1000。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
759
**系统API**:此接口为系统接口。
760 761 762 763 764 765 766 767 768 769 770

**参数**

| 参数名    | 类型     | 必填   | 说明                                 |
| ------ | ------ | ---- | ---------------------------------- |
| maxNum | number | 是    | 返回条目的最大数量,最多支持1000条。 |

**返回值**

| 类型                                       | 说明                                 |
| ---------------------------------------- | ---------------------------------- |
771
| Promise&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 指定的Promise回调方法。返回不超过maxNum条FA使用记录。 |
772

773 774
**错误码**

Z
zengyawen 已提交
775
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
776

777 778 779 780 781
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
782 783 784
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
785

786 787 788 789 790 791 792 793 794 795 796
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords(1000).then( res => {
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
            for (let i = 0; i < res.length; i++) {
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
            }
        }).catch( err=> {
797
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(maxNum: number, callback: AsyncCallback&lt;Array&lt;HapModuleInfo&gt;&gt;): void

查询FA使用记录。使用CallBack形式返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
814
**系统API**:此接口为系统接口。
815 816 817 818 819 820

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                  |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
| maxNum   | number                                   | 是    | 返回FA记录的最大数量,maxNum最大为1000。|
821
| callback | AsyncCallback&lt;Array&lt;[HapModuleInfo](#hapmoduleinfo)&gt;&gt; | 是    | 指定的CallBack回调方法。返回不超过maxNum条FA使用记录。 |
822

823 824
**错误码**

Z
zengyawen 已提交
825
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
826

827 828 829 830 831
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
832 833 834
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
835

836 837 838 839 840
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords(1000, (err, res) => {
Y
yupeng74@huawei.com 已提交
841 842 843 844 845 846 847 848
            if(err) {
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
                }
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryModuleUsageRecords throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryAppGroup

queryAppGroup(bundleName : string): Promise&lt;number&gt;

查询指定bundleName的应用的优先级分组。使用Promise形式返回其应用分组结果。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
866
**系统API**:此接口为系统接口。
867 868 869 870 871 872 873 874 875 876 877 878 879

**参数**

| 参数名        | 类型     | 必填   | 说明                                       |
| ---------- | ------ | ---- | ---------------------------------------- |
| bundleName | string | 是    | 查询指定bundleName的应用的优先级分组。 |

**返回值**

| 类型              | 说明                          |
| --------------- | --------------------------- |
| Promise&lt;number&gt; | 指定的Promise回调方法。返回查询的应用分组结果。 |

880 881
**错误码**

Z
zengyawen 已提交
882
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
883

884 885 886 887 888
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
889
| 10000004   | IPC failed.          |
890
| 10000005   | Application is not installed.      | 
891 892
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
893

894 895 896 897 898 899 900 901 902
**示例**

```javascript
//有bundleName的promise
    let bundleName = "com.ohos.camera";
    try{
        usageStatistics.queryAppGroup(bundleName).then( res => {
            console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
903
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.queryAppGroup

queryAppGroup(bundleName : string, callback: AsyncCallback&lt;number&gt;): void

查询指定bundleName对应应用的分组。使用callback形式返回其应用分组。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
920
**系统API**:此接口为系统接口。
921 922 923 924 925 926 927 928

**参数**

| 参数名        | 类型                    | 必填   | 说明                                       |
| ---------- | --------------------- | ---- | ---------------------------------------- |
| bundleName | string                | 是    | 查询指定bundleName对应应用的分组。 |
| callback   | AsyncCallback&lt;number&gt; | 是    | 指定的CallBack回调方法。返回制指定bundleName的应用分组。|

929 930
**错误码**

Z
zengyawen 已提交
931
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
932

933 934 935 936 937
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
938
| 10000004   | IPC failed.          |
939
| 10000005   | Application is not installed.      | 
940 941
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
942

943 944 945 946 947 948
**示例**

```javascript
    let bundleName = "com.ohos.camera";
    try{
        usageStatistics.queryAppGroup(bundleName, (err, res) => {
Y
yupeng74@huawei.com 已提交
949 950 951 952 953
            if(err) {
                console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
            }
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.setAppGroup

setAppGroup(bundleName: string, newGroup: GroupType): Promise&lt;void&gt;

将指定bundleName的应用的分组设置为newGroup,使用Promise形式返回设置是否成功。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
970
**系统API**:此接口为系统接口。
971 972 973 974 975 976 977 978

**参数**

| 参数名        | 类型        | 必填   | 说明   |
| ---------- | --------- | ---- | ---- |
| bundleName | string    | 是    | 应用名称 |
| newGroup   | [GroupType](#grouptype) | 是    | 应用分组 |

979 980
**错误码**

Z
zengyawen 已提交
981
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
982

983 984 985 986 987
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
988 989 990
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10100001   | Repeated operation on the application group. |
991

992 993 994 995 996 997 998 999 1000 1001
**返回值**

| 类型            | 说明                        |
| ------------- | ------------------------- |
| Promise&lt;void&gt; | 指定的Promise回调方法。返回本次设置是否成功 |

**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
1002
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
1003 1004 1005 1006 1007

    try{
        usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
            console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
1008
            console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE setAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.setAppGroup

setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback&lt;void&gt;): void

将指定bundleName的应用的分组设置为newGroup,使用CallBack形式返回设置是否成功。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1025
**系统API**:此接口为系统接口。
1026 1027 1028 1029 1030 1031 1032 1033 1034

**参数**

| 参数名        | 类型                  | 必填   | 说明                        |
| ---------- | ------------------- | ---- | ------------------------- |
| bundleName | string              | 是    | 应用名称                      |
| newGroup   | [GroupType](#grouptype)           | 是    | 应用分组                      |
| callback   | AsyncCallback&lt;void&gt; | 是    | 指定的CallBack回调方法。返回设置是否成功。 |

1035 1036
**错误码**

Z
zengyawen 已提交
1037
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1038

1039
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1040
| ---------- | ----------------------------          | 
1041 1042 1043
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1044 1045 1046
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10100001   | Repeated operation on the application group. |
1047

1048 1049 1050 1051
**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
1052
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
1053 1054 1055 1056

    try{
        usageStatistics.setAppGroup(bundleName, newGroup, (err) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1057
                console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
1058
            } else {
Y
yupeng74@huawei.com 已提交
1059
                console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE setAppGroup throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.registerAppGroupCallBack

registerAppGroupCallBack(groupCallback: Callback&lt;AppGroupCallbackInfo&gt;): Promise&lt;void&gt;

1071
应用注册分组变化监听,待用户名下的某个应用分组发生变化时,通过callback形式向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Promise形式返回注册是否成功。
1072 1073 1074 1075 1076

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1077
**系统API**:此接口为系统接口。
1078 1079 1080 1081 1082

**参数**

| 参数名   | 类型                                                         | 必填 | 说明                                       |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
1083
| callback | Callback&lt;[AppGroupCallbackInfo](#appgroupcallbackinfo)&gt; | 是   | 指定的callback函数,返回应用分组变化的信息 |
1084

1085 1086
**错误码**

Z
zengyawen 已提交
1087
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1088

1089 1090 1091 1092 1093
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1094 1095
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1096

1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
**返回值**

| 类型            | 说明                      |
| ------------- | ----------------------- |
| Promise&lt;void&gt; | 指定的Promise回调方法。返回注册监听是否成功 |

**示例**

```javascript
    let onBundleGroupChanged = (res) =>{
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.');
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
    };
    try{
        usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => {
            console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.');
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
1118
            console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

## usageStatistics.registerAppGroupCallBack

registerAppGroupCallBack(groupCallback: Callback&lt;AppGroupCallbackInfo&gt;, callback: AsyncCallback&lt;void&gt;): void

1129
应用注册分组变化监听,待用户名下的某个应用分组发生变化时,通过callback形式向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用异步callback形式返回注册监听是否成功。
1130 1131 1132 1133 1134

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1135
**系统API**:此接口为系统接口。
1136 1137 1138 1139 1140

**参数**

| 参数名   | 类型                                                         | 必填 | 说明                                         |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
1141
| groupCallback | Callback&lt;[AppGroupCallbackInfo](#appgroupcallbackinfo)&gt; | 是   | 指定的callback函数,返回应用分组变化的信息   |
1142 1143
| callback | AsyncCallback&lt;void&gt;                                    | 是   | 指定的异步callback函数,返回注册监听是否成功 |

1144 1145
**错误码**

Z
zengyawen 已提交
1146
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1147

1148 1149 1150 1151 1152
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1153 1154
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1155 1156


1157 1158 1159
**示例**

```javascript
1160
    // @ts-nocheck
1161 1162 1163 1164 1165 1166 1167 1168 1169
    let onBundleGroupChanged = (err, res) =>{
        console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
    };
    try{
Y
yupeng74@huawei.com 已提交
1170 1171 1172 1173 1174 1175
        usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, err => {
            if(err) {
                console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.');
            }
1176 1177 1178 1179 1180 1181
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

1182
## usageStatistics.unregisterAppGroupCallBack
1183

1184
unregisterAppGroupCallBack(): Promise&lt;void&gt;
1185 1186 1187 1188 1189 1190 1191

应用解除分组变化监听,解除通过调用注册接口生成的监听。使用Promise形式返回解除监听是否成功。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1192
**系统API**:此接口为系统接口。
1193 1194 1195 1196 1197 1198 1199

**返回值**

| 类型            | 说明                       |
| ------------- | ------------------------ |
| Promise&lt;void&gt; | 指定的Promise回调方法。返回解除监听是否成功 |

1200 1201
**错误码**

Z
zengyawen 已提交
1202
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1203

1204
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1205
| ---------- | ----------------------------          | 
1206 1207 1208
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1209 1210
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1211

1212 1213 1214 1215
**示例**

```javascript
    try{
1216 1217
        usageStatistics.unregisterAppGroupCallBack().then( () => {
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.');
1218
        }).catch( err => {
1219
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1220 1221
        });
    } catch (error) {
1222
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1223 1224 1225
    }
```

1226
## usageStatistics.unregisterAppGroupCallBack
1227

1228
unregisterAppGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
1229 1230 1231 1232 1233 1234 1235

应用解除分组变化监听,解除通过调用注册接口生成的监听。使用异步callback形式返回解除监听是否成功。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1236
**系统API**:此接口为系统接口。
1237 1238 1239 1240 1241 1242 1243

**参数**

| 参数名      | 类型                  | 必填   | 说明             |
| -------- | ------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | 是    | 解除监听是否成功的异步回调函数 |

1244 1245
**错误码**

Z
zengyawen 已提交
1246
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1247

1248
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1249
| ---------- | ----------------------------          | 
1250 1251 1252
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1253 1254
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1255

1256 1257 1258 1259
**示例**

```javascript
    try{
Y
yupeng74@huawei.com 已提交
1260 1261 1262 1263 1264 1265
        usageStatistics.unregisterAppGroupCallBack(err => {
            if(err) {
                console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
            } else {
                console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.');
            }
1266 1267
        });
    } catch (error) {
1268
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
    }
```

## usageStatistics.queryDeviceEventStats

queryDeviceEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;

通过指定起始和结束时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息,使用Promise形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1282
**系统API**:此接口为系统接口。
1283 1284 1285 1286 1287

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
1288 1289
| begin | number | 是    | 起始时间,以毫米为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
1290 1291 1292 1293 1294

**返回值**

| 类型                                       | 说明                                       |
| ---------------------------------------- | ---------------------------------------- |
1295
| Promise&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 指定的Promise回调方法。返回指定起始和结束时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息。 |
1296

1297 1298
**错误码**

Z
zengyawen 已提交
1299
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1300

1301
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1302
| ---------- | ----------------------------          | 
1303 1304 1305
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1306 1307 1308
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1309

1310 1311 1312 1313 1314 1315 1316 1317
**示例**

  ```js
    try{
        usageStatistics.queryDeviceEventStats(0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.');
            console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res));
        }).catch( err=> {
1318
            console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryDeviceEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryDeviceEventStats

queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void

通过指定起始和结束时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息,使用Callback形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1335
**系统API**:此接口为系统接口。
1336 1337 1338 1339 1340

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1341 1342
| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                    |
| end      | number                                   | 是    | 结束时间,以毫秒为单位。                                    |
1343
| callback | AsyncCallback&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 是    | 指定的callback回调方法。返回指定起始和结束时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息。 |
1344

1345 1346
**错误码**

Z
zengyawen 已提交
1347
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1348

1349 1350 1351 1352 1353
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1354 1355 1356
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.           |
| 10000007   | Failed to get the system time.     |
1357

1358 1359 1360 1361 1362 1363
**示例**

  ```js
    try{
        usageStatistics.queryDeviceEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1364
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1365
            } else {
Y
yupeng74@huawei.com 已提交
1366 1367
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
1368 1369 1370 1371 1372 1373 1374 1375 1376
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryDeviceEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1377
queryNotificationEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;
1378 1379 1380 1381 1382 1383 1384

通过指定起始和结束时间查询所有应用的通知次数信息,使用Promise形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1385
**系统API**:此接口为系统接口。
1386 1387 1388 1389 1390

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
1391 1392
| begin | number | 是    | 起始时间,以毫秒为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
1393 1394 1395 1396 1397

**返回值**

| 类型                                       | 说明                                       |
| ---------------------------------------- | ---------------------------------------- |
Y
yupeng74@huawei.com 已提交
1398
| Promise&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 指定的Promise回调方法。返回指定起始和结束时间查询所有应用的通知次数信息。 |
1399

1400 1401
**错误码**

Z
zengyawen 已提交
1402
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1403

1404 1405 1406 1407 1408
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1409 1410 1411
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1412

1413 1414 1415 1416 1417 1418 1419 1420
**示例**

  ```js
    try{
        usageStatistics.queryNotificationEventStats(0, 20000000000000).then( res => {
            console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.');
            console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res));
        }).catch( err=> {
1421
            console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1422 1423 1424 1425 1426 1427 1428 1429
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryNotificationEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1430
queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void
1431 1432 1433 1434 1435 1436 1437

通过指定起始和结束时间查询所有应用的通知次数信息,使用Callback形式返回。

**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1438
**系统API**:此接口为系统接口。
1439 1440 1441 1442 1443

**参数**

| 参数名      | 类型                                       | 必填   | 说明                                       |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
1444 1445
| begin    | number                                   | 是    | 起始时间,以毫秒为单位。                                    |
| end      | number                                   | 是    | 结束时间,以毫米为单位。                                    |
Y
yupeng74@huawei.com 已提交
1446
| callback | AsyncCallback&lt;Array&lt;[DeviceEventStats](#deviceeventstats)&gt;&gt; | 是    | 指定的callback回调方法。返回通过指定起始和结束时间查询所有应用的通知次数信息。 |
1447

1448 1449
**错误码**

Z
zengyawen 已提交
1450
以下错误码的详细介绍请参见[设备信息使用统计错误码](../errorcodes/errorcode-DeviceUsageStatistics.md)
Y
yupeng74@huawei.com 已提交
1451

1452
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1453
| ---------- | ----------------------------          | 
1454 1455 1456
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
1457 1458 1459
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1460

1461 1462 1463 1464 1465 1466
**示例**

  ```js
    try{
        usageStatistics.queryNotificationEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1467
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1468
            } else {
Y
yupeng74@huawei.com 已提交
1469 1470
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryNotificationEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## HapModuleInfo
FA的使用信息的属性集合。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1483
**系统API**:此接口为系统接口。
1484

1485
| 名称                  | 类型                                       | 必填   | 说明                            |
1486 1487
| -------------------- | ---------------------------------------- | ---- | ----------------------------- |
| deviceId             | string                                   | 否    | FA所属deviceId。                 |
1488
| bundleName           | string                                   | 是    | FA所属应用Bundle名称。             |
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498
| moduleName           | string                                   | 是    | FA所属module名。                  |
| abilityName          | string                                   | 否    | FA的MainAbility名。              |
| appLabelId           | number                                   | 否    | FA的应用labelId。                 |
| labelId              | number                                   | 否    | FA所属module的labelId。           |
| descriptionId        | number                                   | 否    | FA所属的应用descriptionId。         |
| abilityLableId       | number                                   | 否    | FA的MainAbility labelId。       |
| abilityDescriptionId | number                                   | 否    | FA的MainAbility descriptionId。 |
| abilityIconId        | number                                   | 否    | FA的MainAbility iconId。        |
| launchedCount        | number                                   | 是    | FA的启动次数。                      |
| lastModuleUsedTime   | number                                   | 是    | FA的上一次使用时间。                   |
1499
| formRecords          | Array&lt;[HapFormInfo](#hapforminfo)&gt; | 是    | FA中卡片的使用记录。                   |
1500 1501 1502 1503 1504 1505

## HapFormInfo
FA卡片的使用信息的属性集合。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1506
**系统API**:此接口为系统接口。
1507

1508
| 名称              | 类型     | 必填   | 说明          |
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
| ---------------- | ------ | ---- | ----------- |
| formName         | string | 是    | 卡片名称。       |
| formDimension    | number | 是    | 卡片尺寸。       |
| formId           | number | 是    | 卡片Id。       |
| formLastUsedTime | number | 是    | 卡片的上一次点击时间。 |
| count            | number | 是    | 卡片的点击次数。    |

## AppGroupCallbackInfo

应用分组变化回调返回的属性集合

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1522
**系统API**:此接口为系统接口。
1523

1524
| 名称           | 类型   | 必填 | 说明             |
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
| ---------------- | ------ | ---- | ---------------- |
| appOldGroup | number | 是   | 变化前的应用分组 |
| appNewGroup | number | 是   | 变化后的应用分组 |
| userId           | number | 是   | 用户id           |
| changeReason     | number | 是   | 分组变化原因     |
| bundleName       | string | 是   | 应用名称         |

## BundleStatsInfo

提供应用使用时长的具体信息。

### 属性

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1540
**系统API**:此接口为系统接口。
1541

1542
| 名称                      | 类型     | 必填   | 说明                                       |
1543 1544 1545 1546
| ------------------------ | ------ | ---- | ---------------------------------------- |
| bundleName               | string | 是    | 应用包名。                                    |
| abilityPrevAccessTime    | number | 是    | 应用最后一次使用的时间。                             |
| abilityInFgTotalTime     | number | 是    | 应用在前台使用的总时间。                             |
Y
yupeng74@huawei.com 已提交
1547 1548 1549 1550 1551 1552 1553
| id                       | number | 否    | 用户id。 |
| abilityPrevSeenTime      | number | 否    | 应用最后一次在前台可见的时间。 |
| abilitySeenTotalTime     | number | 否    | 应用在前台可见的总时间。 |
| fgAbilityAccessTotalTime | number | 否    | 应用访问前台的总时间。 |
| fgAbilityPrevAccessTime  | number | 否    | 应用最后一次访问前台的时间。|
| infosBeginTime           | number | 否    | BundleActiveInfo对象中第一条应用使用统计的记录时间。 |
| infosEndTime             | number | 否    | BundleActiveInfo对象中最后一条应用使用统计的记录时间。 |
1554 1555 1556 1557 1558 1559 1560

## BundleEvents

提供应用事件的具体信息。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

1561
| 名称                   | 类型     | 必填   | 说明                                       |
1562 1563 1564 1565
| --------------------- | ------ | ---- | ---------------------------------------- |
| bundleName            | string | 是    | 应用包名。                                    |
| eventId             | number | 是    | 应用事件类型。                                  |
| eventOccurredTime     | number | 是    | 应用事件发生的时间戳。                              |
Y
yupeng74@huawei.com 已提交
1566 1567 1568
| appGroup | number | 否    | 应用程序的使用优先级组。|
| indexOfLink           | string | 否    | 快捷方式id。|
| nameOfClass           | string | 否    | 类名。|
1569 1570 1571 1572 1573 1574 1575

## BundleStatsMap

提供应用使用时长的具体信息。

**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App

1576 1577
**系统API**:此接口为系统接口。

1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
| 参数名                            | 类型                                       | 必填   | 说明             |
| ------------------------------ | ---------------------------------------- | ---- | -------------- |
| [key: string]: BundleStatsInfo | [key: string]: [BundleStatsInfo](#bundlestatsinfo) | 是    | 不同应用的使用时长统计信息。 |

## DeviceEventStats

提供通知、系统事件的统计信息。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

Y
yupeng74@huawei.com 已提交
1588
**系统API**:此接口为系统接口。
1589

1590
| 名称     | 类型     | 必填   | 说明                |
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
| ------- | ------ | ---- | ----------------- |
| name    | string | 是    | 通知应用包名或者系统事件名。    |
| eventId | number | 是    | 通知、系统事件类型。        |
| count   | number | 是    | 应用通知次数或者系统事件触发次数。 |

## IntervalType

提供应用使用时长的查询类型。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App

1602 1603 1604
**系统API**:此接口为系统接口。

| 名称           | 值  | 说明                                       |
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
| ------------ | ---- | ---------------------------------------- |
| BY_OPTIMIZED | 0    | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 |
| BY_DAILY     | 1    | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。              |
| BY_WEEKLY    | 2    | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。              |
| BY_MONTHLY   | 3    | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。              |
| BY_ANNUALLY  | 4    | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。              |

## GroupType

提供应用分组的设置类型。

**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Y
yupeng74@huawei.com 已提交
1618
**系统API**:此接口为系统接口。
1619

1620
| 名称                 | 值  | 说明                |
1621 1622 1623 1624 1625 1626 1627
| ------------------ | ---- | ----------------- |
| ALIVE_GROUP | 10   | 活跃分组。              |
| DAILY_GROUP | 20   | 经常使用,但当前并未在活跃态。    |
| FIXED_GROUP | 30   | 常用分组,定期使用,但不是每天使用。 |
| RARE_GROUP  | 40   | 极少使用分组,不经常使用。      |
| LIMITED_GROUP | 50   | 受限使用分组。            |
| NEVER_GROUP | 60   | 从未使用分组,安装但是从未运行过。  |