diff --git a/bundle.json b/bundle.json index 785298055c68ec417eac63cb335f91d1344cd15a..a63fa30afd98de99c3053c94610751634fda4813 100644 --- a/bundle.json +++ b/bundle.json @@ -45,7 +45,8 @@ "power_manager_feature_block_long_press", "power_manager_feature_judging_takeover_shutdown", "power_manager_feature_watch_limit_screen_common_event_publish", - "power_manager_feature_watch_update_adapt" + "power_manager_feature_watch_update_adapt", + "power_manager_feature_enable_lid_check" ], "adapted_system_type": [ "standard" diff --git a/powermgr.gni b/powermgr.gni index f79802c61236e58e280c6b12ae3b3745003cc57e..2b9bfcd07b8307d7753f1743d479ebcb3db00b34 100644 --- a/powermgr.gni +++ b/powermgr.gni @@ -41,6 +41,7 @@ declare_args() { power_manager_feature_watch_update_adapt = false power_manager_feature_watch_boot_completed = false power_manager_feature_init_proximity_controller = false + power_manager_feature_enable_lid_check = false } defines = [] @@ -61,6 +62,10 @@ if (power_manager_feature_init_proximity_controller) { defines += [ "POWER_MANAGER_INIT_PROXIMITY_CONTROLLER" ] } +if (power_manager_feature_enable_lid_check) { + defines += [ "POWER_MANAGER_ENABLE_LID_CHECK" ] +} + if (!defined(global_parts_info) || defined(global_parts_info.powermgr_display_manager)) { has_display_manager_part = true diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index 42931ee9f27d52e061e891939a1edac0853ae406..3cf9447dcfbfdbe291e20b333a2c21ec65dc7a6e 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -284,7 +284,7 @@ public: return shutdownController_; } #ifdef HAS_SENSORS_SENSOR_PART - static bool isInLidMode_; + static std::atomic_bool isInLidMode_; #endif private: diff --git a/services/native/include/power_state_machine.h b/services/native/include/power_state_machine.h index 5ffc8737245615de5fddb7fa5064645e136760e7..678b433c81f257830e1d6a25b62b5f3888c5562f 100644 --- a/services/native/include/power_state_machine.h +++ b/services/native/include/power_state_machine.h @@ -131,6 +131,7 @@ public: #ifdef MSDP_MOVEMENT_ENABLE bool IsMovementStateOn(); #endif + bool IsWakeupDeviceSkip(); PowerState GetState() { diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index 202188fe9c05ab743c5f8a22567e1ddf5918f9fa..21b73d8e31896f0533b00ac4e7ceda37b317a134 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -96,7 +96,7 @@ std::atomic_bool PowerMgrService::isBootCompleted_ = false; std::atomic_bool PowerMgrService::isNeedReInit_ = false; std::atomic_bool PowerMgrService::displayManagerServiceCrash_ = false; #ifdef HAS_SENSORS_SENSOR_PART - bool PowerMgrService::isInLidMode_ = false; + std::atomic_bool PowerMgrService::isInLidMode_ = false; #endif using namespace MMI; diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index a31d5e6b1058be54dba30154300f0c4920c0f069..260dee97d3fd2efd7ac6b25f03f9663b7364adb0 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -648,6 +648,19 @@ void PowerStateMachine::HandlePreBrightWakeUp(int64_t callTimeMs, WakeupDeviceTy return; } +bool PowerStateMachine::IsWakeupDeviceSkip() +{ + bool ret = false; + ret |= !IsSwitchOpen(); +#ifdef POWER_MANAGER_POWER_ENABLE_S4 + ret |= IsHibernating(); +#endif +#ifdef POWER_MANAGER_ENABLE_LID_CHECK + ret |= PowerMgrService::isInLidMode_; +#endif + return ret; +} + void PowerStateMachine::WakeupDeviceInner( pid_t pid, int64_t callTimeMs, WakeupDeviceType type, const std::string& details, const std::string& pkgName) { @@ -659,12 +672,8 @@ void PowerStateMachine::WakeupDeviceInner( return; } -#ifdef POWER_MANAGER_POWER_ENABLE_S4 - if (!IsSwitchOpen() || IsHibernating()) { -#else - if (!IsSwitchOpen()) { -#endif - POWER_HILOGI(FEATURE_WAKEUP, "Switch is closed or hibernating, wakeup device do nothing."); + if (IsWakeupDeviceSkip()) { + POWER_HILOGI(FEATURE_WAKEUP, "Switch is closed or hibernating, wakeup device skip."); return; } @@ -905,7 +914,10 @@ void PowerStateMachine::RestoreHibernate(bool clearMemory, HibernateStatus statu switchOpen_ = true; } hibernating_ = false; - notify->PublishExitHibernateEvent(GetTickCount(), clearMemory); + + if (notify) { + notify->PublishExitHibernateEvent(GetTickCount(), clearMemory); + } if (!SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_SYSTEM, true)) { POWER_HILOGE(FEATURE_POWER_STATE, "failed to set state to awake when hibernate."); diff --git a/services/native/src/suspend/suspend_controller.cpp b/services/native/src/suspend/suspend_controller.cpp index 5cce7a29def1fbb3825083a210f9125e8eb62573..7df79ac5c0dfffc5a06ebfa80cbe5d367bd28933 100644 --- a/services/native/src/suspend/suspend_controller.cpp +++ b/services/native/src/suspend/suspend_controller.cpp @@ -393,7 +393,11 @@ bool SuspendController::GetPowerkeyDownWhenScreenOff() void SuspendController::SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t action, uint32_t delay) { +#ifdef POWER_MANAGER_ENABLE_LID_CHECK + if (reason != SuspendDeviceType::SUSPEND_DEVICE_REASON_LID) { +#else if (reason != SuspendDeviceType::SUSPEND_DEVICE_REASON_SWITCH) { +#endif POWER_HILOGI(FEATURE_SUSPEND, "SuspendWhenScreenOff: Do nothing for reason %{public}u", reason); return; } @@ -418,7 +422,11 @@ void SuspendController::SuspendWhenScreenOff(SuspendDeviceType reason, uint32_t SystemSuspendController::GetInstance().Wakeup(); StartSleepTimer(reason, action, 0); } else if (sleepType_ == static_cast(SuspendAction::ACTION_FORCE_SUSPEND)) { +#ifdef POWER_MANAGER_ENABLE_LID_CHECK + if (PowerMgrService::isInLidMode_ == false) { +#else if (stateMachine_->IsSwitchOpen()) { +#endif POWER_HILOGI(FEATURE_SUSPEND, "switch off event is ignored."); return; } diff --git a/services/native/src/wakeup/wakeup_controller.cpp b/services/native/src/wakeup/wakeup_controller.cpp index b168796b053f411530c6f60a8975381a95a9b94c..5d1e58212044210edbb82b280f2db9f5137ecd82 100644 --- a/services/native/src/wakeup/wakeup_controller.cpp +++ b/services/native/src/wakeup/wakeup_controller.cpp @@ -853,7 +853,12 @@ void WakeupController::ProcessPowerOnInternalScreenOnly(const sptr& pms, WakeupDeviceType reason) const { - bool skipWakeup = !stateMachine_->IsSwitchOpen(); + bool skipWakeup = false; +#ifdef POWER_MANAGER_ENABLE_LID_CHECK + skipWakeup = PowerMgrService::isInLidMode_; +#else + skipWakeup = !stateMachine_->IsSwitchOpen(); +#endif #ifdef POWER_MANAGER_ENABLE_EXTERNAL_SCREEN_MANAGEMENT skipWakeup = skipWakeup && (stateMachine_->GetExternalScreenNumber() <= 0); #endif diff --git a/test/unittest/src/native_power_state_machine_test.cpp b/test/unittest/src/native_power_state_machine_test.cpp index 89859eb9e2609770a9af8ebf96bfd80ea766e48f..6a3d2f40253e6043a81ce5b9e5140890e0407acc 100644 --- a/test/unittest/src/native_power_state_machine_test.cpp +++ b/test/unittest/src/native_power_state_machine_test.cpp @@ -234,6 +234,8 @@ HWTEST_F(NativePowerStateMachineTest, NativePowerStateMachine004, TestSize.Level stateMachine->WakeupDeviceInner(PID, CALLTIMEMS, type, "7", "7"); type = WakeupDeviceType::WAKEUP_DEVICE_PICKUP; stateMachine->WakeupDeviceInner(PID, CALLTIMEMS, type, "7", "7"); + + stateMachine->SetSwitchState(false); type = WakeupDeviceType::WAKEUP_DEVICE_UNKNOWN; stateMachine->WakeupDeviceInner(PID, CALLTIMEMS, type, "7", "7"); stateMachine->WakeupDeviceInner(PID, CALLTIMEMS, static_cast(MAXTYPE), "7", "7");