diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 501d877dafe8675315d5a6b903d2656d692d91a3..79ae1dd2cc13cd2c0034829bce16799f38935827 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); } } }