From 6a562d5220b0a3054808fb3d8995a89a9e9fdae0 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 5 Dec 2023 06:45:01 +0000 Subject: [PATCH] =?UTF-8?q?BundleActiveGroupController=E5=9C=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8activeGroupHandler=5F=E5=89=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E5=88=B0shared=5Fptr=E5=90=8E=E5=88=A4?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas --- .../src/bundle_active_group_controller.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 501d877..79ae1dd 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -64,8 +64,9 @@ void BundleActiveGroupController::OnUserRemoved(const int32_t userId) { std::lock_guard lock(mutex_); bundleUserHistory_->userHistory_.erase(userId); - if (!activeGroupHandler_.expired()) { - activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); + auto activeGroupHandler = activeGroupHandler_.lock(); + if (activeGroupHandler) { + activeGroupHandler->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); } } @@ -75,9 +76,10 @@ void BundleActiveGroupController::OnUserSwitched(const int32_t userId, const int CheckEachBundleState(currentUsedUser); bundleUserHistory_->WriteBundleUsage(currentUsedUser); std::lock_guard lock(mutex_); - if (!activeGroupHandler_.expired()) { - activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); - activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE); + auto activeGroupHandler = activeGroupHandler_.lock(); + if (activeGroupHandler) { + activeGroupHandler->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); + activeGroupHandler->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE); } PeriodCheckBundleState(userId); } @@ -145,14 +147,15 @@ bool BundleActiveGroupController::GetBundleMgrProxy() void BundleActiveGroupController::PeriodCheckBundleState(const int32_t userId) { BUNDLE_ACTIVE_LOGI("PeriodCheckBundleState called"); - if (!activeGroupHandler_.expired()) { + auto activeGroupHandler = activeGroupHandler_.lock(); + if (activeGroupHandler) { BundleActiveGroupHandlerObject tmpGroupHandlerObj; tmpGroupHandlerObj.userId_ = userId; std::shared_ptr handlerobjToPtr = std::make_shared(tmpGroupHandlerObj); auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE, handlerobjToPtr); - activeGroupHandler_.lock()->SendEvent(handlerEvent, FIVE_SECOND); + activeGroupHandler->SendEvent(handlerEvent, FIVE_SECOND); } } @@ -181,8 +184,9 @@ void BundleActiveGroupController::CheckIdleStatsOneTime() { auto handlerEvent = AppExecFwk::InnerEvent::Get( BundleActiveGroupHandler::MSG_ONE_TIME_CHECK_BUNDLE_STATE); - if (!activeGroupHandler_.expired()) { - activeGroupHandler_.lock()->SendEvent(handlerEvent); + auto activeGroupHandler = activeGroupHandler_.lock(); + if (activeGroupHandler) { + activeGroupHandler->SendEvent(handlerEvent); } } @@ -253,8 +257,9 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co std::make_shared(tmpGroupHandlerObj); auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE, handlerobjToPtr); - if (!activeGroupHandler_.expired()) { - activeGroupHandler_.lock()->SendEvent(handlerEvent, timeUntilNextCheck); + auto activeGroupHandler = activeGroupHandler_.lock(); + if (activeGroupHandler) { + activeGroupHandler->SendEvent(handlerEvent, timeUntilNextCheck); } } } -- Gitee