js-apis-deviceUsageStatistics.md 53.3 KB
Newer Older
E
ester.zhou 已提交
1 2
# Device Usage Statistics

E
ester.zhou 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
This module provides APIs for collecting statistics on device usage.

System applications can call these APIs to implement the following features:

- Query the usage duration in different time segments, events (foreground, background, start and end of continuous tasks), and the number of notifications, on a per application basis.
- Query statistics about system events (sleep, wakeup, unlock, and screen lock).
- Query the bundle group information of applications, including the invoking application itself.
- Query the idle status of applications, including the invoking application itself.
- Set the bundle group for other applications.
- Register and deregister the callback for application group changes.

Third-party applications can call these APIs to implement the following features:

- Query the idle status of the invoking application itself.
- Query the bundle group information of the invoking application itself.
- Query the events of the invoking application itself.

> **NOTE**
>
22
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
E
ester.zhou 已提交
23 24 25 26 27 28 29 30 31


## Modules to Import

```
import bundleState from '@ohos.bundleState'
```

## bundleState.isIdleState
E
ester.zhou 已提交
32 33 34

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

35
Checks whether the application specified by **bundleName** is in the idle state. This API uses an asynchronous callback to return the result. A third-party application can only check the idle status of itself.
E
ester.zhou 已提交
36 37 38 39 40

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**Parameters**

41 42 43
| Name       | Type                          | Mandatory  | Description                                      |
| ---------- | ---------------------------- | ---- | ---------------------------------------- |
| bundleName | string                       | Yes   | Bundle name of an application.                          |
E
ester.zhou 已提交
44
| callback   | AsyncCallback<boolean> | Yes   | Callback used to return the result. Returns the idle state of the application if the specified **bundleName** is valid; returns **null** otherwise.|
E
ester.zhou 已提交
45 46 47 48 49

**Example**

  ```
    bundleState.isIdleState("com.ohos.camera", (err, res) => {
E
ester.zhou 已提交
50
        if (err) {
E
ester.zhou 已提交
51
            console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
E
ester.zhou 已提交
52 53
        } else {
            console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
E
ester.zhou 已提交
54 55 56 57 58
        }
    });
  ```

## bundleState.isIdleState
E
ester.zhou 已提交
59 60 61

isIdleState(bundleName: string): Promise<boolean>

62
Checks whether the application specified by **bundleName** is in the idle state. This API uses a promise to return the result. A third-party application can only check the idle status of itself.
E
ester.zhou 已提交
63 64 65 66 67

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**Parameters**

68 69 70
| Name       | Type    | Mandatory  | Description            |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes   | Bundle name of an application.|
E
ester.zhou 已提交
71 72 73

**Return value**

74 75
| Type                    | Description                                      |
| ---------------------- | ---------------------------------------- |
E
ester.zhou 已提交
76
| Promise<boolean> | Promise used to return the result. Returns the idle state of the application if the specified **bundleName** is valid; returns **null** otherwise.|
E
ester.zhou 已提交
77 78 79

**Example**

E
ester.zhou 已提交
80
  ```js
E
ester.zhou 已提交
81 82 83 84 85 86 87 88
    bundleState.isIdleState("com.ohos.camera").then( res => {
        console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
    }).catch( err => {
        console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryAppUsagePriorityGroup
E
ester.zhou 已提交
89

E
ester.zhou 已提交
90
queryAppUsagePriorityGroup(): Promise<number>
E
ester.zhou 已提交
91

92
Queries the priority group of this application. This API uses a promise to return the result.
E
ester.zhou 已提交
93 94 95

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

96
**Return value**
E
ester.zhou 已提交
97

98 99
| Type             | Description                         |
| --------------- | --------------------------- |
E
ester.zhou 已提交
100
| Promise<number> | Promise used to return the result.|
E
ester.zhou 已提交
101 102 103

**Example**

104 105 106 107 108 109 110
```javascript
bundleState.queryAppUsagePriorityGroup().then( res => {
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
});
```
E
ester.zhou 已提交
111 112

## bundleState.queryAppUsagePriorityGroup
E
ester.zhou 已提交
113

E
ester.zhou 已提交
114
queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void
E
ester.zhou 已提交
115

116
Queries the priority group of this application. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
117 118 119

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

120
**Parameters**
E
ester.zhou 已提交
121

122 123
| Name     | Type                   | Mandatory  | Description                        |
| -------- | --------------------- | ---- | -------------------------- |
E
ester.zhou 已提交
124
| callback | AsyncCallback<number> | Yes   | Callback used to return the result.|
E
ester.zhou 已提交
125 126 127

**Example**

128 129 130 131 132 133 134 135 136
```javascript
bundleState.queryAppUsagePriorityGroup((err, res) => {
    if(err) {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
    }
});
```
E
ester.zhou 已提交
137 138

## bundleState.queryBundleStateInfos
E
ester.zhou 已提交
139 140 141 142 143

queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void

Queries the application usage duration statistics based on the specified start time and end time. This API uses an asynchronous callback to return the result.

E
ester.zhou 已提交
144 145 146 147
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

148 149
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
150 151
**Parameters**

152 153 154 155 156
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| begin    | number                                   | Yes   | Start time.                                  |
| end      | number                                   | Yes   | End time.                                  |
| callback | AsyncCallback<[BundleActiveInfoResponse](#bundleactiveinforesponse)> | Yes   | Callback used to return the result.|
E
ester.zhou 已提交
157 158 159

**Example**

E
ester.zhou 已提交
160
  ```js
