js-apis-resourceschedule-deviceUsageStatistics.md 72.3 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
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
H
houdisheng 已提交
57 58 59
| 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
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
H
houdisheng 已提交
108 109 110
| 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
        });
    } 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

H
houdisheng 已提交
136 137
**系统API**:此接口为系统接口。

138 139 140 141 142 143
**返回值**

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

144 145
**错误码**

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

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

158 159 160 161 162 163 164
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup().then( res => {
            console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
        }).catch( err => {
165
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
166 167 168 169 170 171 172 173 174 175 176 177 178 179
        });
    } 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

H
houdisheng 已提交
180 181
**系统API**:此接口为系统接口。

182 183 184 185 186 187
**参数**

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

188 189
**错误码**

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

192
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
193 194 195 196
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
197 198 199 200
| 10000004   | IPC failed.          |
| 10000005   | Application is not installed.      |
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
201

202 203 204 205 206
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup((err, res) => {
Y
yupeng74@huawei.com 已提交
207 208 209 210 211
            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));
            }
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        });
    } 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 已提交
228
**系统API**:此接口为系统接口。
229 230 231 232 233

**参数**

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

238 239
**错误码**

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

242
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
243 244 245 246
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
247 248 249
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
250

251 252 253 254 255 256
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
257
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
258
            } else {
Y
yupeng74@huawei.com 已提交
259 260 261 262 263 264 265
                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++;
                }
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
            }
        });
    } 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 已提交
283
**系统API**:此接口为系统接口。
284 285 286 287 288

**参数**

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

**返回值**

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

298 299
**错误码**

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

302
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
303 304 305 306
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
307 308 309
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
310

311 312 313 314 315 316 317 318
**示例**

  ```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 已提交
319 320 321
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise number : ' + i);
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res[key]));
                i++;
322 323
            }
        }).catch( err => {
324
            console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
        });
    } 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 已提交
341
**系统API**:此接口为系统接口。
342 343 344 345 346 347

**参数**

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

352 353
**错误码**

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

356
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
357 358 359 360
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
361 362 363
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
364

365 366 367 368 369 370
**示例**

  ```js
    try{
        usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
371
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
372
            } else {
Y
yupeng74@huawei.com 已提交
373 374 375 376 377
                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]));
                }
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
            }
        });
    } 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 已提交
395
**系统API**:此接口为系统接口。
396 397 398 399 400 401

**参数**

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

**返回值**

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

411 412
**错误码**

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

415
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
416 417 418 419
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
420 421 422
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
423

424 425 426 427 428 429 430
**示例**

  ```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 已提交
431 432
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
433 434
            }
        }).catch( err => {
435
            console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
        });
    } 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 已提交
452
**系统API**:此接口为系统接口。
453 454 455 456 457

**参数**

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

462 463
**错误码**

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

466 467
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
468 469 470
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
471 472 473
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
474

475 476 477 478 479 480
**示例**

  ```js
    try{
        usageStatistics.queryBundleEvents(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
481
                console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
482
            } else {
Y
yupeng74@huawei.com 已提交
483 484 485 486 487
                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]));
                }
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
            }
        });
    } 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 已提交
505
**系统API**:此接口为系统接口。
506 507 508 509 510

**参数**

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

**返回值**

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

520 521
**错误码**

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

524 525
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
526 527 528
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
529 530 531
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
532

533 534 535 536 537 538 539
**示例**

  ```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 已提交
540 541
                console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
542 543
            }
        }).catch( err => {
544
            console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
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

H
houdisheng 已提交
559 560
**系统API**:此接口为系统接口。

561 562 563 564
**参数**

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

569 570
**错误码**

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

573
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
574 575 576 577
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
578 579 580
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
581

582 583 584 585 586 587
**示例**

  ```js
    try{
        usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err, res) => {
            if (err) {
Y
yupeng74@huawei.com 已提交
588
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
589
            } else {
Y
yupeng74@huawei.com 已提交
590 591 592 593 594
                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]));
                }
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
            }
        });
    } 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

H
houdisheng 已提交
610 611
**系统API**:此接口为系统接口。

612 613 614 615
**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
616
| begin | number | 是    | 起始时间,以毫秒为单位。 |
617
| end   | number | 是    | 结束时间,以毫秒为单位。 |
618 619 620 621 622 623 624

**返回值**

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

625 626
**错误码**

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

629
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
630 631 632 633
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
634 635 636
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.      |
| 10000007   | Failed to get the system time.  |
637

