From fd3c500d0c4e4469593df833b02dc0b6d210313b Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 7 Jun 2022 18:40:30 +0800 Subject: [PATCH 1/4] =?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

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 2/4] =?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 3/4] =?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 4/4] =?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