1# @ohos.bundleState (Device Usage Statistics)
2
3This module provides APIs for collecting statistics on device usage.
4
5> **NOTE**
6>
7> The APIs of this module are deprecated since API version 9. The substitute APIs are open only to system applications.
8>
9> 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.
10
11
12## Modules to Import
13
14```js
15import bundleState from '@ohos.bundleState'
16```
17
18## bundleState.isIdleState
19
20isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
21
22Checks 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 state of itself. A system application can check the idle state of other applications only when it is granted with the ohos.permission.BUNDLE_ACTIVE_INFO permission.
23
24**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
25
26**Parameters**
27
28| Name       | Type                          | Mandatory  | Description                                      |
29| ---------- | ---------------------------- | ---- | ---------------------------------------- |
30| bundleName | string                       | Yes   | Bundle name of an application.                          |
31| callback   | AsyncCallback<boolean> | Yes   | Callback used to return the result. If the specified **bundleName** is valid, the idle state of the application is returned; otherwise, **null** is returned.|
32
33**Example**
34
35```ts
36import { BusinessError } from '@ohos.base';
37// When a third-party application uses the sample code, change bundleName to its own bundle name.
38bundleState.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => {
39  if (err) {
40    console.error('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
41  } else {
42    console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
43  }
44});
45```
46
47## bundleState.isIdleState
48
49isIdleState(bundleName: string): Promise<boolean>
50
51Checks 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 state of itself. A system application can check the idle state of other applications only when it is granted with the ohos.permission.BUNDLE_ACTIVE_INFO permission.
52
53**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
54
55**Parameters**
56
57| Name       | Type    | Mandatory  | Description            |
58| ---------- | ------ | ---- | -------------- |
59| bundleName | string | Yes   | Bundle name of an application.|
60
61**Return value**
62
63| Type                    | Description                                      |
64| ---------------------- | ---------------------------------------- |
65| Promise<boolean> | Promise used to return the result. If the specified **bundleName** is valid, the idle state of the application is returned; otherwise, **null** is returned.|
66
67**Example**
68
69```ts
70import { BusinessError } from '@ohos.base';
71// When a third-party application uses the sample code, change bundleName to its own bundle name.
72bundleState.isIdleState("com.ohos.camera").then((res: boolean) => {
73  console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
74}).catch((err: BusinessError) => {
75  console.error('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
76});
77```
78