638 639 640 641 642 643 644
**示例**

  ```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 已提交
645 646
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
647 648
            }
        }).catch( err => {
649
            console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
        });
    } 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 已提交
666
**系统API**:此接口为系统接口。
667 668 669 670 671

**返回值**

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

674 675
**错误码**

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

678
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
679 680 681 682
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
683 684 685
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
686

687 688 689 690 691 692 693 694 695 696 697 698
**示例**

  ```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=> {
699
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
        });
    } 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 已提交
716
**系统API**:此接口为系统接口。
717 718 719 720 721

**参数**

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

724 725
**错误码**

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

728
| 错误码ID        | 错误信息                       |
H
houdisheng 已提交
729 730 731 732
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
733 734 735
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
736

737 738 739 740 741 742
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords((err, res) => {
        if(err) {
743
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
        } 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 已提交
767
**系统API**:此接口为系统接口。
768 769 770 771 772 773 774 775 776 777 778

**参数**

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

**返回值**

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

781 782
**错误码**

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

785 786
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
787 788 789
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
790 791 792
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
793

794 795 796 797 798 799 800 801 802 803 804
**示例**

  ```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=> {
805
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
        });
    } 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 已提交
822
**系统API**:此接口为系统接口。
823 824 825 826 827 828

**参数**

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

831 832
**错误码**

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

835 836
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
837 838 839
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
840 841 842
| 10000004   | IPC failed.          |
| 10000006   | Failed to get the application information.       |
| 10000007   | Failed to get the system time.  |
843

844 845 846 847 848
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords(1000, (err, res) => {
Y
yupeng74@huawei.com 已提交
849 850 851 852 853 854 855 856
            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]));
                }
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
            }
        });
    } 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 已提交
874
**系统API**:此接口为系统接口。
875 876 877 878 879 880 881 882 883 884 885 886 887

**参数**

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

**返回值**

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

888 889
**错误码**

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

892 893
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
894 895 896
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
897
| 10000004   | IPC failed.          |
H
houdisheng 已提交
898
| 10000005   | Application is not installed.      |
899 900
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
901

902 903 904 905 906 907 908 909 910
**示例**

```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 已提交
911
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
        });
    } 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 已提交
928
**系统API**:此接口为系统接口。
929 930 931 932 933 934 935 936

**参数**

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

937 938
**错误码**

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

941 942
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
H
houdisheng 已提交
943 944 945
| 10000001   | Memory operation failed.           |
| 10000002   | Parcel operation failed.           |
| 10000003   | System service operation failed.   |
946
| 10000004   | IPC failed.          |
H
houdisheng 已提交
947
| 10000005   | Application is not installed.      |
948 949
| 10000006   | Failed to get the application information.       |
| 10100002   | Failed to get the application group information. |
950

951 952 953 954 955 956
**示例**

```javascript
    let bundleName = "com.ohos.camera";
    try{
        usageStatistics.queryAppGroup(bundleName, (err, res) => {
Y
yupeng74@huawei.com 已提交
957 958 959 960 961
            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));
            }
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
        });
    } 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 已提交
978
**系统API**:此接口为系统接口。
979 980 981 982 983 984 985 986

**参数**

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

987 988
**错误码**

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

991 992
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
H
houdisheng 已提交
993 994 995
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
996 997 998
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10100001   | Repeated operation on the application group. |
999

1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
**返回值**

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

**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
1010
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
1011 1012 1013 1014 1015

    try{
        usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
            console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
1016
            console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
        });
    } 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 已提交
1033
**系统API**:此接口为系统接口。
1034 1035 1036 1037 1038 1039 1040 1041 1042

**参数**

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

1043 1044
**错误码**

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

1047
| 错误码ID        | 错误信息                          |
H
houdisheng 已提交
1048 1049 1050 1051
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1052 1053 1054
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10100001   | Repeated operation on the application group. |
1055

1056 1057 1058 1059
**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
1060
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
1061 1062 1063 1064

    try{
        usageStatistics.setAppGroup(bundleName, newGroup, (err) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1065
                console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
1066
            } else {
Y
yupeng74@huawei.com 已提交
1067
                console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
            }
        });
    } 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;

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

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

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

Y
yupeng74@huawei.com 已提交
1085
**系统API**:此接口为系统接口。
1086 1087 1088 1089 1090

**参数**

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

1093 1094
**错误码**

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

1097 1098
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
H
houdisheng 已提交
1099 1100 1101
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1102 1103
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1104

1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
**返回值**

| 类型            | 说明                      |
| ------------- | ----------------------- |
| 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 已提交
1126
            console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
        });
    } 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

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

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

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

Y
yupeng74@huawei.com 已提交
1143
**系统API**:此接口为系统接口。
1144 1145 1146 1147 1148

**参数**

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

1152 1153
**错误码**

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

1156 1157
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
H
houdisheng 已提交
1158 1159 1160
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1161 1162
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1163 1164


1165 1166 1167
**示例**

```javascript
1168
    // @ts-nocheck
