js-apis-resourceschedule-deviceUsageStatistics.md 71.5 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 38 39 40 41 42 43 44 45 46


## 导入模块

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

## usageStatistics.isIdleState

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

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

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

**参数**

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

47 48
**错误码**

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

51 52 53 54 55 56 57 58
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
| 10000001   | Memory operation failed.         | 
| 10000002   | Parcel operation failed.         | 
| 10000003   | System service operation failed. | 
| 10000004   | IPC Communication failed.        | 
| 10000006   | Get application info failed.     |

59
**示例**
Y
yupeng74@huawei.com 已提交
60
  ```js
61 62
    try{
        usageStatistics.isIdleState("com.ohos.camera", (err, res) => {
Y
yupeng74@huawei.com 已提交
63 64 65 66 67
            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));
            }
68 69 70 71 72 73
        });
    } catch(error) {
        console.log('BUNDLE_ACTIVE isIdleState throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

Y
yupeng74@huawei.com 已提交
74
## usageStatistics.isIdleState
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

isIdleState(bundleName: string): Promise<boolean>

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

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

**参数**

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

**返回值**

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

94 95
**错误码**

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

98 99 100 101 102 103 104 105
| 错误码ID        | 错误信息                     |
| ---------- | ----------------------------     |
| 10000001   | Memory operation failed.         | 
| 10000002   | Parcel operation failed.         | 
| 10000003   | System service operation failed. | 
| 10000004   | IPC Communication failed.        | 
| 10000006   | Get application info failed.     |

106 107 108 109 110 111 112
**示例**

  ```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 已提交
113
            console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        });
    } 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回调方法。返回查询的应用分组结果。 |

134 135
**错误码**

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

138 139 140 141 142 143 144 145 146 147
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          | 
| 10000005   | Application is not installed.      | 
| 10000006   | Get application info failed.       |
| 10100002   | Get Application group info failed. |

148 149 150 151 152 153 154
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup().then( res => {
            console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
        }).catch( err => {
155
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        });
    } 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回调方法。返回查询的应用分组。 |

176 177
**错误码**

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

180
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
181
| ---------- | ----------------------------       | 
182 183 184 185 186 187 188 189
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          | 
| 10000005   | Application is not installed.      | 
| 10000006   | Get application info failed.       |
| 10100002   | Get Application group info failed. |

190 191 192 193 194
**示例**

```javascript
    try{
        usageStatistics.queryAppGroup((err, res) => {
Y
yupeng74@huawei.com 已提交
195 196 197 198 199
            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));
            }
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        });
    } 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 已提交
216
**系统API**:此接口为系统接口。
217 218 219 220 221 222 223 224 225

**参数**

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

226 227
**错误码**

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

230
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
231
| ---------- | ----------------------------       | 
232 233 234 235 236 237 238
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

239 240 241 242 243 244
**示例**

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

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| begin | number | 是    | 起始时间。 |
| end   | number | 是    | 结束时间。 |

**返回值**

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

286 287
**错误码**

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

290
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
291
| ---------- | ----------------------------       | 
292 293 294 295 296 297 298
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

299 300 301 302 303 304 305 306
**示例**

  ```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 已提交
307 308 309
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise number : ' + i);
                console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res[key]));
                i++;
310 311
            }
        }).catch( err => {
312
            console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
        });
    } 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 已提交
329
**系统API**:此接口为系统接口。
330 331 332 333 334 335 336 337 338 339

**参数**

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

340 341
**错误码**

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

344
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
345
| ---------- | ----------------------------       | 
346 347 348 349 350 351 352
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

353 354 355 356 357 358
**示例**

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

**参数**

