README.md
1# Device usage statistics<a name="EN-US_TOPIC_0000001115588558"></a>
2
3- [Introduction](#section11660541593)
4- [Directory Structure](#section161941989596)
5- [Instruction](#section1312121216216)
6 - [Available APIs](#section1551164914237)
7 - [Usage Guidelines](#section129654513264)
8
9- [Repositories Involved](#section1371113476307)
10
11## Introduction<a name="section11660541593"></a>
12
13The **device usage statistics** includes app usage, notification usage, system usage and other usage statistics. For example, application usage statistics is used to save
14and query application usage details, event log data and application grouping.The application records (usage history statistics and usage event records) cached by
15the component will be periodically refreshed to the database for persistent storage.
16
17
18
19## Directory Structure<a name="section161941989596"></a>
20
21```
22/foundation/resourceschedule/device_usage_statistics
23├── BUILD.gn # Module compilation script
24├── LICENSE # Open source protocol
25├── adapter # Adaptation directory
26├── bundle.json # Component decoupling and compiling script
27├── frameworks # Framework layer directory
28├── interfaces
29│ ├── innerkits # Internal interface directory
30│ └── kits # External interface directory
31├── services # Service layer directory
32└── test # Testing case directory
33```
34
35## Instruction<a name="section1312121216216"></a>
36
37### Available APIs<a name="section1551164914237"></a>
38
39Device usage statistics interfaces include app usage, notification usage, system usage and other interfaces.
40Taking app usage interface as an example, the main exposed interfaces are as follows.
41
42<a name="table775715438253"></a>
43<table><thead align="left"><tr id="row12757154342519"><th class="cellrowborder" valign="top" width="60%" id="mcps1.1.3.1.1"><p id="p1075794372512"><a name="p1075794372512"></a><a name="p1075794372512"></a>API name</p>
44</th>
45<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p375844342518"><a name="p375844342518"></a><a name="p375844342518"></a>API description</p>
46</th>
47</tr>
48</thead>
49<tbody><tr id="row1975804332517"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p5758174313255"><a name="p5758174313255"></a><a name="p5758174313255"></a>queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void</p>
50<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14758743192519"><a name="p14758743192519"></a><a name="p14758743192519"></a>Queries the event collection of all applications through time interval(callback).</p>
51<tbody><tr id="row1975804332517"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p5758174313255"><a name="p5758174313255"></a><a name="p5758174313255"></a>queryBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>></p>
52<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14758743192519"><a name="p14758743192519"></a><a name="p14758743192519"></a>Queries the event collection of all applications through time interval(Promise).</p>
53<tr id="row2758943102514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p107581438250"><a name="p107581438250"></a><a name="p107581438250"></a>queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void</p>
54<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p8758743202512"><a name="p8758743202512"></a><a name="p8758743202512"></a>Uses the start and end time to query the application usage time statistics(callback).</p>
55<tr id="row2758943102514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p107581438250"><a name="p107581438250"></a><a name="p107581438250"></a>queryBundleStateInfos(begin: number, end: number): Promise<BundleActiveInfoResponse></p>
56<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p8758743202512"><a name="p8758743202512"></a><a name="p8758743202512"></a>Uses the start and end time to query the application usage time statistics(Promise).</p>
57<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void</p>
58<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Queries the event collection of the current application through the time interval(callback).</p>
59<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryCurrentBundleActiveStates(begin: number, end: number): Promise<Array<BundleActiveState>></p>
60<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Queries the event collection of the current application through the time interval(Promise).</p>
61<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void</p>
62<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Queries application usage duration statistics by time interval(callback).</p>
63<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStateInfo>></p>
64<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Queries application usage duration statistics by time interval(Promise).</p>
65<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void</p>
66<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the priority group of the application.</p>
67<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppUsagePriorityGroup(): Promise<number></p>
68<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the priority group of the application.</p>
69<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void</p>
70<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Judges whether the application of the specified bundle name is currently idle(callback).</p>
71<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>isIdleState(bundleName: string): Promise<boolean></p>
72<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Judges whether the application of the specified bundle name is currently idle(Promise).</p>
73<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleActiveEventStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void</p>
74<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time(callback).</p>
75<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleActiveEventStates(begin: number, end: number): Promise<Array<BundleActiveEventState>></p>
76<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time(Promise).</p>
77<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppNotificationNumber(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void</p>
78<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the application notification times according to the start and end time(callback).</p>
79<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppNotificationNumber(begin: number, end: number): Promise<Array<BundleActiveEventState>></p>
80<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the application notification times according to the start and end time(Promise).</p>
81<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>getRecentlyUsedModules(callback: AsyncCallback<Array<BundleActiveModuleInfo>>): void</p>
82<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query FA usage records. The maximum returned quantity does not exceed the value set by 1000.(callback)</p>
83<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<Array<BundleActiveModuleInfo>>): void</p>
84<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>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)
85<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>getRecentlyUsedModules(maxNum?: number): Promise<Array<BundleActiveModuleInfo>></p>
86<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>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).</p>
87<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppUsagePriorityGroup(bundleName : string, callback: AsyncCallback<number>): void</p>
88<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the group of the current application or the application of specified bundlename.</p>
89<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppUsagePriorityGroup(bundleName : string): Promise<number></p>
90<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Query the group of the current application or the application of specified bundlename.</p>
91<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void</p>
92<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Set the group of the specified application as the group provided by the parameter(callback).</p>
93<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>setBundleGroup(bundleName: string, newGroup: GroupType): Promise<void></p>
94<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Set the group of the specified application as the group provided by the parameter(Promise).</p>
95<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>, callback: AsyncCallback<void>): void</p>
96<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Register callback for application group change(callback).</p>
97<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>registerGroupCallBack(callback: Callback<BundleActiveGroupCallbackInfo>): Promise<void></p>
98<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Register callback for application group change(Promise).</p>
99<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>unRegisterGroupCallBack(callback: AsyncCallback<void>): void</p>
100<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Unregister the registered application group callback(callback).</p>
101<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>unRegisterGroupCallBack(): Promise<void></p>
102<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>Unregister the registered application group callback(Promise).</p>
103</td>
104</tr>
105</tbody>
106</table>
107
108
109
110### Usage Guidelines<a name="section129654513264"></a>
111
112There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic.
113
114- **device usage statistics saving time**:
115>1. refreshing is triggered every 30 minutes;
116>2. refreshing is triggered when system time changes;
117>3. refreshing is triggered from the next day;
118- **app querying interface**:
119>1. Query the event collection of all applications according to the start and end time;
120>2. Query the usage duration of the application according to the start and end time;
121>3. Query the event collection of the current application according to the start and end time;
122>4. Query the usage duration of the application according to the type of interval (day, week, month, year) and the start and end time;
123>5. Query the priority group of the application;
124>6. Judge whether the specified application is currently idle;
125>7. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time;
126>8. Query the application notification times according to the start and end time;
127>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;
128>10. Query the group of the current application or the application of specified bundlename;
129>11. Set the group of the specified application as the group provided by the parameter;
130>12. Register callback for application group change;
131>13. Unregister the registered application group callback;
132
133## Repositories Involved<a name="section1371113476307"></a>
134
135resource schedule subsystem
136
137**device\_usage\_statistics**
138
139resource_schedule_service
140
141appexecfwk_standard
142
143relational_store
README_zh.md
1# 设备使用信息统计<a name="ZH-CN_TOPIC_0000001115588558"></a>
2- [简介](#section11660541593)
3- [目录](#section161941989596)
4- [说明](#section1312121216216)
5 - [接口说明](#section1551164914237)
6 - [使用说明](#section129654513264)
7
8- [相关仓](#section1371113476307)
9
10## 简介<a name="section11660541593"></a>
11
12设备使用信息统计,包括app usage/notification usage/system usage等使用统计。例如应用使用信息统计,用于保存和查询应用使用详情(app usage)、事件日志数据(event log)、应用分组(bundle group)情况。
13部件缓存的应用记录(使用历史统计和使用事件记录)会在事件上报后30分钟内刷新到数据库持久化保存。
14
15
16
17## 目录<a name="section161941989596"></a>
18
19```
20/foundation/resourceschedule/device_usage_statistics
21├── BUILD.gn # 模块编译脚本
22├── LICENSE # 开源协议
23├── adapter # 适配目录
24├── bundle.json # 部件化解耦及编译脚本
25├── frameworks # 框架层目录
26├── interfaces
27│ ├── innerkits # 对内接口目录
28│ └── kits # 对外接口目录
29├── services # 服务层目录
30└── test # 测试用例目录
31```
32
33## 说明<a name="section1312121216216"></a>
34
35### 接口说明<a name="section1551164914237"></a>
36
37设备使用信息统计接口,包括app usage/notification usage/system usage等接口,以app usage接口为例,对外提供主要接口如下。
38
39<a name="table775715438253"></a>
40<table><thead align="left"><tr id="row12757154342519"><th class="cellrowborder" valign="top" width="73%" id="mcps1.1.3.1.1"><p id="p1075794372512"><a name="p1075794372512"></a><a name="p1075794372512"></a>接口名</p>
41</th>
42<th class="cellrowborder" valign="top" width="50%" id="mcps1.1.3.1.2"><p id="p375844342518"><a name="p375844342518"></a><a name="p375844342518"></a>接口描述</p>
43</th>
44</tr>
45</thead>
46<tbody>
47<tr id="row1975804332517"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p5758174313255"><a name="p5758174313255"></a><a name="p5758174313255"></a>queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void</p>
48<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14758743192519"><a name="p14758743192519"></a><a name="p14758743192519"></a>通过指定起始和结束时间查询所有应用的事件集合(callback形式)。</p>
49<tr id="row1975804332517"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p5758174313255"><a name="p5758174313255"></a><a name="p5758174313255"></a>queryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>></p>
50<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p14758743192519"><a name="p14758743192519"></a><a name="p14758743192519"></a>通过指定起始和结束时间查询所有应用的事件集合(Promise形式)。</p>
51<tr id="row2758943102514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p107581438250"><a name="p107581438250"></a><a name="p107581438250"></a>queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void</p>
52<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p8758743202512"><a name="p8758743202512"></a><a name="p8758743202512"></a>通过指定起始和结束时间查询应用使用时长统计信息(callback形式)。</p>
53<tr id="row2758943102514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p107581438250"><a name="p107581438250"></a><a name="p107581438250"></a>queryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap></p>
54<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p8758743202512"><a name="p8758743202512"></a><a name="p8758743202512"></a>通过指定起始和结束时间查询应用使用时长统计信息(Promise形式)。</p>
55<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void</p>
56<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>通过指定起始和结束时间查询当前应用的事件集合(callback形式)。</p>
57<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryCurrentBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>></p>
58<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>通过指定起始和结束时间查询当前应用的事件集合(Promise形式)。</p>
59<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void</p>
60<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(callback形式)。</p>
61<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStatsInfo>></p>
62<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(Promise形式)。</p>
63<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void</p>
64<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>判断指定Bundle Name的应用当前是否是空闲状态(callback形式)。</p>
65<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>isIdleState(bundleName: string): Promise<boolean></p>
66<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>判断指定Bundle Name的应用当前是否是空闲状态(Promise形式)。</p>
67<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void</p>
68<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息(callback形式)。</p>
69<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryDeviceEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>></p>
70<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息(Promise形式)。</p>
71<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void</p>
72<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>根据起止时间查询应用通知次数(callback形式)。</p>
73<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryNotificationEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>></p>
74<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>根据起止时间查询应用通知次数(Promise形式)。</p>
75<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryModuleUsageRecords(callback: AsyncCallback<Array<HapModuleInfo>>): void</p>
76<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询FA使用记录。返回数量最大不超过1000设置的值,FA使用记录由近及远排序(callback形式)。</p>
77<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryModuleUsageRecords(): Promise<Array<HapModuleInfo>></p>
78<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询FA使用记录。返回数量最大不超过1000设置的值,FA使用记录由近及远排序(Promise形式)。</p>
79<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapModuleInfo>>): void</p>
80<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000(callback形式)。</p>
81<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryModuleUsageRecords(maxNum: number): Promise<Array<HapModuleInfo>></p>
82<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000(Promise形式)。</p>
83<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppGroup(callback: AsyncCallback<number>): void</p>
84<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询当前应用的使用优先级分组(callback形式)。</p>
85<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppGroup(): Promise<number></p>
86<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询当前应用的使用优先级分组(Promise形式)。</p>
87<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void</p>
88<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询指定bundleName的应用的优先级分组(callback形式)。</p>
89<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>queryAppGroup(bundleName : string): Promise<number></p>
90<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>查询指定bundleName的应用的使用优先级分组(Promise形式)。</p>
91<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void</p>
92<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>将指定应用的分组设置为参数提供的分组(callback形式)。</p>
93<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>setAppGroup(bundleName: string, newGroup: GroupType): Promise<void></p>
94<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>将指定应用的分组设置为参数提供的分组(Promise形式)。</p>
95<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>registerAppGroupCallBack(callback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void</p>
96<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>给应用分组变化注册回调(callback形式)。</p>
97<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>registerAppGroupCallBack(callback: Callback<AppGroupCallbackInfo>): Promise<void></p>
98<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>给应用分组变化注册回调(Promise形式)。</p>
99<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>unRegisterAppGroupCallBack(callback: AsyncCallback<void>): void</p>
100<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>将已注册过的应用分组回调解除注册(callback形式)。</p>
101<tr id="row09311240175710"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.1 "><p id="p159328405571"><a name="p159328405571"></a><a name="p159328405571"></a>unRegisterAppGroupCallBack(): Promise<void></p>
102<td class="cellrowborder" valign="top" width="50%" headers="mcps1.1.3.1.2 "><p id="p493294018574"><a name="p493294018574"></a><a name="p493294018574"></a>将已注册过的应用分组回调解除注册(Promise形式)。</p>
103</td>
104</td>
105</tr>
106</tbody>
107</table>
108
109
110### 使用说明<a name="section129654513264"></a>
111
112设备使用信息统计接口众多,以应用使用详情(app usage)接口为例,介绍接口逻辑。
113
114- **应用使用统计信息落盘时机**:
115>1. 每隔30分钟触发一次刷新;
116>2. 系统时间变更触发一次刷新;
117>3. 下一天开始触发一次刷新;
118- **应用查询接口**:
119>1. 根据起止时间查询所有应用的事件集合;
120>2. 根据起止时间查询应用的使用时长;
121>3. 根据起止时间查询当前应用的事件集合;
122>4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长;
123>5. 查询当前应用的优先级分组;
124>6. 判断指定应用当前是否是空闲状态;
125>7. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息;
126>8. 根据起止时间查询应用通知次数;
127>9. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000;
128>10. 查询当前应用或指定bundlename对应的应用的分组;
129>11. 将指定应用的分组设置为参数提供的分组;
130>12. 给应用分组变化注册回调;
131>13. 将已注册过的应用分组回调解除注册;
132
133## 相关仓<a name="section1371113476307"></a>
134
135全局资源调度子系统
136
137**[resourceschedule_device_usage_statistics](https://gitee.com/openharmony/resourceschedule_device_usage_statistics)**
138
139[resourceschedule_resource_schedule_service](https://gitee.com/openharmony/resourceschedule_resource_schedule_service)
140
141[appexecfwk_standard](https://gitee.com/openharmony/appexecfwk_standard)
142
143[distributeddatamgr_appdatamgr](https://gitee.com/openharmony/distributeddatamgr_appdatamgr)
144
145