From cc32a276e3bfb950e218ae83c273e95c646b46b2 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 6 Jun 2022 16:34:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=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 --- services/common/src/bundle_active_core.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index bce0cd6..b25f8c2 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -706,13 +706,21 @@ 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); + } + } } } } -- Gitee From bcdc4d86c7f1cb4edfe540d661f50556a030f0ba Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 6 Jun 2022 20:42:01 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=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 --- services/packagegroup/src/bundle_active_user_history.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index bf6bb17..d27eb23 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -193,14 +193,11 @@ void BundleActiveUserHistory::ReportUsage(shared_ptr } oneBundleUsageHistory->reasonInGroup_ = GROUP_CONTROL_REASON_USAGE | groupReason; oneBundleUsageHistory->isChanged_ = true; - BUNDLE_ACTIVE_LOGI("RegisterGroupCallBack will ReportUsage"); bool isGroupChanged = (oldGroup == newGroup) ? true : false; if (!isGroupChanged) { BundleActiveGroupCallbackInfo callbackInfo( userId, oldGroup, newGroup, oneBundleUsageHistory->reasonInGroup_, bundleName); - BUNDLE_ACTIVE_LOGI("RegisterGroupCallBack BundleActiveGroupCallbackInfo build success"); if (!bundleActiveCore_.expired()) { - BUNDLE_ACTIVE_LOGI("RegisterGroupCallBack will callback!"); bundleActiveCore_.lock()->OnBundleGroupChanged(callbackInfo); } } @@ -229,7 +226,6 @@ int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const oneBundleHistory->currentGroup_ = newGroup; oneBundleHistory->reasonInGroup_ = groupReason; oneBundleHistory->isChanged_ = true; - BUNDLE_ACTIVE_LOGI("SetBundleGroup set success"); bool isGroupChanged = (oldGroup == newGroup) ? true : false; if (!isGroupChanged) { BundleActiveGroupCallbackInfo callbackInfo( -- Gitee From 33c987f1638eef76740058269bc746c3afe374db Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 09:10:31 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=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 --- services/common/src/bundle_active_core.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index fc025b2..3ab6237 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -711,7 +711,8 @@ void BundleActiveCore::OnBundleGroupChanged(const BundleActiveGroupCallbackInfo& callbackInfo.GetOldGroup(), callbackInfo.GetNewGroup()); if (AccessToken::AccessTokenKit::GetTokenType(item.first) == AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { observer->OnBundleGroupChanged(callbackInfo); - } else if (AccessToken::AccessTokenKit::GetTokenType(item.first) == AccessToken::ATokenTypeEnum::TOKEN_HAP) { + } 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); -- Gitee From 0acb7c595188613f7f708cd029827c410e257267 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 15:59:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A4=9A=E7=94=A8=E6=88=B7=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=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 --- README.md | 19 +++++++++++++++++++ README_zh.md | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/README.md b/README.md index b0efeab..d867a8e 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,30 @@ Taking app usage interface as an example, the main exposed interfaces are as fol

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

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

+

queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback): void

+ +

Query the priority group of the caller application whith bundleName.

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

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

+

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

+ +

set the newGroup to the bundle, whose name is bundleName.

+ +

registerGroupCallBack(callback: Callback, callback: AsyncCallback): void

+ +

register the callback of bundle group change.

+ +

unRegisterGroupCallBack(callback: AsyncCallback): void

+ +

unRegister the callback of bundle group change.

+ + ### Usage Guidelines There are many interfaces for device usage statistics. Take app usage interface as an example to introduce the interface logic. @@ -86,6 +102,9 @@ 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; +>6. set the newGroup to the bundle, whose name is bundleName; +>6. register the callback of bundle group change; +>6. unRegister the callback of bundle group change; ## Repositories Involved diff --git a/README_zh.md b/README_zh.md index 4910fdf..f54a892 100644 --- a/README_zh.md +++ b/README_zh.md @@ -60,14 +60,30 @@

queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void

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

+

queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback): void

+ +

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

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

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

+

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

+ +

将指定应用的分组设置为参数提供的分组。

+ +

registerGroupCallBack(callback: Callback, callback: AsyncCallback): void

+ +

给应用分组变化注册回调。

+ +

unRegisterGroupCallBack(callback: AsyncCallback): void

+ +

将已注册过的应用分组回调解除注册。

+ + ### 使用说明 设备使用信息统计接口众多,以应用使用详情(app usage)接口为例,介绍接口逻辑。 @@ -83,6 +99,9 @@ >4. 根据interval(日、周、月、年)类型和起止时间查询应用的使用时长; >5. 查询调用者应用的优先级群组; >6. 判断指定应用当前是否是空闲状态; +>6. 将指定应用的分组设置为参数提供的分组; +>6. 给应用分组变化注册回调; +>6. 将已注册过的应用分组回调解除注册; ## 相关仓 -- Gitee