From 38374e6e0021c3547116630aaa57f917feeb697d Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 7 Jun 2022 14:26:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wyuanchao --- README.md | 83 ++++++++++++++----- README_zh.md | 83 ++++++++++++++----- .../device_usage_statistics_jsunit.test.js | 24 +++--- .../unittest/device_usage_statistics_test.cpp | 28 ++++--- 4 files changed, 148 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index b0efeab..8a66d30 100644 --- a/README.md +++ b/README.md @@ -40,32 +40,62 @@ Taking app usage interface as an example, the main exposed interfaces are as fol - - - - - - - - - - - - @@ -86,6 +116,13 @@ There are many interfaces for device usage statistics. Take app usage interface >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; +>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. Use the optional parameters to query the usage priority group of the current caller application; +>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 diff --git a/README_zh.md b/README_zh.md index 4910fdf..3e044dc 100644 --- a/README_zh.md +++ b/README_zh.md @@ -37,32 +37,64 @@

API name

API description

+

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.

+

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

+

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

+

queryAppUsagePriorityGroup(): Promise<Array<number>

+

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

+

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

+

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(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. If the maxnum parameter is not filled in, the default 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

+

Use the optional parameters to query the usage priority group of the current caller application(callback).

+

queryAppUsagePriorityGroup(bundleName? : string): Promise<number>

+

Use the optional parameters to query the usage priority group of the current caller application(Promise).

+

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

+

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

+

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

+

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

+

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

+

Register callback for application group change(callback).

+

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

+

Register callback for application group change(Promise).

+

unRegisterGroupCallBack(callback: AsyncCallback<boolean>): void

+

Unregister the registered application group callback(callback).

+

unRegisterGroupCallBack(): Promise<boolean>

+

Unregister the registered application group callback(Promise).

- - + - - - - - - - - - - @@ -83,6 +115,13 @@ >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; >5. 查询调用者应用的优先级群组; >6. 判断指定应用当前是否是空闲状态; +>7. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; +>8. 根据起止时间查询应用通知次数; +>9. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000; +>10. 使用可选参数查询当前调用者应用的使用优先级群组; +>11. 将指定应用的分组设置为参数提供的分组; +>12. 给应用分组变化注册回调; +>13. 将已注册过的应用分组回调解除注册; ## 相关仓 diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js index 9ecd0ab..a5c96c4 100644 --- a/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/device_usage_statistics_jsunit.test.js @@ -575,13 +575,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest020 + * @tc.name: DeviceUsageStatisticsJsTest023 * @tc.desc: test queryBundleActiveEventStates promise. * @tc.type: FUNC * @tc.require: SR000H0H9H AR000H0ROG */ - it("DeviceUsageStatisticsJsTest020", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest020---------------------------'); + it("DeviceUsageStatisticsJsTest023", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest023---------------------------'); let beginTime = 0; let endTime = 20000000000000; bundleState.queryBundleActiveEventStates(beginTime, endTime).then((res) => { @@ -598,13 +598,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest021 + * @tc.name: DeviceUsageStatisticsJsTest024 * @tc.desc: test queryBundleActiveEventStates callback. * @tc.type: FUNC * @tc.require: SR000H0H9H AR000H0ROG */ - it("DeviceUsageStatisticsJsTest021", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest021---------------------------'); + it("DeviceUsageStatisticsJsTest024", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest024---------------------------'); let beginTime = 0; let endTime = 20000000000000; bundleState.queryBundleActiveEventStates(beginTime, endTime, (err, res) => { @@ -623,13 +623,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest022 + * @tc.name: DeviceUsageStatisticsJsTest025 * @tc.desc: test queryAppNotificationNumber promise. * @tc.type: FUNC * @tc.require: SR000H0H7D AR000H0RR6 */ - it("DeviceUsageStatisticsJsTest022", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest022---------------------------'); + it("DeviceUsageStatisticsJsTest025", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest025---------------------------'); let beginTime = 0; let endTime = 20000000000000; bundleState.queryAppNotificationNumber(beginTime, endTime).then((res) => { @@ -646,13 +646,13 @@ describe("DeviceUsageStatisticsJsTest", function () { }) /* - * @tc.name: DeviceUsageStatisticsJsTest023 + * @tc.name: DeviceUsageStatisticsJsTest026 * @tc.desc: test queryAppNotificationNumber callback. * @tc.type: FUNC * @tc.require: SR000H0H7D AR000H0RR6 */ - it("DeviceUsageStatisticsJsTest023", 0, async function (done) { - console.info('----------------------DeviceUsageStatisticsJsTest023---------------------------'); + it("DeviceUsageStatisticsJsTest026", 0, async function (done) { + console.info('----------------------DeviceUsageStatisticsJsTest026---------------------------'); let beginTime = 0; let endTime = 20000000000000; bundleState.queryAppNotificationNumber(beginTime, endTime, (err, res) => { diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 3b373a5..967c3c7 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -172,6 +172,19 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryFormStatistic EXPECT_EQ(results.size(), 0); } +/* + * @tc.name: DeviceUsageStatisticsTest_SetBundleGroup_001 + * @tc.desc: setbundlename + * @tc.type: FUNC + * @tc.require: SR000H0HAQ AR000H0ROE + */ +HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetBundleGroup_001, Function | MediumTest | Level0) +{ + int32_t result = BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, + DEFAULT_ERRCODE, COMMON_USERID); + EXPECT_EQ(result, DEFAULT_ERRCODE); +} + /* * @tc.name: DeviceUsageStatisticsTest_QueryPackageGroup_001 * @tc.desc: querypackagegroup, no bundleName @@ -180,6 +193,8 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryFormStatistic */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackageGroup_001, Function | MediumTest | Level0) { + BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, + DEFAULT_ERRCODE, COMMON_USERID); int32_t result = BundleActiveClient::GetInstance().QueryPackageGroup(DEFAULT_BUNDLENAME, COMMON_USERID); bool flag = false; for (auto item = GROUP_TYPE.begin(); item != GROUP_TYPE.end(); item++) { @@ -191,19 +206,6 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackageGroup_ EXPECT_EQ(flag, true); } -/* - * @tc.name: DeviceUsageStatisticsTest_SetBundleGroup_001 - * @tc.desc: setbundlename - * @tc.type: FUNC - * @tc.require: SR000H0HAQ AR000H0ROE - */ -HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetBundleGroup_001, Function | MediumTest | Level0) -{ - int32_t result = BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, - DEFAULT_ERRCODE, COMMON_USERID); - EXPECT_EQ(result, DEFAULT_ERRCODE); -} - /* * @tc.name: DeviceUsageStatisticsTest_RegisterGroupCallBack_001 * @tc.desc: registercallback -- Gitee From 00ab66cca31fb986f42b4d7862fd9363eed541c4 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 7 Jun 2022 14:46:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wyuanchao --- test/unittest/device_usage_statistics_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 967c3c7..0a1cd85 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -180,6 +180,8 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryFormStatistic */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetBundleGroup_001, Function | MediumTest | Level0) { + int32_t result = BundleActiveClient::GetInstance().QueryPackageGroup(DEFAULT_BUNDLENAME, COMMON_USERID); + DEFAULT_GROUP = (result == DEFAULT_GROUP) ? (result + 10) : DEFAULT_GROUP; int32_t result = BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, DEFAULT_ERRCODE, COMMON_USERID); EXPECT_EQ(result, DEFAULT_ERRCODE); -- Gitee From de83d134d795920f80d7923e437b916d1a1a5428 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 7 Jun 2022 15:11:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wyuanchao --- test/unittest/device_usage_statistics_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 0a1cd85..01fbb0b 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -182,7 +182,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetBundleGroup_001 { int32_t result = BundleActiveClient::GetInstance().QueryPackageGroup(DEFAULT_BUNDLENAME, COMMON_USERID); DEFAULT_GROUP = (result == DEFAULT_GROUP) ? (result + 10) : DEFAULT_GROUP; - int32_t result = BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, + result = BundleActiveClient::GetInstance().SetBundleGroup(DEFAULT_BUNDLENAME, DEFAULT_GROUP, DEFAULT_ERRCODE, COMMON_USERID); EXPECT_EQ(result, DEFAULT_ERRCODE); } -- Gitee

接口名

接口描述

+

接口描述

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

+

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

+

通过指定起始和结束时间查询所有应用的事件集合(callback形式)。

+

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

+

通过指定起始和结束时间查询所有应用的事件集合(Promise形式)。

+

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

+

通过指定起始和结束时间查询应用使用时长统计信息(callback形式)。

+

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

+

通过指定起始和结束时间查询应用使用时长统计信息(Promise形式)。

+

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

+

通过指定起始和结束时间查询当前应用的事件集合(callback形式)。

+

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

+

通过指定起始和结束时间查询当前应用的事件集合(Promise形式)。

+

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

+

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(callback形式)。

+

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

+

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(Promise形式)。

+

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

+

查询(返回)当前调用者应用的使用优先级群组(callback形式)。

+

queryAppUsagePriorityGroup(): Promise<number>

+

查询(返回)当前调用者应用的使用优先级群组(Promise形式)。

+

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

+

判断指定Bundle Name的应用当前是否是空闲状态(callback形式)。

+

isIdleState(bundleName: string): Promise<boolean>

+

判断指定Bundle Name的应用当前是否是空闲状态(Promise形式)。

+

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

+

根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息(callback形式)。

+

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

+

根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息(Promise形式)。

+

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

+

根据起止时间查询应用通知次数(callback形式)。

+

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

+

根据起止时间查询应用通知次数(Promise形式)。

+

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

+

查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000(callback形式)。

+

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

+

查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000(Promise形式)。

+

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

+

使用可选参数查询当前调用者应用的使用优先级群组(callback形式)。

+

queryAppUsagePriorityGroup(bundleName? : string): Promise<number>

+

使用可选参数查询当前调用者应用的使用优先级群组(Promise形式)。

+

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

+

将指定应用的分组设置为参数提供的分组(callback形式)。

+

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

+

将指定应用的分组设置为参数提供的分组(Promise形式)。

+

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

+

给应用分组变化注册回调(callback形式)。

+

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

+

给应用分组变化注册回调(Promise形式)。

+

unRegisterGroupCallBack(callback: AsyncCallback<boolean>): void

+

将已注册过的应用分组回调解除注册(callback形式)。

+

unRegisterGroupCallBack(): Promise<boolean>

+

将已注册过的应用分组回调解除注册(Promise形式)。

通过指定起始和结束时间查询所有应用的事件集合。

-

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

-

通过指定起始和结束时间查询应用使用时长统计信息。

-

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

-

通过指定起始和结束时间查询当前应用的事件集合。

-

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

-

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息。

-

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

-

查询(返回)当前调用者应用的使用优先级群组。

-

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

-

判断指定Bundle Name的应用当前是否是空闲状态。