| 参数名        | 类型                            | 必填   | 说明    |
| ---------- | ----------------------------- | ---- | ----- |
| byInterval | [IntervalType](#intervaltype) | 是    | 查询类型。 |
| begin      | number                        | 是    | 起始时间。 |
| end        | number                        | 是    | 结束时间。 |

**返回值**

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

399 400
**错误码**

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

403
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
404
| ---------- | ----------------------------       | 
405 406 407 408 409 410 411
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

412 413 414 415 416 417 418
**示例**

  ```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 已提交
419 420
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
421 422
            }
        }).catch( err => {
423
            console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
        });
    } 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 已提交
440
**系统API**:此接口为系统接口。
441 442 443 444 445 446 447 448 449

**参数**

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

450 451
**错误码**

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

454 455 456 457 458 459 460 461 462
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

463 464 465 466 467 468
**示例**

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

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| begin | number | 是    | 起始时间。 |
| end   | number | 是    | 结束时间。 |

**返回值**

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

508 509
**错误码**

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

512 513 514 515 516 517 518 519 520
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

521 522 523 524 525 526 527
**示例**

  ```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 已提交
528 529
                console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
530 531
            }
        }).catch( err => {
532
            console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
        });
    } 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

**参数**

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

555 556
**错误码**

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

559
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
560
| ---------- | ----------------------------       | 
561 562 563 564 565 566 567
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

568 569 570 571 572 573
**示例**

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

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| begin | number | 是    | 起始时间。 |
| end   | number | 是    | 结束时间。 |

**返回值**

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

609 610
**错误码**

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

613
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
614
| ---------- | ----------------------------       | 
615 616 617 618 619 620 621
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

622 623 624 625 626 627 628
**示例**

  ```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 已提交
629 630
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
631 632
            }
        }).catch( err => {
633
            console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
        });
    } 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 已提交
650
**系统API**:此接口为系统接口。
651 652 653 654 655

**返回值**

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

658 659
**错误码**

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

662
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
663
| ---------- | ----------------------------       | 
664 665 666 667 668 669 670
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

671 672 673 674 675 676 677 678 679 680 681 682
**示例**

  ```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=> {
683
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
        });
    } 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 已提交
700
**系统API**:此接口为系统接口。
701 702 703 704 705

**参数**

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

708 709
**错误码**

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

712
| 错误码ID        | 错误信息                       |
Y
yupeng74@huawei.com 已提交
713
| ---------- | ----------------------------       | 
714 715 716 717 718 719 720
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

721 722 723 724 725 726
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords((err, res) => {
        if(err) {
727
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
        } 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 已提交
751
**系统API**:此接口为系统接口。
752 753 754 755 756 757 758 759 760 761 762

**参数**

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

**返回值**

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

765 766
**错误码**

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

769 770 771 772 773 774 775 776 777
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

778 779 780 781 782 783 784 785 786 787 788
**示例**

  ```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=> {
789
            console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
        });
    } 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 已提交
806
**系统API**:此接口为系统接口。
807 808 809 810 811 812

**参数**

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

815 816
**错误码**

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

819 820 821 822 823 824 825 826 827
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          |  
| 10000006   | Get application info failed.       |
| 10000007   | Get system or actual time failed.  |

828 829 830 831 832
**示例**

  ```js
    try{
        usageStatistics.queryModuleUsageRecords(1000, (err, res) => {
Y
yupeng74@huawei.com 已提交
833 834 835 836 837 838 839 840
            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]));
                }
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
            }
        });
    } 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 已提交
858
**系统API**:此接口为系统接口。
859 860 861 862 863 864 865 866 867 868 869 870 871

**参数**

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

**返回值**

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

872 873
**错误码**

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

876 877 878 879 880 881 882 883 884 885
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          | 
| 10000005   | Application is not installed.      | 
| 10000006   | Get application info failed.       |
| 10100002   | Get Application group info failed. |

886 887 888 889 890 891 892 893 894
**示例**

```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 已提交
895
            console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
        });
    } 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 已提交
912
**系统API**:此接口为系统接口。
913 914 915 916 917 918 919 920

**参数**

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

921 922
**错误码**

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

925 926 927 928 929 930 931 932 933 934
| 错误码ID        | 错误信息                       |
| ---------- | ----------------------------       |
| 10000001   | Memory operation failed.           | 
| 10000002   | Parcel operation failed.           | 
| 10000003   | System service operation failed.   | 
| 10000004   | IPC Communication failed.          | 
| 10000005   | Application is not installed.      | 
| 10000006   | Get application info failed.       |
| 10100002   | Get Application group info failed. |

935 936 937 938 939 940
**示例**

```javascript
    let bundleName = "com.ohos.camera";
    try{
        usageStatistics.queryAppGroup(bundleName, (err, res) => {
Y
yupeng74@huawei.com 已提交
941 942 943 944 945
            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));
            }
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
        });
    } 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 已提交
