diff --git a/README.md b/README.md index b0efeabb09a11cdbf6214cb6c5a5bdd6e6e423af..d867a8e363a2b083347089c69821b024f3b4d829 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 4910fdf7a7e31e268df1b286d53afcb7863d70e8..f54a892a6113b574e6464da9ccd757540817b548 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. 将已注册过的应用分组回调解除注册; ## 相关仓 diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index b6b5dad0c4726a1dacd4a4bb998d798e8133387b..3ab62373c8b883864d1aab9292d582d4f41e9a58 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/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index bf6bb1713b6a1919ba744cc7c698b122bb4cb9fa..d27eb23dc0e837cff1c11202ea7b468f41d9518e 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(