diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index e9315f3772b57cb450b5d1c17250f532d7c31bba..7a57cf5907727e782f49243a7d7da5d57608dcdf 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 75b4e530f7720dd276c0f462236cda9dcd533140..ba688ada52911fac42bce82589e640db9bae64c7 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 9222f05561f5e53f290eac02946389f28bde25e0..f6104c86621ac7858f49e3b893e08965989d94f8 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 efffccb0e258ed9a7845cd957a04a70fd14473af..fc800e8910729534b5ed09b869ab2b7f5a495023 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 {