# Device usage statistics - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Instruction](#section1312121216216) - [Available APIs](#section1551164914237) - [Usage Guidelines](#section129654513264) - [Repositories Involved](#section1371113476307) ## Introduction The **device usage statistics** includes app usage, notification usage, system usage and other usage statistics. For example, application usage statistics is used to save and query application usage details, event log data and application grouping.The application records (usage history statistics and usage event records) cached by the component will be periodically refreshed to the database for persistent storage. ![](figures/en-us_image001.png) ## Directory Structure ``` /foundation/resourceschedule/device_usage_statistics ├── BUILD.gn # Module compilation script ├── LICENSE # Open source protocol ├── adapter # Adaptation directory ├── bundle.json # Component decoupling and compiling script ├── frameworks # Framework layer directory ├── interfaces │   ├── innerkits # Internal interface directory │   └── kits # External interface directory ├── services # Service layer directory └── test # Testing case directory ``` ## Instruction ### Available APIs Device usage statistics interfaces include app usage, notification usage, system usage and other interfaces. Taking app usage interface as an example, the main exposed interfaces are as follows.

API name

API description

queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void

Queries the event collection of all applications through time interval(callback).

queryBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>

Queries the event collection of all applications through time interval(Promise).

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

Uses the start and end time to query the application usage time statistics(callback).

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

Uses the start and end time to query the application usage time statistics(Promise).

queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void

Queries the event collection of the current application through the time interval(callback).

queryCurrentBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>>

Queries the event collection of the current application through the time interval(Promise).

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

Queries application usage duration statistics by time interval(callback).

queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStateInfo>>

Queries application usage duration statistics by time interval(Promise).

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

Query the priority group of the application.

queryAppUsagePriorityGroup(): Promise<number>

Query the priority group of the application.

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

Judges whether the application of the specified bundle name is currently idle(callback).

isIdleState(bundleName: string): Promise<boolean>

Judges whether the application of the specified bundle name is currently idle(Promise).

isIdleStateSync(bundleName: string): boolean

Judges whether the application of the specified bundle name is currently idle.

queryBundleActiveEventStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void

Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time(callback).

queryBundleActiveEventStates(begin: number, end: number): Promise<Array<BundleActiveEventState>>

Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time(Promise).

queryAppNotificationNumber(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void

Query the application notification times according to the start and end time(callback).

queryAppNotificationNumber(begin: number, end: number): Promise<Array<BundleActiveEventState>>

Query the application notification times according to the start and end time(Promise).

getRecentlyUsedModules(callback: AsyncCallback<Array<BundleActiveModuleInfo>>): void

Query FA usage records. The maximum returned quantity does not exceed the value set by 1000.(callback)

getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<Array<BundleActiveModuleInfo>>): void

Query FA usage records. The maximum returned quantity does not exceed the value set by maxnum. FA usage records are sorted from near to far. The maximum maxnum is 1000.(callback)

getRecentlyUsedModules(maxNum?: number): Promise<Array<BundleActiveModuleInfo>>

Query FA usage records. The maximum returned quantity does not exceed the value set by maxnum. FA usage records are sorted from near to far. The maximum maxnum is 1000. If the maxnum parameter is not filled in, the default maxnum is 1000(Promise).

queryAppUsagePriorityGroup(bundleName : string, callback: AsyncCallback<number>): void

Query the group of the current application or the application of specified bundlename.

queryAppUsagePriorityGroup(bundleName : string): Promise<number>

Query the group of the current application or the application of specified bundlename.

setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void

Set the group of the specified application as the group provided by the parameter(callback).

setBundleGroup(bundleName: string, newGroup: GroupType): Promise<void>

Set the group of the specified application as the group provided by the parameter(Promise).

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<void>): void

Register callback for application group change(callback).

registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<void>

Register callback for application group change(Promise).

unRegisterGroupCallBack(callback: AsyncCallback<void>): void

Unregister the registered application group callback(callback).

unRegisterGroupCallBack(): Promise<void>

Unregister the registered application group callback(Promise).

### Usage Guidelines There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic. - **device usage statistics saving time**: >1. refreshing is triggered every 30 minutes; >2. refreshing is triggered when system time changes; >3. refreshing is triggered from the next day; - **app querying interface**: >1. Query the event collection of all applications according to the start and end time; >2. Query the usage duration of the application according to the start and end time; >3. Query the event collection of the current application according to the start and end time; >4. Query the usage duration of the application according to the type of interval (day, week, month, year) and the start and end time; >5. Query the priority group of the application; >6. Judge whether the specified application is currently idle; >7. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; >8. Query the application notification times according to the start and end time; >9. Query FA usage records. The maximum returned quantity does not exceed the value set by maxnum. FA usage records are sorted from near to far. The maximum maxnum is 1000. If the maxnum parameter is not filled in, the default maxnum is 1000; >10. Query the group of the current application or the application of specified bundlename; >11. Set the group of the specified application as the group provided by the parameter; >12. Register callback for application group change; >13. Unregister the registered application group callback; ## Repositories Involved resource schedule subsystem **device\_usage\_statistics** resource_schedule_service appexecfwk_standard relational_store