From 2c17fa1a07b1154d827566657628fd760b11dccf Mon Sep 17 00:00:00 2001 From: houdisheng Date: Fri, 11 Mar 2022 19:16:16 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=8A=A0=E5=9B=BA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=97=B6=E5=BA=94=E7=94=A8=E5=88=86=E7=BB=84?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=80=BB=E8=BE=91=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=9C=A8=E6=96=B0=E4=B8=80=E5=A4=A9=E5=BC=80=E5=A7=8B=E7=AD=89?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=AD=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../src/bundle_active_group_controller.cpp | 3 +++ .../src/bundle_active_group_handler.cpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 97b3297..e2d9ada 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -53,8 +53,11 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) void BundleActiveGroupController::OnUserSwitched(const int userId) { std::lock_guard lock(mutex_); + CheckEachBundleState(userId); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); + activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_ONE_TIME_CHECK_BUNDLE_STATE); + activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE); } PeriodCheckBundleState(userId); } diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index ff45231..2b44748 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -54,19 +54,18 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe break; } case MSG_ONE_TIME_CHECK_BUNDLE_STATE: { - std::vector osAccountInfos; - OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(osAccountInfos); - if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGI("BundleActiveCore::GetAllActiveUser failed"); + std::vector activatedOsAccountIds; + if (AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds) != ERR_OK) { + BUNDLE_ACTIVE_LOGI("query activated account failed"); return; } - if (osAccountInfos.size() == 0) { - BUNDLE_ACTIVE_LOGI("BundleActiveCore::GetAllActiveUser size is 0"); + if (activatedOsAccountIds.size() == 0) { + BUNDLE_ACTIVE_LOGI("GetAllActiveUser size is 0"); return; } - for (uint32_t i = 0; i < osAccountInfos.size(); i++) { - bundleActiveGroupController_->CheckEachBundleState(osAccountInfos[i].GetLocalId()); - bundleActiveGroupController_->RestoreToDatabase(osAccountInfos[i].GetLocalId()); + for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { + bundleActiveGroupController_->CheckEachBundleState(activatedOsAccountIds[i]); + bundleActiveGroupController_->RestoreToDatabase(activatedOsAccountIds[i]); } RemoveEvent(MSG_ONE_TIME_CHECK_BUNDLE_STATE); break; -- Gitee From c033acce821de4d19dea9dc6ca25fb28a8ee0114 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 09:52:20 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 2 +- .../packagegroup/include/bundle_active_group_controller.h | 2 +- .../packagegroup/src/bundle_active_group_controller.cpp | 7 +++---- services/packagegroup/src/bundle_active_user_history.cpp | 4 ++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 1d431ec..bc4f3ce 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -397,7 +397,7 @@ void BundleActiveCore::OnUserSwitched(const int userId) } for (uint32_t i = 0; i < activatedOsAccountIds.size(); i++) { BUNDLE_ACTIVE_LOGI("start to period check for userId %{public}d", activatedOsAccountIds[i]); - bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i]); + bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], lastUsedUser_); } lastUsedUser_ = userId; OnStatsChanged(userId); diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 90c03cb..ee2f45c 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -84,7 +84,7 @@ public: int IsBundleIdle(const std::string& bundleName, const int userId); int QueryPackageGroup(const int userId, const std::string& bundleName); void ShutDown(const int64_t bootBasedTimeStamp, const int userId); - void OnUserSwitched(const int userId); + void OnUserSwitched(const int userId, const int lastUsedUser); private: std::mutex mutex_; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index e2d9ada..55eb291 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -50,14 +50,13 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) } } -void BundleActiveGroupController::OnUserSwitched(const int userId) +void BundleActiveGroupController::OnUserSwitched(const int userId, const int lastUsedUser) { + BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); + CheckEachBundleState(lastUsedUser); std::lock_guard lock(mutex_); - CheckEachBundleState(userId); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); - activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_ONE_TIME_CHECK_BUNDLE_STATE); - activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE); } PeriodCheckBundleState(userId); } diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index e1d59b5..3d0f0f9 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -197,6 +197,10 @@ void BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int if (oneBundleHistory == nullptr) { return; } + if (oneBundleHistory->currentGroup_ == newGroup || oneBundleHistory->reasonInGroup_ == groupReason) { + BUNDLE_ACTIVE_LOGI("%{public}s group and reason is same as before, not update", bundleName.c_str()); + return; + } oneBundleHistory->currentGroup_ = newGroup; oneBundleHistory->reasonInGroup_ = groupReason; int64_t setTimeStamp = GetBootBasedTimeStamp(bootBasedTimeStamp); -- Gitee From 088f6be6cede314524c70338dce6fd83db56f293 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 09:54:29 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/src/bundle_active_group_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 55eb291..3665aba 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -53,8 +53,8 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) void BundleActiveGroupController::OnUserSwitched(const int userId, const int lastUsedUser) { BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); - CheckEachBundleState(lastUsedUser); std::lock_guard lock(mutex_); + CheckEachBundleState(lastUsedUser); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); } -- Gitee From 60082aa3f65ebc6ce1d73388d8880c950a85b5d9 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 09:58:29 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/src/bundle_active_group_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 3665aba..545ee45 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -52,8 +52,8 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) void BundleActiveGroupController::OnUserSwitched(const int userId, const int lastUsedUser) { - BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); std::lock_guard lock(mutex_); + BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); CheckEachBundleState(lastUsedUser); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); -- Gitee From 39914661b085b56f881f08261a0ff498b61e152d Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 10:15:59 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/src/bundle_active_group_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 545ee45..55eb291 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -52,9 +52,9 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) void BundleActiveGroupController::OnUserSwitched(const int userId, const int lastUsedUser) { - std::lock_guard lock(mutex_); BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); CheckEachBundleState(lastUsedUser); + std::lock_guard lock(mutex_); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); } -- Gitee From ea73efb9fd81ec0f7d9502d5a40ff6973530fa5e Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 10:17:44 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/src/bundle_active_group_controller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 55eb291..c08a36f 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -54,6 +54,7 @@ void BundleActiveGroupController::OnUserSwitched(const int userId, const int las { BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", lastUsedUser); CheckEachBundleState(lastUsedUser); + bundleUserHistory_->WriteBundleUsage(lastUsedUser); std::lock_guard lock(mutex_); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); -- Gitee From 14c3e48a30a19847c2e295b3d74d58d66c4b55c7 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 11:00:39 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=88=B7=E7=9B=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_core.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index bc4f3ce..9d61cde 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -225,7 +225,7 @@ void BundleActiveCore::OnStatsChanged(const int userId) auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); if (handler_.lock()->HasInnerEvent(static_cast(BundleActiveReportHandler::MSG_FLUSH_TO_DISK)) == false) { - BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event"); + BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event for user %{public}d", userId); handler_.lock()->SendEvent(event, FLUSH_INTERVAL); } } @@ -389,6 +389,10 @@ void BundleActiveCore::OnUserSwitched(const int userId) it->second->RestoreStats(true); } } + if (!handler_.expired()) { + BUNDLE_ACTIVE_LOGI("OnUserSwitched remove flush to disk event"); + handler_.lock()->RemoveEvent(BundleActiveReportHandler::MSG_FLUSH_TO_DISK); + } std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); if (activatedOsAccountIds.size() == 0) { @@ -400,7 +404,6 @@ void BundleActiveCore::OnUserSwitched(const int userId) bundleGroupController_->OnUserSwitched(activatedOsAccountIds[i], lastUsedUser_); } lastUsedUser_ = userId; - OnStatsChanged(userId); } int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) -- Gitee From 1af208a7e39dc447c4e54edecf95e3b9c2167021 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 12:22:05 +0800 Subject: [PATCH 8/9] add log print Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 9682bbc..f85072c 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -170,6 +170,7 @@ void BundleActiveUserService::RestoreStats(bool forced) } currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; + BUNDLE_ACTIVE_LOGI("RestoreStats change to %{public}d user is is %{public}d", statsChanged_, userId_); } } -- Gitee From bfb180433cf4a0eb6f5dbfcd4a28d59347eca4ca Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 12 Mar 2022 12:26:17 +0800 Subject: [PATCH 9/9] add log print Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index f85072c..14e767b 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -170,7 +170,7 @@ void BundleActiveUserService::RestoreStats(bool forced) } currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; - BUNDLE_ACTIVE_LOGI("RestoreStats change to %{public}d user is is %{public}d", statsChanged_, userId_); + BUNDLE_ACTIVE_LOGI("change statsChanged_ to %{public}d user is %{public}d", statsChanged_, userId_); } } -- Gitee