962
**系统API**:此接口为系统接口。
963 964 965 966 967 968 969 970

**参数**

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

971 972
**错误码**

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

975 976 977 978 979 980 981 982 983
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10000006   | Get application info failed.          |
| 10100001   | Application group operation repeated. |

984 985 986 987 988 989 990 991 992 993
**返回值**

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

**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
994
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
995 996 997 998 999

    try{
        usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
            console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
        }).catch( err => {
Y
yupeng74@huawei.com 已提交
1000
            console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
        });
    } 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 已提交
1017
**系统API**:此接口为系统接口。
1018 1019 1020 1021 1022 1023 1024 1025 1026

**参数**

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

1027 1028
**错误码**

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

1031
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1032
| ---------- | ----------------------------          | 
1033 1034 1035 1036 1037 1038 1039
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10000006   | Get application info failed.          |
| 10100001   | Application group operation repeated. |

1040 1041 1042 1043
**示例**

```javascript
    let bundleName = "com.example.deviceUsageStatistics";
1044
    let newGroup = usageStatistics.GroupType.DAILY_GROUP;
1045 1046 1047 1048

    try{
        usageStatistics.setAppGroup(bundleName, newGroup, (err) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1049
                console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
1050
            } else {
Y
yupeng74@huawei.com 已提交
1051
                console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
            }
        });
    } 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;

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

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

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

Y
yupeng74@huawei.com 已提交
1069
**系统API**:此接口为系统接口。
1070 1071 1072 1073 1074

**参数**

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

1077 1078
**错误码**

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

1081 1082 1083 1084 1085 1086 1087 1088
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10100001   | Application group operation repeated. |

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
**返回值**

| 类型            | 说明                      |
| ------------- | ----------------------- |
| 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 已提交
1110
            console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
        });
    } 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

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

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

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

Y
yupeng74@huawei.com 已提交
1127
**系统API**:此接口为系统接口。
1128 1129 1130 1131 1132

**参数**

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

1136 1137
**错误码**

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

1140 1141 1142 1143 1144 1145 1146 1147 1148
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10100001   | Application group operation repeated. |


1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
**示例**

```javascript
    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 已提交
1161 1162 1163 1164 1165 1166
        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.');
            }
1167 1168 1169 1170 1171 1172
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE registerAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
```

1173
## usageStatistics.unregisterAppGroupCallBack
1174

1175
unregisterAppGroupCallBack(): Promise&lt;void&gt;
1176 1177 1178 1179 1180 1181 1182

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

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

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

Y
yupeng74@huawei.com 已提交
1183
**系统API**:此接口为系统接口。
1184 1185 1186 1187 1188 1189 1190

**返回值**

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

1191 1192
**错误码**

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

1195
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1196
| ---------- | ----------------------------          | 
1197 1198 1199 1200 1201 1202
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10100001   | Application group operation repeated. |

1203 1204 1205 1206
**示例**

```javascript
    try{
1207 1208
        usageStatistics.unregisterAppGroupCallBack().then( () => {
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.');
1209
        }).catch( err => {
1210
            console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
1211 1212
        });
    } catch (error) {
1213
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1214 1215 1216
    }
```

1217
## usageStatistics.unregisterAppGroupCallBack
1218

1219
unregisterAppGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
1220 1221 1222 1223 1224 1225 1226

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

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

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

Y
yupeng74@huawei.com 已提交
1227
**系统API**:此接口为系统接口。
1228 1229 1230 1231 1232 1233 1234

**参数**

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

1235 1236
**错误码**

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

1239
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1240
| ---------- | ----------------------------          | 
1241 1242 1243 1244 1245 1246
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
| 10100001   | Application group operation repeated. |

1247 1248 1249 1250
**示例**

```javascript
    try{
Y
yupeng74@huawei.com 已提交
1251 1252 1253 1254 1255 1256
        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.');
            }