1169 1170 1171 1172 1173 1174 1175 1176 1177
    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 已提交
1178 1179 1180 1181 1182 1183
        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.');
            }
1184 1185 1186 1187 1188 1189
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

1190
## usageStatistics.unregisterAppGroupCallBack
1191

1192
unregisterAppGroupCallBack(): Promise&lt;void&gt;
1193 1194 1195 1196 1197 1198 1199

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

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

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

Y
yupeng74@huawei.com 已提交
1200
**系统API**:此接口为系统接口。
1201 1202 1203 1204 1205 1206 1207

**返回值**

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

1208 1209
**错误码**

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

1212
| 错误码ID        | 错误信息                          |
H
houdisheng 已提交
1213 1214 1215 1216
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1217 1218
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1219

1220 1221 1222 1223
**示例**

```javascript
    try{
1224 1225
        usageStatistics.unregisterAppGroupCallBack().then( () => {
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.');
1226
        }).catch( err => {
1227
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1228 1229
        });
    } catch (error) {
1230
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1231 1232 1233
    }
```

1234
## usageStatistics.unregisterAppGroupCallBack
1235

1236
unregisterAppGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
1237 1238 1239 1240 1241 1242 1243

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

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

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

Y
yupeng74@huawei.com 已提交
1244
**系统API**:此接口为系统接口。
1245 1246 1247 1248 1249 1250 1251

**参数**

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

1252 1253
**错误码**

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

1256
| 错误码ID        | 错误信息                          |
H
houdisheng 已提交
1257 1258 1259 1260
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1261 1262
| 10000004   | IPC failed.             |
| 10100001   | Repeated operation on the application group. |
1263

1264 1265 1266 1267
**示例**

```javascript
    try{
Y
yupeng74@huawei.com 已提交
1268 1269 1270 1271 1272 1273
        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.');
            }
1274 1275
        });
    } catch (error) {
1276
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289
    }
```

## 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 已提交
1290
**系统API**:此接口为系统接口。
1291 1292 1293 1294 1295

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
1296
| begin | number | 是    | 起始时间,以毫秒为单位。 |
1297
| end   | number | 是    | 结束时间,以毫秒为单位。 |
1298 1299 1300 1301 1302

**返回值**

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

1305 1306
**错误码**

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

1309
| 错误码ID        | 错误信息                          |
H
houdisheng 已提交
1310 1311 1312 1313
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1314 1315 1316
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1317

1318 1319 1320 1321 1322 1323 1324 1325
**示例**

  ```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=> {
1326
            console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
        });
    } 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 已提交
1343
**系统API**:此接口为系统接口。
1344 1345 1346 1347 1348

**参数**

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

1353 1354
**错误码**

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

1357 1358
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
H
houdisheng 已提交
1359 1360 1361
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1362 1363 1364
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.           |
| 10000007   | Failed to get the system time.     |
1365

1366 1367 1368 1369 1370 1371
**示例**

  ```js
    try{
        usageStatistics.queryDeviceEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1372
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1373
            } else {
Y
yupeng74@huawei.com 已提交
1374 1375
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
1376 1377 1378 1379 1380 1381 1382 1383 1384
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryDeviceEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1385
queryNotificationEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;
1386 1387 1388 1389 1390 1391 1392

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

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

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

Y
yupeng74@huawei.com 已提交
1393
**系统API**:此接口为系统接口。
1394 1395 1396 1397 1398

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
1399 1400
| begin | number | 是    | 起始时间,以毫秒为单位。 |
| end   | number | 是    | 结束时间,以毫秒为单位。 |
1401 1402 1403 1404 1405

**返回值**

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

1408 1409
**错误码**

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

1412 1413
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
H
houdisheng 已提交
1414 1415 1416
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1417 1418 1419
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1420

1421 1422 1423 1424 1425 1426 1427 1428
**示例**

  ```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=> {
1429
            console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1430 1431 1432 1433 1434 1435 1436 1437
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryNotificationEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1438
queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void
1439 1440 1441 1442 1443 1444 1445

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

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

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

Y
yupeng74@huawei.com 已提交
1446
**系统API**:此接口为系统接口。
1447 1448 1449 1450 1451

**参数**

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

1456 1457
**错误码**

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

1460
| 错误码ID        | 错误信息                          |
H
houdisheng 已提交
1461 1462 1463 1464
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              |
| 10000002   | Parcel operation failed.              |
| 10000003   | System service operation failed.      |
1465 1466 1467
| 10000004   | IPC failed.             |
| 10000006   | Failed to get the application information.          |
| 10000007   | Failed to get the system time.     |
1468

1469 1470 1471 1472 1473 1474
**示例**

  ```js
    try{
        usageStatistics.queryNotificationEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1475
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1476
            } else {
Y
yupeng74@huawei.com 已提交
1477 1478
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
            }
        });
    } 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 已提交
