diff --git a/interfaces/inner_api/native/include/idisplay_power_callback.h b/interfaces/inner_api/native/include/idisplay_power_callback.h index dd98af2dcb7aea7bdf057cb1aaf6a4c37cbf215e..5af66a3b1defe6714b74d38c0253233b773cc579 100644 --- a/interfaces/inner_api/native/include/idisplay_power_callback.h +++ b/interfaces/inner_api/native/include/idisplay_power_callback.h @@ -25,7 +25,7 @@ namespace OHOS { namespace DisplayPowerMgr { class IDisplayPowerCallback : public IRemoteBroker { public: - virtual void OnDisplayStateChanged(uint32_t displayId, DisplayState state) = 0; + virtual void OnDisplayStateChanged(uint32_t displayId, DisplayState state, uint32_t reason) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IDisplayPowerCallback"); }; diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h index 87b0b0b245f9ec1fe02807385d81cef9727d8b70..2c9a37c702df107eb966fab488b9265e251aae91 100644 --- a/service/native/include/display_power_mgr_service.h +++ b/service/native/include/display_power_mgr_service.h @@ -62,7 +62,7 @@ public: virtual uint32_t GetDeviceBrightness(uint32_t displayId) override; virtual int32_t Dump(int32_t fd, const std::vector& args) override; virtual DisplayErrors GetError() override; - void NotifyStateChangeCallback(uint32_t displayId, DisplayState state); + void NotifyStateChangeCallback(uint32_t displayId, DisplayState state, uint32_t reason); void Init(); void Deinit(); static uint32_t GetSafeBrightness(uint32_t value); diff --git a/service/native/include/screen_controller.h b/service/native/include/screen_controller.h index 8a963115e6296e86e25a4fb42512fba89a7210d8..1e0974fff48f6a49aebb3aa05c73ade5997d726a 100644 --- a/service/native/include/screen_controller.h +++ b/service/native/include/screen_controller.h @@ -51,6 +51,7 @@ public: DisplayState SetDelayOffState(); DisplayState SetOnState(); bool UpdateState(DisplayState state, uint32_t reason); + bool UpdateState(DisplayState state); bool IsScreenOn(); bool SetBrightness(uint32_t value, uint32_t gradualDuration = 0); @@ -75,7 +76,7 @@ public: uint32_t GetAnimationUpdateTime() const; private: - void OnStateChanged(DisplayState state); + void OnStateChanged(DisplayState state, uint32_t reason); bool CanSetBrightness(); bool CanDiscountBrightness(); diff --git a/service/native/src/display_power_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp index fd1f0117508684a0ab0ebc3a945379d886e0d87b..e9e7678f53dee374b43c54289b603ef1939965c8 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -465,11 +465,11 @@ uint32_t DisplayPowerMgrService::GetDeviceBrightness(uint32_t displayId) return iter->second->GetDeviceBrightness(); } -void DisplayPowerMgrService::NotifyStateChangeCallback(uint32_t displayId, DisplayState state) +void DisplayPowerMgrService::NotifyStateChangeCallback(uint32_t displayId, DisplayState state, uint32_t reason) { std::lock_guard lock(mutex_); if (callback_ != nullptr) { - callback_->OnDisplayStateChanged(displayId, state); + callback_->OnDisplayStateChanged(displayId, state, reason); } } diff --git a/service/native/src/screen_controller.cpp b/service/native/src/screen_controller.cpp index 5c93a4659bde4b0c409c281cd5714c29d966b058..6f8df55471a3fbc9aa6683873777a607da864ea5 100644 --- a/service/native/src/screen_controller.cpp +++ b/service/native/src/screen_controller.cpp @@ -113,7 +113,8 @@ 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); + function callback = + bind(&ScreenController::OnStateChanged, this, placeholders::_1, reason); bool ret = action_->SetDisplayState(state, callback); if (!ret) { DISPLAY_HILOGW(FEAT_STATE, "SetDisplayState failed state=%{public}d", state); @@ -257,7 +258,7 @@ bool ScreenController::IsBrightnessBoosted() const return isBrightnessBoosted_; } -void ScreenController::OnStateChanged(DisplayState state) +void ScreenController::OnStateChanged(DisplayState state, uint32_t reason) { auto pms = DelayedSpSingleton::GetInstance(); if (pms == nullptr) { @@ -273,7 +274,7 @@ void ScreenController::OnStateChanged(DisplayState state) } if (ret) { - pms->NotifyStateChangeCallback(action_->GetDisplayId(), state); + pms->NotifyStateChangeCallback(action_->GetDisplayId(), state, reason); } } diff --git a/service/zidl/include/display_power_callback_proxy.h b/service/zidl/include/display_power_callback_proxy.h index 5bac9b8f811d422a4a001d3bf2841de66e9250ad..ac8dcd0ef5c8ebe90b87f7767397bb03512ef8c6 100644 --- a/service/zidl/include/display_power_callback_proxy.h +++ b/service/zidl/include/display_power_callback_proxy.h @@ -32,7 +32,7 @@ public: explicit DisplayPowerCallbackProxy(const sptr& impl) : IRemoteProxy(impl) {} ~DisplayPowerCallbackProxy() override = default; - virtual void OnDisplayStateChanged(uint32_t displayId, DisplayState state) override; + virtual void OnDisplayStateChanged(uint32_t displayId, DisplayState state, uint32_t reason) override; private: static inline BrokerDelegator delegator_; diff --git a/service/zidl/src/display_power_callback_proxy.cpp b/service/zidl/src/display_power_callback_proxy.cpp index c5b1d4bd39da07df7eb977515601486026a226c5..159c4669cc0d90a45c533a824dcd11fda53e74c6 100644 --- a/service/zidl/src/display_power_callback_proxy.cpp +++ b/service/zidl/src/display_power_callback_proxy.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace DisplayPowerMgr { -void DisplayPowerCallbackProxy::OnDisplayStateChanged(uint32_t displayId, DisplayState state) +void DisplayPowerCallbackProxy::OnDisplayStateChanged(uint32_t displayId, DisplayState state, uint32_t reason) { sptr remote = Remote(); RETURN_IF(remote == nullptr); @@ -40,6 +40,7 @@ void DisplayPowerCallbackProxy::OnDisplayStateChanged(uint32_t displayId, Displa WRITE_PARCEL_NO_RET(data, Uint32, displayId); WRITE_PARCEL_NO_RET(data, Uint32, static_cast(state)); + WRITE_PARCEL_NO_RET(data, Uint32, reason); int ret = remote->SendRequest( static_cast(PowerMgr::DisplayPowerCallbackInterfaceCode::ON_DISPLAY_STATE_CHANGED), diff --git a/service/zidl/src/display_power_callback_stub.cpp b/service/zidl/src/display_power_callback_stub.cpp index 49ec89574792f2c1aa3a1a3a393a701850bcb84f..2546555a0cc25fa2452e1a9875b74edcafdf2e44 100644 --- a/service/zidl/src/display_power_callback_stub.cpp +++ b/service/zidl/src/display_power_callback_stub.cpp @@ -59,11 +59,13 @@ int32_t DisplayPowerCallbackStub::OnDisplayStateChangedStub(MessageParcel& data, { uint32_t id = 0; uint32_t state = 0; + uint32_t reason = 0; READ_PARCEL_WITH_RET(data, Uint32, id, E_READ_PARCEL_ERROR); READ_PARCEL_WITH_RET(data, Uint32, state, E_READ_PARCEL_ERROR); + READ_PARCEL_WITH_RET(data, Uint32, reason, E_READ_PARCEL_ERROR); - OnDisplayStateChanged(id, static_cast(state)); + OnDisplayStateChanged(id, static_cast(state), reason); return ERR_OK; } } // namespace DisplayPowerMgr diff --git a/test/unittest/include/mock/display_mock_object_test.h b/test/unittest/include/mock/display_mock_object_test.h index 369c5f8a6f283a8b04586316907e7043b15a1331..fc5df22b095041ec46905db14c4680348f9c6ca0 100644 --- a/test/unittest/include/mock/display_mock_object_test.h +++ b/test/unittest/include/mock/display_mock_object_test.h @@ -28,7 +28,8 @@ public: public: DisplayPowerMgrTestCallback() {}; virtual ~DisplayPowerMgrTestCallback() {}; - virtual void OnDisplayStateChanged(uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state) override; + virtual void OnDisplayStateChanged( + uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state, uint32_t reason) override; }; }; } // namespace PowerMgr diff --git a/test/unittest/include/mock/display_mock_parcel_test.h b/test/unittest/include/mock/display_mock_parcel_test.h index ac2aaf8decf8f35a104fd63ce702c19e3637d982..e3e07a766e837c7e0b8de16af3e13fc8fe44a68a 100644 --- a/test/unittest/include/mock/display_mock_parcel_test.h +++ b/test/unittest/include/mock/display_mock_parcel_test.h @@ -29,7 +29,8 @@ public: public: DisplayPowerMgrTestCallback() {}; virtual ~DisplayPowerMgrTestCallback() {}; - virtual void OnDisplayStateChanged(uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state) override; + virtual void OnDisplayStateChanged( + uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state, uint32_t reason) override; }; }; } // namespace PowerMgr diff --git a/test/unittest/include/mock/display_mock_test.h b/test/unittest/include/mock/display_mock_test.h index 5821d0f181080c596e9796685de7d0f0ac0e8653..79271a988297aea06b77d5410043f1dd7d3c9b8d 100644 --- a/test/unittest/include/mock/display_mock_test.h +++ b/test/unittest/include/mock/display_mock_test.h @@ -28,7 +28,8 @@ public: public: DisplayPowerMgrTestCallback() {}; virtual ~DisplayPowerMgrTestCallback() {}; - virtual void OnDisplayStateChanged(uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state) override; + virtual void OnDisplayStateChanged( + uint32_t displayId, OHOS::DisplayPowerMgr::DisplayState state, uint32_t reason) override; }; }; } // namespace PowerMgr diff --git a/test/unittest/src/mock/display_mock_object_test.cpp b/test/unittest/src/mock/display_mock_object_test.cpp index 178edf0a2a39dbe9f60f0d12384e4317a218a7e6..41e2ae7928f78c0dc8e1cf64706220ad4e6d2bb0 100644 --- a/test/unittest/src/mock/display_mock_object_test.cpp +++ b/test/unittest/src/mock/display_mock_object_test.cpp @@ -44,7 +44,7 @@ static constexpr double DISCOUNT_VALUE = 0.30; } // namespace void DisplayMockObjectTest::DisplayPowerMgrTestCallback::OnDisplayStateChanged( - uint32_t displayId, DisplayPowerMgr::DisplayState state) + uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason) { DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrTestCallback::OnDisplayStateChangedStub"); } diff --git a/test/unittest/src/mock/display_mock_parcel_test.cpp b/test/unittest/src/mock/display_mock_parcel_test.cpp index 2f2069ddd3d32bc22fdd1610d6b4ed107b389c04..08322a8879c0bb636221bbac3430631a0644246e 100644 --- a/test/unittest/src/mock/display_mock_parcel_test.cpp +++ b/test/unittest/src/mock/display_mock_parcel_test.cpp @@ -73,7 +73,7 @@ void DisplayMockParcelTest::DisplayProxyTestFunc(std::shared_ptr