From 0fee661201e864a58b43b3499da2116b3f26bfe8 Mon Sep 17 00:00:00 2001 From: zhjs Date: Fri, 22 Aug 2025 15:18:32 +0800 Subject: [PATCH] !618 feat: notify poweronreason. Signed-off-by: zhjs Signed-off-by: zhongruqi --- brightness_manager/include/brightness_manager.h | 2 +- .../include/brightness_manager_ext.h | 2 +- brightness_manager/include/brightness_service.h | 2 +- brightness_manager/src/brightness_manager.cpp | 9 +++++---- brightness_manager/src/brightness_manager_ext.cpp | 6 +++--- brightness_manager/src/brightness_service.cpp | 3 ++- .../frameworks/native/display_power_mgr_client.cpp | 5 +++-- .../native/include/display_power_mgr_client.h | 4 +++- state_manager/service/IDisplayPowerMgr.idl | 2 +- .../native/include/display_power_mgr_service.h | 6 ++++-- .../native/src/display_power_mgr_service.cpp | 14 ++++++++------ .../mock/include/mock_display_power_mgr_proxy.h | 3 ++- .../mock/src/mock_display_power_mgr_proxy.cpp | 2 +- .../src/display_power_mgr_brightness_test.cpp | 6 ++++-- .../src/display_power_mgr_service_test.cpp | 3 ++- .../test/unittest/src/display_service_test.cpp | 5 +++-- 16 files changed, 44 insertions(+), 30 deletions(-) diff --git a/brightness_manager/include/brightness_manager.h b/brightness_manager/include/brightness_manager.h index a5b7894..ce6f95c 100644 --- a/brightness_manager/include/brightness_manager.h +++ b/brightness_manager/include/brightness_manager.h @@ -56,7 +56,7 @@ public: void SetDisplayId(uint32_t id = 0); bool SetMaxBrightness(double value); bool SetMaxBrightnessNit(uint32_t nit); - int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status); + int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status, uint32_t reason); private: BrightnessManager() = default; diff --git a/brightness_manager/include/brightness_manager_ext.h b/brightness_manager/include/brightness_manager_ext.h index 0a342dd..8a5d198 100644 --- a/brightness_manager/include/brightness_manager_ext.h +++ b/brightness_manager/include/brightness_manager_ext.h @@ -56,7 +56,7 @@ public: uint32_t SetLightBrightnessThreshold(std::vector threshold, sptr callback); bool SetMaxBrightness(double value); bool SetMaxBrightnessNit(uint32_t maxNit); - int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status); + int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status, uint32_t reason); private: bool LoadBrightnessExtLibrary(); diff --git a/brightness_manager/include/brightness_service.h b/brightness_manager/include/brightness_service.h index 4e9dc4c..da618ab 100644 --- a/brightness_manager/include/brightness_service.h +++ b/brightness_manager/include/brightness_service.h @@ -151,7 +151,7 @@ public: int GetSensorIdWithDisplayMode(Rosen::FoldDisplayMode mode); uint32_t GetCurrentSensorId(); void SetCurrentSensorId(uint32_t sensorId); - int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status); + int NotifyScreenPowerStatus(uint32_t displayId, uint32_t status, uint32_t reason); static uint32_t GetSafeBrightness(uint32_t value); bool SetMaxBrightness(double value); diff --git a/brightness_manager/src/brightness_manager.cpp b/brightness_manager/src/brightness_manager.cpp index cbac464..a1aee1f 100644 --- a/brightness_manager/src/brightness_manager.cpp +++ b/brightness_manager/src/brightness_manager.cpp @@ -263,14 +263,15 @@ bool BrightnessManager::SetMaxBrightnessNit(uint32_t nit) #endif } -int BrightnessManager::NotifyScreenPowerStatus(uint32_t displayId, uint32_t status) +int BrightnessManager::NotifyScreenPowerStatus(uint32_t displayId, uint32_t status, uint32_t reason) { DISPLAY_HILOGI(FEAT_BRIGHTNESS, - "BrightnessManager::NotifyScreenPowerStatus displayId:%{public}u, status:%{public}u", displayId, status); + "BrightnessManager::NotifyScreenPowerStatus displayId:%{public}u, status:%{public}u"\ + "reason:%{public}u", displayId, status, reason); #ifdef OHOS_BUILD_ENABLE_BRIGHTNESS_WRAPPER - return mBrightnessManagerExt.NotifyScreenPowerStatus(displayId, status); + return mBrightnessManagerExt.NotifyScreenPowerStatus(displayId, status, reason); #else - return BrightnessService::Get().NotifyScreenPowerStatus(displayId, status); + return BrightnessService::Get().NotifyScreenPowerStatus(displayId, status, reason); #endif } } // namespace DisplayPowerMgr diff --git a/brightness_manager/src/brightness_manager_ext.cpp b/brightness_manager/src/brightness_manager_ext.cpp index 5d683c4..10b2d41 100644 --- a/brightness_manager/src/brightness_manager_ext.cpp +++ b/brightness_manager/src/brightness_manager_ext.cpp @@ -476,14 +476,14 @@ bool BrightnessManagerExt::SetMaxBrightnessNit(uint32_t nit) return setMaxBrightnessNitFunc(nit); } -int BrightnessManagerExt::NotifyScreenPowerStatus(uint32_t displayId, uint32_t status) +int BrightnessManagerExt::NotifyScreenPowerStatus(uint32_t displayId, uint32_t status, uint32_t reason) { if (!mBrightnessManagerExtEnable) { return -1; // -1 means return failed } auto NotifyScreenPowerStatusFunc = - reinterpret_cast(mNotifyScreenPowerStatusFunc); - return NotifyScreenPowerStatusFunc(displayId, status); + reinterpret_cast(mNotifyScreenPowerStatusFunc); + return NotifyScreenPowerStatusFunc(displayId, status, reason); } } // namespace DisplayPowerMgr } // namespace OHOS \ No newline at end of file diff --git a/brightness_manager/src/brightness_service.cpp b/brightness_manager/src/brightness_service.cpp index 6646573..9107d95 100644 --- a/brightness_manager/src/brightness_service.cpp +++ b/brightness_manager/src/brightness_service.cpp @@ -1252,7 +1252,8 @@ bool BrightnessService::SetMaxBrightnessNit(uint32_t maxNit) return UpdateBrightness(mCurrentBrightness.load(), DEFAULT_MAX_BRIGHTNESS_DURATION, true); } -int BrightnessService::NotifyScreenPowerStatus([[maybe_unused]] uint32_t displayId, [[maybe_unused]] uint32_t status) +int BrightnessService::NotifyScreenPowerStatus([[maybe_unused]] uint32_t displayId, [[maybe_unused]] uint32_t status, + [[maybe_unused]] uint32_t reason) { DISPLAY_HILOGI(FEAT_BRIGHTNESS, "NotifyScreenPowerStatusify"); return 0; diff --git a/state_manager/frameworks/native/display_power_mgr_client.cpp b/state_manager/frameworks/native/display_power_mgr_client.cpp index 4a07c9e..0c505b3 100644 --- a/state_manager/frameworks/native/display_power_mgr_client.cpp +++ b/state_manager/frameworks/native/display_power_mgr_client.cpp @@ -437,12 +437,13 @@ bool DisplayPowerMgrClient::SetMaxBrightnessNit(uint32_t maxNit, uint32_t enterT return result; } -int DisplayPowerMgrClient::NotifyBrightnessManagerScreenPowerStatus(uint32_t displayId, uint32_t status) +int DisplayPowerMgrClient::NotifyBrightnessManagerScreenPowerStatus(uint32_t displayId, uint32_t status, + uint32_t reason) { auto proxy = GetProxy(); RETURN_IF_WITH_RET(proxy == nullptr, -1); // -1 means failed int32_t result = DEFAULT_VALUE; - auto ret = proxy->NotifyScreenPowerStatus(displayId, status, result); + auto ret = proxy->NotifyScreenPowerStatus(displayId, status, reason, result); if (ret != ERR_OK) { DISPLAY_HILOGE(COMP_FWK, "NotifyBrightnessManagerScreenPowerStatus, ret = %{public}d", ret); return DEFAULT_VALUE; diff --git a/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h b/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h index aa5d0b5..aa6a6f7 100644 --- a/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h +++ b/state_manager/interfaces/inner_api/native/include/display_power_mgr_client.h @@ -60,7 +60,8 @@ public: bool SetCoordinated(bool coordinated, uint32_t displayId = 0); uint32_t SetLightBrightnessThreshold(std::vector threshold, sptr callback); DisplayErrors GetError(); - int NotifyBrightnessManagerScreenPowerStatus(uint32_t displayId, uint32_t status); + int NotifyBrightnessManagerScreenPowerStatus(uint32_t displayId, uint32_t status, + uint32_t reason); #ifndef DISPLAY_SERVICE_DEATH_UT private: @@ -82,6 +83,7 @@ private: void OnRemoteDied(const wptr& remote); static constexpr int32_t INVALID_DISPLAY_ID {-1}; static constexpr int32_t DEFAULT_MAIN_DISPLAY_ID {0}; + static constexpr uint32_t DEFAULT_NOTIFY_REASON {0}; static constexpr uint32_t BRIGHTNESS_OFF {0}; static constexpr uint32_t BRIGHTNESS_DEFAULT {102}; static constexpr uint32_t BRIGHTNESS_MAX {255}; diff --git a/state_manager/service/IDisplayPowerMgr.idl b/state_manager/service/IDisplayPowerMgr.idl index a09a134..bbd57ef 100644 --- a/state_manager/service/IDisplayPowerMgr.idl +++ b/state_manager/service/IDisplayPowerMgr.idl @@ -48,6 +48,6 @@ interface OHOS.DisplayPowerMgr.IDisplayPowerMgr { void SetMaxBrightnessNit([in] unsigned int maxNit, [in] unsigned int enterTestMode, [out] boolean bResult, [out] int retCode); void NotifyScreenPowerStatus([in] unsigned int displayId, [in] unsigned int displayPowerStatus, - [out] int retCode); + [in] unsigned int reason, [out] int retCode); void SetScreenOnBrightness([out] boolean bResult); } \ No newline at end of file diff --git a/state_manager/service/native/include/display_power_mgr_service.h b/state_manager/service/native/include/display_power_mgr_service.h index e2522ac..7884522 100644 --- a/state_manager/service/native/include/display_power_mgr_service.h +++ b/state_manager/service/native/include/display_power_mgr_service.h @@ -74,7 +74,8 @@ public: int32_t SetLightBrightnessThreshold(const std::vector& threshold, const sptr& callback, uint32_t& result) override; int32_t SetScreenOnBrightness(bool& result) override; - int32_t NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, int32_t& result) override; + int32_t NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, + uint32_t reason, int32_t& result) override; private: bool SetDisplayStateInner(uint32_t id, DisplayState state, uint32_t reason); DisplayState GetDisplayStateInner(uint32_t id); @@ -102,7 +103,8 @@ private: bool SetCoordinatedInner(bool coordinated, uint32_t displayId); uint32_t SetLightBrightnessThresholdInner( std::vector threshold, sptr callback); - int NotifyScreenPowerStatusInner(uint32_t displayId, uint32_t displayPowerStatus); + int NotifyScreenPowerStatusInner(uint32_t displayId, uint32_t displayPowerStatus, + uint32_t reason); public: DisplayErrors GetError(); virtual int32_t Dump(int32_t fd, const std::vector& args) override; diff --git a/state_manager/service/native/src/display_power_mgr_service.cpp b/state_manager/service/native/src/display_power_mgr_service.cpp index 7b4d929..da56bf8 100644 --- a/state_manager/service/native/src/display_power_mgr_service.cpp +++ b/state_manager/service/native/src/display_power_mgr_service.cpp @@ -710,15 +710,17 @@ bool DisplayPowerMgrService::SetMaxBrightnessNitInner(uint32_t maxNit, uint32_t return BrightnessManager::Get().SetMaxBrightnessNit(maxNit); } -int DisplayPowerMgrService::NotifyScreenPowerStatusInner(uint32_t displayId, uint32_t displayPowerStatus) +int DisplayPowerMgrService::NotifyScreenPowerStatusInner(uint32_t displayId, uint32_t displayPowerStatus, + uint32_t reason) { if (!Permission::IsSystem()) { lastError_ = DisplayErrors::ERR_SYSTEM_API_DENIED; return -1; // -1 means failed } - DISPLAY_HILOGI(COMP_SVC, "[UL_POWER]NotifyScreenPowerStatus displayId=%{public}u, Status=%{public}u", displayId, - displayPowerStatus); - return BrightnessManager::Get().NotifyScreenPowerStatus(displayId, displayPowerStatus); + DISPLAY_HILOGI(COMP_SVC, "[UL_POWER]NotifyScreenPowerStatus displayId=%{public}u,"\ + "Status=%{public}u,reason=%{public}u", displayId, displayPowerStatus, reason); + return BrightnessManager::Get().NotifyScreenPowerStatus(displayId, displayPowerStatus, + reason); } int32_t DisplayPowerMgrService::SetDisplayState(uint32_t id, uint32_t state, uint32_t reason, bool& result) @@ -905,10 +907,10 @@ int32_t DisplayPowerMgrService::SetScreenOnBrightness(bool& result) } int32_t DisplayPowerMgrService::NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, - int32_t& result) + uint32_t reason, int32_t& result) { DisplayXCollie displayXCollie("DisplayPowerMgrService::NotifyScreenPowerStatus"); - result = NotifyScreenPowerStatusInner(displayId, displayPowerStatus); + result = NotifyScreenPowerStatusInner(displayId, displayPowerStatus, reason); return ERR_OK; } } // namespace DisplayPowerMgr diff --git a/state_manager/test/unittest/mock/include/mock_display_power_mgr_proxy.h b/state_manager/test/unittest/mock/include/mock_display_power_mgr_proxy.h index fd220f4..6d51b1e 100644 --- a/state_manager/test/unittest/mock/include/mock_display_power_mgr_proxy.h +++ b/state_manager/test/unittest/mock/include/mock_display_power_mgr_proxy.h @@ -53,7 +53,8 @@ public: const sptr& displayBrightnessCallback, uint32_t& retCode) override; int32_t RegisterCallback(const sptr& displayPowercallback, bool& bResult) override; int32_t SetScreenOnBrightness(bool& bResult) override; - int32_t NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, int32_t& retCode) override; + int32_t NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, + uint32_t reason, int32_t& retCode) override; }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/state_manager/test/unittest/mock/src/mock_display_power_mgr_proxy.cpp b/state_manager/test/unittest/mock/src/mock_display_power_mgr_proxy.cpp index 690bf3d..2546f6d 100644 --- a/state_manager/test/unittest/mock/src/mock_display_power_mgr_proxy.cpp +++ b/state_manager/test/unittest/mock/src/mock_display_power_mgr_proxy.cpp @@ -151,7 +151,7 @@ int32_t MockDisplayPowerMgrProxy::SetScreenOnBrightness(bool& isResult) } int32_t MockDisplayPowerMgrProxy::NotifyScreenPowerStatus(uint32_t displayId, uint32_t displayPowerStatus, - int32_t& retCode) + uint32_t reason, int32_t& retCode) { return ERR_FAIL; } diff --git a/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp b/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp index 70c08b8..48b318b 100644 --- a/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp +++ b/state_manager/test/unittest/src/display_power_mgr_brightness_test.cpp @@ -1141,8 +1141,9 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, NotifyBrightnessManagerScreenPowerStatus DISPLAY_HILOGI(LABEL_TEST, "NotifyBrightnessManagerScreenPowerStatus001 function start!"); uint32_t displayId = 0; uint32_t screenPowerStatus = 0; // 0 represent the POWER_STATUS_ON + uint32_t reason = 0; // 0 represent the POWER_DEFAULT_REASON uint32_t result = DisplayPowerMgrClient::GetInstance().NotifyBrightnessManagerScreenPowerStatus(displayId, - screenPowerStatus); + screenPowerStatus, reason); const uint32_t FAILED_RESULT = 0; EXPECT_EQ(result, FAILED_RESULT); DISPLAY_HILOGI(LABEL_TEST, "NotifyBrightnessManagerScreenPowerStatus001 function end!"); @@ -1159,8 +1160,9 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, NotifyBrightnessManagerScreenPowerStatus DISPLAY_HILOGI(LABEL_TEST, "NotifyBrightnessManagerScreenPowerStatus002 function start!"); uint32_t displayId = 0; uint32_t screenPowerStatus = 3; // 3 represent the POWER_STATUS_OFF + uint32_t reason = 0; // 0 represent the POWER_DEFAULT_REASON uint32_t result = DisplayPowerMgrClient::GetInstance().NotifyBrightnessManagerScreenPowerStatus(displayId, - screenPowerStatus); + screenPowerStatus, reason); const uint32_t FAILED_RESULT = 0; EXPECT_EQ(result, FAILED_RESULT); DISPLAY_HILOGI(LABEL_TEST, "NotifyBrightnessManagerScreenPowerStatus002 function end!"); 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 685ad2c..6ed7105 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 @@ -1032,7 +1032,8 @@ HWTEST_F(DisplayPowerMgrServiceTest, DisplayPowerMgrClient027, TestSize.Level0) client.proxy_ = g_mockProxy; auto ret = client.NotifyBrightnessManagerScreenPowerStatus( OHOS::DisplayPowerMgr::DisplayPowerMgrClient::DEFAULT_MAIN_DISPLAY_ID, - static_cast(DisplayState::DISPLAY_ON)); + static_cast(DisplayState::DISPLAY_ON), + OHOS::DisplayPowerMgr::DisplayPowerMgrClient::DEFAULT_NOTIFY_REASON); client.proxy_ = proxy; static constexpr int32_t DEFAULT_VALUE = -1; EXPECT_EQ(ret, DEFAULT_VALUE); diff --git a/state_manager/test/unittest/src/display_service_test.cpp b/state_manager/test/unittest/src/display_service_test.cpp index 3d01b8b..5526344 100644 --- a/state_manager/test/unittest/src/display_service_test.cpp +++ b/state_manager/test/unittest/src/display_service_test.cpp @@ -378,9 +378,10 @@ HWTEST_F(DisplayServiceTest, DisplayServiceTest013, TestSize.Level1) DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest013 function start!"); EXPECT_TRUE(g_service != nullptr); int32_t errCode = 0; - int32_t displayState = 0; + int32_t displayState = 0; // 0 represent the POWER_STATUS_ON + uint32_t reason = 0; // 0 represent the POWER_DEFAULT_REASON g_service->GetDisplayState(DISPLAY_MAIN_ID, displayState); - g_service->NotifyScreenPowerStatus(DISPLAY_MAIN_ID, displayState, errCode); + g_service->NotifyScreenPowerStatus(DISPLAY_MAIN_ID, displayState, reason, errCode); EXPECT_NE(errCode, DEFAULT_VALUE); DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest013 function end!"); } -- Gitee