From 96f548daaaaf98361cda2f1d4f21491094b3dc8e Mon Sep 17 00:00:00 2001 From: xiahaiqin Date: Sat, 8 Jan 2022 14:22:43 +0800 Subject: [PATCH] modify problem about window remote died Signed-off-by: xiahaiqin Change-Id: I99bfadf738918567342a92b7ed08151ef66ed6e7 --- wmserver/include/window_manager_service.h | 1 + wmserver/include/window_root.h | 13 ++++++++++--- wmserver/src/window_manager_service.cpp | 14 +++++++++++++- wmserver/src/window_root.cpp | 5 +++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 9d7f1d23f1..36935f3a10 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -62,6 +62,7 @@ protected: private: bool Init(); + void OnWindowEvent(Event event, uint32_t windowId); static inline SingletonDelegator delegator; std::recursive_mutex mutex_; sptr windowRoot_; diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 136537fbf9..486290089b 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -44,9 +44,15 @@ private: std::function&)> callback_; }; +enum class Event : uint32_t { + REMOTE_DIED, +}; + class WindowRoot : public RefBase { +using Callback = std::function; + public: - WindowRoot(std::recursive_mutex& mutex) : mutex_(mutex) {} + WindowRoot(std::recursive_mutex& mutex, Callback callback) : mutex_(mutex), callback_(callback) {} ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(int32_t displayId); @@ -66,7 +72,7 @@ public: void UnregisterFocusChangedListener(const sptr& windowManagerAgent); private: - void ClearWindow(const sptr& remoteObject); + void OnRemoteDied(const sptr& remoteObject); void ClearWindowManagerAgent(const sptr& remoteObject); void UnregisterFocusChangedListener(const sptr& windowManagerAgent); void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, @@ -80,10 +86,11 @@ private: std::vector> focusChangedListenerAgents_; - sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow, + sptr windowDeath_ = new WindowDeathRecipient(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_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 2f7542f483..36e61710a8 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -33,7 +33,8 @@ const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonCon WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true) { - windowRoot_ = new WindowRoot(mutex_); + windowRoot_ = new WindowRoot(mutex_, + std::bind(&WindowManagerService::OnWindowEvent, this, std::placeholders::_1, std::placeholders::_2)); windowController_ = new WindowController(windowRoot_); inputWindowMonitor_ = new InputWindowMonitor(windowRoot_); } @@ -198,5 +199,16 @@ void WindowManagerService::UnregisterFocusChangedListener(const sptr lock(mutex_); windowController_->UnregisterFocusChangedListener(windowManagerAgent); } + +void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId) +{ + switch (event) { + case Event::REMOTE_DIED: + DestroyWindow(windowId); + break; + default: + break; + } +} } } \ No newline at end of file diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index 4b20ff0cb8..ce2ccbe20c 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -251,7 +251,7 @@ void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& } } -void WindowRoot::ClearWindow(const sptr& remoteObject) +void WindowRoot::OnRemoteDied(const sptr& remoteObject) { std::lock_guard lock(mutex_); auto iter = windowIdMap_.find(remoteObject); @@ -260,7 +260,7 @@ void WindowRoot::ClearWindow(const sptr& remoteObject) return; } uint32_t windowId = iter->second; - DestroyWindow(windowId); + callback_(Event::REMOTE_DIED, windowId); } void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject) @@ -271,6 +271,7 @@ void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject } std::lock_guard lock(mutex_); UnregisterFocusChangedListener(remoteObject); + remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_); } void WindowDeathRecipient::OnRemoteDied(const wptr& wptrDeath) -- Gitee