diff --git a/etc/para/powermgr.para b/etc/para/powermgr.para index c40fb19ccb4da95aef7be2ceb9435f1e333b99b7..6097b990cec735662129e8b88810035a92dbfd8c 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 e7f8a773488fe30b0dbd1b0b9b6a28976c2e0d0d..017af2ea7005793b8af589c72be8467a67884d1e 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 42931ee9f27d52e061e891939a1edac0853ae406..83d6566f633ac7d6a0e6988cf7e5c17fe1ddf334 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; @@ -283,6 +285,10 @@ public: { return shutdownController_; } + bool IsDuringCallStateEnable() + { + return isDuringCallStateEnable_; + } #ifdef HAS_SENSORS_SENSOR_PART static bool isInLidMode_; #endif @@ -361,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 7ab14f30138b3dca4fdd63eb3d3dec8c66e7c401..bd3389551508606cf72a7e8c0d235031cb90fd00 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 { @@ -216,6 +217,14 @@ public: { return mDeviceState_.screenState.lastOnTime; } + void SetDuringCallState(bool state) + { + isDuringCall_ = state; + } + bool IsDuringCall() + { + return isDuringCall_; + } void DumpInfo(std::string& result); void EnableMock(IDeviceStateAction* mockAction); @@ -232,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 { @@ -418,6 +428,7 @@ private: std::atomic externalScreenNumber_ {0}; std::mutex internalScreenStateMutex_; #endif + 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 202188fe9c05ab743c5f8a22567e1ddf5918f9fa..b044d48644de0d09a029406fe51983afbf1aa923 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; } @@ -244,6 +245,7 @@ void PowerMgrService::PowerExternalAbilityInit() POWER_HILOGI(COMP_SVC, "Not allow subscribe Hall sensor"); #endif power->RegisterSettingPowerModeObservers(); + power->RegisterSettingDuringCallObservers(); power->RegisterExternalCallback(); } @@ -265,6 +267,30 @@ void PowerMgrService::PowerModeSettingUpdateFunc(const std::string &key) power->SetDeviceMode(static_cast(saveMode)); } +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); +} + +void PowerMgrService::DuringCallSettingUpdateFunc(const std::string &key) +{ + auto power = DelayedSpSingleton::GetInstance(); + bool duringCallState = SettingHelper::GetSettingDuringCallState(key); + POWER_HILOGI(COMP_SVC, "DuringCallState is %{public}d", duringCallState); + auto stateMachine = power->GetPowerStateMachine(); + if (stateMachine == nullptr) { + POWER_HILOGE(FEATURE_RUNNING_LOCK, "PowerStateMachine is nullptr"); + return; + } + stateMachine->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 ea765cf06ded7765d9df9f0cc278110149d20670..54e1d4ba52470d94dd5cc86901a53c9aca30759d 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; } @@ -2546,6 +2550,24 @@ bool PowerStateMachine::StateController::IsReallyFailed(StateChangeReason reason return true; } +bool PowerStateMachine::HandleDuringCall(bool isProximityClose) +{ + // when screen is off or duringcall is false, wakeup or suspend is normal + if (!isDuringCall_ || !IsScreenOn()) { + 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() { std::string value = ""; diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 504c05a225deaa2115bc673224b251238d13e946..ed1c06fd180f23d0ef61a387e8064950449148b4 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -205,6 +205,12 @@ void RunningLockMgr::InitLocksTypeProximity() 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(); @@ -953,6 +959,24 @@ void RunningLockMgr::HandleProximityCloseEvent() 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 { @@ -974,6 +998,13 @@ 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); diff --git a/services/native/src/setting/setting_helper.cpp b/services/native/src/setting/setting_helper.cpp index 91cf0588527bcd3c3039b8d371ae83e9b8012034..aaae63436b72dcf5df18fee216bdea88de6c4ffb 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::GetSettingDuringCallState(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 8673df65e3fa69ce7177c8bd3c29dd1ec1ad7431..95fdf231f101b464bfbc0f2148283df2bd803ddc 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 GetSettingDuringCallState(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/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 5cce7a29def1fbb3825083a210f9125e8eb62573..bbfab6ae4dae844aa57c08b52bb8e56ce1f6cace 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 5c406612a4459b1707e9a7bd04b083638ff85689..517021fb0744e36a18526902d1b815e6d8d6b7a6 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/include/native_power_state_machine_test.h b/test/unittest/include/native_power_state_machine_test.h index 7c672deb64bf8b15efa30a173346bf27cd27863b..6b3c552cf14a5cf9e92e58de82d2feb327103a54 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 30676e7b4ec66ef288dabb769a8523c87558b10b..c240e67e27aa92272615726a3798be8630484e46 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) @@ -405,6 +420,60 @@ HWTEST_F(NativePowerStateMachineTest, NativePowerStateMachine009, TestSize.Level 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(); + pmsTest->SuspendControllerInit(); + pmsTest->WakeupControllerInit(); + auto stateMachine = pmsTest->GetPowerStateMachine(); + + 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); + + 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 = 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!"); +} + /** * @tc.name: NativePowerStateMachine011 * @tc.desc: test Lid Sensor diff --git a/test/unittest/src/power_mgr_service_native_test.cpp b/test/unittest/src/power_mgr_service_native_test.cpp index c6c6d3316602ec4f423a8413c633d71e8e20fb3f..271502adc002baa4285b7c129844ab0238c17306 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 @@ -457,4 +458,40 @@ 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!"); + 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."; +} } // namespace diff --git a/test/unittest/src/scenario_test/proximity_controller/BUILD.gn b/test/unittest/src/scenario_test/proximity_controller/BUILD.gn index 0ac7f7a48e0649148f8bd58c92059c7591254c76..571bc4adec33d47f70901a6baca9e7170e2bde76 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 582095a528df7b105317ff74211c380c264d30b8..c17e2b363aec77681a086e6de54016e6bf61f91e 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 986f5b6f496b4fd1c3df319c46f2115715203b65..81f75bb9c548a4533eb8095fd691406da996145e 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 543bedd723131d8edf5120990a33d6ebcd79902a..8462a27a67031b794bdcc8b0b5e5e38fd00778a7 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 { diff --git a/utils/setting/include/setting_provider.h b/utils/setting/include/setting_provider.h index a938ff821fbc9485e208263d20d56be549c32c39..52390595b630de9975594c2c6f263ee09e64c257 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 d74ae9ceee9aff1531f8d83af43887df1a382df6..e30aee4ee44bdc21ec6f0639ee653edf12557e12 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,