diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index c59de7b8a4b98fb62f4f9bd14ff571319cee9869..facdbcba80324aa5fe504d7f4d70a10bf2679a24 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -50,7 +50,7 @@ public: bool SuspendBegin(PowerStateChangeReason reason); bool SuspendEnd(); bool SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason); - bool SetDisplayState(DisplayState state, DisplayStateCallback callback); + bool SetDisplayState(DisplayState state); DisplayState GetDisplayState(uint64_t displayId); void NotifyDisplayEvent(DisplayEvent event); DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId); @@ -60,7 +60,6 @@ private: DisplayManagerAdapter() = default; ~DisplayManagerAdapter() = default; bool InitDMSProxyLocked(); - void NotifyDisplayChange(DisplayState state); static inline SingletonDelegator delegator; @@ -69,7 +68,6 @@ private: sptr dmsDeath_ = nullptr; std::map> displayMap_; DisplayId defaultDisplayId_; - DisplayStateCallback callback_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/include/display_manager_agent.h b/dm/include/display_manager_agent.h index b36947b6b2b3f5e2f3c55b68e5d4a8fb8155531d..7753ab43b6a870fab8885f75513d187e2596797e 100644 --- a/dm/include/display_manager_agent.h +++ b/dm/include/display_manager_agent.h @@ -27,6 +27,7 @@ public: ~DisplayManagerAgent() = default; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override; + virtual void NotifyDisplayStateChanged(DisplayState state) override; }; } } diff --git a/dm/include/zidl/display_manager_agent_interface.h b/dm/include/zidl/display_manager_agent_interface.h index 69f16e4501c435a11e73f85f671e0b14e1c03bd3..0c068bad4fce86af114c5668ab237e8a85b953dd 100644 --- a/dm/include/zidl/display_manager_agent_interface.h +++ b/dm/include/zidl/display_manager_agent_interface.h @@ -22,7 +22,8 @@ namespace OHOS { namespace Rosen { enum class DisplayManagerAgentType : uint32_t { - DISPLAY_POWER_EVENT_LISTENER + DISPLAY_POWER_EVENT_LISTENER, + DISPLAY_STATE_LISTENER, }; class IDisplayManagerAgent : public IRemoteBroker { @@ -31,8 +32,10 @@ public: enum { TRANS_ID_NOTIFY_DISPLAY_POWER_EVENT = 1, + TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, }; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0; + virtual void NotifyDisplayStateChanged(DisplayState state) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/dm/include/zidl/display_manager_agent_proxy.h b/dm/include/zidl/display_manager_agent_proxy.h index cb725acf98a7ad460aad80ab0ad5a2f911d5490f..92c3d311238ff9fd226cdbed7da58f6c47397039 100644 --- a/dm/include/zidl/display_manager_agent_proxy.h +++ b/dm/include/zidl/display_manager_agent_proxy.h @@ -27,6 +27,7 @@ public: ~DisplayManagerAgentProxy() = default; virtual void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override; + virtual void NotifyDisplayStateChanged(DisplayState state) override; private: static inline BrokerDelegator delegator_; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index bafc327433f04586e04af5ccce07bb24d4c013df..cfcda3a0afa727a439202331a85a824577531bfb 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -206,6 +206,7 @@ void DisplayManager::UnregisterDisplayPowerEventListener(sptr().UnregisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); + powerEventListenerAgent_ = nullptr; } WLOGFI("UnregisterDisplayPowerEventListener end"); } @@ -220,6 +221,23 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu } } +void DisplayManager::NotifyDisplayStateChanged(DisplayState state) +{ + WLOGFI("state:%{public}u", state); + std::lock_guard lock(mutex_); + if (displayStateCallback_) { + displayStateCallback_(state); + displayStateCallback_ = nullptr; + if (displayStateAgent_ != nullptr) { + SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + displayStateAgent_ = nullptr; + } + return; + } + WLOGFW("callback_ target is not set!"); +} + bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason) { return SingletonContainer::Get().WakeUpBegin(reason); @@ -278,7 +296,20 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) { WLOGFI("state:%{public}u", state); - return SingletonContainer::Get().SetDisplayState(state, callback); + { + std::lock_guard lock(mutex_); + if (displayStateCallback_ != nullptr) { + WLOGFI("previous callback not called, can't reset"); + return false; + } + displayStateCallback_ = callback; + if (displayStateAgent_ == nullptr) { + displayStateAgent_ = new DisplayManagerAgent(); + SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + } + } + return SingletonContainer::Get().SetDisplayState(state); } DisplayState DisplayManager::GetDisplayState(uint64_t displayId) diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 2e81963a8f01c76c8f10c92ad72a83ff94723feb..2205b975483d7a41aab9efa2f6d062adb84bdbfe 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -162,19 +162,13 @@ bool DisplayManagerAdapter::SetScreenPowerForAll(DisplayPowerState state, PowerS } -bool DisplayManagerAdapter::SetDisplayState(DisplayState state, DisplayStateCallback callback) +bool DisplayManagerAdapter::SetDisplayState(DisplayState state) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { return false; } - callback_ = callback; - bool ret = displayManagerServiceProxy_->SetDisplayState(state); - if (state == DisplayState::OFF) { - NotifyDisplayChange(state); - } - // TODO: NotifyDisplayChange ON when keyguard is drawn - return ret; + return displayManagerServiceProxy_->SetDisplayState(state); } DisplayState DisplayManagerAdapter::GetDisplayState(uint64_t displayId) @@ -195,15 +189,6 @@ void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event) displayManagerServiceProxy_->NotifyDisplayEvent(event); } -void DisplayManagerAdapter::NotifyDisplayChange(DisplayState state) -{ - if (callback_) { - callback_(state); - return; - } - WLOGFW("callback_ target is not set!"); -} - bool DisplayManagerAdapter::InitDMSProxyLocked() { if (!displayManagerServiceProxy_) { diff --git a/dm/src/display_manager_agent.cpp b/dm/src/display_manager_agent.cpp index 9ca4be500e8144c79b084e12fc73678b6158ddd5..135d78592da7148d75b0dc346e6c2f5d7c0937f4 100644 --- a/dm/src/display_manager_agent.cpp +++ b/dm/src/display_manager_agent.cpp @@ -23,5 +23,10 @@ void DisplayManagerAgent::NotifyDisplayPowerEvent(DisplayPowerEvent event, Event { SingletonContainer::Get().NotifyDisplayPowerEvent(event, status); } + +void DisplayManagerAgent::NotifyDisplayStateChanged(DisplayState state) +{ + SingletonContainer::Get().NotifyDisplayStateChanged(state); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/dm/src/zidl/display_manager_agent_proxy.cpp b/dm/src/zidl/display_manager_agent_proxy.cpp index 8bf4a31173460b0a61c0d2ddc32c66b24edff3b7..609f042b578cced2b28eb29b3954f2cc57a30415 100644 --- a/dm/src/zidl/display_manager_agent_proxy.cpp +++ b/dm/src/zidl/display_manager_agent_proxy.cpp @@ -47,6 +47,26 @@ void DisplayManagerAgentProxy::NotifyDisplayPowerEvent(DisplayPowerEvent event, WLOGFE("SendRequest failed"); } } + +void DisplayManagerAgentProxy::NotifyDisplayStateChanged(DisplayState state) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return; + } + + if (!data.WriteUint32(static_cast(state))) { + WLOGFE("Write DisplayState failed"); + return; + } + + if (Remote()->SendRequest(TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/dm/src/zidl/display_manager_agent_stub.cpp b/dm/src/zidl/display_manager_agent_stub.cpp index 0acc80ce5b6914f6ffb8333944900da9e682ec1c..e6899531ee5d985a9f72a27f3177c958fc878214 100644 --- a/dm/src/zidl/display_manager_agent_stub.cpp +++ b/dm/src/zidl/display_manager_agent_stub.cpp @@ -38,6 +38,11 @@ int32_t DisplayManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& d NotifyDisplayPowerEvent(event, status); break; } + case TRANS_ID_NOTIFY_DISPLAY_STATE_CHANGED: { + DisplayState state = static_cast(data.ReadUint32()); + NotifyDisplayStateChanged(state); + break; + } default: break; } diff --git a/dmserver/BUILD.gn b/dmserver/BUILD.gn index ed23069e0aa7747e424427fb99e364fa9da7a0ca..853a11d99f4c8dc180997374e4313b8b9fd50a9e 100644 --- a/dmserver/BUILD.gn +++ b/dmserver/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("libdms") { "src/abstract_display_controller.cpp", "src/abstract_screen.cpp", "src/abstract_screen_controller.cpp", + "src/display_manager_agent_controller.cpp", "src/display_manager_service.cpp", "src/display_manager_service_inner.cpp", "src/display_manager_stub.cpp", diff --git a/dmserver/include/display_manager_agent_controller.h b/dmserver/include/display_manager_agent_controller.h new file mode 100644 index 0000000000000000000000000000000000000000..dec0d87f9a46e558b3e771f927d480574d06cbf6 --- /dev/null +++ b/dmserver/include/display_manager_agent_controller.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H +#define OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H + +#include +#include "wm_single_instance.h" +#include "client_agent_container.h" +#include "zidl/display_manager_agent_interface.h" + +namespace OHOS { +namespace Rosen { +class DisplayManagerAgentController { +WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAgentController) +public: + void RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type); + void UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type); + + bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + bool NotifyDisplayStateChanged(DisplayState state); + +private: + DisplayManagerAgentController() : dmAgentContainer_(mutex_) {} + virtual ~DisplayManagerAgentController() = default; + + std::mutex mutex_; + ClientAgentContainer dmAgentContainer_; +}; +} +} +#endif // OHOS_ROSEN_DISPLAY_MANAGER_AGENT_CONTROLLER_H diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index fbbefa7ae33464928202eaa96607093034581db5..898c3cab4d4951f2e0a316ca3fd95ef24acad066 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -29,24 +29,11 @@ #include "abstract_screen_controller.h" #include "display_manager_stub.h" #include "display_power_controller.h" -#include "wm_single_instance.h" #include "singleton_delegator.h" namespace OHOS::Rosen { -class DMAgentDeathRecipient : public IRemoteObject::DeathRecipient { -public: - DMAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~DMAgentDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - class DisplayManagerService : public SystemAbility, public DisplayManagerStub { DECLARE_SYSTEM_ABILITY(DisplayManagerService); - WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService); public: @@ -72,6 +59,7 @@ public: DisplayState GetDisplayState(uint64_t displayId) override; void NotifyDisplayEvent(DisplayEvent event) override; bool NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + sptr GetAbstractScreenController(); DMError AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) override; @@ -81,27 +69,13 @@ private: bool Init(); DisplayId GetDisplayIdFromScreenId(ScreenId screenId); ScreenId GetScreenIdFromDisplayId(DisplayId displayId); - void RemoveDisplayManagerAgent(const sptr& remoteObject); - bool UnregisterDisplayManagerAgent(std::vector>& displayManagerAgents, - const sptr& displayManagerAgent); - struct finder_t { - finder_t(sptr remoteObject) : remoteObject_(remoteObject) {} - bool operator()(sptr displayManagerAgent) - { - return displayManagerAgent->AsObject() == remoteObject_; - } - sptr remoteObject_; - }; std::recursive_mutex mutex_; static inline SingletonDelegator delegator_; std::map> abstractDisplayMap_; sptr abstractScreenController_; sptr abstractDisplayController_; DisplayPowerController displayPowerController_; - std::map> > displayManagerAgentMap_; - sptr dmAgentDeath_ = new DMAgentDeathRecipient( - std::bind(&DisplayManagerService::RemoveDisplayManagerAgent, this, std::placeholders::_1)); std::map> displayNodeMap_; }; } // namespace OHOS::Rosen diff --git a/dmserver/src/display_manager_agent_controller.cpp b/dmserver/src/display_manager_agent_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff46111ccff2896c6d19b3480c162e84945d2469 --- /dev/null +++ b/dmserver/src/display_manager_agent_controller.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "display_manager_agent_controller.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAgentController"}; +} +WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAgentController) + +void DisplayManagerAgentController::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type) +{ + std::lock_guard lock(mutex_); + dmAgentContainer_.RegisterAgentLocked(displayManagerAgent, type); +} + +void DisplayManagerAgentController::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, + DisplayManagerAgentType type) +{ + std::lock_guard lock(mutex_); + dmAgentContainer_.UnregisterAgentLocked(displayManagerAgent, type); +} + +bool DisplayManagerAgentController::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) +{ + std::lock_guard lock(mutex_); + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); + if (agents.empty()) { + return false; + } + WLOGFI("NotifyDisplayPowerEvent"); + for (auto& agent : agents) { + agent->NotifyDisplayPowerEvent(event, status); + } + return true; +} + +bool DisplayManagerAgentController::NotifyDisplayStateChanged(DisplayState state) +{ + std::lock_guard lock(mutex_); + auto agents = dmAgentContainer_.GetAgentsByType(DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + if (agents.empty()) { + return false; + } + WLOGFI("NotifyDisplayStateChanged"); + for (auto& agent : agents) { + agent->NotifyDisplayStateChanged(state); + } + return true; +} +} +} \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 8c9e58bbd7581d0a926308daba4f4e67d8d7cb36..256290e13f5beea938cd11a68df6c8d5cc2bd60d 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -17,12 +17,9 @@ #include "window_manager_service.h" #include -#include - -#include #include #include - +#include "display_manager_agent_controller.h" #include "window_manager_hilog.h" #include "transaction/rs_interfaces.h" @@ -138,99 +135,49 @@ void DisplayManagerService::RegisterDisplayManagerAgent(const sptr lock(mutex_); - displayManagerAgentMap_[type].push_back(displayManagerAgent); - WLOGFI("agent registered"); - if (dmAgentDeath_ == nullptr) { - WLOGFI("death Recipient is nullptr"); - return; - } - if (!displayManagerAgent->AsObject()->AddDeathRecipient(dmAgentDeath_)) { - WLOGFI("failed to add death recipient"); - } + DisplayManagerAgentController::GetInstance().RegisterDisplayManagerAgent(displayManagerAgent, type); } void DisplayManagerService::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { - if (displayManagerAgent == nullptr || displayManagerAgentMap_.count(type) == 0) { + if ((displayManagerAgent == nullptr) || (displayManagerAgent->AsObject() == nullptr)) { WLOGFE("displayManagerAgent invalid"); return; } - std::lock_guard lock(mutex_); - auto& displayManagerAgents = displayManagerAgentMap_.at(type); - UnregisterDisplayManagerAgent(displayManagerAgents, displayManagerAgent->AsObject()); -} - -bool DisplayManagerService::UnregisterDisplayManagerAgent(std::vector>& displayManagerAgents, - const sptr& displayManagerAgent) -{ - auto iter = std::find_if(displayManagerAgents.begin(), displayManagerAgents.end(), - finder_t(displayManagerAgent)); - if (iter == displayManagerAgents.end()) { - WLOGFE("could not find this listener"); - return false; - } - displayManagerAgents.erase(iter); - WLOGFI("agent unregistered"); - return true; -} - -void DisplayManagerService::RemoveDisplayManagerAgent(const sptr& remoteObject) -{ - WLOGFI("RemoveDisplayManagerAgent"); - std::lock_guard lock(mutex_); - for (auto& elem : displayManagerAgentMap_) { - if (UnregisterDisplayManagerAgent(elem.second, remoteObject)) { - break; - } - } - remoteObject->RemoveDeathRecipient(dmAgentDeath_); -} - -bool DisplayManagerService::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) -{ - if (displayManagerAgentMap_.count(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER) == 0) { - WLOGFI("no display power event agent registered!"); - return false; - } - WLOGFI("NotifyDisplayPowerEvent"); - for (auto& agent : displayManagerAgentMap_.at(DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER)) { - agent->NotifyDisplayPowerEvent(event, status); - } - return true; + DisplayManagerAgentController::GetInstance().UnregisterDisplayManagerAgent(displayManagerAgent, type); } bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::BEGIN); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, + EventStatus::BEGIN); } bool DisplayManagerService::WakeUpEnd() { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, EventStatus::END); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::WAKE_UP, + EventStatus::END); } bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason) { - std::lock_guard lock(mutex_); displayPowerController_.SuspendBegin(reason); - return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::BEGIN); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, + EventStatus::BEGIN); } bool DisplayManagerService::SuspendEnd() { - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, EventStatus::END); + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::SLEEP, + EventStatus::END); } bool DisplayManagerService::SetScreenPowerForAll(DisplayPowerState state, PowerStateChangeReason reason) { WLOGFI("SetScreenPowerForAll"); - std::lock_guard lock(mutex_); - return NotifyDisplayPowerEvent(state == DisplayPowerState::POWER_ON ? DisplayPowerEvent::DISPLAY_ON : + return DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent( + state == DisplayPowerState::POWER_ON ? DisplayPowerEvent::DISPLAY_ON : DisplayPowerEvent::DISPLAY_OFF, EventStatus::END); } @@ -257,22 +204,6 @@ sptr DisplayManagerService::GetAbstractScreenControlle return abstractScreenController_; } -void DMAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("call OnRemoteDied callback"); - callback_(object); -} - DMError DisplayManagerService::AddMirror(ScreenId mainScreenId, ScreenId mirrorScreenId) { if (mainScreenId == SCREEN_ID_INVALID) { diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp index 6f7531da3667cfe83d0196a1c641295d6d7de98f..225c19aadd759e367fc749c6f2ec78e16b80cfcf 100644 --- a/dmserver/src/display_power_controller.cpp +++ b/dmserver/src/display_power_controller.cpp @@ -14,8 +14,7 @@ */ #include "display_power_controller.h" -#include "display_manager_service.h" -//#include "window_manager_service_inner.h" +#include "display_manager_agent_controller.h" #include "window_manager_hilog.h" namespace OHOS { @@ -41,19 +40,23 @@ bool DisplayPowerController::SetDisplayState(DisplayState state) switch (state) { case DisplayState::ON: { // TODO: open vsync and SendSystemEvent to keyguard - DisplayManagerService::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON, + displayState_ = state; + DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON, EventStatus::BEGIN); break; } case DisplayState::OFF: { displayState_ = state; - DisplayManagerService::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF, + DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_OFF, EventStatus::BEGIN); break; } - default: + default: { WLOGFW("unknown DisplayState!"); + return false; + } } + DisplayManagerAgentController::GetInstance().NotifyDisplayStateChanged(state); return true; } diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index cc202640b042168a772b00501ebd30f85e49d07c..402f3181ec43212642c3a2ade16a8731d0094631 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -67,12 +67,15 @@ private: bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth); void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); + void NotifyDisplayStateChanged(DisplayState state); static inline SingletonDelegator delegator; const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K std::mutex mutex_; std::vector> powerEventListeners_; sptr powerEventListenerAgent_; + sptr displayStateAgent_; + DisplayStateCallback displayStateCallback_; }; } // namespace OHOS::Rosen diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index aacbca50fcdc943b105a1fc31a16aa74a01dac1d..d1ae64824e1fb7021b49d17d73ad0a6a6a93b7ff 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Rosen { constexpr int32_t INVALID_DISPLAY_ID = -1; enum class PowerStateChangeReason : uint32_t { - POWER_BUTTON + POWER_BUTTON, }; enum class DisplayPowerState : uint32_t { @@ -31,17 +31,18 @@ enum class DisplayPowerState : uint32_t { POWER_SUSPEND, POWER_OFF, POWER_BUTT, - INVALID_STATE + INVALID_STATE, }; enum class DisplayState : uint32_t { ON, OFF, - UNKNOWN + UNKNOWN, }; enum class DisplayEvent : uint32_t { - UNLOCK + UNLOCK, + KEYGUARD_DRAWN, }; enum class DMError : int32_t { @@ -64,12 +65,12 @@ enum class DisplayPowerEvent : uint32_t { SLEEP, DISPLAY_ON, DISPLAY_OFF, - DESKTOP_READY + DESKTOP_READY, }; enum class EventStatus : uint32_t { BEGIN, - END + END, }; class IDisplayPowerEventListener : public RefBase { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f8a56ff343f578757c7a49ae8f775e125e09f0df..cacd977f3c941e9067cb1d88b58fcf4d2aa4ca0e 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -29,6 +29,7 @@ config("libwmutil_public_config") { ## Build libwmutil.so ohos_shared_library("libwmutil") { sources = [ + "src/agent_death_recipient.cpp", "src/display_info.cpp", "src/singleton_container.cpp", "src/window_property.cpp", diff --git a/utils/include/agent_death_recipient.h b/utils/include/agent_death_recipient.h new file mode 100644 index 0000000000000000000000000000000000000000..88865d1562fdc57e5c8f5e7996b75473d79c5aac --- /dev/null +++ b/utils/include/agent_death_recipient.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H +#define OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H + +#include + +namespace OHOS { +namespace Rosen { +class AgentDeathRecipient : public IRemoteObject::DeathRecipient { +public: + AgentDeathRecipient(std::function&)> callback = nullptr) : callback_(callback) {} + ~AgentDeathRecipient() = default; + + virtual void OnRemoteDied(const wptr& wptrDeath) override; + +private: + std::function&)> callback_; +}; +} +} +#endif // OHOS_ROSEN_AGENT_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/utils/include/client_agent_container.h b/utils/include/client_agent_container.h new file mode 100644 index 0000000000000000000000000000000000000000..3d46b4f9203780b09179692d7ac78f3c9f2c750e --- /dev/null +++ b/utils/include/client_agent_container.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_CLIENT_AGENT_MANAGER_H +#define OHOS_ROSEN_CLIENT_AGENT_MANAGER_H + +#include +#include +#include +#include "agent_death_recipient.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +template +class ClientAgentContainer { +public: + ClientAgentContainer(std::mutex& mutex); + virtual ~ClientAgentContainer() = default; + + void RegisterAgentLocked(const sptr& agent, T2 type); + void UnregisterAgentLocked(const sptr& agent, T2 type); + std::vector> GetAgentsByType(T2 type); + +private: + void RemoveAgent(const sptr& remoteObject); + bool UnregisterAgentLocked(std::vector>& agents, const sptr& agent); + + struct finder_t { + finder_t(sptr remoteObject) : remoteObject_(remoteObject) {} + + bool operator()(sptr agent) + { + return agent->AsObject() == remoteObject_; + } + + sptr remoteObject_; + }; + + std::mutex& mutex_; + std::map>> agentMap_; + sptr deathRecipient_; +}; + +template +ClientAgentContainer::ClientAgentContainer(std::mutex& mutex) + : mutex_(mutex), deathRecipient_(new AgentDeathRecipient( + std::bind(&ClientAgentContainer::RemoveAgent, this, std::placeholders::_1))) {} + +template +void ClientAgentContainer::RegisterAgentLocked(const sptr& agent, T2 type) +{ + agentMap_[type].push_back(agent); + WLOG_I("ClientAgentContainer agent registered type:%{public}u", type); + if (deathRecipient_ == nullptr) { + WLOG_I("death Recipient is nullptr"); + return; + } + if (!agent->AsObject()->AddDeathRecipient(deathRecipient_)) { + WLOG_I("ClientAgentContainer failed to add death recipient"); + } +} + +template +void ClientAgentContainer::UnregisterAgentLocked(const sptr& agent, T2 type) +{ + if (agent == nullptr || agentMap_.count(type) == 0) { + WLOG_E("ClientAgentContainer agent or type is invalid"); + return; + } + auto& agents = agentMap_.at(type); + UnregisterAgentLocked(agents, agent->AsObject()); + agent->AsObject()->RemoveDeathRecipient(deathRecipient_); +} + +template +std::vector> ClientAgentContainer::GetAgentsByType(T2 type) +{ + if (agentMap_.count(type) == 0) { + WLOG_E("no such type of agent registered! type:%{public}u", type); + return std::vector>(); + } + return agentMap_.at(type); +} + +template +bool ClientAgentContainer::UnregisterAgentLocked(std::vector>& agents, + const sptr& agent) +{ + auto iter = std::find_if(agents.begin(), agents.end(), finder_t(agent)); + if (iter == agents.end()) { + WLOG_W("ClientAgentContainer could not find this agent"); + return false; + } + agents.erase(iter); + WLOG_I("ClientAgentContainer agent unregistered"); + return true; +} + +template +void ClientAgentContainer::RemoveAgent(const sptr& remoteObject) +{ + WLOG_I("ClientAgentContainer RemoveAgent"); + std::lock_guard lock(mutex_); + for (auto& elem : agentMap_) { + if (UnregisterAgentLocked(elem.second, remoteObject)) { + break; + } + } + remoteObject->RemoveDeathRecipient(deathRecipient_); +} +} +} +#endif // OHOS_ROSEN_CLIENT_AGENT_MANAGER_H diff --git a/utils/src/agent_death_recipient.cpp b/utils/src/agent_death_recipient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..917c1517af3bb49a56f29834c52159e4e3cd503d --- /dev/null +++ b/utils/src/agent_death_recipient.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "agent_death_recipient.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AgentDeathRecipient"}; +} + +void AgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) +{ + if (wptrDeath == nullptr) { + WLOGFE("wptrDeath is null"); + return; + } + + sptr object = wptrDeath.promote(); + if (!object) { + WLOGFE("object is null"); + return; + } + if (callback_ != nullptr) { + WLOGFI("call OnRemoteDied callback"); + callback_(object); + } +} +} +} \ No newline at end of file diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 7182f9bdc22f8f0ca420657f91191868dfba6b5e..461710915c7705cde8bf4ebd9716c5486ce4f8cd 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("libwms") { "../dmserver/src/abstract_display_controller.cpp", "../dmserver/src/abstract_screen.cpp", "../dmserver/src/abstract_screen_controller.cpp", + "../dmserver/src/display_manager_agent_controller.cpp", "../dmserver/src/display_manager_service.cpp", "../dmserver/src/display_manager_service_inner.cpp", "../dmserver/src/display_manager_stub.cpp", @@ -49,6 +50,7 @@ ohos_shared_library("libwms") { "src/window_controller.cpp", "src/window_inner_manager.cpp", "src/window_layout_policy.cpp", + "src/window_manager_agent_controller.cpp", "src/window_manager_service.cpp", "src/window_manager_service_inner.cpp", "src/window_manager_stub.cpp", diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index c40fc70164db200e85f910b76e1b4417267a4e0d..83d6aa82155afa8020edd7df6f61887f5641b193 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -43,11 +43,6 @@ public: std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError MinimizeAllAppNodeAbility(uint32_t windowId); - void RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - void UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - private: uint32_t GenWindowId(); diff --git a/wmserver/include/window_manager_agent_controller.h b/wmserver/include/window_manager_agent_controller.h new file mode 100644 index 0000000000000000000000000000000000000000..eacf785982674f46e7d84706120c44b3be9bf750 --- /dev/null +++ b/wmserver/include/window_manager_agent_controller.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H +#define OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H + +#include +#include "client_agent_container.h" +#include "wm_single_instance.h" +#include "zidl/window_manager_agent_interface.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerAgentController { +WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerAgentController) +public: + void RegisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type); + void UnregisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type); + + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, + int32_t displayId, bool focused); + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); + +private: + WindowManagerAgentController() : wmAgentContainer_(mutex_) {} + virtual ~WindowManagerAgentController() = default; + + std::mutex mutex_; + ClientAgentContainer wmAgentContainer_; +}; +} +} +#endif // OHOS_ROSEN_WINDOW_MANAGER_AGENT_CONTROLLER_H diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index b6a335ac51e9cd0bbdacaade902d68c67e543fc9..cbaf17dbb3c26d0922119f7f5be21cf6f0be150f 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -25,18 +25,9 @@ namespace OHOS { namespace Rosen { -using UpdateFocusStatusFunc = std::function& abilityToken, - WindowType windowType, int32_t displayId, bool focused)>; -using UpdateSystemBarPropsFunc = std::function; - -struct WindowNodeContainerCallbacks { - UpdateFocusStatusFunc focusStatusCallBack_; - UpdateSystemBarPropsFunc systemBarChangedCallBack_; -}; - class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, WindowNodeContainerCallbacks callbacks); + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); @@ -119,8 +110,6 @@ private: uint32_t zOrder_ { 0 }; uint32_t focusedWindow_ { 0 }; uint64_t screenId_ = 0; - UpdateFocusStatusFunc focusStatusCallBack_; - WindowNodeContainerCallbacks callbacks_; void DumpScreenWindowTree(); struct WindowPairInfo { diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 0054e99e2f1179d43bf37e2a222d71c7756baee7..dd261feb327ecad9b529ceb74c497f8428705c81 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -17,34 +17,14 @@ #include #include + +#include "agent_death_recipient.h" #include "display_manager_service_inner.h" #include "window_node_container.h" #include "zidl/window_manager_agent_interface.h" namespace OHOS { namespace Rosen { -class WindowDeathRecipient : public IRemoteObject::DeathRecipient { -public: - WindowDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~WindowDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - -class WindowManagerAgentDeathRecipient : public IRemoteObject::DeathRecipient { -public: - WindowManagerAgentDeathRecipient(std::function&)> callback) : callback_(callback) {} - ~WindowManagerAgentDeathRecipient() = default; - - virtual void OnRemoteDied(const wptr& wptrDeath) override; - -private: - std::function&)> callback_; -}; - enum class Event : uint32_t { REMOTE_DIED, }; @@ -73,21 +53,10 @@ public: std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError MinimizeAllAppNodeAbility(sptr& node); WMError HandleSplitWindowModeChange(sptr& node, bool isChangeToSplit); - - void RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - void UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); - std::shared_ptr GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const; private: void OnRemoteDied(const sptr& remoteObject); - void ClearWindowManagerAgent(const sptr& remoteObject); - void UnregisterWindowManagerAgent(const sptr& object); - void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, - int32_t displayId, bool focused); - void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); WMError DestroyWindowInner(sptr& node); bool CheckDisplayInfo(const sptr& display); @@ -98,10 +67,8 @@ private: std::map>> windowManagerAgents_; - sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, + sptr windowDeath_ = new AgentDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, this, std::placeholders::_1)); - sptr windowManagerAgentDeath_ = new WindowManagerAgentDeathRecipient( - std::bind(&WindowRoot::ClearWindowManagerAgent, this, std::placeholders::_1)); Callback callback_; }; } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 963bb30517702d0e9fe58750d774ab753a8c68dd..66436fa05aa0f28a873b654e32e5c8b2b88839c2 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -261,17 +261,5 @@ std::vector WindowController::GetAvoidAreaByType(uint32_t windowId, AvoidA std::vector avoidArea = windowRoot_->GetAvoidAreaByType(windowId, avoidAreaType); return avoidArea; } - -void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent); -} - -void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent); -} } } diff --git a/wmserver/src/window_manager_agent_controller.cpp b/wmserver/src/window_manager_agent_controller.cpp new file mode 100644 index 0000000000000000000000000000000000000000..998ea6e9742afb7385eadd7367da6ea5a2220334 --- /dev/null +++ b/wmserver/src/window_manager_agent_controller.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_manager_agent_controller.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentController"}; +} +WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerAgentController) + +void WindowManagerAgentController::RegisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type) +{ + std::lock_guard lock(mutex_); + wmAgentContainer_.RegisterAgentLocked(windowManagerAgent, type); +} + +void WindowManagerAgentController::UnregisterWindowManagerAgent(const sptr& windowManagerAgent, + WindowManagerAgentType type) +{ + std::lock_guard lock(mutex_); + wmAgentContainer_.UnregisterAgentLocked(windowManagerAgent, type); +} + +void WindowManagerAgentController::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, + WindowType windowType, int32_t displayId, bool focused) +{ + std::lock_guard lock(mutex_); + WLOGFI("UpdateFocusStatus"); + for (auto& agent : wmAgentContainer_.GetAgentsByType(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS)) { + agent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); + } +} + +void WindowManagerAgentController::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + if (props.empty()) { + return; + } + std::lock_guard lock(mutex_); + WLOGFI("UpdateSystemBarProperties"); + for (auto& agent : wmAgentContainer_.GetAgentsByType( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR)) { + agent->UpdateSystemBarProperties(displayId, props); + } +} +} +} \ No newline at end of file diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index a3cd2840bdb33a2db51feed476285b8a59d3e924..00cb0be3c2b25ee8b3dd0054d71f8495f56e0bde 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -23,6 +23,7 @@ #include "dm_common.h" #include "singleton_container.h" +#include "window_manager_agent_controller.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -229,7 +230,7 @@ void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType typ return; } std::lock_guard lock(mutex_); - windowController_->RegisterWindowManagerAgent(type, windowManagerAgent); + WindowManagerAgentController::GetInstance().RegisterWindowManagerAgent(windowManagerAgent, type); } void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, @@ -240,7 +241,7 @@ void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType t return; } std::lock_guard lock(mutex_); - windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent); + WindowManagerAgentController::GetInstance().UnregisterWindowManagerAgent(windowManagerAgent, type); } std::shared_ptr WindowManagerService::GetDisplayNode(int32_t displayId) const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index fb771bc9967731ea7a5f8e88de38ad3e7880ed75..43e86ba5ec1289143369a6b075b9dbe71af0e067 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -20,6 +20,7 @@ #include #include "window_helper.h" +#include "window_manager_agent_controller.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" #include "wm_trace.h" @@ -31,9 +32,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowNodeContainer"}; } -WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, - WindowNodeContainerCallbacks callbacks) - : screenId_(screenId), callbacks_(callbacks) +WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId) { struct RSDisplayNodeConfig config = {screenId}; displayNode_ = RSDisplayNode::Create(config); @@ -323,8 +322,8 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const if (node->abilityToken_ == nullptr) { WLOGFI("abilityToken is null, window : %{public}d", id); } - callbacks_.focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), - node->GetDisplayId(), focused); + WindowManagerAgentController::GetInstance().UpdateFocusStatus( + node->GetWindowId(), node->abilityToken_, node->GetWindowType(), node->GetDisplayId(), focused); } } @@ -439,7 +438,7 @@ void WindowNodeContainer::NotifySystemBarIfChanged() props.emplace_back(item); } } - callbacks_.systemBarChangedCallBack_(screenId_, props); + WindowManagerAgentController::GetInstance().UpdateSystemBarProperties(screenId_, props); } void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 6b226a6963d0eb37af572e7c9a68712ba94afa9d..6bfa3aef5b8f885e5d76c672c3fc785858393dce 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -44,18 +44,8 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis WLOGFI("create new window node container display width:%{public}d, height:%{public}d, screenId:%{public}" PRIu64"", abstractDisplay->GetWidth(), abstractDisplay->GetHeight(), abstractDisplay->GetId()); - - UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); - UpdateSystemBarPropsFunc sysBarUpdateFunc = std::bind(&WindowRoot::UpdateSystemBarProperties, this, - std::placeholders::_1, std::placeholders::_2); - WindowNodeContainerCallbacks callbacks = { - focusStatusFunc, - sysBarUpdateFunc - }; sptr container = new WindowNodeContainer(abstractDisplay->GetId(), - static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), - callbacks); + static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight())); windowNodeContainerMap_.insert({ displayId, container }); return container; } @@ -298,50 +288,6 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } -void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - WLOGFI("RegisterWindowManagerAgent Type:%{public}u", static_cast(type)); - windowManagerAgents_[type].push_back(windowManagerAgent); - if (windowManagerAgentDeath_ == nullptr) { - WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); - return; - } - if (!windowManagerAgent->AsObject()->AddDeathRecipient(windowManagerAgentDeath_)) { - WLOGFI("failed to add death recipient"); - } -} - -void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent) -{ - auto iter = std::find(windowManagerAgents_[type].begin(), windowManagerAgents_[type].end(), windowManagerAgent); - if (iter == windowManagerAgents_[type].end()) { - WLOGFE("could not find this listener"); - return; - } - windowManagerAgents_[type].erase(iter); -} - -void WindowRoot::UnregisterWindowManagerAgent(const sptr& object) -{ - for (auto agents : windowManagerAgents_) { - for (auto iter = agents.second.begin(); iter < agents.second.end(); ++iter) { - if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { - iter = agents.second.erase(iter); - } - } - } -} - -void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, - int32_t displayId, bool focused) -{ - for (auto& windowManagerAgent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS]) { - windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); - } -} - std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sptr &abilityToken) const { for (auto iter = windowNodeMap_.begin(); iter != windowNodeMap_.end(); iter++) { @@ -354,16 +300,6 @@ std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sp return nullptr; } -void WindowRoot::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) -{ - if (props.empty()) { - return; - } - for (auto& agent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR]) { - agent->UpdateSystemBarProperties(displayId, props); - } -} - void WindowRoot::OnRemoteDied(const sptr& remoteObject) { std::lock_guard lock(mutex_); @@ -375,48 +311,5 @@ void WindowRoot::OnRemoteDied(const sptr& remoteObject) uint32_t windowId = iter->second; callback_(Event::REMOTE_DIED, windowId); } - -void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject) -{ - if (remoteObject == nullptr) { - WLOGFI("remoteObject is null"); - return; - } - std::lock_guard lock(mutex_); - UnregisterWindowManagerAgent(remoteObject); - remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_); -} - -void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("WindowDeathRecipient callback"); - callback_(object); -} - -void WindowManagerAgentDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -{ - if (wptrDeath == nullptr) { - WLOGFE("wptrDeath is null"); - return; - } - - sptr object = wptrDeath.promote(); - if (!object) { - WLOGFE("object is null"); - return; - } - WLOGFI("WindowManagerAgentDeathRecipient callback"); - callback_(object); -} } }