1257 1258
        });
    } catch (error) {
1259
        console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack throw error, code is: ' + error.code + ',message is: ' + error.message);
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
    }
```

## 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 已提交
1273
**系统API**:此接口为系统接口。
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| begin | number | 是    | 起始时间。 |
| end   | number | 是    | 结束时间。 |

**返回值**

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

1288 1289
**错误码**

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

1292
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1293
| ---------- | ----------------------------          | 
1294 1295 1296 1297
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
1298
| 10000006   | Get application info failed.          |
1299 1300
| 10000007   | Get system or actual time failed.     |

1301 1302 1303 1304 1305 1306 1307 1308
**示例**

  ```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=> {
1309
            console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
        });
    } 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 已提交
1326
**系统API**:此接口为系统接口。
1327 1328 1329 1330 1331 1332 1333

**参数**

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

1336 1337
**错误码**

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

1340 1341 1342 1343 1344 1345
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
1346
| 10000006   | Get application info failed.           |
1347 1348
| 10000007   | Get system or actual time failed.     |

1349 1350 1351 1352 1353 1354
**示例**

  ```js
    try{
        usageStatistics.queryDeviceEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1355
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1356
            } else {
Y
yupeng74@huawei.com 已提交
1357 1358
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
1359 1360 1361 1362 1363 1364 1365 1366 1367
            }
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryDeviceEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1368
queryNotificationEventStats(begin: number, end: number): Promise&lt;Array&lt;DeviceEventStats&gt;&gt;
1369 1370 1371 1372 1373 1374 1375

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

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

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

Y
yupeng74@huawei.com 已提交
1376
**系统API**:此接口为系统接口。
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388

**参数**

| 参数名   | 类型     | 必填   | 说明    |
| ----- | ------ | ---- | ----- |
| begin | number | 是    | 起始时间。 |
| end   | number | 是    | 结束时间。 |

**返回值**

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

1391 1392
**错误码**

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

1395 1396 1397 1398 1399 1400
| 错误码ID        | 错误信息                          |
| ---------- | ----------------------------          |
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
1401
| 10000006   | Get application info failed.          |
1402 1403
| 10000007   | Get system or actual time failed.     |

1404 1405 1406 1407 1408 1409 1410 1411
**示例**

  ```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=> {
1412
            console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
1413 1414 1415 1416 1417 1418 1419 1420
        });
    } catch (error) {
        console.log('BUNDLE_ACTIVE queryNotificationEventStats throw error, code is: ' + error.code + ',message is: ' + error.message);
    }
  ```

## usageStatistics.queryNotificationEventStats

Y
yupeng74@huawei.com 已提交
1421
queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;DeviceEventStats&gt;&gt;): void
1422 1423 1424 1425 1426 1427 1428

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

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

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

Y
yupeng74@huawei.com 已提交
1429
**系统API**:此接口为系统接口。
1430 1431 1432 1433 1434 1435 1436

**参数**

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

1439 1440
**错误码**

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

1443
| 错误码ID        | 错误信息                          |
Y
yupeng74@huawei.com 已提交
1444
| ---------- | ----------------------------          | 
1445 1446 1447 1448
| 10000001   | Memory operation failed.              | 
| 10000002   | Parcel operation failed.              | 
| 10000003   | System service operation failed.      | 
| 10000004   | IPC Communication failed.             | 
1449
| 10000006   | Get application info failed.          |
1450 1451
| 10000007   | Get system or actual time failed.     |

1452 1453 1454 1455 1456 1457
**示例**

  ```js
    try{
        usageStatistics.queryNotificationEventStats(0, 20000000000000, (err, res) => {
            if(err) {
Y
yupeng74@huawei.com 已提交
1458
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
1459
            } else {
Y
yupeng74@huawei.com 已提交
1460 1461
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
                console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
            }
        });
    } 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 已提交
1474
**系统API**:此接口为系统接口。
1475

