diff --git a/services/native/src/actions/default/display/device_state_action.cpp b/services/native/src/actions/default/display/device_state_action.cpp index 88e999d202471f45f19cd728813d655f23249937..4c55340c5eba41663a9b16c411fd4d88ddd8a54c 100644 --- a/services/native/src/actions/default/display/device_state_action.cpp +++ b/services/native/src/actions/default/display/device_state_action.cpp @@ -103,7 +103,7 @@ uint32_t DeviceStateAction::SetDisplayState(const DisplayState state, StateChang switch (state) { case DisplayState::DISPLAY_ON: { dispState = DisplayPowerMgr::DisplayState::DISPLAY_ON; - if (currentState == DisplayState::DISPLAY_OFF) { + if (currentState == DisplayState::DISPLAY_OFF && reason != StateChangeReason::STATE_CHANGE_REASON_SENSOR) { std::string identity = IPCSkeleton::ResetCallingIdentity(); DisplayManager::GetInstance().WakeUpBegin(PowerStateChangeReason::POWER_BUTTON); IPCSkeleton::SetCallingIdentity(identity); @@ -115,8 +115,8 @@ uint32_t DeviceStateAction::SetDisplayState(const DisplayState state, StateChang break; case DisplayState::DISPLAY_OFF: { dispState = DisplayPowerMgr::DisplayState::DISPLAY_OFF; - if (currentState == DisplayState::DISPLAY_ON - || currentState == DisplayState::DISPLAY_DIM) { + if ((currentState == DisplayState::DISPLAY_ON || currentState == DisplayState::DISPLAY_DIM) && + reason != StateChangeReason::STATE_CHANGE_REASON_SENSOR) { std::string identity = IPCSkeleton::ResetCallingIdentity(); DisplayManager::GetInstance().SuspendBegin(PowerStateChangeReason::POWER_BUTTON); IPCSkeleton::SetCallingIdentity(identity); @@ -148,7 +148,7 @@ void DeviceStateAction::RegisterCallback(std::function& callback } void DeviceStateAction::DisplayPowerCallback::OnDisplayStateChanged(uint32_t displayId, - DisplayPowerMgr::DisplayState state) + DisplayPowerMgr::DisplayState state, uint32_t reason) { POWER_HILOGD(FEATURE_POWER_STATE, "Callback: OnDisplayStateChanged"); int32_t mainDisp = DisplayPowerMgrClient::GetInstance().GetMainDisplayId(); @@ -158,16 +158,20 @@ void DeviceStateAction::DisplayPowerCallback::OnDisplayStateChanged(uint32_t dis } switch (state) { case DisplayPowerMgr::DisplayState::DISPLAY_ON: { - std::string identity = IPCSkeleton::ResetCallingIdentity(); - DisplayManager::GetInstance().WakeUpEnd(); - IPCSkeleton::SetCallingIdentity(identity); + if (StateChangeReason(reason) != StateChangeReason::STATE_CHANGE_REASON_SENSOR) { + std::string identity = IPCSkeleton::ResetCallingIdentity(); + DisplayManager::GetInstance().WakeUpEnd(); + IPCSkeleton::SetCallingIdentity(identity); + } NotifyDisplayActionDone(DISPLAY_ON_DONE); break; } case DisplayPowerMgr::DisplayState::DISPLAY_OFF: { - std::string identity = IPCSkeleton::ResetCallingIdentity(); - DisplayManager::GetInstance().SuspendEnd(); - IPCSkeleton::SetCallingIdentity(identity); + if (StateChangeReason(reason) != StateChangeReason::STATE_CHANGE_REASON_SENSOR) { + std::string identity = IPCSkeleton::ResetCallingIdentity(); + DisplayManager::GetInstance().SuspendEnd(); + IPCSkeleton::SetCallingIdentity(identity); + } NotifyDisplayActionDone(DISPLAY_OFF_DONE); break; } diff --git a/services/native/src/actions/default/display/device_state_action.h b/services/native/src/actions/default/display/device_state_action.h index 065e30c7958e31a250d8237e953c261683ba99cb..be6d27dc20fd8a18586b74394f1abc79f4d83cbe 100644 --- a/services/native/src/actions/default/display/device_state_action.h +++ b/services/native/src/actions/default/display/device_state_action.h @@ -42,7 +42,7 @@ private: class DisplayPowerCallback : public DisplayPowerMgr::DisplayPowerCallbackStub { friend DeviceStateAction; public: - void OnDisplayStateChanged(uint32_t displayId, DisplayPowerMgr::DisplayState state) override; + void OnDisplayStateChanged(uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason) override; private: void NotifyDisplayActionDone(uint32_t event); std::function notify_ {nullptr}; diff --git a/services/native/src/running_lock_mgr.cpp b/services/native/src/running_lock_mgr.cpp index 5acda0c2c79cedf1c73723a4ce0ab1856b24620a..050d5d4108046cdf301313719d06df06ee19bb8b 100644 --- a/services/native/src/running_lock_mgr.cpp +++ b/services/native/src/running_lock_mgr.cpp @@ -21,18 +21,12 @@ #include #include -#ifdef HAS_DISPLAY_MANAGER_PART -#include "dm_common.h" -#endif #include "hitrace_meter.h" #include "ffrt_utils.h" #include "power_log.h" #include "power_mgr_factory.h" #include "power_mgr_service.h" #include "system_suspend_controller.h" -#ifdef HAS_DISPLAY_MANAGER_PART -#include "screen_manager.h" -#endif using namespace std; @@ -880,10 +874,7 @@ void RunningLockMgr::ProximityController::OnClose() if (runningLock->GetValidRunningLockNum( RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGD(FEATURE_RUNNING_LOCK, "Change state to INACITVE when holding PROXIMITY LOCK"); -#ifdef HAS_DISPLAY_MANAGER_PART - Rosen::ScreenManager::GetInstance().SetScreenPowerForAll(Rosen::ScreenPowerState::POWER_OFF, - Rosen::PowerStateChangeReason::POWER_BUTTON); -#endif + stateMachine->SetState(PowerState::INACTIVE, StateChangeReason::STATE_CHANGE_REASON_SENSOR, true); } } @@ -909,10 +900,7 @@ void RunningLockMgr::ProximityController::OnAway() if (runningLock->GetValidRunningLockNum( RunningLockType::RUNNINGLOCK_PROXIMITY_SCREEN_CONTROL) > 0) { POWER_HILOGD(FEATURE_RUNNING_LOCK, "Change state to AWAKE when holding PROXIMITY LOCK"); -#ifdef HAS_DISPLAY_MANAGER_PART - Rosen::ScreenManager::GetInstance().SetScreenPowerForAll(Rosen::ScreenPowerState::POWER_ON, - Rosen::PowerStateChangeReason::POWER_BUTTON); -#endif + stateMachine->SetState(PowerState::AWAKE, StateChangeReason::STATE_CHANGE_REASON_SENSOR, true); } } diff --git a/test/systemtest/src/power_mgr_mock_system_test.cpp b/test/systemtest/src/power_mgr_mock_system_test.cpp index 59841aef4ca7774c90253c4d3033b682053ffc96..d724b64fc3d3877abeff1b23675e4819c1343da9 100644 --- a/test/systemtest/src/power_mgr_mock_system_test.cpp +++ b/test/systemtest/src/power_mgr_mock_system_test.cpp @@ -83,7 +83,7 @@ HWTEST_F(PowerMgrMockSystemTest, PowerMgrMock106, TestSize.Level2) pms->Lock(token, 0); EXPECT_EQ(pms->IsUsed(token), true); pms->MockProximity(RunningLockMgr::PROXIMITY_CLOSE); - EXPECT_EQ(PowerState::AWAKE, pms->GetState()); + EXPECT_EQ(PowerState::INACTIVE, pms->GetState()); POWER_HILOGD(LABEL_TEST, "PowerMgrMock106:End"); GTEST_LOG_(INFO) << "PowerMgrMock106: end"; diff --git a/test/systemtest/src/power_mgr_st_mock_test.cpp b/test/systemtest/src/power_mgr_st_mock_test.cpp index 3ae7dc7377f2ccec0a0ac86e88a06d55e7bff588..bf07cc2378af8a5057fad3fe8e25eadb80a43802 100644 --- a/test/systemtest/src/power_mgr_st_mock_test.cpp +++ b/test/systemtest/src/power_mgr_st_mock_test.cpp @@ -449,7 +449,7 @@ HWTEST_F(PowerMgrSTMockTest, PowerMgrMock076, TestSize.Level2) pms->Lock(token, 0); EXPECT_EQ(pms->IsUsed(token), true); pms->MockProximity(RunningLockMgr::PROXIMITY_CLOSE); - EXPECT_EQ(PowerState::AWAKE, pms->GetState()); + EXPECT_EQ(PowerState::INACTIVE, pms->GetState()); pms->SetDisplayOffTime(DEFAULT_DISPLAY_OFF_TIME); POWER_HILOGD(LABEL_TEST, "PowerMgrMock076:End"); diff --git a/test/unittest/src/device_state_action_native_test.cpp b/test/unittest/src/device_state_action_native_test.cpp index 8dcef64b3d1cd81d900cc7bfbfe1ac612c691b28..b30051b27c18d174ccd3a3e5ff27f2e0d7a4f064 100644 --- a/test/unittest/src/device_state_action_native_test.cpp +++ b/test/unittest/src/device_state_action_native_test.cpp @@ -65,12 +65,16 @@ HWTEST_F (DeviceStateActionNativeTest, DeviceStateActionNative001, TestSize.Leve EXPECT_FALSE(deviceStateAction->GetDisplayState() == DisplayState::DISPLAY_UNKNOWN); DisplayPowerMgr::DisplayState stateType = DisplayPowerMgr::DisplayState::DISPLAY_ON; - deviceStateAction->dispCallback_->OnDisplayStateChanged(DISPLAYID, stateType); - deviceStateAction->dispCallback_->OnDisplayStateChanged(DISPLAYID_A, stateType); + deviceStateAction->dispCallback_->OnDisplayStateChanged( + DISPLAYID, stateType, static_cast(StateChangeReason::STATE_CHANGE_REASON_APPLICATION)); + deviceStateAction->dispCallback_->OnDisplayStateChanged( + DISPLAYID_A, stateType, static_cast(StateChangeReason::STATE_CHANGE_REASON_APPLICATION)); stateType = DisplayPowerMgr::DisplayState::DISPLAY_OFF; - deviceStateAction->dispCallback_->OnDisplayStateChanged(DISPLAYID_A, stateType); + deviceStateAction->dispCallback_->OnDisplayStateChanged( + DISPLAYID_A, stateType, static_cast(StateChangeReason::STATE_CHANGE_REASON_APPLICATION)); stateType = DisplayPowerMgr::DisplayState::DISPLAY_UNKNOWN; - deviceStateAction->dispCallback_->OnDisplayStateChanged(DISPLAYID_A, stateType); + deviceStateAction->dispCallback_->OnDisplayStateChanged( + DISPLAYID_A, stateType, static_cast(StateChangeReason::STATE_CHANGE_REASON_APPLICATION)); stateType = static_cast(UNDISPLAYSTATE); EXPECT_TRUE(DisplayPowerMgr::DisplayPowerMgrClient::GetInstance().SetDisplayState(stateType, reason) == ActionResult::FAILED);