From 38374e6e0021c3547116630aaa57f917feeb697d Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Tue, 7 Jun 2022 14:26:32 +0800 Subject: [PATCH 01/16] =?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 fcaf29f6f10bdaf4d7a51f414266617529b45f38 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 7 Jun 2022 14:27:06 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=9C=A8=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6?= =?UTF-8?q?=EF=BC=8Cnative=E6=8E=A5=E5=8F=A3=E8=A2=AB=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=BF=9B=E7=A8=8Bcrash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../innerkits/src/bundle_active_client.cpp | 2 +- services/common/src/bundle_active_service.cpp | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index efaf269..25bc813 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -38,7 +38,7 @@ bool BundleActiveClient::GetBundleActiveProxy() sptr object = samgr->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); if (!object) { - BUNDLE_ACTIVE_LOGE("Failed to get SystemAbility[1920] ."); + BUNDLE_ACTIVE_LOGE("Failed to get SystemAbility[1907] ."); return false; } diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index d38c0de..fd6e68a 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -62,15 +62,8 @@ void BundleActiveService::OnStart() BUNDLE_ACTIVE_LOGI("BundleActiveService handler create failed!"); return; } - - InitNecessaryState(); - int32_t ret = Publish(DelayedSingleton::GetInstance().get()); - if (!ret) { - BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); - return; - } - BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); - return; + auto registerTask = [this]() { this->InitNecessaryState(); }; + handler_->PostSyncTask(registerTask); } void BundleActiveService::InitNecessaryState() @@ -103,6 +96,12 @@ void BundleActiveService::InitNecessaryState() } InitService(); ready_ = true; + int32_t ret = Publish(DelayedSingleton::GetInstance().get()); + if (!ret) { + BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); + return; + } + BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); } void BundleActiveService::InitService() @@ -470,7 +469,7 @@ int32_t BundleActiveService::UnregisterGroupCallBack(const sptr Date: Tue, 7 Jun 2022 14:46:24 +0800 Subject: [PATCH 03/16] =?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 04/16] =?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 From fd3c500d0c4e4469593df833b02dc0b6d210313b Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 18:40:30 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- README.md | 22 +++++++++---------- README_zh.md | 19 ++++++---------- services/common/src/bundle_active_core.cpp | 11 +++++++++- services/common/src/bundle_active_service.cpp | 14 ++++++++++-- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8a66d30..edb104b 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,6 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

接口名

接口描述

+

接口描述

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的应用当前是否是空闲状态。

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

@@ -81,9 +79,9 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

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

+

Query the current application or the grouping of the application corresponding to the specified bundlename.

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

-

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

+

Query the current application or the grouping of the application corresponding to the specified bundlename.

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>

@@ -101,6 +99,7 @@ Taking app usage interface as an example, the main exposed interfaces are as fol
+ ### Usage Guidelines There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic. @@ -114,14 +113,13 @@ There are many interfaces for device usage statistics. Take app usage interface >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; ->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; +>5. Judge whether the specified application is currently idle; +>6. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; +>7. Query the application notification times according to the start and end time; +>8. 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; +>9. Query the current application or the grouping of the application corresponding to the specified bundlename; +>10. Set the group of the specified application as the group provided by the parameter; +>11. 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 3e044dc..dd85e86 100644 --- a/README_zh.md +++ b/README_zh.md @@ -58,10 +58,6 @@

