From b1815aa5b8debee1041ef56d16299fc55248beaf Mon Sep 17 00:00:00 2001 From: wangyantian Date: Thu, 22 Aug 2024 16:59:51 +0800 Subject: [PATCH] fix: Close switch not send ENTER_FORCE_SLEEP event Signed-off-by: wangyantian --- services/native/include/power_state_machine.h | 3 --- services/native/src/power_state_machine.cpp | 11 +++++------ services/native/src/suspend/suspend_controller.cpp | 4 ++++ services/native/src/suspend/suspend_controller.h | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index e9315f37..7a57cf59 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -331,9 +331,6 @@ private: std::atomic switchOpen_ {true}; #ifdef POWER_MANAGER_POWER_ENABLE_S4 std::atomic hibernating_ {false}; -#endif -#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST - std::atomic forceSleeping_ {false}; #endif std::unordered_map>> allowMapByReason_; std::atomic forceTimingOut_ {false}; diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index 75b4e530..ba688ada 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -614,9 +614,6 @@ bool PowerStateMachine::ForceSuspendDeviceInner(pid_t pid, int64_t callTimeMs) auto suspendController = pms->GetSuspendController(); if (suspendController != nullptr) { POWER_HILOGI(FEATURE_SUSPEND, "ForceSuspendDeviceInner StartSleepTimer start."); -#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST - forceSleeping_.store(true, std::memory_order_relaxed); -#endif suspendController->StartSleepTimer( SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, static_cast(SuspendAction::ACTION_FORCE_SUSPEND), 0); @@ -857,9 +854,10 @@ void PowerStateMachine::SendEventToPowerMgrNotify(PowerState state, int64_t call case PowerState::AWAKE: { notify->PublishScreenOnEvents(callTime); #ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST - if (forceSleeping_.load()) { + auto suspendController = pms->GetSuspendController(); + if (suspendController != nullptr && suspendController->GetForceSleepingFlag()) { notify->PublishExitForceSleepEvents(callTime); - forceSleeping_.store(false, std::memory_order_relaxed); + suspendController->SetForceSleepingFlag(false); } #endif break; @@ -870,7 +868,8 @@ void PowerStateMachine::SendEventToPowerMgrNotify(PowerState state, int64_t call } case PowerState::SLEEP: { #ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST - if (forceSleeping_.load()) { + auto suspendController = pms->GetSuspendController(); + if (suspendController != nullptr && suspendController->GetForceSleepingFlag()) { notify->PublishEnterForceSleepEvents(callTime); } break; diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 9222f055..f6104c86 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -487,6 +487,10 @@ void SuspendController::HandleForceSleep(SuspendDeviceType reason) POWER_HILOGE(FEATURE_SUSPEND, "Can't get PowerStateMachine"); return; } + +#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST + SetForceSleepingFlag(true); +#endif bool ret = stateMachine_->SetState(PowerState::SLEEP, stateMachine_->GetReasionBySuspendType(reason), true); if (ret) { diff --git a/services/native/src/suspend/suspend_controller.h b/services/native/src/suspend/suspend_controller.h index efffccb0..fc800e89 100644 --- a/services/native/src/suspend/suspend_controller.h +++ b/services/native/src/suspend/suspend_controller.h @@ -74,6 +74,17 @@ public: void StartSleepTimer(SuspendDeviceType reason, uint32_t action, uint32_t delay); void Reset(); +#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST + void SetForceSleepingFlag(bool isForceSleeping) + { + forceSleeping_.store(isForceSleeping, std::memory_order_relaxed); + } + bool GetForceSleepingFlag() + { + return forceSleeping_.load(); + } +#endif + private: void ControlListener(SuspendDeviceType reason, uint32_t action, uint32_t delay); void HandleAutoSleep(SuspendDeviceType reason); @@ -98,6 +109,9 @@ private: std::mutex mutex_; std::shared_ptr ffrtTimer_; FFRTMutexMap ffrtMutexMap_; +#ifdef POWER_MANAGER_ENABLE_FORCE_SLEEP_BROADCAST + std::atomic forceSleeping_ {false}; +#endif }; class SuspendMonitor { -- Gitee