1476
| 名称                  | 类型                                       | 必填   | 说明                            |
1477 1478
| -------------------- | ---------------------------------------- | ---- | ----------------------------- |
| deviceId             | string                                   | 否    | FA所属deviceId。                 |
1479
| bundleName           | string                                   | 是    | FA所属应用Bundle名称。             |
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
| 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的上一次使用时间。                   |
1490
| formRecords          | Array&lt;[HapFormInfo](#hapforminfo)&gt; | 是    | FA中卡片的使用记录。                   |
1491 1492 1493 1494 1495 1496

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

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

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

1499
| 名称              | 类型     | 必填   | 说明          |
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
| ---------------- | ------ | ---- | ----------- |
| formName         | string | 是    | 卡片名称。       |
| formDimension    | number | 是    | 卡片尺寸。       |
| formId           | number | 是    | 卡片Id。       |
| formLastUsedTime | number | 是    | 卡片的上一次点击时间。 |
| count            | number | 是    | 卡片的点击次数。    |

## AppGroupCallbackInfo

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

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

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

1515
| 名称           | 类型   | 必填 | 说明             |
1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
| ---------------- | ------ | ---- | ---------------- |
| appOldGroup | number | 是   | 变化前的应用分组 |
| appNewGroup | number | 是   | 变化后的应用分组 |
| userId           | number | 是   | 用户id           |
| changeReason     | number | 是   | 分组变化原因     |
| bundleName       | string | 是   | 应用名称         |

## BundleStatsInfo

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

### 属性

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

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

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

## BundleEvents

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

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

1552
| 名称                   | 类型     | 必填   | 说明                                       |
1553 1554 1555 1556
| --------------------- | ------ | ---- | ---------------------------------------- |
| bundleName            | string | 是    | 应用包名。                                    |
| eventId             | number | 是    | 应用事件类型。                                  |
| eventOccurredTime     | number | 是    | 应用事件发生的时间戳。                              |
Y
yupeng74@huawei.com 已提交
1557 1558 1559
| appGroup | number | 否    | 应用程序的使用优先级组。|
| indexOfLink           | string | 否    | 快捷方式id。|
| nameOfClass           | string | 否    | 类名。|
1560 1561 1562 1563 1564 1565 1566

## BundleStatsMap

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

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

1567 1568
**系统API**:此接口为系统接口。

1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
| 参数名                            | 类型                                       | 必填   | 说明             |
| ------------------------------ | ---------------------------------------- | ---- | -------------- |
| [key: string]: BundleStatsInfo | [key: string]: [BundleStatsInfo](#bundlestatsinfo) | 是    | 不同应用的使用时长统计信息。 |

## DeviceEventStats

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

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

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

1581
| 名称     | 类型     | 必填   | 说明                |
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
| ------- | ------ | ---- | ----------------- |
| name    | string | 是    | 通知应用包名或者系统事件名。    |
| eventId | number | 是    | 通知、系统事件类型。        |
| count   | number | 是    | 应用通知次数或者系统事件触发次数。 |

## IntervalType

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

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

1593 1594 1595
**系统API**:此接口为系统接口。

| 名称           | 值  | 说明                                       |
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
| ------------ | ---- | ---------------------------------------- |
| BY_OPTIMIZED | 0    | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 |
| BY_DAILY     | 1    | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。              |
| BY_WEEKLY    | 2    | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。              |
| BY_MONTHLY   | 3    | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。              |
| BY_ANNUALLY  | 4    | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。              |

## GroupType

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

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

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

1611
| 名称                 | 值  | 说明                |
1612 1613 1614 1615 1616 1617 1618
| ------------------ | ---- | ----------------- |
| ALIVE_GROUP | 10   | 活跃分组。              |
| DAILY_GROUP | 20   | 经常使用,但当前并未在活跃态。    |
| FIXED_GROUP | 30   | 常用分组,定期使用,但不是每天使用。 |
| RARE_GROUP  | 40   | 极少使用分组,不经常使用。      |
| LIMITED_GROUP | 50   | 受限使用分组。            |
| NEVER_GROUP | 60   | 从未使用分组,安装但是从未运行过。  |