# 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. ## 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.

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

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

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

Queries the event collection of the current application through the time interval.

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

Queries application usage duration statistics by time interval.

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

Queries (returns) the priority group used by the current caller application.

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

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

### 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 caller application; >6. Judge whether the specified application is currently idle; ## Repositories Involved resource schedule subsystem **device\_usage\_statistics** resource_schedule_service appexecfwk_standard native_appdatamgr