From c3c4d477724185599cebd0bb058f74ae339bc2cf Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 8 Aug 2022 17:39:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=BF=9B=E7=A8=8BsetBund?= =?UTF-8?q?leGroup=E7=AB=8B=E9=A9=AC=E8=90=BD=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/include/bundle_active_core.h | 9 +++++++-- services/common/src/bundle_active_core.cpp | 6 ++++-- services/common/src/bundle_active_service.cpp | 7 ++++--- .../include/bundle_active_group_controller.h | 2 +- .../packagegroup/include/bundle_active_user_history.h | 2 +- .../packagegroup/src/bundle_active_group_controller.cpp | 6 +++--- services/packagegroup/src/bundle_active_user_history.cpp | 7 ++++++- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 4f61f05..5d14d6a 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -164,8 +164,13 @@ public: void OnUserRemoved(const int32_t userId); // when user switched, restore old userdata. void OnUserSwitched(const int32_t userId); - // force set app group. - int32_t SetBundleGroup(const std::string& bundleName, const int32_t newGroup, const int32_t userId); + /* + * function: SetBundleGroup, change bundleGroup to the newGroup. + * parameters: bundleName, newGroup, userId, flushflag, + * return: errorcode. + */ + int32_t SetBundleGroup( + const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool flushflag); // get all user in device. void GetAllActiveUser(std::vector& activatedOsAccountIds); // when service stop, call it to unregister commen event and shutdown call back. diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 723dd8b..ae4b838 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -645,12 +645,14 @@ int32_t BundleActiveCore::QueryAppNotificationNumber(int64_t beginTime, int64_t return errCode; } -int32_t BundleActiveCore::SetBundleGroup(const std::string& bundleName, const int32_t newGroup, const int32_t userId) +int32_t BundleActiveCore::SetBundleGroup( + const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool flushflag) { int32_t newReason = GROUP_CONTROL_REASON_FORCED; sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - return bundleGroupController_->SetBundleGroup(bundleName, userId, newGroup, newReason, bootBasedTimeStamp); + return bundleGroupController_->SetBundleGroup( + bundleName, userId, newGroup, newReason, bootBasedTimeStamp, flushflag); } int32_t BundleActiveCore::QueryPackageGroup(const std::string bundleName, const int32_t userId) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index ada143a..dac35e3 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -361,7 +361,6 @@ int32_t BundleActiveService::SetBundleGroup(const std::string& bundleName, int32 int32_t userId) { int32_t result = -1; - int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); if (!GetBundleMgrProxy()) { BUNDLE_ACTIVE_LOGE("get bundle manager proxy failed!"); @@ -371,22 +370,24 @@ int32_t BundleActiveService::SetBundleGroup(const std::string& bundleName, int32 sptrBundleMgr_->GetBundleNameForUid(callingUid, localBundleName); if (localBundleName == bundleName) { BUNDLE_ACTIVE_LOGI("SetBundleGroup can not set its bundleName"); - return -1; + return result; } AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + bool flushflag = false; if (userId == -1) { OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); if (ret != ERR_OK) { errCode = -1; return result; } + flushflag = true; } if (userId != -1) { BUNDLE_ACTIVE_LOGI("SetBundleGroup userid is %{public}d", userId); auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode) || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { - result = bundleActiveCore_->SetBundleGroup(bundleName, newGroup, userId); + result = bundleActiveCore_->SetBundleGroup(bundleName, newGroup, userId, flushflag); } } return result; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 6cfa429..6799c2a 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -64,7 +64,7 @@ public: void OnBundleUninstalled(const int32_t userId, const std::string bundleName); void OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp); int32_t SetBundleGroup(const std::string& bundleName, const int32_t userId, int32_t newGroup, uint32_t reason, - const int64_t bootBasedTimeStamp); + const int64_t bootBasedTimeStamp, const bool flushflag); void RestoreToDatabase(const int32_t userId); void RestoreDurationToDatabase(); bool IsBundleInstalled(const std::string& bundleName, const int32_t userId); diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index b661701..882694a 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -52,7 +52,7 @@ public: const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, const int64_t timeUntilNextCheck, const int32_t userId); int32_t SetBundleGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, - int32_t newGroup, uint32_t groupReason); + int32_t newGroup, uint32_t groupReason, const bool flushflag); int32_t GetLevelIndex(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const std::vector screenTimeLeve, const std::vector bootFromTimeLevel); void WriteDeviceDuration(); diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 94f2272..d524bd4 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -310,12 +310,12 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN } if (oldGroup < newGroup || notTimeout) { BUNDLE_ACTIVE_LOGI("CheckAndUpdateGroup called SetBundleGroup"); - bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, groupReason); + bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, groupReason, false); } } int32_t BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, const int32_t userId, - int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp) + int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool flushflag) { std::lock_guard lock(mutex_); if (!IsBundleInstalled(bundleName, userId)) { @@ -325,7 +325,7 @@ int32_t BundleActiveGroupController::SetBundleGroup(const std::string& bundleNam if (!oneBundleHistory) { return -1; } - return bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason); + return bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason, flushflag); } int32_t BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, const int32_t userId) diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index bf6bb17..c690e0d 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -207,7 +207,7 @@ void BundleActiveUserHistory::ReportUsage(shared_ptr } int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int32_t userId, - const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason) + const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool flushflag) { std::lock_guard lock(setGroupMutex_); BUNDLE_ACTIVE_LOGI("set %{public}s to group %{public}d, reason is %{public}d, userId is %{public}d", @@ -230,6 +230,11 @@ int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const oneBundleHistory->reasonInGroup_ = groupReason; oneBundleHistory->isChanged_ = true; BUNDLE_ACTIVE_LOGI("SetBundleGroup set success"); + if (flushflag) { + BUNDLE_ACTIVE_LOGD("SetBundleGroup will RestoreToDatabase"); + WriteBundleUsage(userId); + } + bool isGroupChanged = (oldGroup == newGroup) ? true : false; if (!isGroupChanged) { BundleActiveGroupCallbackInfo callbackInfo( -- Gitee From ad1b36fdd073bb8b6c9740cf868a5197d31111b9 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 9 Aug 2022 09:26:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=BF=9B=E7=A8=8BsetBund?= =?UTF-8?q?leGroup=E7=AB=8B=E9=A9=AC=E8=90=BD=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/include/bundle_active_core.h | 4 ++-- services/common/src/bundle_active_core.cpp | 4 ++-- services/common/src/bundle_active_service.cpp | 6 +++--- .../packagegroup/include/bundle_active_group_controller.h | 2 +- services/packagegroup/include/bundle_active_user_history.h | 2 +- .../packagegroup/src/bundle_active_group_controller.cpp | 4 ++-- services/packagegroup/src/bundle_active_user_history.cpp | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 5d14d6a..11061e3 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -166,11 +166,11 @@ public: void OnUserSwitched(const int32_t userId); /* * function: SetBundleGroup, change bundleGroup to the newGroup. - * parameters: bundleName, newGroup, userId, flushflag, + * parameters: bundleName, newGroup, userId, isFlush, * return: errorcode. */ int32_t SetBundleGroup( - const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool flushflag); + const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool isFlush); // get all user in device. void GetAllActiveUser(std::vector& activatedOsAccountIds); // when service stop, call it to unregister commen event and shutdown call back. diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index ae4b838..e97e0db 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -646,13 +646,13 @@ int32_t BundleActiveCore::QueryAppNotificationNumber(int64_t beginTime, int64_t } int32_t BundleActiveCore::SetBundleGroup( - const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool flushflag) + const std::string& bundleName, const int32_t newGroup, const int32_t userId, const bool isFlush) { int32_t newReason = GROUP_CONTROL_REASON_FORCED; sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); return bundleGroupController_->SetBundleGroup( - bundleName, userId, newGroup, newReason, bootBasedTimeStamp, flushflag); + bundleName, userId, newGroup, newReason, bootBasedTimeStamp, isFlush); } int32_t BundleActiveCore::QueryPackageGroup(const std::string bundleName, const int32_t userId) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index dac35e3..c5ee773 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -373,21 +373,21 @@ int32_t BundleActiveService::SetBundleGroup(const std::string& bundleName, int32 return result; } AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); - bool flushflag = false; + bool isFlush = false; if (userId == -1) { OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); if (ret != ERR_OK) { errCode = -1; return result; } - flushflag = true; + isFlush = true; } if (userId != -1) { BUNDLE_ACTIVE_LOGI("SetBundleGroup userid is %{public}d", userId); auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode) || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { - result = bundleActiveCore_->SetBundleGroup(bundleName, newGroup, userId, flushflag); + result = bundleActiveCore_->SetBundleGroup(bundleName, newGroup, userId, isFlush); } } return result; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 6799c2a..65d0c77 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -64,7 +64,7 @@ public: void OnBundleUninstalled(const int32_t userId, const std::string bundleName); void OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp); int32_t SetBundleGroup(const std::string& bundleName, const int32_t userId, int32_t newGroup, uint32_t reason, - const int64_t bootBasedTimeStamp, const bool flushflag); + const int64_t bootBasedTimeStamp, const bool isFlush); void RestoreToDatabase(const int32_t userId); void RestoreDurationToDatabase(); bool IsBundleInstalled(const std::string& bundleName, const int32_t userId); diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index 882694a..3fe62a5 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -52,7 +52,7 @@ public: const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, const int64_t timeUntilNextCheck, const int32_t userId); int32_t SetBundleGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, - int32_t newGroup, uint32_t groupReason, const bool flushflag); + int32_t newGroup, uint32_t groupReason, const bool isFlush); int32_t GetLevelIndex(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const std::vector screenTimeLeve, const std::vector bootFromTimeLevel); void WriteDeviceDuration(); diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index d524bd4..d835842 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -315,7 +315,7 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN } int32_t BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, const int32_t userId, - int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool flushflag) + int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool isFlush) { std::lock_guard lock(mutex_); if (!IsBundleInstalled(bundleName, userId)) { @@ -325,7 +325,7 @@ int32_t BundleActiveGroupController::SetBundleGroup(const std::string& bundleNam if (!oneBundleHistory) { return -1; } - return bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason, flushflag); + return bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason, isFlush); } int32_t BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, const int32_t userId) diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index c690e0d..af54ad4 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -207,7 +207,7 @@ void BundleActiveUserHistory::ReportUsage(shared_ptr } int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int32_t userId, - const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool flushflag) + const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool isFlush) { std::lock_guard lock(setGroupMutex_); BUNDLE_ACTIVE_LOGI("set %{public}s to group %{public}d, reason is %{public}d, userId is %{public}d", @@ -230,7 +230,7 @@ int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const oneBundleHistory->reasonInGroup_ = groupReason; oneBundleHistory->isChanged_ = true; BUNDLE_ACTIVE_LOGI("SetBundleGroup set success"); - if (flushflag) { + if (isFlush) { BUNDLE_ACTIVE_LOGD("SetBundleGroup will RestoreToDatabase"); WriteBundleUsage(userId); } -- Gitee From a1bd9972b9c81b5bf293211ae91722b6296fad37 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 9 Aug 2022 14:12:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BA=94=E7=94=A8=E8=BF=9B=E7=A8=8BsetBund?= =?UTF-8?q?leGroup=E7=AB=8B=E9=A9=AC=E8=90=BD=E7=9B=98?= 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 | 1 - 1 file changed, 1 deletion(-) diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index af54ad4..22fe0e1 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -231,7 +231,6 @@ int32_t BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const oneBundleHistory->isChanged_ = true; BUNDLE_ACTIVE_LOGI("SetBundleGroup set success"); if (isFlush) { - BUNDLE_ACTIVE_LOGD("SetBundleGroup will RestoreToDatabase"); WriteBundleUsage(userId); } -- Gitee