E
ester.zhou 已提交
161
    bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => {
E
ester.zhou 已提交
162 163 164
        if (err) {
            console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
        } else {
E
ester.zhou 已提交
165 166 167 168 169 170 171 172 173 174 175 176
            console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
            let i = 1;
            for(let key in res){
                console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
                console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
                i++;
            }
        }
    });
  ```

## bundleState.queryBundleStateInfos
E
ester.zhou 已提交
177 178 179 180 181

queryBundleStateInfos(begin: number, end: number): Promise<BundleActiveInfoResponse>

Queries the application usage duration statistics based on the specified start time and end time. This API uses a promise to return the result.

E
ester.zhou 已提交
182 183 184 185
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

186 187
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
188 189
**Parameters**

190 191 192 193
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| begin | number | Yes   | Start time.|
| end   | number | Yes   | End time.|
E
ester.zhou 已提交
194 195 196

**Return value**

197 198
| Type                                      | Description                                    |
| ---------------------------------------- | -------------------------------------- |
E
ester.zhou 已提交
199
| Promise<[BundleActiveInfoResponse](#bundleactiveinforesponse)> | Promise used to return the result.|
E
ester.zhou 已提交
200 201 202

**Example**

E
ester.zhou 已提交
203
  ```js
E
ester.zhou 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217
    bundleState.queryBundleStateInfos(0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
        let i = 1;
        for(let key in res){
            console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
            console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
            i++;
        }
    }).catch( err => {
        console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryBundleStateInfoByInterval
E
ester.zhou 已提交
218 219 220 221 222

queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void

Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses an asynchronous callback to return the result.

E
ester.zhou 已提交
223 224 225 226
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

227 228
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
229 230
**Parameters**

231 232 233 234 235 236
| Name       | Type                                      | Mandatory  | Description                                      |
| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
| byInterval | [IntervalType](#intervaltype)            | Yes   | Type of information to be queried.                                   |
| begin      | number                                   | Yes   | Start time.                                   |
| end        | number                                   | Yes   | End time.                                   |
| callback   | AsyncCallback<Array<[BundleStateInfo](#bundlestateinfo)>> | Yes   | Callback used to return the result.|
E
ester.zhou 已提交
237 238 239

**Example**

E
ester.zhou 已提交
240
  ```js
E
ester.zhou 已提交
241
    bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
E
ester.zhou 已提交
242 243 244
        if (err) {
            console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
        } else {
E
ester.zhou 已提交
245 246 247 248 249 250 251 252 253 254
            console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
            for (let i = 0; i < res.length; i++) {
                console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
            }
        }
    });
  ```

## bundleState.queryBundleStateInfoByInterval
E
ester.zhou 已提交
255 256 257 258 259

queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise&lt;Array&lt;BundleStateInfo&gt;&gt;

Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses a promise to return the result.

E
ester.zhou 已提交
260 261 262 263
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

264 265
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
266 267
**Parameters**

268 269 270 271 272
| Name       | Type                           | Mandatory  | Description   |
| ---------- | ----------------------------- | ---- | ----- |
| byInterval | [IntervalType](#intervaltype) | Yes   | Type of information to be queried.|
| begin      | number                        | Yes   | Start time.|
| end        | number                        | Yes   | End time.|
E
ester.zhou 已提交
273 274 275

**Return value**

276 277
| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
278
| Promise&lt;Array&lt;[BundleStateInfo](#bundlestateinfo)&gt;&gt; | Promise used to return the result. |
E
ester.zhou 已提交
279 280 281

**Example**

E
ester.zhou 已提交
282
  ```js
E
ester.zhou 已提交
283 284 285 286 287 288 289 290 291 292 293 294
    bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
        for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
        }
    }).catch( err => {
        console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryBundleActiveStates
E
ester.zhou 已提交
295 296 297 298 299

queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleActiveState&gt;&gt;): void

Queries events of all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result.

E
ester.zhou 已提交
300 301 302 303
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

304 305
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
306 307
**Parameters**

308 309 310 311
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| begin    | number                                   | Yes   | Start time.                                  |
| end      | number                                   | Yes   | End time.                                  |
E
ester.zhou 已提交
312
| callback | AsyncCallback&lt;Array&lt;[BundleActiveState](#bundleactivestate)&gt;&gt; | Yes   | Callback used to return the result. |
E
ester.zhou 已提交
313 314 315

**Example**

E
ester.zhou 已提交
316
  ```js
E
ester.zhou 已提交
317
    bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => {
E
ester.zhou 已提交
318 319 320
        if (err) {
            console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
        } else {
E
ester.zhou 已提交
321 322 323 324 325 326 327 328 329 330
            console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
            for (let i = 0; i < res.length; i++) {
                console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
            }
        }
    });
  ```

## bundleState.queryBundleActiveStates
E
ester.zhou 已提交
331 332 333 334 335

queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleActiveState&gt;&gt;

Queries events of all applications based on the specified start time and end time. This API uses a promise to return the result.

E
ester.zhou 已提交
336 337 338 339
**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

340 341
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
342 343
**Parameters**

344 345 346 347
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| begin | number | Yes   | Start time.|
| end   | number | Yes   | End time.|
E
ester.zhou 已提交
348 349 350

**Return value**

351 352
| Type                                      | Description                                    |
| ---------------------------------------- | -------------------------------------- |
E
ester.zhou 已提交
353
| Promise&lt;Array&lt;[BundleActiveState](#bundleactivestate)&gt;&gt; | Promise used to return the result. |
E
ester.zhou 已提交
354 355 356

**Example**

E
ester.zhou 已提交
357
  ```js
E
ester.zhou 已提交
358 359 360 361 362 363 364 365 366 367 368 369
    bundleState.queryBundleActiveStates(0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
        for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
        }
    }).catch( err => {
        console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryCurrentBundleActiveStates
E
ester.zhou 已提交
370 371 372

queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleActiveState&gt;&gt;): void

E
ester.zhou 已提交
373 374 375 376 377 378
Queries events of this application based on the specified start time and end time. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**Parameters**

379 380 381 382
| Name     | Type                                      | Mandatory  | Description                                     |
| -------- | ---------------------------------------- | ---- | --------------------------------------- |
| begin    | number                                   | Yes   | Start time.                                  |
| end      | number                                   | Yes   | End time.                                  |
E
ester.zhou 已提交
383
| callback | AsyncCallback&lt;Array&lt;[BundleActiveState](#bundleactivestate)&gt;&gt; | Yes   | Callback used to return the result. |
E
ester.zhou 已提交
384 385 386

**Example**

E
ester.zhou 已提交
387
  ```js
E
ester.zhou 已提交
388
    bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
E
ester.zhou 已提交
389 390 391
        if (err) {
            console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
        } else {
E
ester.zhou 已提交
392 393 394 395
            console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
            for (let i = 0; i < res.length; i++) {
                console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
                console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
E
ester.zhou 已提交
396
            }
E
ester.zhou 已提交
397 398 399 400 401
        }
    });
  ```

## bundleState.queryCurrentBundleActiveStates
E
ester.zhou 已提交
402 403 404

queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleActiveState&gt;&gt;

E
ester.zhou 已提交
405 406 407 408 409 410
Queries events of this application based on the specified start time and end time. This API uses a promise to return the result.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**Parameters**

411 412 413 414
| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| begin | number | Yes   | Start time.|
| end   | number | Yes   | End time.|
E
ester.zhou 已提交
415 416 417

**Return value**

418 419
| Type                                      | Description                                    |
| ---------------------------------------- | -------------------------------------- |
E
ester.zhou 已提交
420
| Promise&lt;Array&lt;[BundleActiveState](#bundleactivestate)&gt;&gt; | Promise used to return the result. |
E
ester.zhou 已提交
421 422 423

**Example**

E
ester.zhou 已提交
424
  ```js
E
ester.zhou 已提交
425 426 427 428 429 430 431 432 433 434 435
    bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
        for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
        }
    }).catch( err => {
        console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
    });
  ```

E
ester.zhou 已提交
436 437
## bundleState.getRecentlyUsedModules<sup>9+</sup>

E
ester.zhou 已提交
438
getRecentlyUsedModules(maxNum?: number): Promise&lt;Array&lt;BundleActiveModuleInfo&gt;&gt;
E
ester.zhou 已提交
439 440 441 442 443 444 445

Obtains the number of FA usage records specified by **maxNum**. This API uses a promise to return the records sorted by time (most recent first).

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

446 447
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
448 449
**Parameters**

450 451 452
| Name   | Type    | Mandatory  | Description                                |
| ------ | ------ | ---- | ---------------------------------- |
| maxNum | number | No   | Maximum number of returned records. The maximum and default value is **1000**. If this parameter is not specified, **1000** is used.|
E
ester.zhou 已提交
453 454 455

**Return value**

456 457
| Type                                      | Description                                |
| ---------------------------------------- | ---------------------------------- |
E
ester.zhou 已提交
458
| Promise&lt;Array&lt;[BundleActiveModuleInfo](#bundleactivemoduleinfo9)&gt;&gt; | Promise used to return the result. |
E
ester.zhou 已提交
459 460 461 462

**Example**

  ```js
463
    bundleState.getRecentlyUsedModules(1000).then( res => {
E
ester.zhou 已提交
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
        console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
        for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i]));
        }
    }).catch( err=> {
        console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code);
    });

    // Invocation when maxNum is not passed
    bundleState.getRecentlyUsedModules().then( res => {
        console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise succeeded');
        for (let i = 0; i < res.length; i++) {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise number : ' + (i + 1));
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise result ' + JSON.stringify(res[i]));
        }
    }).catch( err=> {
        console.log('BUNDLE_ACTIVE getRecentlyUsedModules promise failed, because: ' + err.code);
    });
  ```

## bundleState.getRecentlyUsedModules<sup>9+</sup>

487
getRecentlyUsedModules(callback: AsyncCallback&lt;Array&lt;BundleActiveModuleInfo&gt;&gt;): void
E
ester.zhou 已提交
488

E
ester.zhou 已提交
489
Obtains FA usage records. This API uses an asynchronous callback to return a maximum of 1000 FA usage records sorted by time in descending order.
E
ester.zhou 已提交
490 491 492 493 494

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

495 496
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
497 498
**Parameters**

499 500
| Name     | Type                                      | Mandatory  | Description                                 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
E
ester.zhou 已提交
501
| callback | AsyncCallback&lt;Array&lt;[BundleActiveModuleInfo](#bundleactivemoduleinfo9)&gt;&gt; | Yes   | Callback used to return the result. |
E
ester.zhou 已提交
502 503 504 505

**Example**

  ```js
506
    bundleState.getRecentlyUsedModules((err, res) => {
E
ester.zhou 已提交
507 508 509 510 511 512 513 514
        if(err) {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
        } else {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback result ' + JSON.stringify(res[i]));
                }
515
            }
E
ester.zhou 已提交
516
    });
517
  ```
E
ester.zhou 已提交
518

519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
## bundleState.getRecentlyUsedModules<sup>9+</sup>

getRecentlyUsedModules(maxNum: number, callback: AsyncCallback&lt;Array&lt;BundleActiveModuleInfo&gt;&gt;): void

Obtains the number of FA usage records specified by **maxNum**. This API uses an asynchronous callback to return the records sorted by time (most recent first).

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                 |
| -------- | ---------------------------------------- | ---- | ----------------------------------- |
E
ester.zhou 已提交
535 536
| maxNum   | number                                   | Yes   | Maximum number of returned records. The maximum value is **1000**.|
| callback | AsyncCallback&lt;Array&lt;[BundleActiveModuleInfo](#bundleactivemoduleinfo9)&gt;&gt; | Yes   | Callback used to return the result. |
537 538 539 540 541

**Example**

  ```js
    bundleState.getRecentlyUsedModules(1000,(err, res) => {
E
ester.zhou 已提交
542 543 544 545 546 547 548 549
        if(err) {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback failed, because: ' + err.code);
        } else {
            console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback succeeded.');
                for (let i = 0; i < res.length; i++) {
                    console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback number : ' + (i + 1));
                    console.log('BUNDLE_ACTIVE getRecentlyUsedModules callback result ' + JSON.stringify(res[i]));
                }
550
        }
E
ester.zhou 已提交
551 552 553
    });
  ```

554 555
## bundleState.queryAppUsagePriorityGroup<sup>9+</sup>

E
ester.zhou 已提交
556
queryAppUsagePriorityGroup(bundleName? : string): Promise&lt;number&gt;
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575

Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses a promise to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name       | Type    | Mandatory  | Description                                      |
| ---------- | ------ | ---- | ---------------------------------------- |
| bundleName | string | No   | Bundle name of the target application. If this parameter is not specified, the priority group of the current application is queried.|

**Return value**

| Type             | Description                         |
| --------------- | --------------------------- |
E
ester.zhou 已提交
576
| Promise&lt;number&gt; | Promise used to return the result.|
577 578 579 580

**Example**

```javascript
E
ester.zhou 已提交
581
// Promise mode when bundleName is specified
E
ester.zhou 已提交
582 583
let bundleName = "com.ohos.camera";
bundleState.queryAppUsagePriorityGroup(bundleName).then( res => {
584 585 586 587
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
});
E
ester.zhou 已提交
588
// Promise mode when bundleName is not specified
589 590 591 592 593 594 595 596 597
bundleState.queryAppUsagePriorityGroup().then( res => {
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
    console.log('BUNDLE_ACTIVE QueryPackageGroup promise failed. because: ' + err.code);
});
```

## bundleState.queryAppUsagePriorityGroup<sup>9+</sup>

598
queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void
599

E
ester.zhou 已提交
600
Queries the priority group of this application. This API uses an asynchronous callback to return the result.
601 602 603 604 605 606 607 608 609 610 611

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name       | Type                   | Mandatory  | Description                                      |
| ---------- | --------------------- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
612
| callback   | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the result.               |
613 614 615 616

**Example**

```javascript
617
bundleState.queryAppUsagePriorityGroup((err, res) => {
618 619 620 621 622 623
    if(err) {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
    }
});
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
```

## bundleState.queryAppUsagePriorityGroup<sup>9+</sup>

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

Queries the priority group of the application specified by **bundleName**. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name       | Type                   | Mandatory  | Description                                      |
| ---------- | --------------------- | ---- | ---------------------------------------- |
E
ester.zhou 已提交
642 643
| bundleName | string                | Yes   | Bundle name of the target application.|
| callback   | AsyncCallback&lt;number&gt; | Yes   | Callback used to return the result. |
644 645 646 647 648 649

**Example**

```javascript
let bundleName = "com.ohos.camera";
bundleState.queryAppUsagePriorityGroup(bundleName, (err, res) => {
650 651 652 653 654 655 656 657 658 659
    if(err) {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback failed. because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE QueryPackageGroup callback succeeded. result: ' + JSON.stringify(res));
    }
});
```

## bundleState.setBundleGroup<sup>9+</sup>

E
ester.zhou 已提交
660
setBundleGroup(bundleName: string, newGroup: GroupType): Promise&lt;void&gt;
661 662 663 664 665 666 667 668 669 670 671 672 673

Sets the group for the application specified by **bundleName**. This API uses a promise to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name       | Type       | Mandatory  | Description  |
| ---------- | --------- | ---- | ---- |
E
ester.zhou 已提交
674 675
| bundleName | string    | Yes   | Bundle name of an application.|
| newGroup   | [GroupType](#grouptype) | Yes   | Application group.|
676 677 678 679 680

**Return value**

| Type           | Description                       |
| ------------- | ------------------------- |
E
ester.zhou 已提交
681
| Promise&lt;void&gt; | Promise used to return the result. |
682 683 684 685

**Example**

```javascript
E
ester.zhou 已提交
686 687
let bundleName = "com.example.deviceUsageStatistics";
let newGroup = bundleState.GroupType.ACTIVE_GROUP_DAILY;
688

E
ester.zhou 已提交
689
bundleState.setBundleGroup(bundleName, newGroup).then( () => {
690 691 692 693 694 695 696 697
    console.log('BUNDLE_ACTIVE SetBundleGroup promise succeeded.');
}).catch( err => {
    console.log('BUNDLE_ACTIVE SetBundleGroup promise failed. because: ' + err.code);
});
```

## bundleState.setBundleGroup<sup>9+</sup>

E
ester.zhou 已提交
698
setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback&lt;void&gt;): void
699 700 701 702 703 704 705 706 707 708 709 710 711

Sets the group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name       | Type                 | Mandatory  | Description                       |
| ---------- | ------------------- | ---- | ------------------------- |
E
ester.zhou 已提交
712 713
| bundleName | string              | Yes   | Bundle name of an application.                     |
| newGroup   | [GroupType](#grouptype)           | Yes   | Application group.                     |
E
ester.zhou 已提交
714
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result. |
715 716 717 718

**Example**

```javascript
E
ester.zhou 已提交
719 720
let bundleName = "com.example.deviceUsageStatistics";
let newGroup = bundleState.GroupType.ACTIVE_GROUP_DAILY;
721

E
ester.zhou 已提交
722
bundleState.setBundleGroup(bundleName, newGroup, (err) => {
723 724 725 726 727 728 729 730 731 732
    if(err) {
        console.log('BUNDLE_ACTIVE SetBundleGroup callback failed. because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE SetBundleGroup callback succeeded.');
    }
});
```

## bundleState.registerGroupCallBack<sup>9+</sup>

733
registerGroupCallBack(groupCallback: Callback&lt;BundleActiveGroupCallbackInfo&gt;): Promise&lt;void&gt;
734

E
ester.zhou 已提交
735
Registers a callback for application group changes. When an application group of the user changes, a **[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)** instance is returned to all applications that have registered the callback. This API uses a promise to return the result.
736 737 738 739 740 741 742 743 744

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

E
ester.zhou 已提交
745 746 747
| Name  | Type                                                        | Mandatory| Description                                      |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
| callback | Callback&lt;[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)&gt; | Yes  | Callback used to return the application group changes.|
748 749 750 751 752

**Return value**

| Type           | Description                     |
| ------------- | ----------------------- |
E
ester.zhou 已提交
753
| Promise&lt;void&gt; | Promise used to return the result. |
754 755 756 757 758 759

**Example**

```javascript
let onBundleGroupChanged = (err,res) =>{
    console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
E
ester.zhou 已提交
760 761 762 763 764
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
765 766 767 768 769 770 771 772 773 774
};
bundleState.registerGroupCallBack(onBundleGroupChanged).then( () => {
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise succeeded.');
}).catch( err => {
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack promise failed. because: ' + err.code);
});
```

## bundleState.registerGroupCallBack<sup>9+</sup>

775
registerGroupCallBack(groupCallback: Callback&lt;BundleActiveGroupCallbackInfo&gt;, callback: AsyncCallback&lt;void&gt;): void
776

E
ester.zhou 已提交
777
Registers a callback for application group changes. When an application group of the user changes, a **[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)** instance is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.
778 779 780 781 782 783 784 785 786

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

E
ester.zhou 已提交
787 788 789 790
| Name  | Type                                                        | Mandatory| Description                                        |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- |
| callback | Callback&lt;[BundleActiveGroupCallbackInfo](#bundleactivegroupcallbackinfo9)&gt; | Yes  | Callback used to return the application group changes.  |
| callback | AsyncCallback&lt;void&gt;                                    | Yes  | Callback used to return the result.|
791 792 793 794 795 796

**Example**

```javascript
let onBundleGroupChanged = (err,res) =>{
    console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
E
ester.zhou 已提交
797 798 799 800 801
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageOldGroup is : ' + res.appUsageOldGroup);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result appUsageNewGroup is : ' + res.appUsageNewGroup);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result changeReason is : ' + res.changeReason);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result userId is : ' + res.userId);
    console.log('BUNDLE_ACTIVE RegisterGroupCallBack result bundleName is : ' + res.bundleName);
802 803 804 805 806 807 808 809 810 811 812 813
};
bundleState.registerGroupCallBack(onBundleGroupChanged, (err)=>{
    if(err) {
        console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback failed, because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE RegisterGroupCallBack callback success.');
    }
});
```

## bundleState.unRegisterGroupCallBack<sup>9+</sup>

E
ester.zhou 已提交
814
unRegisterGroupCallBack(): Promise&lt;void&gt;
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829

Deregisters the callback for application group changes. This API uses a promise to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**: none

**Return value**

| Type           | Description                      |
| ------------- | ------------------------ |
E
ester.zhou 已提交
830
| Promise&lt;void&gt; | Promise used to return the result. |
831 832 833 834 835 836 837 838 839 840 841 842 843

**Example**

```javascript
bundleState.unRegisterGroupCallBack().then( () => {
    console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise succeeded.');
}).catch( err => {
    console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack promise failed. because: ' + err.code);
});
```

## bundleState.unRegisterGroupCallBack<sup>9+</sup>

E
ester.zhou 已提交
844
unRegisterGroupCallBack(callback: AsyncCallback&lt;void&gt;): void;
845 846 847 848 849 850 851 852 853 854 855 856 857

Deregisters the callback for application group changes. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type                 | Mandatory  | Description            |
| -------- | ------------------- | ---- | -------------- |
E
ester.zhou 已提交
858
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894

**Example**

```javascript
bundleState.unRegisterGroupCallBack((err)=>{
    if(err) {
        console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback failed, because: ' + err.code);
    } else {
        console.log('BUNDLE_ACTIVE UnRegisterGroupCallBack callback success.');
    }
});
```

## bundleState.queryBundleActiveEventStates<sup>9+</sup>

queryBundleActiveEventStates(begin: number, end: number): Promise&lt;Array&lt;BundleActiveEventState&gt;&gt;

Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This API uses a promise to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| begin | number | Yes   | Start time.|
| end   | number | Yes   | End time.|

**Return value**

| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
895
| Promise&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Promise used to return the result. |
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925

**Example**

  ```js
    bundleState.queryBundleActiveEventStates(0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise success.');
        console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise result ' + JSON.stringify(res));
    }).catch( err=> {
        console.log('BUNDLE_ACTIVE queryBundleActiveEventStates promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryBundleActiveEventStates<sup>9+</sup>

queryBundleActiveEventStates(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleActiveEventState&gt;&gt;): void

Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| begin    | number                                   | Yes   | Start time.                                   |
| end      | number                                   | Yes   | End time.                                   |
E
ester.zhou 已提交
926
| callback | AsyncCallback&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Yes   | Callback used to return the result. |
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963

**Example**

  ```js
    bundleState.queryBundleActiveEventStates(0, 20000000000000, (err, res) => {
        if(err) {
            console.log('BUNDLE_ACTIVE queryBundleActiveEventStates callback failed, because: ' + err.code);
        } else {
            console.log('BUNDLE_ACTIVE queryBundleActiveEventStates callback success.');
            console.log('BUNDLE_ACTIVE queryBundleActiveEventStates callback result ' + JSON.stringify(res));
        }
    });
  ```

## bundleState.queryAppNotificationNumber<sup>9+</sup>

queryAppNotificationNumber(begin: number, end: number): Promise&lt;Array&lt;BundleActiveEventState&gt;&gt;

Queries the number of notifications from all applications based on the specified start time and end time. This API uses a promise to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name  | Type    | Mandatory  | Description   |
| ----- | ------ | ---- | ----- |
| begin | number | Yes   | Start time.|
| end   | number | Yes   | End time.|

**Return value**

| Type                                      | Description                                      |
| ---------------------------------------- | ---------------------------------------- |
E
ester.zhou 已提交
964
| Promise&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Promise used to return the result. |
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994

**Example**

  ```js
    bundleState.queryAppNotificationNumber(0, 20000000000000).then( res => {
        console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise success.');
        console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise result ' + JSON.stringify(res));
    }).catch( err=> {
        console.log('BUNDLE_ACTIVE queryAppNotificationNumber promise failed, because: ' + err.code);
    });
  ```

## bundleState.queryAppNotificationNumber<sup>9+</sup>

queryAppNotificationNumber(begin: number, end: number, callback: AsyncCallback&lt;Array&lt;BundleActiveEventState&gt;&gt;): void

Queries the number of notifications from all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.BUNDLE_ACTIVE_INFO

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name     | Type                                      | Mandatory  | Description                                      |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| begin    | number                                   | Yes   | Start time.                                   |
| end      | number                                   | Yes   | End time.                                   |
E
ester.zhou 已提交
995
| callback | AsyncCallback&lt;Array&lt;[BundleActiveEventState](#bundleactiveeventstate9)&gt;&gt; | Yes   | Callback used to return the result. |
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009

**Example**

  ```js
    bundleState.queryAppNotificationNumber(0, 20000000000000, (err, res) => {
        if(err) {
            console.log('BUNDLE_ACTIVE queryAppNotificationNumberCallBack callback failed, because: ' + err.code);
        } else {
            console.log('BUNDLE_ACTIVE queryAppNotificationNumberCallBack callback success.');
            console.log('BUNDLE_ACTIVE queryAppNotificationNumberCallBack callback result ' + JSON.stringify(res));
        }
    });
  ```

E
ester.zhou 已提交
1010 1011 1012 1013 1014
## BundleActiveModuleInfo<sup>9+</sup>
Provides the information about the FA usage.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

E
ester.zhou 已提交
1015 1016
**System API**: This is a system API and cannot be called by third-party applications.

1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
| Name                 | Type                                      | Mandatory  | Description                           |
| -------------------- | ---------------------------------------- | ---- | ----------------------------- |
| deviceId             | string                                   | No   | ID of the device to which the FA belongs.                |
| bundleName           | string                                   | Yes   | Name of the application bundle to which the FA belongs.                    |
| moduleName           | string                                   | Yes   | Name of the module to which the FA belongs.                 |
| abilityName          | string                                   | No   | **MainAbility** name of the FA.             |
| appLabelId           | number                                   | No   | Application label ID of the FA.                |
| labelId              | number                                   | No   | Label ID of the module to which the FA belongs.          |
| descriptionId        | number                                   | No   | Description ID of the application to which the FA belongs.        |
| abilityLableId       | number                                   | No   | **MainAbility** label ID of the FA.      |
| abilityDescriptionId | number                                   | No   | **MainAbility** description ID of the FA.|
| abilityIconId        | number                                   | No   | **MainAbility** icon ID of the FA.       |
| launchedCount        | number                                   | Yes   | Number of FA startup times.                     |
| lastModuleUsedTime   | number                                   | Yes   | Last time when the FA was used.                  |
| formRecords          | Array&lt;[BundleActiveFormInfo](#bundleactiveforminfo9)&gt; | Yes   | Array of widget usage records in the FA.                  |
E
ester.zhou 已提交
1032 1033 1034 1035 1036 1037

## BundleActiveFormInfo<sup>9+</sup>
Provides the FA widget usage information.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

E
ester.zhou 已提交
1038 1039
**System API**: This is a system API and cannot be called by third-party applications.

1040 1041
| Name             | Type    | Mandatory  | Description         |
| ---------------- | ------ | ---- | ----------- |
E
ester.zhou 已提交
1042
| formName         | string | Yes   | Widget name.      |
1043 1044 1045 1046 1047 1048 1049 1050 1051
| formDimension    | number | Yes   | Widget dimensions.      |
| formId           | number | Yes   | Widget ID.      |
| formLastUsedTime | number | Yes   | Last time when the widget was clicked.|
| count            | number | Yes   | Number of clicks on the widget.   |

## BundleActiveGroupCallbackInfo<sup>9+</sup>

Provides the application group changes returned through a callback.

E
ester.zhou 已提交
1052
**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
1053

E
ester.zhou 已提交
1054 1055
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
1056 1057 1058 1059 1060 1061 1062
| Name          | Type  | Mandatory| Description            |
| ---------------- | ------ | ---- | ---------------- |
| appUsageOldGroup | number | Yes  | Application group before the change.|
| appUsageNewGroup | number | Yes  | Application group after the change.|
| userId           | number | Yes  | User ID.          |
| changeReason     | number | Yes  | Reason for the group change.    |
| bundleName       | string | Yes  | Bundle name of an application.        |
E
ester.zhou 已提交
1063

E
ester.zhou 已提交
1064
## BundleStateInfo
1065 1066

Provides the usage duration information of applications.
E
ester.zhou 已提交
1067 1068

### Attributes
E
ester.zhou 已提交
1069

E
ester.zhou 已提交
1070
**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App
E
ester.zhou 已提交
1071

1072 1073
| Name                     | Type    | Mandatory  | Description                                      |
| ------------------------ | ------ | ---- | ---------------------------------------- |
E
ester.zhou 已提交
1074
| bundleName               | string | Yes   | Bundle name of an application.                                   |
1075 1076 1077 1078 1079 1080 1081 1082 1083
| abilityPrevAccessTime    | number | Yes   | Last time when the application was used.                            |
| abilityInFgTotalTime     | number | Yes   | Total time that the application runs in the foreground.                            |
| id                       | number | No   | User ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilityPrevSeenTime      | number | No   | Last time when the application was visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilitySeenTotalTime     | number | No   | Total time that the application is visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityAccessTotalTime | number | No   | Total time that the application accesses the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityPrevAccessTime  | number | No   | Last time when the application accessed the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosBeginTime           | number | No   | Time logged in the first application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosEndTime             | number | No   | Time logged in the last application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
E
ester.zhou 已提交
1084 1085

## BundleActiveState
E
ester.zhou 已提交
1086

E
ester.zhou 已提交
1087 1088 1089 1090
Provides information about an application event.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

1091 1092
| Name                  | Type    | Mandatory  | Description                                      |
| --------------------- | ------ | ---- | ---------------------------------------- |
E
ester.zhou 已提交
1093
| bundleName            | string | Yes   | Bundle name of an application.                                   |
1094 1095 1096 1097 1098
| stateType             | number | Yes   | Application event type.                                 |
| stateOccurredTime     | number | Yes   | Timestamp when the application event occurs.                             |
| appUsagePriorityGroup | number | No   | Usage priority group of the application.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| indexOfLink           | string | No   | Shortcut ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| nameOfClass           | string | No   | Class name.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
E
ester.zhou 已提交
1099 1100

## BundleActiveInfoResponse
E
ester.zhou 已提交
1101

E
ester.zhou 已提交
1102 1103 1104 1105
Provides the usage duration information of applications.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
| Name                           | Type                                      | Mandatory  | Description            |
| ------------------------------ | ---------------------------------------- | ---- | -------------- |
| [key: string]: BundleStateInfo | [key: string]: [BundleStateInfo](#bundlestateinfo) | Yes   | Usage duration information by application.|

## BundleActiveEventState<sup>9+</sup>

Provides statistics about notifications and system events.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

**System API**: This is a system API and cannot be called by third-party applications.

| Name    | Type    | Mandatory  | Description               |
| ------- | ------ | ---- | ----------------- |
| name    | string | Yes   | Bundle name of the notification sending application or system event name.   |
| eventId | number | Yes   | Type of the notification or system event.       |
| count   | number | Yes   | Number of application notifications or system event triggering times.|
E
ester.zhou 已提交
1123 1124

## IntervalType
E
ester.zhou 已提交
1125

E
ester.zhou 已提交
1126 1127 1128 1129
Enumerates the interval types for querying the application usage duration.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.App

1130 1131 1132 1133 1134 1135 1136 1137
| Name          | Default Value | Description                                      |
| ------------ | ---- | ---------------------------------------- |
| BY_OPTIMIZED | 0    | The system obtains the application usage duration statistics in the specified time frame at the interval the system deems appropriate.|
| BY_DAILY     | 1    | The system obtains the application usage duration statistics in the specified time frame on a daily basis.             |
| BY_WEEKLY    | 2    | The system obtains the application usage duration statistics in the specified time frame on a weekly basis.             |
| BY_MONTHLY   | 3    | The system obtains the application usage duration statistics in the specified time frame on a monthly basis.             |
| BY_ANNUALLY  | 4    | The system obtains the application usage duration statistics in the specified time frame on an annual basis.             |

E
ester.zhou 已提交
1138
## GroupType<sup>9+</sup>
1139 1140 1141 1142 1143

Enumerates the application group types.

**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

E
ester.zhou 已提交
1144 1145
**System API**: This is a system API and cannot be called by third-party applications.

1146 1147 1148 1149 1150 1151 1152 1153
| Name                | Default Value | Description               |
| ------------------ | ---- | ----------------- |
| ACTIVE_GROUP_ALIVE | 10   | Group of active applications.             |
| ACTIVE_GROUP_DAILY | 20   | Group of frequently used applications that are not in the active state.   |
| ACTIVE_GROUP_FIXED | 30   | Group of applications that are used periodically but not every day.|
| ACTIVE_GROUP_RARE  | 40   | Group of rarely used applications.     |
| ACTIVE_GROUP_LIMIT | 50   | Group of restricted applications.           |
| ACTIVE_GROUP_NEVER | 60   | Group of applications that have been installed but never run. |