通过指定时间段间隔(天、周、月、年)查询应用使用时长统计信息(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>

@@ -113,14 +109,13 @@ >2. 根据起止时间查询应用的使用时长; >3. 根据起止时间查询当前应用的事件集合; >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; ->5. 查询调用者应用的优先级群组; ->6. 判断指定应用当前是否是空闲状态; ->7. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; ->8. 根据起止时间查询应用通知次数; ->9. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000; ->10. 使用可选参数查询当前调用者应用的使用优先级群组; ->11. 将指定应用的分组设置为参数提供的分组; ->12. 给应用分组变化注册回调; +>5. 判断指定应用当前是否是空闲状态; +>6. 根据起止时间查询系统事件(休眠、唤醒、解锁、锁屏)统计信息; +>7. 根据起止时间查询应用通知次数; +>8. 查询FA使用记录。返回数量最大不超过maxNum设置的值,FA使用记录由近及远排序,maxNum最大为1000,若不填写maxNum参数,则maxNum默认为1000; +>9. 查询当前应用或指定bundlename对应的应用的分组; +>10. 将指定应用的分组设置为参数提供的分组; +>11. 给应用分组变化注册回调; >13. 将已注册过的应用分组回调解除注册; ## 相关仓 diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index b6b5dad..3ab6237 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -702,13 +702,22 @@ int64_t BundleActiveCore::GetSystemTimeMs() void BundleActiveCore::OnBundleGroupChanged(const BundleActiveGroupCallbackInfo& callbackInfo) { std::lock_guard lock(callbackMutex_); + AccessToken::HapTokenInfo tokenInfo = AccessToken::HapTokenInfo(); for (const auto &item : groupChangeObservers_) { auto observer = item.second; if (observer) { BUNDLE_ACTIVE_LOGI( "RegisterGroupCallBack will OnBundleGroupChanged!,oldGroup is %{public}d, newGroup is %{public}d", callbackInfo.GetOldGroup(), callbackInfo.GetNewGroup()); - observer->OnBundleGroupChanged(callbackInfo); + if (AccessToken::AccessTokenKit::GetTokenType(item.first) == AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + observer->OnBundleGroupChanged(callbackInfo); + } else if (AccessToken::AccessTokenKit::GetTokenType(item.first) == + AccessToken::ATokenTypeEnum::TOKEN_HAP) { + AccessToken::AccessTokenKit::GetHapTokenInfo(item.first, tokenInfo); + if (tokenInfo.userID == callbackInfo.GetUserId()) { + observer->OnBundleGroupChanged(callbackInfo); + } + } } } } diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index fd6e68a..fbee0e8 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -329,9 +329,19 @@ std::vector BundleActiveService::QueryEvents(const int64_t be int32_t BundleActiveService::SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t errCode, int32_t userId) { - bool result = -1; - // get uid + int32_t result = -1; + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); + if (!GetBundleMgrProxy()) { + BUNDLE_ACTIVE_LOGE("get bundle manager proxy failed!"); + return result; + } + std::string g_bundleName = ""; + sptrBundleMgr_->GetBundleNameForUid(callingUid, g_bundleName); + if (g_bundleName == bundleName) { + BUNDLE_ACTIVE_LOGI("SetBundleGroup can not set its bundleName"); + return -1; + } AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); if (userId == -1) { OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); -- Gitee From c5ae8abfc50f6e798dbd447dbaa5806d972ad456 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 20:50:43 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_service.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index fbee0e8..874148e 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -336,9 +336,9 @@ int32_t BundleActiveService::SetBundleGroup(const std::string& bundleName, int32 BUNDLE_ACTIVE_LOGE("get bundle manager proxy failed!"); return result; } - std::string g_bundleName = ""; - sptrBundleMgr_->GetBundleNameForUid(callingUid, g_bundleName); - if (g_bundleName == bundleName) { + std::string localBundleName = ""; + sptrBundleMgr_->GetBundleNameForUid(callingUid, localBundleName); + if (localBundleName == bundleName) { BUNDLE_ACTIVE_LOGI("SetBundleGroup can not set its bundleName"); return -1; } @@ -441,9 +441,9 @@ int32_t BundleActiveService::QueryPackageGroup(std::string& bundleName, int32_t BUNDLE_ACTIVE_LOGE("get bundle manager proxy failed!"); return result; } - std::string g_bundleName = ""; - sptrBundleMgr_->GetBundleNameForUid(callingUid, g_bundleName); - bundleName = g_bundleName; + std::string localBundleName = ""; + sptrBundleMgr_->GetBundleNameForUid(callingUid, localBundleName); + bundleName = localBundleName; result = bundleActiveCore_->QueryPackageGroup(bundleName, userId); } else { AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); -- Gitee From f149095e330b8f5d378d840d4578bf2a6132c12b Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 21:20:12 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index edb104b..59fc520 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,6 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

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(): 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>

@@ -79,9 +77,9 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

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 current application or the grouping of the application corresponding to the specified bundlename.

+

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

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

-

Query the current application or the grouping of the application corresponding to the specified bundlename.

+

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

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>

@@ -117,7 +115,7 @@ There are many interfaces for device usage statistics. Take app usage interface >6. Query the statistical information of system events (sleep, wake-up, unlock and screen lock) according to the start and end time; >7. Query the application notification times according to the start and end time; >8. 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; ->9. Query the current application or the grouping of the application corresponding to the specified bundlename; +>9. Query the group of the current application or the application of specified bundlename; >10. Set the group of the specified application as the group provided by the parameter; >11. Register callback for application group change; >13. Unregister the registered application group callback; -- Gitee From ad62eb47648b46b54bd1eb6143a9a80059bab8e1 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 09:41:54 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 874148e..4375637 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -536,10 +536,10 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_t u int32_t bundleHasPermission = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, NEEDED_PERMISSION); if (bundleHasPermission != 0) { errCode = bundleHasPermission; - BUNDLE_ACTIVE_LOGE("UnRegisterGroupCallBack %{public}s hasn't permission", bundleName.c_str()); + BUNDLE_ACTIVE_LOGE("%{public}s hasn't permission", bundleName.c_str()); return false; } else { - BUNDLE_ACTIVE_LOGI("UnRegisterGroupCallBack %{public}s has permission %{public}d", + BUNDLE_ACTIVE_LOGI("%{public}s has permission %{public}d", bundleName.c_str(), bundleHasPermission); return true; } -- Gitee From bbc6b6e9e02d7f2549c24dbd477bd81803d1ab9a Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 15:43:18 +0800 Subject: [PATCH 09/16] =?UTF-8?q?d.ts=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index 265e869..7f073cb 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -226,8 +226,8 @@ declare namespace bundleState { stateType?: number; } /** - * @since 7 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @since 9 + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup */ interface BundleActiveGroupCallbackInfo { /* @@ -433,7 +433,7 @@ declare namespace bundleState { * set bundle group by bundleName and number. * * @since 9 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup * @return Returns the result of setBundleGroup, true of false. */ function setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback): void; @@ -443,7 +443,7 @@ declare namespace bundleState { * register callback to service. * * @since 9 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup * @return Returns BundleActiveGroupCallbackInfo when the group of bundle changed. the result of AsyncCallback is true or false. */ function registerGroupCallBack(callback: Callback, callback: AsyncCallback): void; @@ -453,7 +453,7 @@ declare namespace bundleState { * unRegister callback from service. * * @since 9 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup * @return Returns the result of unRegisterGroupCallBack, true of false. */ function unRegisterGroupCallBack(callback: AsyncCallback): void; -- Gitee From f63c2b4cc9f66ecefc03d06effb26f544554d760 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 15:52:50 +0800 Subject: [PATCH 10/16] =?UTF-8?q?d.ts=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index 7f073cb..889065a 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -182,7 +182,7 @@ declare namespace bundleState { /** * the bundle name or system event name. */ - name?: string; + name: string; /** * the event id. -- Gitee From d1e55e762eb7301c1bf636a5458e0eaf48e70f15 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 16:14:48 +0800 Subject: [PATCH 11/16] =?UTF-8?q?d.ts=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../bundlestats/js/@ohos.bundleState.d.ts | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index 889065a..8c0eeff 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -233,23 +233,23 @@ declare namespace bundleState { /* * the usage old group of the application */ - appUsageOldGroup?: number; + appUsageOldGroup: number; /* * the usage new group of the application */ - appUsageNewGroup?: number; + appUsageNewGroup: number; /* - * the use id + * the use id */ - userId?: number; + userId: number; /* - * the change reason + * the change reason */ - changeReason?: number; + changeReason: number; /* - * the bundle name + * the bundle name */ - bundleName?: string; + bundleName: string; } /** @@ -366,14 +366,14 @@ declare namespace bundleState { function queryCurrentBundleActiveStates(begin: number, end: number): Promise>; /** - * Queries module usage records. + * Queries recently module usage records. * * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App * @permission ohos.permission.BUNDLE_ACTIVE_INFO * @systemapi Hide this for inner system use. * @param maxNum Indicates max record number in result, max value is 1000, default value is 1000. - * @return Returns the {@link BundleActiveModuleInfo} object Array containing the state data of the current module. + * @return Returns the {@link BundleActiveModuleInfo} object Array containing the usage data of the modules. */ function getRecentlyUsedModules(maxNum?: number, callback: AsyncCallback>): void; function getRecentlyUsedModules(maxNum?: number): Promise>; @@ -386,6 +386,9 @@ declare namespace bundleState { * * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + * @permission ohos.permission.BUNDLE_ACTIVE_INFO + * @systemapi Hide this for inner system use. + * @param bundleName, name of the application. * @return Returns the usage priority group of the calling application. */ function queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback): void; @@ -395,7 +398,7 @@ declare namespace bundleState { * Declares group type. * * @since 9 - * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup */ export enum GroupType { /** @@ -422,7 +425,7 @@ declare namespace bundleState { * Indicates the limit group. */ ACTIVE_GROUP_LIMIT = 50, - + /** * Indicates the never group. */ @@ -434,6 +437,10 @@ declare namespace bundleState { * * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + * @permission ohos.permission.BUNDLE_ACTIVE_INFO + * @systemapi Hide this for inner system use. + * @param bundleName, name of the application. + * @param newGroup,the group of the application whose name is bundleName. * @return Returns the result of setBundleGroup, true of false. */ function setBundleGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback): void; @@ -444,16 +451,21 @@ declare namespace bundleState { * * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + * @permission ohos.permission.BUNDLE_ACTIVE_INFO + * @systemapi Hide this for inner system use. + * @param Callback, callback when application group change,return the BundleActiveGroupCallbackInfo. * @return Returns BundleActiveGroupCallbackInfo when the group of bundle changed. the result of AsyncCallback is true or false. */ function registerGroupCallBack(callback: Callback, callback: AsyncCallback): void; function registerGroupCallBack(callback: Callback): Promise; - + /** * unRegister callback from service. * * @since 9 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + * @permission ohos.permission.BUNDLE_ACTIVE_INFO + * @systemapi Hide this for inner system use. * @return Returns the result of unRegisterGroupCallBack, true of false. */ function unRegisterGroupCallBack(callback: AsyncCallback): void; -- Gitee From a971c9ba06f937a1a2d75106ae21adff457965d7 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 16:20:20 +0800 Subject: [PATCH 12/16] =?UTF-8?q?d.ts=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../bundlestats/js/@ohos.bundleState.d.ts | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index 8c0eeff..f60c425 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -231,25 +231,25 @@ declare namespace bundleState { */ interface BundleActiveGroupCallbackInfo { /* - * the usage old group of the application - */ - appUsageOldGroup: number; + * the usage old group of the application + */ + appUsageOldGroup: number; + /* + * the usage new group of the application + */ + appUsageNewGroup: number; + /* + * the use id + */ + userId: number; /* - * the usage new group of the application - */ - appUsageNewGroup: number; - /* - * the use id - */ - userId: number; - /* - * the change reason - */ - changeReason: number; - /* - * the bundle name - */ - bundleName: string; + * the change reason + */ + changeReason: number; + /* + * the bundle name + */ + bundleName: string; } /** -- Gitee From eb58855e7853d47421f451b5f94cc31413cbddc5 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 8 Jun 2022 16:52:32 +0800 Subject: [PATCH 13/16] =?UTF-8?q?d.ts=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../kits/bundlestats/js/@ohos.bundleState.d.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts index f60c425..0518178 100644 --- a/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts +++ b/interfaces/kits/bundlestats/js/@ohos.bundleState.d.ts @@ -265,6 +265,19 @@ declare namespace bundleState { function isIdleState(bundleName: string, callback: AsyncCallback): void; function isIdleState(bundleName: string): Promise; + /** + * Queries the usage priority group of the calling application. + * + *

The priority defined in a priority group restricts the resource usage of an application, + * for example, restricting the running of background tasks.

+ * + * @since 7 + * @syscap SystemCapability.ResourceSchedule.UsageStatistics.AppGroup + * @return Returns the usage priority group of the calling application. + */ + function queryAppUsagePriorityGroup(callback: AsyncCallback): void; + function queryAppUsagePriorityGroup(): Promise; + /** * @since 7 * @syscap SystemCapability.ResourceSchedule.UsageStatistics.App -- Gitee From 762151f3741c0978e2e820b49d4f4dcc30128842 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 9 Jun 2022 09:38:37 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E6=B3=A8=E5=86=8Cdelete=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=87=BA=E7=8E=B0cppcrash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_active_group_observer.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frameworks/src/bundle_active_group_observer.cpp b/frameworks/src/bundle_active_group_observer.cpp index 8de846d..208e3d8 100644 --- a/frameworks/src/bundle_active_group_observer.cpp +++ b/frameworks/src/bundle_active_group_observer.cpp @@ -234,10 +234,6 @@ napi_value RegisterGroupCallBack(napi_env env, napi_callback_info info) ParseRegisterGroupCallBackParameters(env, info, params, registerObserver); if (params.errorCode != ERR_OK || !registerObserver) { - if (registerObserver) { - delete registerObserver; - registerObserver = nullptr; - } return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } napi_value promise = nullptr; -- Gitee From fdc2fda08d26a02c83b9225c732516c196e6a06a Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 9 Jun 2022 12:41:54 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E6=B3=A8=E5=86=8Cdelete=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=87=BA=E7=8E=B0cppcrash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../src/bundle_active_group_observer.cpp | 24 +++++++++---------- .../innerkits/src/bundle_active_client.cpp | 8 +++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/frameworks/src/bundle_active_group_observer.cpp b/frameworks/src/bundle_active_group_observer.cpp index 208e3d8..e30f620 100644 --- a/frameworks/src/bundle_active_group_observer.cpp +++ b/frameworks/src/bundle_active_group_observer.cpp @@ -181,25 +181,23 @@ void BundleActiveGroupObserver::OnBundleGroupChanged(const BundleActiveGroupCall } } -napi_value GetBundleGroupChangeCallback( - const napi_env &env, const napi_value &value, BundleActiveGroupObserverInfo &bundleActiveGroupObserverInfo) +napi_value GetBundleGroupChangeCallback(const napi_env &env, const napi_value &value) { napi_ref result = nullptr; - bundleActiveGroupObserverInfo.callback = new (std::nothrow) BundleActiveGroupObserver(); - if (!bundleActiveGroupObserverInfo.callback) { + registerObserver = new (std::nothrow) BundleActiveGroupObserver(); + if (!registerObserver) { BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack callback is null"); return BundleStateCommon::NapiGetNull(env); } - napi_create_reference(env, value, 1, &result); - bundleActiveGroupObserverInfo.callback->SetCallbackInfo(env, result); + registerObserver->SetCallbackInfo(env, result); return BundleStateCommon::NapiGetNull(env); } napi_value ParseRegisterGroupCallBackParameters(const napi_env &env, const napi_callback_info &info, - RegisterCallbackInfo ¶ms, sptr &observer) + RegisterCallbackInfo ¶ms) { size_t argc = REGISTER_GROUP_CALLBACK_PARAMS; napi_value argv[REGISTER_GROUP_CALLBACK_PARAMS] = {nullptr}; @@ -210,12 +208,12 @@ napi_value ParseRegisterGroupCallBackParameters(const napi_env &env, const napi_ // arg[0] : callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - BundleActiveGroupObserverInfo bundleActiveGroupObserverInfo; - if (valuetype != napi_function || !GetBundleGroupChangeCallback(env, argv[0], bundleActiveGroupObserverInfo)) { + if (registerObserver) { + BUNDLE_ACTIVE_LOGI("RegisterGroupCallBack repeat!"); + params.errorCode = ERR_REPEAT_OPERATION; + } else if (valuetype != napi_function || !GetBundleGroupChangeCallback(env, argv[0])) { BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack bundleActiveGroupObserverInfo parse failed"); params.errorCode = ERR_OBSERVER_CALLBACK_IS_INVALID; - } else { - observer = bundleActiveGroupObserverInfo.callback; } // argv[1]: asyncCallback @@ -231,9 +229,9 @@ napi_value ParseRegisterGroupCallBackParameters(const napi_env &env, const napi_ napi_value RegisterGroupCallBack(napi_env env, napi_callback_info info) { RegisterCallbackInfo params; - ParseRegisterGroupCallBackParameters(env, info, params, registerObserver); + ParseRegisterGroupCallBackParameters(env, info, params); - if (params.errorCode != ERR_OK || !registerObserver) { + if (params.errorCode != ERR_OK) { return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } napi_value promise = nullptr; diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 763f4fe..9153983 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -143,7 +143,12 @@ int32_t BundleActiveClient::RegisterGroupCallBack(const sptrRegisterGroupCallBack(observer); + int32_t result = bundleActiveProxy_->RegisterGroupCallBack(observer); + if (/* condition */) { + /* code */ + } + + return result; } int32_t BundleActiveClient::UnregisterGroupCallBack(const sptr &observer) @@ -219,7 +224,6 @@ int32_t BundleActiveClient::ShellDump(const std::vector &dumpOption } } } - return ret; } } // namespace DeviceUsageStats -- Gitee From 81e19b4140b71c750d6c9511bf364b114650c256 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Thu, 9 Jun 2022 12:44:24 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E6=B3=A8=E5=86=8Cdelete=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=87=BA=E7=8E=B0cppcrash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- interfaces/innerkits/src/bundle_active_client.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 9153983..58478d4 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -144,10 +144,6 @@ int32_t BundleActiveClient::RegisterGroupCallBack(const sptrRegisterGroupCallBack(observer); - if (/* condition */) { - /* code */ - } - return result; } -- Gitee