未验证 提交 a1156b55 编写于 作者: O openharmony_ci 提交者: Gitee

!3165 新增FA使用记录查询接口

Merge pull request !3165 from Houdisheng/master
......@@ -21,6 +21,7 @@ import stats from '@ohos.bundleState';
| function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void | 通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。 |
| function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void | 查询(返回)当前调用者应用的使用优先级群组。 |
| function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | 判断指定Bundle Name的应用当前是否是空闲状态。 |
| function getRecentUsageModules(maxNum: number, callback: AsyncCallback<BundleActiveModuleInfo>): void | 根据maxNum,查询FA使用记录,返回不超过maxNum条FA使用记录。 |
## 开发步骤
......@@ -204,4 +205,35 @@ import stats from '@ohos.bundleState';
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
}
});
```
\ No newline at end of file
```
8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,config.json中需要配置权限:ohos.permission.BUNDLE_ACTIVE_INFO。
```js
import stats from '@ohos.bundleState'
// 异步方法promise方式
stats.getRecentUsageModules(this.maxNum).then( res => {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise succeeded');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentUsageModules promise result ' + JSON.stringify(res[i]));
}
}).catch( err=> {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise failed, because: ' + err.code);
});
// 异步方法callback方式
stats.getRecentUsageModules(this.maxNum,(err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback succeeded.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentUsageModules callback result ' + JSON.stringify(res[i]));
}
}
});
```
......@@ -7,17 +7,18 @@
设备使用信息统计接口众多,目前只支持app usage使用统计,接下来介绍下应用使用详情(app usage)的接口逻辑。
- **应用使用统计信息落盘时机**
>1. 每隔30分钟触发一次刷新;
>2. 系统时间变更触发一次刷新;
>3. 下一天开始触发一次刷新;
1. 每隔30分钟触发一次刷新。
2. 系统时间变更触发一次刷新。
3. 下一天开始触发一次刷新。
- **应用查询接口**
>1. 根据起止时间查询所有应用的事件集合;
>2. 根据起止时间查询应用的使用时长;
>3. 根据起止时间查询当前应用的事件集合;
>4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长;
>5. 查询调用者应用的优先级群组;
>6. 判断指定应用当前是否是空闲状态;
1. 根据起止时间查询所有应用的事件集合。
2. 根据起止时间查询应用的使用时长。
3. 根据起止时间查询当前应用的事件集合。
4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长。
5. 查询调用者应用的优先级群组。
6. 判断指定应用当前是否是空闲状态。
7. 查询FA使用记录。返回数量最大不超过maxNum设置的值,maxNum最大为1000。
### 设备使用信息统计使用权限
- 设备使用信息统计的queryBundleActiveStates、queryBundleStateInfos、queryBundleStateInfoByInterval接口为系统api,调用前需要申请ohos.permission.BUNDLE_ACTIVE_INFO权限。
......
......@@ -59,7 +59,7 @@ isIdleState(bundleName: string): Promise&lt;boolean&gt;
**示例**
```
```js
bundleState.isIdleState("com.ohos.camera").then( res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => {
......@@ -83,7 +83,7 @@ queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void
**示例**
```
```js
bundleState.queryAppUsagePriorityGroup((err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
......@@ -109,7 +109,7 @@ queryAppUsagePriorityGroup(): Promise&lt;number&gt;
**示例**
```
```js
bundleState.queryAppUsagePriorityGroup().then( res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => {
......@@ -137,7 +137,7 @@ queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback&lt;Bun
**示例**
```
```js
bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
......@@ -178,7 +178,7 @@ queryBundleStateInfos(begin: number, end: number): Promise&lt;BundleActiveInfoRe
**示例**
```
```js
bundleState.queryBundleStateInfos(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1;
......@@ -213,7 +213,7 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例**
```
```js
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
......@@ -253,7 +253,7 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例**
```
```js
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) {
......@@ -285,7 +285,7 @@ queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;A
**示例**
```
```js
bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
......@@ -324,7 +324,7 @@ queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleA
**示例**
```
```js
bundleState.queryBundleActiveStates(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
......@@ -354,7 +354,7 @@ queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallba
**示例**
```
```js
bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
......@@ -391,7 +391,7 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;
**示例**
```
```js
bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) {
......@@ -403,6 +403,113 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;
});
```
## bundleState.getRecentUsageModules<sup>9+</sup>
getRecentUsageModules(maxNum: number): Promise&lt;Array&lt;BundleActiveModuleInfo&gt;&gt;
据maxNum,查询FA使用记录,使用Promise形式返回不超过maxNum条FA使用记录,maxNum最大为1000。
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| maxNum | number | 是 | 返回条目的最大数量。|
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Array&lt;[BundleActiveModuleInfo](#bundleactivestate)&gt;&gt; | 指定的Promise回调方法。返回不超过maxNum条FA使用记录。|
**示例**
```js
bundleState.getRecentUsageModules(this.maxNum).then( res => {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise succeeded');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentUsageModules promise result ' + JSON.stringify(res[i]));
}
}).catch( err=> {
console.log('BUNDLE_ACTIVE getRecentUsageModules promise failed, because: ' + err.code);
});
```
## bundleState.getRecentUsageModules<sup>9+</sup>
getRecentUsageModules(maxNum: number): Promise&lt;Array&lt;BundleActiveModuleInfo&gt;&gt;
查询FA使用记录。使用callback形式返回数量最大不超过maxNum设置的值,maxNum最大为1000。
**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO
**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| maxNum | number | 是 | 返回条目的最大数量。|
| callback | AsyncCallback&lt;Array&lt;[BundleActiveModuleInfo](#bundleactivestate)&gt;&gt; | 是 | 指定的CallBack回调方法。返回不超过maxNum条FA使用记录。|
**示例**
```js
bundleState.getRecentUsageModules(this.maxNum,(err, res) => {
if(err) {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback succeeded.');
for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE getRecentUsageModules callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE getRecentUsageModules callback result ' + JSON.stringify(res[i]));
}
}
});
```
## BundleActiveModuleInfo<sup>9+</sup>
FA的使用信息的属性集合。
### 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| deviceId | string | 是 | FA所属deviceId。|
| bundleName | string | 是 | FA所属应用包名。|
| moduleName | string | 是 | FA所属module名。|
| abilityName | string | 是 | FA的MainAbility名。|
| appLabelId | number | 是 | FA的应用labelId。|
| labelId | number | 是 | FA所属module的labelId。|
| descriptionId | number | 是 | FA的应用descriptionId。|
| abilityLableId | number | 是 | FA的MainAbility labelId。|
| abilityDescriptionId | number | 是 | FA的MainAbility descriptionId。|
| abilityIconId | number | 是 | FA的MainAbility iconId。|
| launchedCount | number | 是 | FA的启动次数。|
| lastModuleUsedTime | number | 是 | FA的上一次使用时间。|
| formRecords | Array<BundleActiveFormInfo> | 是 | FA中卡片的使用记录。|
## BundleActiveFormInfo<sup>9+</sup>
FA卡片的使用信息的属性集合。
### 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| formName | number | 是 | 卡片名称。|
| formDimension | number | 是 | 卡片尺寸。|
| formId | number | 是 | 卡片Id。|
| formLastUsedTime | number | 是 | 卡片的上一次点击时间。|
| count | number | 是 | 卡片的点击次数。|
## BundleStateInfo
提供应用使用时长的具体信息。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册