1491
**系统API**:此接口为系统接口。
1492

1493
| 名称                  | 类型                                       | 必填   | 说明                            |
1494 1495
| -------------------- | ---------------------------------------- | ---- | ----------------------------- |
| deviceId             | string                                   | 否    | FA所属deviceId。                 |
1496
| bundleName           | string                                   | 是    | FA所属应用Bundle名称。             |
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
| 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的上一次使用时间。                   |
1507
| formRecords          | Array&lt;[HapFormInfo](#hapforminfo)&gt; | 是    | FA中卡片的使用记录。                   |
1508 1509 1510 1511 1512 1513

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

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

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

1516
| 名称              | 类型     | 必填   | 说明          |
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
| ---------------- | ------ | ---- | ----------- |
| formName         | string | 是    | 卡片名称。       |
| formDimension    | number | 是    | 卡片尺寸。       |
| formId           | number | 是    | 卡片Id。       |
| formLastUsedTime | number | 是    | 卡片的上一次点击时间。 |
| count            | number | 是    | 卡片的点击次数。    |

## AppGroupCallbackInfo

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

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

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

1532
| 名称           | 类型   | 必填 | 说明             |
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
| ---------------- | ------ | ---- | ---------------- |
| appOldGroup | number | 是   | 变化前的应用分组 |
| appNewGroup | number | 是   | 变化后的应用分组 |
| userId           | number | 是   | 用户id           |
| changeReason     | number | 是   | 分组变化原因     |
| bundleName       | string | 是   | 应用名称         |

## BundleStatsInfo

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

### 属性

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

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

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

## BundleEvents

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

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

H
houdisheng 已提交
1569 1570
**系统API**:此接口为系统接口。

1571
| 名称                   | 类型     | 必填   | 说明                                       |
1572 1573 1574 1575
| --------------------- | ------ | ---- | ---------------------------------------- |
| bundleName            | string | 是    | 应用包名。                                    |
| eventId             | number | 是    | 应用事件类型。                                  |
| eventOccurredTime     | number | 是    | 应用事件发生的时间戳。                              |
Y
yupeng74@huawei.com 已提交
1576 1577 1578
| appGroup | number | 否    | 应用程序的使用优先级组。|
| indexOfLink           | string | 否    | 快捷方式id。|
| nameOfClass           | string | 否    | 类名。|
1579 1580 1581 1582 1583 1584 1585

## BundleStatsMap

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

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

1586 1587
**系统API**:此接口为系统接口。

1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
| 参数名                            | 类型                                       | 必填   | 说明             |
| ------------------------------ | ---------------------------------------- | ---- | -------------- |
| [key: string]: BundleStatsInfo | [key: string]: [BundleStatsInfo](#bundlestatsinfo) | 是    | 不同应用的使用时长统计信息。 |

## DeviceEventStats

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

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

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

1600
| 名称     | 类型     | 必填   | 说明                |
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
| ------- | ------ | ---- | ----------------- |
| name    | string | 是    | 通知应用包名或者系统事件名。    |
| eventId | number | 是    | 通知、系统事件类型。        |
| count   | number | 是    | 应用通知次数或者系统事件触发次数。 |

## IntervalType

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

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

1612 1613 1614
**系统API**:此接口为系统接口。

| 名称           | 值  | 说明                                       |
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
| ------------ | ---- | ---------------------------------------- |
| BY_OPTIMIZED | 0    | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 |
| BY_DAILY     | 1    | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。              |
| BY_WEEKLY    | 2    | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。              |
| BY_MONTHLY   | 3    | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。              |
| BY_ANNUALLY  | 4    | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。              |

## GroupType

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

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

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

1630
| 名称                 | 值  | 说明                |
1631 1632 1633 1634 1635 1636 1637
| ------------------ | ---- | ----------------- |
| ALIVE_GROUP | 10   | 活跃分组。              |
| DAILY_GROUP | 20   | 经常使用,但当前并未在活跃态。    |
| FIXED_GROUP | 30   | 常用分组,定期使用,但不是每天使用。 |
| RARE_GROUP  | 40   | 极少使用分组,不经常使用。      |
| LIMITED_GROUP | 50   | 受限使用分组。            |
| NEVER_GROUP | 60   | 从未使用分组,安装但是从未运行过。  |