From 076bf903fae77bb36da36c9f76987996f7be13c4 Mon Sep 17 00:00:00 2001 From: chenjunwu Date: Wed, 21 May 2025 19:39:30 +0800 Subject: [PATCH 1/3] fix: add during call feature Signed-off-by: chenjunwu --- services/native/include/power_mgr_service.h | 2 + services/native/include/power_state_machine.h | 6 ++ services/native/src/power_mgr_service.cpp | 15 +++++ services/native/src/power_state_machine.cpp | 34 +++++++++++ .../src/runninglock/running_lock_mgr.cpp | 9 +++ .../native/src/runninglock/running_lock_mgr.h | 5 ++ .../native/src/setting/setting_helper.cpp | 34 +++++++++++ services/native/src/setting/setting_helper.h | 5 ++ .../include/native_power_state_machine_test.h | 1 + .../src/native_power_state_machine_test.cpp | 57 +++++++++++++++++++ .../src/power_mgr_service_native_test.cpp | 23 ++++++++ .../unittest/src/running_lock_native_test.cpp | 36 ++++++++++++ utils/setting/include/setting_provider.h | 1 + utils/setting/src/setting_provider.cpp | 1 + 14 files changed, 229 insertions(+) diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 42931ee9..ea6bc23a 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -68,6 +68,8 @@ public: static void PowerModeSettingUpdateFunc(const std::string& key); static void RegisterSettingWakeUpLidObserver(); static void WakeupLidSettingUpdateFunc(const std::string& key); + static void RegisterSettingDuringCallObservers(); + static void DuringCallSettingUpdateFunc(const std::string& key); virtual void OnStart() override; virtual void OnStop() override; diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index 67c75406..de538fe9 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -216,6 +216,10 @@ public: { return mDeviceState_.screenState.lastOnTime; } + void SetDuringCallState(bool state) + { + isDuringCallState_ = state; + } void DumpInfo(std::string& result); void EnableMock(IDeviceStateAction* mockAction); @@ -356,6 +360,7 @@ private: void ShowCurrentScreenLocks(); void HandleProximityScreenOffTimer(PowerState state, StateChangeReason reason); bool HandlePreBrightState(PowerState targetState, StateChangeReason reason); + bool HandleDuringCallState(PowerState state, StateChangeReason reason); bool IsPreBrightAuthReason(StateChangeReason reason); bool IsPreBrightWakeUp(WakeupDeviceType type); bool NeedShowScreenLocks(PowerState state); @@ -417,6 +422,7 @@ private: std::atomic externalScreenNumber_ {0}; std::mutex internalScreenStateMutex_; #endif + bool isDuringCallState_ {false}; bool SetDreamingState(StateChangeReason reason); }; } // namespace PowerMgr diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 67360457..177f0e02 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -244,6 +244,7 @@ void PowerMgrService::PowerExternalAbilityInit() POWER_HILOGI(COMP_SVC, "Not allow subscribe Hall sensor"); #endif power->RegisterSettingPowerModeObservers(); + power->RegisterSettingDuringCallObservers(); power->RegisterExternalCallback(); } @@ -265,6 +266,20 @@ void PowerMgrService::PowerModeSettingUpdateFunc(const std::string &key) power->SetDeviceMode(static_cast(saveMode)); } +void PowerMgrService::RegisterSettingDuringCallObservers() +{ + SettingObserver::UpdateFunc updateFunc = [&](const std::string &key) { DuringCallSettingUpdateFunc(key); }; + SettingHelper::RegisterSettingDuringCallObserver(updateFunc); +} + +void PowerMgrService::DuringCallSettingUpdateFunc(const std::string &key) +{ + auto power = DelayedSpSingleton::GetInstance(); + bool duringCallState = SettingHelper::GetDuringCallState(key); + POWER_HILOGI(COMP_SVC, "DuringCallState is %{public}d", duringCallState); + power->runningLockMgr_->SetDuringCallState(duringCallState); +} + bool PowerMgrService::IsDeveloperMode() { return OHOS::system::GetBoolParameter("const.security.developermode.state", true); diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index fa655a54..bc8c4c8a 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -1986,6 +1986,11 @@ bool PowerStateMachine::SetState(PowerState state, StateChangeReason reason, boo POWER_HILOGD(FEATURE_POWER_STATE, "state=%{public}s, reason=%{public}s, force=%{public}d", PowerUtils::GetPowerStateString(state).c_str(), PowerUtils::GetReasonTypeString(reason).c_str(), force); std::lock_guard lock(stateMutex_); + if (HandleDuringCallState(state, reason)) { + POWER_HILOGI(FEATURE_POWER_STATE, "Duringcall action trigger, state=%{public}s, reason=%{public}s", + PowerUtils::GetPowerStateString(state).c_str(), PowerUtils::GetReasonTypeString(reason).c_str()); + return true; + } if (!CheckFFRTTaskAvailability(state, reason)) { POWER_HILOGI(FEATURE_POWER_STATE, "this timeout task is invalidated, directly return"); return false; @@ -2537,6 +2542,35 @@ bool PowerStateMachine::StateController::IsReallyFailed(StateChangeReason reason return true; } +bool PowerStateMachine::HandleDuringCallState(PowerState state, StateChangeReason reason) +{ + if (isDuringCallState_) { + POWER_HILOGI(FEATURE_POWER_STATE, "enter HandleDuringCallState, state=%{public}s, resaon=%{public}s" + " isDuringCallState_=%{public}d", PowerUtils::GetPowerStateString(state).c_str(), + PowerUtils::GetReasonTypeString(reason).c_str(), isDuringCallState_); + // PROXIMITY away or PROXIMITY lock release and fold display mode is sub + if (state == PowerState::AWAKE && + (reason == StateChangeReason::STATE_CHANGE_REASON_PROXIMITY || + reason == StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK) && + Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB) { + Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::MAIN); + return true; + // power_key down for wakeup main and fold display mode is sub + } else if (state == PowerState::INACTIVE && reason == StateChangeReason::STATE_CHANGE_REASON_HARD_KEY && + Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB) { + Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::MAIN); + return true; + // PROXIMITY close and fold display mode is main + } else if (state == PowerState::INACTIVE && reason == StateChangeReason::STATE_CHANGE_REASON_PROXIMITY && + Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::MAIN) { + Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::SUB); + return true; + } + return false; + } + return false; +} + bool PowerStateMachine::IsSwitchOpenByPath() { std::string value = ""; diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 504c05a2..9b0b0d5a 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -47,6 +47,7 @@ constexpr uint32_t FOREGROUND_INCALL_DELAY_TIME_MS = 300; constexpr uint32_t BACKGROUND_INCALL_DELAY_TIME_MS = 800; #endif } +bool RunningLockMgr::isDuringCallState_ = false; RunningLockMgr::~RunningLockMgr() {} @@ -199,6 +200,7 @@ void RunningLockMgr::InitLocksTypeProximity() } PreprocessBeforeAwake(); stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK); + stateMachine->SetDuringCallState(false); }; if (active) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "[UL_POWER] RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL active"); @@ -947,6 +949,9 @@ void RunningLockMgr::HandleProximityCloseEvent() POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr"); return; } + if (isDuringCallState_) { + stateMachine->SetDuringCallState(true); + } if (GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK"); uint32_t delayTime = FOREGROUND_INCALL_DELAY_TIME_MS; @@ -977,6 +982,10 @@ void RunningLockMgr::HandleProximityAwayEvent() POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to AWAKE when holding PROXIMITY LOCK"); runningLock->PreprocessBeforeAwake(); stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY, true); + if (isDuringCallState_) { + // Proximity away need keep origin action after first away + stateMachine->SetDuringCallState(false); + } } else { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Unholding PROXIMITY LOCK"); } diff --git a/services/native/src/runninglock/running_lock_mgr.h b/services/native/src/runninglock/running_lock_mgr.h index ef94ff26..38394557 100644 --- a/services/native/src/runninglock/running_lock_mgr.h +++ b/services/native/src/runninglock/running_lock_mgr.h @@ -79,6 +79,10 @@ public: void DumpInfo(std::string& result); void EnableMock(IRunningLockAction* mockAction); bool IsExistAudioStream(pid_t uid); + void SetDuringCallState(bool state) + { + isDuringCallState_ = state; + } private: void AsyncWakeup(); @@ -142,6 +146,7 @@ private: RunningLockInfo FillAppRunningLockInfo(const RunningLockParam& info); void UpdateUnSceneLockLists(RunningLockParam& singleLockParam, bool fill); + static bool isDuringCallState_; const wptr pms_; std::mutex mutex_; std::mutex screenLockListsMutex_; diff --git a/services/native/src/setting/setting_helper.cpp b/services/native/src/setting/setting_helper.cpp index 91cf0588..d26db7a1 100644 --- a/services/native/src/setting/setting_helper.cpp +++ b/services/native/src/setting/setting_helper.cpp @@ -32,6 +32,7 @@ sptr SettingHelper::doubleClickObserver_ = nullptr; sptr SettingHelper::pickUpObserver_ = nullptr; sptr SettingHelper::powerModeObserver_ = nullptr; sptr SettingHelper::lidObserver_ = nullptr; +sptr SettingHelper::duringCallObserver_ = nullptr; void SettingHelper::RegisterAodSwitchObserver() { @@ -542,6 +543,39 @@ void SettingHelper::UnRegisterSettingPowerModeObserver() powerModeObserver_ = nullptr; } +void SettingHelper::RegisterSettingDuringCallObserver(SettingObserver::UpdateFunc& func) +{ + if (duringCallObserver_) { + POWER_HILOGI(COMP_UTILS, "setting during call observer is already registered"); + return; + } + duringCallObserver_ = RegisterSettingKeyObserver(SETTING_DURING_CALL_STATE_KEY, func); +} + +void SettingHelper::UnRegisterSettingDuringCallObserver() +{ + if (!duringCallObserver_) { + POWER_HILOGI(COMP_UTILS, "duringCallObserver_ is nullptr, no need to unregister"); + return; + } + auto ret = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID).UnregisterObserver(duringCallObserver_); + if (ret != ERR_OK) { + POWER_HILOGE(COMP_UTILS, "unregister setting during call observer failed, ret=%{public}d", ret); + } + duringCallObserver_ = nullptr; +} + +bool SettingHelper::GetDuringCallState(const std::string& key) +{ + SettingProvider& settingProvider = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID); + bool value = false; + ErrCode ret = settingProvider.GetBoolValue(key, value); + if (ret != ERR_OK) { + POWER_HILOGE(COMP_UTILS, "get setting during call state key failed, ret=%{public}d", ret); + } + return value; +} + const std::string SettingHelper::ReadPowerModeRecoverMap() { return GetSettingStringValue(SETTING_POWER_MODE_BACKUP_KEY); diff --git a/services/native/src/setting/setting_helper.h b/services/native/src/setting/setting_helper.h index 8673df65..c5a01660 100644 --- a/services/native/src/setting/setting_helper.h +++ b/services/native/src/setting/setting_helper.h @@ -107,6 +107,9 @@ public: static bool GetSettingWakeupLid(const std::string& key = SETTING_POWER_WAKEUP_LID_KEY); static void SetSettingWakeupLid(bool enable); static bool IsWakeupLidSettingValid(); + static void RegisterSettingDuringCallObserver(SettingObserver::UpdateFunc& func); + static void UnRegisterSettingDuringCallObserver(); + static bool GetDuringCallState(const std::string& key = SETTING_DURING_CALL_STATE_KEY); #ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS static const std::string GetBlockLongPress(); #endif @@ -147,10 +150,12 @@ private: static constexpr const char* SETTING_POWER_MODE_KEY {"settings.power.smart_mode_status"}; static constexpr const char* SETTING_POWER_MODE_BACKUP_KEY {"settings.power.smart_mode_status.backup"}; static constexpr const char* SETTING_POWER_WAKEUP_LID_KEY {"settings.power.wakeup_lid"}; + static constexpr const char* SETTING_DURING_CALL_STATE_KEY {"during_call_state"}; static sptr doubleClickObserver_; static sptr pickUpObserver_; static sptr powerModeObserver_; static sptr lidObserver_; + static sptr duringCallObserver_; }; } // namespace PowerMgr } // namespace OHOS diff --git a/test/unittest/include/native_power_state_machine_test.h b/test/unittest/include/native_power_state_machine_test.h index 7c672deb..6b3c552c 100644 --- a/test/unittest/include/native_power_state_machine_test.h +++ b/test/unittest/include/native_power_state_machine_test.h @@ -26,6 +26,7 @@ #include #include +#include #include "power_mgr_client.h" #include "power_mgr_service.h" diff --git a/test/unittest/src/native_power_state_machine_test.cpp b/test/unittest/src/native_power_state_machine_test.cpp index 719eb014..062bf8d4 100644 --- a/test/unittest/src/native_power_state_machine_test.cpp +++ b/test/unittest/src/native_power_state_machine_test.cpp @@ -24,6 +24,21 @@ using namespace OHOS::PowerMgr; using namespace OHOS; using namespace std; +namespace { +OHOS::Rosen::FoldDisplayMode g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::MAIN; +} // namespace +namespace OHOS::Rosen { +FoldDisplayMode DisplayManagerLite::GetFoldDisplayMode() +{ + return g_foldDisplayMode; +} + +void DisplayManagerLite::SetFoldDisplayMode(FoldDisplayMode mode) +{ + g_foldDisplayMode = mode; +} +} // namespace OHOS::Rosen + void NativePowerStateMachineTest::SetUpTestCase() {} void PowerStateTest1Callback::OnPowerStateChanged(PowerState state) @@ -402,4 +417,46 @@ HWTEST_F(NativePowerStateMachineTest, NativePowerStateMachine009, TestSize.Level #endif POWER_HILOGI(LABEL_TEST, "NativePowerStateMachine009 function end!"); } + +/** + * @tc.name: NativePowerStateMachine010 + * @tc.desc: test HandleDuringCallState + * @tc.type: FUNC + */ +HWTEST_F(NativePowerStateMachineTest, NativePowerStateMachine010, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "NativePowerStateMachine010 function start!"); + auto pmsTest = DelayedSpSingleton::GetInstance(); + pmsTest->OnStart(); + auto stateMachine = std::make_shared(pmsTest); + EXPECT_TRUE(stateMachine->Init()); + + bool ret = stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_BATTERY, true); + EXPECT_TRUE(ret); + stateMachine->SetDuringCallState(true); + ret = stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_DOUBLE_CLICK, true); + EXPECT_TRUE(ret); + + ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PICKUP); + EXPECT_FALSE(ret); + g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::SUB; + ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); + EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN); + ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); + EXPECT_FALSE(ret); + ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK); + EXPECT_FALSE(ret); + ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_TIMEOUT); + EXPECT_FALSE(ret); + ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_HARD_KEY); + EXPECT_FALSE(ret); + g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::SUB; + ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_HARD_KEY); + EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN); + ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); + EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::SUB); + ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); + EXPECT_FALSE(ret); + POWER_HILOGI(LABEL_TEST, "NativePowerStateMachine010 function end!"); +} } // namespace diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index c6c6d331..4d559b5b 100644 --- a/test/unittest/src/power_mgr_service_native_test.cpp +++ b/test/unittest/src/power_mgr_service_native_test.cpp @@ -457,4 +457,27 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative015, TestSize.Level1) GTEST_LOG_(INFO) << "PowerMgrServiceNative015 end."; } +/** + * @tc.name: PowerMgrServiceNative016 + * @tc.desc: test RegisterSettingDuringCallObservers + * @tc.type: FUNC + */ +HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative016, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PowerMgrServiceNative016 start."; + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative016 function start!"); + g_pmsTest->RegisterSettingDuringCallObservers(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); + g_pmsTest->RegisterSettingDuringCallObservers(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); + SettingHelper::UnRegisterSettingDuringCallObserver(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); + SettingHelper::UnRegisterSettingDuringCallObserver(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); + g_pmsTest->DuringCallSettingUpdateFunc(SettingHelper::SETTING_DURING_CALL_STATE_KEY); + auto runningLockMgr = g_pmsTest->GetRunningLockMgr(); + EXPECT_FALSE(runningLockMgr->isDuringCallState_); + POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative016 function end!"); + GTEST_LOG_(INFO) << "PowerMgrServiceNative016 end."; +} } // namespace diff --git a/test/unittest/src/running_lock_native_test.cpp b/test/unittest/src/running_lock_native_test.cpp index a2699c39..d05ad954 100644 --- a/test/unittest/src/running_lock_native_test.cpp +++ b/test/unittest/src/running_lock_native_test.cpp @@ -732,4 +732,40 @@ HWTEST_F (RunningLockNativeTest, RunningLockNative023, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "RunningLockNative023 function end!"); } + +/** + * @tc.name: RunningLockNative024 + * @tc.desc: test SetDuringCallState + * @tc.type: FUNC + */ +HWTEST_F(RunningLockNativeTest, RunningLockNative024, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "RunningLockNative024 function start!"); + auto pmsTest = DelayedSpSingleton::GetInstance(); + pmsTest->OnStart(); + auto runningLockMgr = std::make_shared(pmsTest); + EXPECT_TRUE(runningLockMgr->Init()); + EXPECT_FALSE(runningLockMgr->isDuringCallState_); +#ifdef HAS_SENSORS_SENSOR_PART + RunningLockParam runningLockParam {0, + "RunningLockNative024", "", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, TIMEOUTMS, PID, UID}; + sptr token = new RunningLockTokenStub(); + EXPECT_TRUE(runningLockMgr->CreateRunningLock(token, runningLockParam) != nullptr); + runningLockMgr->Lock(token); + auto stateMachine = pmsTest->GetPowerStateMachine(); + runningLockMgr->HandleProximityCloseEvent(); + EXPECT_FALSE(stateMachine->isDuringCallState_); + runningLockMgr->HandleProximityAwayEvent(); + EXPECT_FALSE(stateMachine->isDuringCallState_); + + runningLockMgr->SetDuringCallState(true); + EXPECT_TRUE(runningLockMgr->isDuringCallState_); + runningLockMgr->HandleProximityCloseEvent(); + EXPECT_TRUE(stateMachine->isDuringCallState_); + runningLockMgr->HandleProximityAwayEvent(); + EXPECT_FALSE(stateMachine->isDuringCallState_); + runningLockMgr->UnLock(token); +#endif + POWER_HILOGI(LABEL_TEST, "RunningLockNative024 function end!"); +} } // namespace diff --git a/utils/setting/include/setting_provider.h b/utils/setting/include/setting_provider.h index a938ff82..52390595 100644 --- a/utils/setting/include/setting_provider.h +++ b/utils/setting/include/setting_provider.h @@ -68,6 +68,7 @@ private: static constexpr const char* SETTING_POWER_MODE_KEY {"settings.power.smart_mode_status"}; static constexpr const char* SETTING_POWER_MODE_BACKUP_KEY {"settings.power.smart_mode_status.backup"}; static constexpr const char* SETTING_POWER_WAKEUP_LID_KEY {"settings.power.wakeup_lid"}; + static constexpr const char* SETTING_DURING_CALL_STATE_KEY {"during_call_state"}; static std::atomic instance_; static std::mutex settingMutex_; static sptr remoteObj_; diff --git a/utils/setting/src/setting_provider.cpp b/utils/setting/src/setting_provider.cpp index d74ae9ce..e30aee4e 100644 --- a/utils/setting/src/setting_provider.cpp +++ b/utils/setting/src/setting_provider.cpp @@ -408,6 +408,7 @@ bool SettingProvider::IsNeedMultiUser(const std::string& key) SETTING_POWER_WAKEUP_DOUBLE_KEY, SETTING_POWER_WAKEUP_PICKUP_KEY, SETTING_POWER_WAKEUP_SOURCES_KEY, + SETTING_DURING_CALL_STATE_KEY, #ifdef POWER_MANAGER_ENABLE_CHARGING_TYPE_SETTING SETTING_DISPLAY_AC_OFF_TIME_KEY, SETTING_DISPLAY_DC_OFF_TIME_KEY, -- Gitee From 4f77b7e8d03f58dd01f8574ed581bfe2fb5fe6b9 Mon Sep 17 00:00:00 2001 From: cjw123qq Date: Sat, 26 Jul 2025 15:22:25 +0800 Subject: [PATCH 2/3] fix: add during call feature Signed-off-by: cjw123qq --- services/native/src/power_state_machine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index bc8c4c8a..0b0343d9 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -2548,7 +2548,7 @@ bool PowerStateMachine::HandleDuringCallState(PowerState state, StateChangeReaso POWER_HILOGI(FEATURE_POWER_STATE, "enter HandleDuringCallState, state=%{public}s, resaon=%{public}s" " isDuringCallState_=%{public}d", PowerUtils::GetPowerStateString(state).c_str(), PowerUtils::GetReasonTypeString(reason).c_str(), isDuringCallState_); - // PROXIMITY away or PROXIMITY lock release and fold display mode is sub + // PROXIMITY away or PROXIMITY lock release and fold display mode is sub if (state == PowerState::AWAKE && (reason == StateChangeReason::STATE_CHANGE_REASON_PROXIMITY || reason == StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK) && -- Gitee From 77e260c13be2ed2b54b3268141aa311a3182c839 Mon Sep 17 00:00:00 2001 From: cjw123qq Date: Mon, 28 Jul 2025 22:00:20 +0800 Subject: [PATCH 3/3] fix: add during call feature Signed-off-by: cjw123qq --- etc/para/powermgr.para | 3 +- etc/para/powermgr.para.dac | 3 +- services/native/include/power_mgr_service.h | 5 ++ services/native/include/power_state_machine.h | 11 +++- services/native/src/power_mgr_service.cpp | 17 ++++- services/native/src/power_state_machine.cpp | 46 +++++--------- .../src/runninglock/running_lock_mgr.cpp | 40 +++++++++--- .../native/src/runninglock/running_lock_mgr.h | 5 -- .../native/src/setting/setting_helper.cpp | 2 +- services/native/src/setting/setting_helper.h | 2 +- .../native/src/suspend/suspend_controller.cpp | 62 ++++++++++++------- .../native/src/suspend/suspend_controller.h | 1 + .../src/native_power_state_machine_test.cpp | 62 +++++++++++-------- .../src/power_mgr_service_native_test.cpp | 36 +++++++---- .../unittest/src/running_lock_native_test.cpp | 36 ----------- .../proximity_controller/BUILD.gn | 3 + .../proximity_running_lock_test.cpp | 13 ++++ .../running_lock_mgr_abnormal_test.cpp | 15 +++++ utils/ffrt/include/ffrt_utils.h | 1 + 19 files changed, 214 insertions(+), 149 deletions(-) diff --git a/etc/para/powermgr.para b/etc/para/powermgr.para index c40fb19c..6097b990 100644 --- a/etc/para/powermgr.para +++ b/etc/para/powermgr.para @@ -16,4 +16,5 @@ persist.powermgr.stopservice = false persist.dfx.userclicktime = 0 persist.dfx.shutdownactiontime = 0 persist.dfx.shutdowncompletetime = 0 -persist.dfx.eventtype = 0 \ No newline at end of file +persist.dfx.eventtype = 0 +const.power.during_call_state_enable = false \ No newline at end of file diff --git a/etc/para/powermgr.para.dac b/etc/para/powermgr.para.dac index e7f8a773..017af2ea 100644 --- a/etc/para/powermgr.para.dac +++ b/etc/para/powermgr.para.dac @@ -16,4 +16,5 @@ persist.powermgr. = powermgr:powermgr:0775 persist.dfx.userclicktime = powermgr:powermgr:0776 persist.dfx.shutdownactiontime = powermgr:powermgr:0776 persist.dfx.shutdowncompletetime = powermgr:powermgr:0776 -persist.dfx.eventtype = powermgr:powermgr:0776 \ No newline at end of file +persist.dfx.eventtype = powermgr:powermgr:0776 +const.power.during_call_state_enable = powermgr:powermgr:0444 \ No newline at end of file diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index ea6bc23a..83d6566f 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -285,6 +285,10 @@ public: { return shutdownController_; } + bool IsDuringCallStateEnable() + { + return isDuringCallStateEnable_; + } #ifdef HAS_SENSORS_SENSOR_PART static bool isInLidMode_; #endif @@ -363,6 +367,7 @@ private: void UnregisterExternalCallback(); bool ready_ {false}; + bool isDuringCallStateEnable_ {false}; std::mutex wakeupMutex_; std::mutex suspendMutex_; #ifdef POWER_MANAGER_POWER_ENABLE_S4 diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index 4f09bf7a..bd338955 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -78,6 +78,7 @@ public: CHECK_PRE_BRIGHT_AUTH_TIMEOUT_MSG, CHECK_PROXIMITY_SCREEN_OFF_MSG, SET_INTERNAL_SCREEN_STATE_MSG, + CHECK_PROXIMITY_SCREEN_SWITCH_TO_SUB_MSG, }; class PowerStateCallbackDeathRecipient : public IRemoteObject::DeathRecipient { @@ -218,7 +219,11 @@ public: } void SetDuringCallState(bool state) { - isDuringCallState_ = state; + isDuringCall_ = state; + } + bool IsDuringCall() + { + return isDuringCall_; } void DumpInfo(std::string& result); @@ -236,6 +241,7 @@ public: #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT void SetInternalScreenDisplayState(DisplayState state, StateChangeReason reason); #endif + bool HandleDuringCall(bool isProximityClose); private: enum PreBrightState : uint32_t { @@ -360,7 +366,6 @@ private: void ShowCurrentScreenLocks(); void HandleProximityScreenOffTimer(PowerState state, StateChangeReason reason); bool HandlePreBrightState(PowerState targetState, StateChangeReason reason); - bool HandleDuringCallState(PowerState state, StateChangeReason reason); bool IsPreBrightAuthReason(StateChangeReason reason); bool IsPreBrightWakeUp(WakeupDeviceType type); bool NeedShowScreenLocks(PowerState state); @@ -423,7 +428,7 @@ private: std::atomic externalScreenNumber_ {0}; std::mutex internalScreenStateMutex_; #endif - bool isDuringCallState_ {false}; + std::atomic isDuringCall_ {false}; bool SetDreamingState(StateChangeReason reason); }; } // namespace PowerMgr diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index bbab1228..b044d486 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -166,7 +166,8 @@ bool PowerMgrService::Init() screenOffPreController_ = std::make_shared(powerStateMachine_); screenOffPreController_->Init(); } - POWER_HILOGI(COMP_SVC, "powermgr service init success"); + isDuringCallStateEnable_ = system::GetBoolParameter("const.power.during_call_state_enable", false); + POWER_HILOGI(COMP_SVC, "powermgr service init success %{pubilc}d", isDuringCallStateEnable_); return true; } @@ -268,6 +269,11 @@ void PowerMgrService::PowerModeSettingUpdateFunc(const std::string &key) void PowerMgrService::RegisterSettingDuringCallObservers() { + auto pms = DelayedSpSingleton::GetInstance(); + if (!pms->IsDuringCallStateEnable()) { + return; + } + POWER_HILOGI(COMP_SVC, "will RegisterSettingDuringCallObservers"); SettingObserver::UpdateFunc updateFunc = [&](const std::string &key) { DuringCallSettingUpdateFunc(key); }; SettingHelper::RegisterSettingDuringCallObserver(updateFunc); } @@ -275,9 +281,14 @@ void PowerMgrService::RegisterSettingDuringCallObservers() void PowerMgrService::DuringCallSettingUpdateFunc(const std::string &key) { auto power = DelayedSpSingleton::GetInstance(); - bool duringCallState = SettingHelper::GetDuringCallState(key); + bool duringCallState = SettingHelper::GetSettingDuringCallState(key); POWER_HILOGI(COMP_SVC, "DuringCallState is %{public}d", duringCallState); - power->runningLockMgr_->SetDuringCallState(duringCallState); + auto stateMachine = power->GetPowerStateMachine(); + if (stateMachine == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "PowerStateMachine is nullptr"); + return; + } + stateMachine->SetDuringCallState(duringCallState); } bool PowerMgrService::IsDeveloperMode() diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index cd70846e..54e1d4ba 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -1343,6 +1343,10 @@ void PowerStateMachine::CancelDelayTimer(int32_t event) proximityScreenOffTimerStarted_.store(false, std::memory_order_relaxed); break; } + case CHECK_PROXIMITY_SCREEN_SWITCH_TO_SUB_MSG: { + ffrtTimer_->CancelTimer(TIMER_ID_PROXIMITY_SCREEN_SWITCH_TO_SUB); + break; + } default: { break; } @@ -1995,11 +1999,6 @@ bool PowerStateMachine::SetState(PowerState state, StateChangeReason reason, boo POWER_HILOGD(FEATURE_POWER_STATE, "state=%{public}s, reason=%{public}s, force=%{public}d", PowerUtils::GetPowerStateString(state).c_str(), PowerUtils::GetReasonTypeString(reason).c_str(), force); std::lock_guard lock(stateMutex_); - if (HandleDuringCallState(state, reason)) { - POWER_HILOGI(FEATURE_POWER_STATE, "Duringcall action trigger, state=%{public}s, reason=%{public}s", - PowerUtils::GetPowerStateString(state).c_str(), PowerUtils::GetReasonTypeString(reason).c_str()); - return true; - } if (!CheckFFRTTaskAvailability(state, reason)) { POWER_HILOGI(FEATURE_POWER_STATE, "this timeout task is invalidated, directly return"); return false; @@ -2551,33 +2550,22 @@ bool PowerStateMachine::StateController::IsReallyFailed(StateChangeReason reason return true; } -bool PowerStateMachine::HandleDuringCallState(PowerState state, StateChangeReason reason) +bool PowerStateMachine::HandleDuringCall(bool isProximityClose) { - if (isDuringCallState_) { - POWER_HILOGI(FEATURE_POWER_STATE, "enter HandleDuringCallState, state=%{public}s, resaon=%{public}s" - " isDuringCallState_=%{public}d", PowerUtils::GetPowerStateString(state).c_str(), - PowerUtils::GetReasonTypeString(reason).c_str(), isDuringCallState_); - // PROXIMITY away or PROXIMITY lock release and fold display mode is sub - if (state == PowerState::AWAKE && - (reason == StateChangeReason::STATE_CHANGE_REASON_PROXIMITY || - reason == StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK) && - Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB) { - Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::MAIN); - return true; - // power_key down for wakeup main and fold display mode is sub - } else if (state == PowerState::INACTIVE && reason == StateChangeReason::STATE_CHANGE_REASON_HARD_KEY && - Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB) { - Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::MAIN); - return true; - // PROXIMITY close and fold display mode is main - } else if (state == PowerState::INACTIVE && reason == StateChangeReason::STATE_CHANGE_REASON_PROXIMITY && - Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::MAIN) { - Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::SUB); - return true; - } + // when screen is off or duringcall is false, wakeup or suspend is normal + if (!isDuringCall_ || !IsScreenOn()) { return false; } - return false; + Rosen::FoldDisplayMode mode = Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode(); + POWER_HILOGI(FEATURE_POWER_STATE, "HandleDuringCall mode:%{public}d, isProximityClose:%{public}d", + static_cast(mode), isProximityClose); + if (mode == Rosen::FoldDisplayMode::MAIN && isProximityClose && + IsRunningLockEnabled(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL)) { + Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::SUB); + } else if (mode == Rosen::FoldDisplayMode::SUB && !isProximityClose) { + Rosen::DisplayManagerLite::GetInstance().SetFoldDisplayMode(Rosen::FoldDisplayMode::MAIN); + } + return true; } bool PowerStateMachine::IsSwitchOpenByPath() diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 9b0b0d5a..ed1c06fd 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -47,7 +47,6 @@ constexpr uint32_t FOREGROUND_INCALL_DELAY_TIME_MS = 300; constexpr uint32_t BACKGROUND_INCALL_DELAY_TIME_MS = 800; #endif } -bool RunningLockMgr::isDuringCallState_ = false; RunningLockMgr::~RunningLockMgr() {} @@ -200,13 +199,18 @@ void RunningLockMgr::InitLocksTypeProximity() } PreprocessBeforeAwake(); stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK); - stateMachine->SetDuringCallState(false); }; if (active) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "[UL_POWER] RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL active"); proximityController_->Enable(); } else { POWER_HILOGI(FEATURE_RUNNING_LOCK, "[UL_POWER] RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL inactive"); + auto pms = DelayedSpSingleton::GetInstance(); + auto stateMachine = pms->GetPowerStateMachine(); + if (stateMachine == nullptr) { + return RUNNINGLOCK_FAILURE; + } + stateMachine->CancelDelayTimer(PowerStateMachine::CHECK_PROXIMITY_SCREEN_SWITCH_TO_SUB_MSG); FFRTUtils::SubmitTask(task); proximityController_->Disable(); proximityController_->Clear(); @@ -949,15 +953,30 @@ void RunningLockMgr::HandleProximityCloseEvent() POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr"); return; } - if (isDuringCallState_) { - stateMachine->SetDuringCallState(true); - } if (GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK"); uint32_t delayTime = FOREGROUND_INCALL_DELAY_TIME_MS; if (!PowerUtils::IsForegroundApplication(INCALL_APP_BUNDLE_NAME)) { delayTime = BACKGROUND_INCALL_DELAY_TIME_MS; } + if (pms->IsDuringCallStateEnable() && stateMachine->IsDuringCall() && stateMachine->IsScreenOn()) { + POWER_HILOGI( + FEATURE_RUNNING_LOCK, "Start proximity-screen-switch timer, delay time:%{public}u", delayTime); + FFRTTask delayScreenSwitchToSubTask = [] { + auto pms = DelayedSpSingleton::GetInstance(); + auto stateMachine = pms->GetPowerStateMachine(); + if (stateMachine == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "state machine is nullptr"); + return; + } + POWER_HILOGI(FEATURE_POWER_STATE, "proximity-screen-switch timer task is triggered"); + bool ret = stateMachine->HandleDuringCall(true); + POWER_HILOGI(FEATURE_POWER_STATE, "Proximity close when duringcall mode, ret:%{public}d", ret); + }; + stateMachine->SetDelayTimer( + delayTime, FFRTTimerId::TIMER_ID_PROXIMITY_SCREEN_SWITCH_TO_SUB, delayScreenSwitchToSubTask); + return; + } POWER_HILOGI(FEATURE_RUNNING_LOCK, "Start proximity-screen-off timer, delay time:%{public}u", delayTime); stateMachine->SetDelayTimer(delayTime, PowerStateMachine::CHECK_PROXIMITY_SCREEN_OFF_MSG); } else { @@ -979,13 +998,16 @@ void RunningLockMgr::HandleProximityAwayEvent() } auto runningLock = pms->GetRunningLockMgr(); if (GetValidRunningLockNum(RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { + if (pms->IsDuringCallStateEnable()) { + stateMachine->CancelDelayTimer(PowerStateMachine::CHECK_PROXIMITY_SCREEN_SWITCH_TO_SUB_MSG); + if (stateMachine->HandleDuringCall(false)) { + POWER_HILOGI(FEATURE_RUNNING_LOCK, "Proximity away when duringcall mode"); + return; + } + } POWER_HILOGI(FEATURE_RUNNING_LOCK, "Change state to AWAKE when holding PROXIMITY LOCK"); runningLock->PreprocessBeforeAwake(); stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY, true); - if (isDuringCallState_) { - // Proximity away need keep origin action after first away - stateMachine->SetDuringCallState(false); - } } else { POWER_HILOGI(FEATURE_RUNNING_LOCK, "Unholding PROXIMITY LOCK"); } diff --git a/services/native/src/runninglock/running_lock_mgr.h b/services/native/src/runninglock/running_lock_mgr.h index 38394557..ef94ff26 100644 --- a/services/native/src/runninglock/running_lock_mgr.h +++ b/services/native/src/runninglock/running_lock_mgr.h @@ -79,10 +79,6 @@ public: void DumpInfo(std::string& result); void EnableMock(IRunningLockAction* mockAction); bool IsExistAudioStream(pid_t uid); - void SetDuringCallState(bool state) - { - isDuringCallState_ = state; - } private: void AsyncWakeup(); @@ -146,7 +142,6 @@ private: RunningLockInfo FillAppRunningLockInfo(const RunningLockParam& info); void UpdateUnSceneLockLists(RunningLockParam& singleLockParam, bool fill); - static bool isDuringCallState_; const wptr pms_; std::mutex mutex_; std::mutex screenLockListsMutex_; diff --git a/services/native/src/setting/setting_helper.cpp b/services/native/src/setting/setting_helper.cpp index d26db7a1..aaae6343 100644 --- a/services/native/src/setting/setting_helper.cpp +++ b/services/native/src/setting/setting_helper.cpp @@ -565,7 +565,7 @@ void SettingHelper::UnRegisterSettingDuringCallObserver() duringCallObserver_ = nullptr; } -bool SettingHelper::GetDuringCallState(const std::string& key) +bool SettingHelper::GetSettingDuringCallState(const std::string& key) { SettingProvider& settingProvider = SettingProvider::GetInstance(POWER_MANAGER_SERVICE_ID); bool value = false; diff --git a/services/native/src/setting/setting_helper.h b/services/native/src/setting/setting_helper.h index c5a01660..95fdf231 100644 --- a/services/native/src/setting/setting_helper.h +++ b/services/native/src/setting/setting_helper.h @@ -109,7 +109,7 @@ public: static bool IsWakeupLidSettingValid(); static void RegisterSettingDuringCallObserver(SettingObserver::UpdateFunc& func); static void UnRegisterSettingDuringCallObserver(); - static bool GetDuringCallState(const std::string& key = SETTING_DURING_CALL_STATE_KEY); + static bool GetSettingDuringCallState(const std::string& key = SETTING_DURING_CALL_STATE_KEY); #ifdef POWER_MANAGER_ENABLE_BLOCK_LONG_PRESS static const std::string GetBlockLongPress(); #endif diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 5cce7a29..bbfab6ae 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -15,9 +15,7 @@ #include "suspend_controller.h" #include -#ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT #include -#endif #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART #include #endif @@ -435,35 +433,14 @@ void SuspendController::SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t void SuspendController::ControlListener(SuspendDeviceType reason, uint32_t action, uint32_t delay) { - auto pms = DelayedSpSingleton::GetInstance(); - if (pms == nullptr) { - return; - } if (stateMachine_ == nullptr) { POWER_HILOGE(FEATURE_SUSPEND, "get PowerStateMachine instance error"); return; } - if (pms->CheckDialogAndShuttingDown()) { + if (NeedToSkipCurrentSuspend(reason, action, delay)) { return; } - - if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { - stateMachine_->SetSwitchAction(action); - } - bool isScreenOn = stateMachine_->IsScreenOn(); - if (!isScreenOn) { - SuspendWhenScreenOff(reason, action, delay); - return; - } - -#ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT - if (IsPowerOffInernalScreenOnlyScene(reason, static_cast(action), isScreenOn)) { - ProcessPowerOffInternalScreenOnly(pms, reason); - return; - } -#endif - pid_t pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); POWER_HILOGI(FEATURE_SUSPEND, @@ -486,6 +463,43 @@ void SuspendController::ControlListener(SuspendDeviceType reason, uint32_t actio } } +bool SuspendController::NeedToSkipCurrentSuspend(SuspendDeviceType reason, uint32_t action, uint32_t delay) +{ + auto pms = DelayedSpSingleton::GetInstance(); + if (pms == nullptr) { + POWER_HILOGE(FEATURE_SUSPEND, "get PowerMgrService instance error"); + return true; + } + if (pms->CheckDialogAndShuttingDown()) { + return true; + } + + if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { + stateMachine_->SetSwitchAction(action); + } + bool isScreenOn = stateMachine_->IsScreenOn(); + if (!isScreenOn) { + SuspendWhenScreenOff(reason, action, delay); + return true; + } + if (pms->IsDuringCallStateEnable()) { + if (reason == SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY && + Rosen::DisplayManagerLite::GetInstance().GetFoldDisplayMode() == Rosen::FoldDisplayMode::SUB && + stateMachine_->HandleDuringCall(false)) { + POWER_HILOGI(FEATURE_SUSPEND, "switch to main display when duringcall mode"); + return true; + } + } + +#ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT + if (IsPowerOffInernalScreenOnlyScene(reason, static_cast(action), isScreenOn)) { + ProcessPowerOffInternalScreenOnly(pms, reason); + return true; + } +#endif + return false; +} + std::shared_ptr SuspendController::GetSpecifiedSuspendMonitor(SuspendDeviceType type) const { auto iter = monitorMap_.find(type); diff --git a/services/native/src/suspend/suspend_controller.h b/services/native/src/suspend/suspend_controller.h index 5c406612..517021fb 100644 --- a/services/native/src/suspend/suspend_controller.h +++ b/services/native/src/suspend/suspend_controller.h @@ -113,6 +113,7 @@ private: SleepCallbackHolder::SleepCallbackContainerType& callbacks, const std::string& priority, bool isWakeup); static constexpr int32_t FORCE_SLEEP_DELAY_MS = 8000; void SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t action, uint32_t delay); + bool NeedToSkipCurrentSuspend(SuspendDeviceType reason, uint32_t action, uint32_t delay); std::vector sourceList_; std::map> monitorMap_; std::shared_ptr shutdownController_; diff --git a/test/unittest/src/native_power_state_machine_test.cpp b/test/unittest/src/native_power_state_machine_test.cpp index 82bdf703..c240e67e 100644 --- a/test/unittest/src/native_power_state_machine_test.cpp +++ b/test/unittest/src/native_power_state_machine_test.cpp @@ -430,35 +430,47 @@ HWTEST_F(NativePowerStateMachineTest, NativePowerStateMachine010, TestSize.Level POWER_HILOGI(LABEL_TEST, "NativePowerStateMachine010 function start!"); auto pmsTest = DelayedSpSingleton::GetInstance(); pmsTest->OnStart(); - auto stateMachine = std::make_shared(pmsTest); - EXPECT_TRUE(stateMachine->Init()); + pmsTest->SuspendControllerInit(); + pmsTest->WakeupControllerInit(); + auto stateMachine = pmsTest->GetPowerStateMachine(); - bool ret = stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_BATTERY, true); - EXPECT_TRUE(ret); + EXPECT_TRUE(pmsTest->SuspendDevice(SUSCALLTIMEMS, SuspendDeviceType::SUSPEND_DEVICE_REASON_APPLICATION, false) + == PowerErrors::ERR_OK); + constexpr int ONE_SECOND = 1; + sleep(ONE_SECOND); + EXPECT_EQ(stateMachine->IsScreenOn(), false) << "NativePowerStateMachine010: Prepare Fail, Screen is On"; + pmsTest->WakeupDevice(0, WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, "NativePowerStateMachine010"); + sleep(ONE_SECOND); + EXPECT_EQ(stateMachine->IsScreenOn(), true) << "NativePowerStateMachine010: Prepare Fail, Screen is Off"; stateMachine->SetDuringCallState(true); - ret = stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_DOUBLE_CLICK, true); - EXPECT_TRUE(ret); - ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PICKUP); - EXPECT_FALSE(ret); + g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::MAIN; + bool ret = stateMachine->HandleDuringCall(true); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::SUB && ret); + ret = stateMachine->HandleDuringCall(true); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::SUB && ret); + ret = stateMachine->HandleDuringCall(false); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN && ret); + ret = stateMachine->HandleDuringCall(false); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN && ret); + g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::FULL; + ret = stateMachine->HandleDuringCall(true); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::FULL && ret); + + constexpr int WAIT_TIME_MS = 100; + usleep(WAIT_TIME_MS); + pmsTest->isDuringCallStateEnable_ = true; g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::SUB; - ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); - EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN); - ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); - EXPECT_FALSE(ret); - ret = stateMachine->HandleDuringCallState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_RUNNING_LOCK); - EXPECT_FALSE(ret); - ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_TIMEOUT); - EXPECT_FALSE(ret); - ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_HARD_KEY); - EXPECT_FALSE(ret); - g_foldDisplayMode = OHOS::Rosen::FoldDisplayMode::SUB; - ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_HARD_KEY); - EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN); - ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); - EXPECT_TRUE(ret && g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::SUB); - ret = stateMachine->HandleDuringCallState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_PROXIMITY); - EXPECT_FALSE(ret); + ret = pmsTest->GetSuspendController()->NeedToSkipCurrentSuspend( + SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, 0, 0); + EXPECT_TRUE(g_foldDisplayMode == OHOS::Rosen::FoldDisplayMode::MAIN && ret); + pmsTest->isDuringCallStateEnable_ = false; + pmsTest->GetSuspendController()->NeedToSkipCurrentSuspend( + SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, 0, 0); + stateMachine->SetDuringCallState(false); + pmsTest->suspendController_ = nullptr; + EXPECT_TRUE(pmsTest->GetSuspendController() == nullptr); + usleep(WAIT_TIME_MS); POWER_HILOGI(LABEL_TEST, "NativePowerStateMachine010 function end!"); } diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index 4d559b5b..271502ad 100644 --- a/test/unittest/src/power_mgr_service_native_test.cpp +++ b/test/unittest/src/power_mgr_service_native_test.cpp @@ -41,6 +41,7 @@ constexpr pid_t PID = 1; constexpr pid_t UID = 1; constexpr int32_t UNCANCELID = -1; constexpr int32_t INVALID_CODE = -1; +constexpr int32_t TRY_TIMES = 2; sptr g_pmsTest; } // namespace @@ -466,17 +467,30 @@ HWTEST_F(PowerMgrServiceNativeTest, PowerMgrServiceNative016, TestSize.Level1) { GTEST_LOG_(INFO) << "PowerMgrServiceNative016 start."; POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative016 function start!"); - g_pmsTest->RegisterSettingDuringCallObservers(); - EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); - g_pmsTest->RegisterSettingDuringCallObservers(); - EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); - SettingHelper::UnRegisterSettingDuringCallObserver(); - EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); - SettingHelper::UnRegisterSettingDuringCallObserver(); - EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); - g_pmsTest->DuringCallSettingUpdateFunc(SettingHelper::SETTING_DURING_CALL_STATE_KEY); - auto runningLockMgr = g_pmsTest->GetRunningLockMgr(); - EXPECT_FALSE(runningLockMgr->isDuringCallState_); + for (int i = 0; i < TRY_TIMES; i++) { + if (i) { + g_pmsTest->isDuringCallStateEnable_ = true; + EXPECT_TRUE(g_pmsTest->IsDuringCallStateEnable()); + } + g_pmsTest->RegisterSettingDuringCallObservers(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); + g_pmsTest->RegisterSettingDuringCallObservers(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ != nullptr); + SettingHelper::UnRegisterSettingDuringCallObserver(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); + SettingHelper::UnRegisterSettingDuringCallObserver(); + EXPECT_TRUE(SettingHelper::duringCallObserver_ == nullptr); + g_pmsTest->DuringCallSettingUpdateFunc(SettingHelper::SETTING_DURING_CALL_STATE_KEY); + auto stateMachine = g_pmsTest->GetPowerStateMachine(); + EXPECT_TRUE(stateMachine != nullptr && !stateMachine->isDuringCall_); + g_pmsTest->powerStateMachine_ = nullptr; + EXPECT_TRUE(g_pmsTest->GetPowerStateMachine() == nullptr); + g_pmsTest->DuringCallSettingUpdateFunc(SettingHelper::SETTING_DURING_CALL_STATE_KEY); + if (i) { + g_pmsTest->isDuringCallStateEnable_ = false; + EXPECT_FALSE(g_pmsTest->IsDuringCallStateEnable()); + } + } POWER_HILOGI(LABEL_TEST, "PowerMgrServiceNative016 function end!"); GTEST_LOG_(INFO) << "PowerMgrServiceNative016 end."; } diff --git a/test/unittest/src/running_lock_native_test.cpp b/test/unittest/src/running_lock_native_test.cpp index d05ad954..a2699c39 100644 --- a/test/unittest/src/running_lock_native_test.cpp +++ b/test/unittest/src/running_lock_native_test.cpp @@ -732,40 +732,4 @@ HWTEST_F (RunningLockNativeTest, RunningLockNative023, TestSize.Level1) POWER_HILOGI(LABEL_TEST, "RunningLockNative023 function end!"); } - -/** - * @tc.name: RunningLockNative024 - * @tc.desc: test SetDuringCallState - * @tc.type: FUNC - */ -HWTEST_F(RunningLockNativeTest, RunningLockNative024, TestSize.Level1) -{ - POWER_HILOGI(LABEL_TEST, "RunningLockNative024 function start!"); - auto pmsTest = DelayedSpSingleton::GetInstance(); - pmsTest->OnStart(); - auto runningLockMgr = std::make_shared(pmsTest); - EXPECT_TRUE(runningLockMgr->Init()); - EXPECT_FALSE(runningLockMgr->isDuringCallState_); -#ifdef HAS_SENSORS_SENSOR_PART - RunningLockParam runningLockParam {0, - "RunningLockNative024", "", RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL, TIMEOUTMS, PID, UID}; - sptr token = new RunningLockTokenStub(); - EXPECT_TRUE(runningLockMgr->CreateRunningLock(token, runningLockParam) != nullptr); - runningLockMgr->Lock(token); - auto stateMachine = pmsTest->GetPowerStateMachine(); - runningLockMgr->HandleProximityCloseEvent(); - EXPECT_FALSE(stateMachine->isDuringCallState_); - runningLockMgr->HandleProximityAwayEvent(); - EXPECT_FALSE(stateMachine->isDuringCallState_); - - runningLockMgr->SetDuringCallState(true); - EXPECT_TRUE(runningLockMgr->isDuringCallState_); - runningLockMgr->HandleProximityCloseEvent(); - EXPECT_TRUE(stateMachine->isDuringCallState_); - runningLockMgr->HandleProximityAwayEvent(); - EXPECT_FALSE(stateMachine->isDuringCallState_); - runningLockMgr->UnLock(token); -#endif - POWER_HILOGI(LABEL_TEST, "RunningLockNative024 function end!"); -} } // namespace diff --git a/test/unittest/src/scenario_test/proximity_controller/BUILD.gn b/test/unittest/src/scenario_test/proximity_controller/BUILD.gn index 0ac7f7a4..571bc4ad 100644 --- a/test/unittest/src/scenario_test/proximity_controller/BUILD.gn +++ b/test/unittest/src/scenario_test/proximity_controller/BUILD.gn @@ -30,6 +30,7 @@ config("module_mock_private_config") { "${powermgr_service_path}/native/src/suspend", "${powermgr_service_path}/native/src/wakeup", "${powermgr_service_path}/native/src/screenoffpre", + "${powermgr_service_path}/native/src/setting", ] } @@ -41,6 +42,7 @@ deps_ex = [ "c_utils:utils", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", + "data_share:datashare_consumer", "drivers_interface_power:libpower_proxy_1.2", "drivers_interface_power:libpower_proxy_1.3", "ffrt:libffrt", @@ -78,6 +80,7 @@ ohos_unittest("test_proximity_running_lock_abnormal") { sources = [ "${powermgr_service_path}/native/src/runninglock/running_lock_mgr.cpp", + "${powermgr_service_path}/native/src/suspend/suspend_controller.cpp", "running_lock_mgr_abnormal_test.cpp", ] diff --git a/test/unittest/src/scenario_test/proximity_controller/proximity_running_lock_test.cpp b/test/unittest/src/scenario_test/proximity_controller/proximity_running_lock_test.cpp index 582095a5..c17e2b36 100644 --- a/test/unittest/src/scenario_test/proximity_controller/proximity_running_lock_test.cpp +++ b/test/unittest/src/scenario_test/proximity_controller/proximity_running_lock_test.cpp @@ -95,8 +95,21 @@ HWTEST_F(ProximityRunningLockTest, ProximityRunningLockTest001, TestSize.Level1) EXPECT_FALSE(g_pmsTest->GetRunningLockMgr()->proximityController_->IsClose()); POWER_HILOGI(LABEL_TEST, "ProximityRunningLockTest away IsScreenOn:%{public}d", g_pmsTest->IsScreenOn()); EXPECT_TRUE(g_pmsTest->IsScreenOn()); + + if (i) { + g_pmsTest->isDuringCallStateEnable_ = true; + EXPECT_TRUE(g_pmsTest->IsDuringCallStateEnable()); + } + g_pmsTest->GetPowerStateMachine()->SetDuringCallState(true); + g_pmsTest->GetRunningLockMgr()->HandleProximityAwayEvent(); + g_pmsTest->GetPowerStateMachine()->SetDuringCallState(false); + EXPECT_TRUE(g_pmsTest->IsScreenOn()); g_pmsTest->UnLock(runningLockToken); usleep(SLEEP_WAIT_TIME_MS * TRANSFER_NS_TO_MS / 10); // 100ms for unlock async screen on + if (i) { + g_pmsTest->isDuringCallStateEnable_ = false; + EXPECT_FALSE(g_pmsTest->IsDuringCallStateEnable()); + } } POWER_HILOGI(LABEL_TEST, "ProximityRunningLockTest001 function end!"); } diff --git a/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp b/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp index 986f5b6f..81f75bb9 100644 --- a/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp +++ b/test/unittest/src/scenario_test/proximity_controller/running_lock_mgr_abnormal_test.cpp @@ -350,4 +350,19 @@ HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest008, TestSize.Lev POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest008 function end!"); } #endif + +/** + * @tc.name: RunningLockMgrAbnormalTest009 + * @tc.desc: Test SuspendController pms == nullptr + * @tc.type: FUNC + * @tc.require: ICGV1M + */ +HWTEST_F(RunningLockMgrAbnormalTest, RunningLockMgrAbnormalTest009, TestSize.Level1) +{ + POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest009 function start!"); + auto suspendController = std::make_shared(nullptr, nullptr, nullptr); + EXPECT_TRUE(suspendController->NeedToSkipCurrentSuspend( + SuspendDeviceType::SUSPEND_DEVICE_REASON_POWER_KEY, 0, 0)); + POWER_HILOGI(LABEL_TEST, "RunningLockMgrAbnormalTest009 function end!"); +} } // namespace \ No newline at end of file diff --git a/utils/ffrt/include/ffrt_utils.h b/utils/ffrt/include/ffrt_utils.h index 543bedd7..8462a27a 100644 --- a/utils/ffrt/include/ffrt_utils.h +++ b/utils/ffrt/include/ffrt_utils.h @@ -132,6 +132,7 @@ enum FFRTTimerId { TIMER_ID_SCREEN_TIMEOUT_CHECK, TIMER_ID_PRE_BRIGHT_AUTH, TIMER_ID_PROXIMITY_SCREEN_OFF, + TIMER_ID_PROXIMITY_SCREEN_SWITCH_TO_SUB, }; class FFRTMutexMap { -- Gitee