From fcc1eeb015d8e780add2aae1636a69f03374b0a7 Mon Sep 17 00:00:00 2001 From: wangyantian Date: Sat, 29 Jun 2024 16:12:28 +0800 Subject: [PATCH] fix: Check whether proximity is close when double-click Signed-off-by: wangyantian --- services/native/include/power_state_machine.h | 3 ++ services/native/src/power_state_machine.cpp | 35 +++++++++++++++++-- .../src/runninglock/running_lock_mgr.cpp | 15 +++++--- .../native/src/runninglock/running_lock_mgr.h | 10 +++--- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index a9a49443..fc9fc18e 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -283,6 +283,9 @@ private: std::shared_ptr GetStateController(PowerState state); void ResetScreenOffPreTimeForSwing(int64_t displayOffTime); void ShowCurrentScreenLocks(); +#ifdef HAS_SENSORS_SENSOR_PART + bool IsProximityClose(); +#endif const wptr pms_; PowerState currentState_; diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index 9ad3a4af..4f0320af 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -140,9 +140,21 @@ void PowerStateMachine::InitTransitMap() bool PowerStateMachine::CanTransitTo(PowerState to, StateChangeReason reason) { - return (!forbidMap_.count(currentState_) || !forbidMap_[currentState_].count(to)) && - (!allowMapByReason_.count(reason) || - (allowMapByReason_[reason].count(currentState_) && allowMapByReason_[reason][currentState_].count(to))); + bool isForbidden = forbidMap_.count(currentState_) && forbidMap_[currentState_].count(to); + if (isForbidden) { + return false; + } +#ifdef HAS_SENSORS_SENSOR_PART + // prevent the unexpected double click to light up the screen when calling + if (reason == StateChangeReason::STATE_CHANGE_REASON_DOUBLE_CLICK && IsProximityClose() && + to == PowerState::AWAKE) { + POWER_HILOGI(FEATURE_POWER_STATE, "Double-click isn't allowed to wakeup device when proximity is close."); + return false; + } +#endif + bool isAllowed = (!allowMapByReason_.count(reason) || + (allowMapByReason_[reason].count(currentState_) && allowMapByReason_[reason][currentState_].count(to))); + return isAllowed; } void PowerStateMachine::InitState() @@ -916,6 +928,23 @@ void PowerStateMachine::ShowCurrentScreenLocks() POWER_HILOGI(FEATURE_RUNNING_LOCK, "%{public}d screen on locks as follows: %{public}s", mapSize, message.c_str()); } +#ifdef HAS_SENSORS_SENSOR_PART +bool PowerStateMachine::IsProximityClose() +{ + auto pms = pms_.promote(); + if (pms == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "Pms is nullptr"); + return false; + } + auto runningLockMgr = pms->GetRunningLockMgr(); + if (runningLockMgr == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "RunningLockMgr is nullptr"); + return false; + } + return runningLockMgr->IsProximityClose(); +} +#endif + void PowerStateMachine::HandleActivityTimeout() { POWER_HILOGD(FEATURE_ACTIVITY, "Enter, displayState = %{public}d", stateAction_->GetDisplayState()); diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index caf546df..e928534d 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -862,8 +862,8 @@ void RunningLockMgr::ProximityController::Disable() bool RunningLockMgr::ProximityController::IsClose() { - POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY IsClose: %{public}d", isClose); - return isClose; + POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY IsClose: %{public}d", isClose_); + return isClose_; } void RunningLockMgr::ProximityController::OnClose() @@ -883,7 +883,7 @@ void RunningLockMgr::ProximityController::OnClose() POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr"); return; } - isClose = true; + isClose_ = true; POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is closed"); auto runningLock = pms->GetRunningLockMgr(); if (runningLock->GetValidRunningLockNum( @@ -913,7 +913,7 @@ void RunningLockMgr::ProximityController::OnAway() POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr"); return; } - isClose = false; + isClose_ = false; POWER_HILOGD(FEATURE_RUNNING_LOCK, "PROXIMITY is away"); auto runningLock = pms->GetRunningLockMgr(); if (runningLock->GetValidRunningLockNum( @@ -926,7 +926,7 @@ void RunningLockMgr::ProximityController::OnAway() void RunningLockMgr::ProximityController::Clear() { - isClose = false; + isClose_ = false; } void RunningLockMgr::SetProximity(uint32_t status) @@ -942,6 +942,11 @@ void RunningLockMgr::SetProximity(uint32_t status) break; } } + +bool RunningLockMgr::IsProximityClose() +{ + return proximityController_.IsClose(); +} #endif } // namespace PowerMgr diff --git a/services/native/src/runninglock/running_lock_mgr.h b/services/native/src/runninglock/running_lock_mgr.h index 2a692789..51105586 100644 --- a/services/native/src/runninglock/running_lock_mgr.h +++ b/services/native/src/runninglock/running_lock_mgr.h @@ -73,6 +73,7 @@ public: bool IsUsed(const sptr& remoteObj); static constexpr uint32_t CHECK_TIMEOUT_INTERVAL_MS = 60 * 1000; void SetProximity(uint32_t status); + bool IsProximityClose(); void DumpInfo(std::string& result); void EnableMock(IRunningLockAction* mockAction); private: @@ -135,7 +136,7 @@ private: static const uint32_t SAMPLING_RATE = 100000000; bool support_ {false}; bool enabled_ {false}; - bool isClose {false}; + bool isClose_ {false}; uint32_t status_ {0}; SensorUser user_; }; @@ -154,6 +155,10 @@ private: bool IsValidType(RunningLockType type); void PreprocessBeforeAwake(); void ProximityLockOn(); + static void NotifyRunningLockChanged(const RunningLockParam& lockInnerParam, const std::string &tag); + RunningLockInfo FillAppRunningLockInfo(const RunningLockParam& info); + void UpdateUnSceneLockLists(RunningLockParam& singleLockParam, bool fill); + const wptr pms_; std::mutex mutex_; std::mutex screenLockListsMutex_; @@ -162,9 +167,6 @@ private: std::shared_ptr runninglockProxy_; sptr runningLockDeathRecipient_; std::shared_ptr runningLockAction_; - static void NotifyRunningLockChanged(const RunningLockParam& lockInnerParam, const std::string &tag); - RunningLockInfo FillAppRunningLockInfo(const RunningLockParam& info); - void UpdateUnSceneLockLists(RunningLockParam& singleLockParam, bool fill); std::map unSceneLockLists_; }; } // namespace PowerMgr -- Gitee