From b589b6d696464ab1678d66c408a88b6fad3e6296 Mon Sep 17 00:00:00 2001 From: volcano6322 Date: Thu, 21 Mar 2024 23:48:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=98=BE=E7=A4=BA=E7=94=B5=E6=BA=90?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=94=AF=E6=8C=81=E9=A2=84=E4=BA=AE=E5=B1=8F?= =?UTF-8?q?=E5=8F=8A=E5=90=8E=E7=BB=AD=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: volcano6322 --- .../service/native/include/screen_action.h | 5 ++ .../native/include/screen_controller.h | 1 + .../service/native/src/screen_action.cpp | 43 ++++++++-- .../service/native/src/screen_controller.cpp | 45 ++++++++-- .../src/display_power_mgr_service_test.cpp | 82 +++++++++++++++++++ 5 files changed, 161 insertions(+), 15 deletions(-) diff --git a/state_manager/service/native/include/screen_action.h b/state_manager/service/native/include/screen_action.h index 116990f..b25fcf4 100644 --- a/state_manager/service/native/include/screen_action.h +++ b/state_manager/service/native/include/screen_action.h @@ -22,6 +22,8 @@ #include #include +#include "dm_common.h" +#include "display_manager.h" #include "display_power_info.h" namespace OHOS { @@ -41,6 +43,7 @@ public: uint32_t GetBrightness(); bool SetBrightness(uint32_t value); void SetCoordinated(bool coordinated); + bool EnableSkipSetDisplayState(uint32_t reason); private: static constexpr uint32_t DEFAULT_DISPLAY_ID = 0; @@ -48,6 +51,8 @@ private: uint32_t brightness_ {102}; uint32_t displayId_ {DEFAULT_DISPLAY_ID}; bool coordinated_ {false}; + bool skipSetDisplayState_ {false}; + Rosen::PowerStateChangeReason ParseSpecialReason(uint32_t reason); }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/state_manager/service/native/include/screen_controller.h b/state_manager/service/native/include/screen_controller.h index 9aa4a1a..d60a7cf 100644 --- a/state_manager/service/native/include/screen_controller.h +++ b/state_manager/service/native/include/screen_controller.h @@ -82,6 +82,7 @@ private: bool CanDiscountBrightness(); bool CanOverrideBrightness(); bool CanBoostBrightness(); + bool IsNeedSkipNextProc(uint32_t reason); bool UpdateBrightness(uint32_t value, uint32_t gradualDuration = 0, bool updateSetting = false); void SetSettingBrightness(uint32_t value); uint32_t GetSettingBrightness(const std::string& key = SETTING_BRIGHTNESS_KEY) const; diff --git a/state_manager/service/native/src/screen_action.cpp b/state_manager/service/native/src/screen_action.cpp index 0f5662f..d4fc9bb 100644 --- a/state_manager/service/native/src/screen_action.cpp +++ b/state_manager/service/native/src/screen_action.cpp @@ -18,8 +18,6 @@ #include #include -#include "dm_common.h" -#include "display_manager.h" #include "display_log.h" #include "power_state_machine_info.h" #include "screen_manager.h" @@ -83,6 +81,14 @@ DisplayState ScreenAction::GetDisplayState() return state; } +bool ScreenAction::EnableSkipSetDisplayState(uint32_t reason) +{ + if (reason == static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS)) { + return true; + } + return false; +} + bool ScreenAction::SetDisplayState(DisplayState state, const std::function& callback) { DISPLAY_HILOGI(FEAT_STATE, "[UL_POWER] SetDisplayState displayId=%{public}u, state=%{public}u", displayId_, @@ -122,6 +128,34 @@ bool ScreenAction::SetDisplayState(DisplayState state, const std::function(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT; + break; + case static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_ON): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_ON; + break; + case static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS; + break; + case static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF; + break; + case static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_SWITCH): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_SWITCH; + break; + case static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_POWER_KEY): + changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_POWER_KEY; + break; + default: + break; + } + return changeReason; +} + bool ScreenAction::SetDisplayPower(DisplayState state, uint32_t reason) { DISPLAY_HILOGI(FEAT_STATE, "[UL_POWER] SetDisplayPower displayId=%{public}u, state=%{public}u, reason=%{public}u", @@ -145,14 +179,11 @@ bool ScreenAction::SetDisplayPower(DisplayState state, uint32_t reason) } bool ret = false; + auto changeReason = ParseSpecialReason(reason); if (coordinated_ && reason == static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_TIMEOUT)) { ret = Rosen::ScreenManager::GetInstance().SetSpecifiedScreenPower( displayId_, status, Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_COLLABORATION); } else { - auto changeReason = Rosen::PowerStateChangeReason::POWER_BUTTON; - if (reason == static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_SWITCH)) { - changeReason = Rosen::PowerStateChangeReason::STATE_CHANGE_REASON_SWITCH; - } ret = Rosen::ScreenManager::GetInstance().SetScreenPowerForAll(status, changeReason); } DISPLAY_HILOGI( diff --git a/state_manager/service/native/src/screen_controller.cpp b/state_manager/service/native/src/screen_controller.cpp index 554fc89..a42abca 100644 --- a/state_manager/service/native/src/screen_controller.cpp +++ b/state_manager/service/native/src/screen_controller.cpp @@ -25,6 +25,7 @@ #include "refbase.h" #include "setting_provider.h" #include "system_ability_definition.h" +#include "power_state_machine_info.h" using namespace std; using namespace OHOS::PowerMgr; @@ -100,7 +101,10 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) { DISPLAY_HILOGI(FEAT_STATE, "[UL_POWER] UpdateState, state=%{public}u, current state=%{public}u, reason=%{public}u", static_cast(state), static_cast(state_), reason); - RETURN_IF_WITH_RET(state == state_, true); + if (reason != static_cast + (PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF)) { + RETURN_IF_WITH_RET(state == state_, true); + } if (state == DisplayState::DISPLAY_DIM && state_ == DisplayState::DISPLAY_OFF) { DISPLAY_HILOGI(FEAT_STATE, "Not allowed to set DIM state."); return true; @@ -108,12 +112,16 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) switch (state) { case DisplayState::DISPLAY_ON: case DisplayState::DISPLAY_OFF: { - function callback = - bind(&ScreenController::OnStateChanged, this, placeholders::_1, reason); - bool ret = action_->SetDisplayState(state, callback); - if (!ret) { - DISPLAY_HILOGW(FEAT_STATE, "[UL_POWER] Update display state failed, state=%{public}d", state); - return ret; + if (action_->EnableSkipSetDisplayState(reason)) { + OnStateChanged(state, reason); + } else { + function callback = + bind(&ScreenController::OnStateChanged, this, placeholders::_1, reason); + bool ret = action_->SetDisplayState(state, callback); + if (!ret) { + DISPLAY_HILOGW(FEAT_STATE, "Update display state failed, state=%{public}d", state); + return ret; + } } break; } @@ -130,6 +138,12 @@ bool ScreenController::UpdateState(DisplayState state, uint32_t reason) break; } + if (IsNeedSkipNextProc(reason)) { + DISPLAY_HILOGI(FEAT_STATE, + "Need interrupt next process when updating state because of reason = %{public}d", reason); + return false; + } + lock_guard lock(mutexState_); state_ = state; stateChangeReason_ = reason; @@ -253,6 +267,16 @@ bool ScreenController::IsBrightnessBoosted() const return isBrightnessBoosted_; } +bool ScreenController::IsNeedSkipNextProc(uint32_t reason) +{ + if (reason == static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT) || + reason == static_cast( + PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF)) { + return true; + } + return false; +} + void ScreenController::OnStateChanged(DisplayState state, uint32_t reason) { auto pms = DelayedSpSingleton::GetInstance(); @@ -263,12 +287,15 @@ void ScreenController::OnStateChanged(DisplayState state, uint32_t reason) DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[UL_POWER] OnStateChanged state=%{public}d, reason=%{public}u", static_cast(state), reason); bool ret = action_->SetDisplayPower(state, reason); + if (reason == static_cast(PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT)) { + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "No need to set brightness, reason=%{public}d", reason); + return; + } if (state == DisplayState::DISPLAY_ON) { pms->SetScreenOnBrightness(); // Restore the brightness before screen off uint32_t screenOnBrightness = GetScreenOnBrightness(); - DISPLAY_HILOGI( - FEAT_BRIGHTNESS, "[UL_POWER] OnStateChanged set screenOnBrightness=%{public}d", screenOnBrightness); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "OnStateChanged set screenOnBrightness=%{public}d", screenOnBrightness); } if (ret) { diff --git a/state_manager/test/unittest/src/display_power_mgr_service_test.cpp b/state_manager/test/unittest/src/display_power_mgr_service_test.cpp index e6d7956..b462244 100644 --- a/state_manager/test/unittest/src/display_power_mgr_service_test.cpp +++ b/state_manager/test/unittest/src/display_power_mgr_service_test.cpp @@ -363,4 +363,86 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService021, TestSize.Level0) DisplayState::DISPLAY_OFF, PowerMgr::StateChangeReason::STATE_CHANGE_REASON_TIMEOUT); EXPECT_TRUE(ret); } + +/** + * @tc.name: DisplayPowerMgrService022 + * @tc.desc: Test set display state in Pre-light the screen + * @tc.type: FUNCs + * @tc.require: issue#I9AJ1S + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService022, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrService022 is start"); + DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); + DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + DisplayState currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); + + bool ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON, + PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT); + EXPECT_FALSE(ret); + currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); +} + +/** + * @tc.name: DisplayPowerMgrService023 + * @tc.desc: Test set display state in Pre-light the screen and auth success + * @tc.type: FUNC + * @tc.require: issue#I9AJ1S + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService023, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrService023 is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + DisplayState currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); + + ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON, + PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS); + EXPECT_TRUE(ret); + currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_ON); +} + +/** + * @tc.name: DisplayPowerMgrService024 + * @tc.desc: Test set display state in Pre-light the screen and auth failed but screen on + * @tc.type: FUNC + * @tc.require: issue#I9AJ1S + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService024, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrService024 is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + DisplayState currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); + + ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON, + PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_ON); + EXPECT_TRUE(ret); + currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_ON); +} + +/** + * @tc.name: DisplayPowerMgrService025 + * @tc.desc: Test set display state in Pre-light the screen and auth failed but screen on + * @tc.type: FUNC + * @tc.require: issue#I9AJ1S + */ +HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrService025, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrService025 is start"); + bool ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + DisplayState currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); + + ret = DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF, + PowerMgr::StateChangeReason::STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF); + EXPECT_FALSE(ret); + currentState = DisplayPowerMgrClient::GetInstance().GetDisplayState(); + EXPECT_TRUE(currentState == DisplayState::DISPLAY_OFF); +} + } // namespace -- Gitee