From 5030140515c2852aad8585150afbfdd00463bccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=B6=8A?= Date: Thu, 28 Aug 2025 16:02:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=9A=E5=B1=8F=E5=A4=9A=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/innerkits/wm/window_manager_lite.h | 16 +- wm/src/window_manager_lite.cpp | 140 +++++++++++++----- 2 files changed, 112 insertions(+), 44 deletions(-) diff --git a/interfaces/innerkits/wm/window_manager_lite.h b/interfaces/innerkits/wm/window_manager_lite.h index 10359312a4..05a97ce870 100644 --- a/interfaces/innerkits/wm/window_manager_lite.h +++ b/interfaces/innerkits/wm/window_manager_lite.h @@ -35,12 +35,15 @@ namespace Rosen { * * @brief WindowManagerLite used to manage window. */ -class WindowManagerLite { +class WindowManagerLite : public RefBase{ WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManagerLite); friend class WindowManagerAgentLite; friend class WMSDeathRecipient; friend class SSMDeathRecipient; public: + static sptr GetInstance(const int32_t userId); + static WMError RemoveInstanceByUserId(const int32_t userId); + /** * @brief Register focus changed listener. * @@ -366,13 +369,20 @@ public: WMError SendPointerEventForHover(const std::shared_ptr& pointerEvent); private: - WindowManagerLite(); - ~WindowManagerLite(); + WindowManagerLite(const int32_t userId = INVALID_USER_ID) + std::recursive_mutex mutex_; class Impl; std::unique_ptr pImpl_; bool destroyed_ = false; + /** + * Multi user and multi screen + */ + int32_t userId_; + static std::unordered_map> windowManagerLiteMap_; + static std::mutex_ windowManagerLiteMapMutex_; + void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, DisplayId displayId, bool focused) const; void UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const; diff --git a/wm/src/window_manager_lite.cpp b/wm/src/window_manager_lite.cpp index 75f62e1ae7..35bd8fbe7a 100644 --- a/wm/src/window_manager_lite.cpp +++ b/wm/src/window_manager_lite.cpp @@ -30,7 +30,8 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerLite"}; } -WM_IMPLEMENT_SINGLE_INSTANCE(WindowManagerLite) +std::unordered_map> WindowManagerLite::windowManagerLiteMap_ = {}; +std::mutex_ WindowManagerLite::windowManagerLiteMapMutex_; class WindowManagerLite::Impl { public: @@ -58,6 +59,10 @@ public: void NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type); + /** + * Compatible with the singleton pattern, ensuring that calls can + * still be made through SingletonContainer::Get + */ static inline SingletonDelegator delegator_; std::recursive_mutex& mutex_; @@ -350,16 +355,69 @@ void WindowManagerLite::Impl::UpdatePiPWindowStateChanged(const std::string& bun } } -WindowManagerLite::WindowManagerLite() : pImpl_(std::make_unique(mutex_)) -{ -} +WindowManagerLite::WindowManagerLite(const int32_t userId) + : pImpl_(std::make_unique(mutex_)),userId_(userId){} WindowManagerLite::~WindowManagerLite() { + TLOGI(WmsLogTag::WMS_SCB, "window manager lite destroyed"); std::lock_guard lock(mutex_); destroyed_ = true; } +WindowAdapterLite& WindowAdapterLite::GetInstance() +{ + static sptr instance = nullptr; + static std::mutex mtx; + if (instance == nullptr) { + std::lock_guard lock(mtx); + if(instance == nullptr){ + instance = new WindowManagerLite(); + } + } + return *instance; +} + +WindowAdapterLite& WindowAdapterLite::GetInstance(const int32_t userId) +{ + /** + * Only system applications or services with a userId of 0 are allowed to communicate + * with multiple WMS-Servers and are permitted to listen for WMS connection status. + */ + sptr instance = nullptr; + int32_t clientUserId = GetUserIdByUid(getuid()); + if (clientUserId != SYSTEM_USERID || userId <= INVALID_USER_ID) { + TLOGI(WmsLogTag::WMS_MULTI_USER, "user singleton mode"); + instance = &WindowAdapterLite::GetInstance(); + return instance; + } + + //multi-instance mode + { + std:lock_guard lock(windowManagerLiteMapMutex_); + auto iter = windowManagerLiteMap_.find(userId); + if (iter != windowManagerLiteMap_.end()) { + return iter->second; + } + } + TLOGI(WmsLogTag::WMS_MULTI_USER, "create new instance userId:%{public}d", userId); + instance = new WindowAdapterLite(userId); + { + std::lock_guard lock(windowManagerLiteMapMutex_); + windowManagerLiteMap_.insert({userId,instance}); + } + return instance; +} + +WMError WindowManagerLite::RemoveInstanceByUserId(const int userId) +{ + TLOGI(WmsLogTag::WMS_MULTI_USER, "create new instance userId:%{public}d", userId); + std:lock_guard lock(windowManagerLiteMapMutex_); + windowManagerLiteMap_.erase(userId); + return WMError::OK; +} + + WMError WindowManagerLite::RegisterFocusChangedListener(const sptr& listener) { if (listener == nullptr) { @@ -371,7 +429,7 @@ WMError WindowManagerLite::RegisterFocusChangedListener(const sptrfocusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); } if (ret != WMError::WM_OK) { @@ -404,7 +462,7 @@ WMError WindowManagerLite::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->focusChangedListenerAgent_ = nullptr; @@ -423,7 +481,7 @@ WMError WindowManagerLite::RegisterVisibilityChangedListener(const sptrwindowVisibilityListenerAgent_ == nullptr) { pImpl_->windowVisibilityListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); } @@ -456,7 +514,7 @@ WMError WindowManagerLite::UnregisterVisibilityChangedListener(const sptrwindowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret == WMError::WM_OK) { @@ -477,7 +535,7 @@ WMError WindowManagerLite::RegisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListenerAgent_ == nullptr) { pImpl_->windowVisibilityStateListenerAgent_ = new WindowManagerAgentLite(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret != WMError::WM_OK) { @@ -509,7 +567,7 @@ WMError WindowManagerLite::UnregisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListeners_.empty() && pImpl_->windowVisibilityStateListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret == WMError::WM_OK) { @@ -522,7 +580,7 @@ WMError WindowManagerLite::UnregisterVisibilityStateChangedListener(const sptr().GetFocusWindowInfo(focusInfo, displayId); + WindowAdapterLite::GetInstance(userId_).GetFocusWindowInfo(focusInfo, displayId); } void WindowManagerLite::UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const @@ -548,7 +606,7 @@ void WindowManagerLite::UpdateWindowVisibilityInfo( WMError WindowManagerLite::GetVisibilityWindowInfo(std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetVisibilityWindowInfo(infos); + WMError ret = WindowAdapterLite::GetInstance(userId_).GetVisibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } @@ -590,7 +648,7 @@ WMError WindowManagerLite::RegisterDrawingContentChangedListener(const sptrwindowDrawingContentListenerAgent_ == nullptr) { pImpl_->windowDrawingContentListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); } @@ -623,7 +681,7 @@ WMError WindowManagerLite::UnregisterDrawingContentChangedListener(const sptrwindowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret == WMError::WM_OK) { @@ -646,7 +704,7 @@ void WindowManagerLite::NotifyAccessibilityWindowInfo(const std::vector().GetWindowModeType(windowModeType); + WMError ret = WindowAdapterLite::GetInstance(userId_).GetWindowModeType(windowModeType); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } @@ -664,7 +722,7 @@ WMError WindowManagerLite::RegisterWindowModeChangedListener(const sptrwindowModeListenerAgent_ == nullptr) { pImpl_->windowModeListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); } - WMError ret = SingletonContainer::Get().RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -696,7 +754,7 @@ WMError WindowManagerLite::UnregisterWindowModeChangedListener(const sptrwindowModeListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowModeListeners_.empty() && pImpl_->windowModeListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowModeListenerAgent_ = nullptr; @@ -716,7 +774,7 @@ WMError WindowManagerLite::RegisterCameraWindowChangedListener(const sptrcameraWindowChangedListenerAgent_ == nullptr) { pImpl_->cameraWindowChangedListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = SingletonContainer::Get().RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pImpl_->cameraWindowChangedListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_SYSTEM, "RegisterWindowManagerAgent failed!"); @@ -751,7 +809,7 @@ WMError WindowManagerLite::UnregisterCameraWindowChangedListener(const sptrcameraWindowChangedListeners_.empty() && pImpl_->cameraWindowChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pImpl_->cameraWindowChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -763,7 +821,7 @@ WMError WindowManagerLite::UnregisterCameraWindowChangedListener(const sptr().RaiseWindowToTop(persistentId); + WMError ret = WindowAdapterLite::GetInstance(userId_).RaiseWindowToTop(persistentId); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_SYSTEM, "raise window to top failed."); } @@ -773,12 +831,12 @@ WMError WindowManagerLite::RaiseWindowToTop(int32_t persistentId) WMError WindowManagerLite::GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) { TLOGI(WmsLogTag::WMS_MAIN, "Get main window info lite"); - return SingletonContainer::Get().GetMainWindowInfos(topNum, topNInfo); + return WindowAdapterLite::GetInstance(userId_).GetMainWindowInfos(topNum, topNInfo); } WMError WindowManagerLite::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) { - return SingletonContainer::Get().GetCallingWindowInfo(callingWindowInfo); + return WindowAdapterLite::GetInstance(userId_).GetCallingWindowInfo(callingWindowInfo); } WMError WindowManagerLite::RegisterWMSConnectionChangedListener(const sptr& listener) @@ -838,7 +896,7 @@ WMError WindowManagerLite::GetAllMainWindowInfos(std::vector& in TLOGE(WmsLogTag::WMS_MAIN, "infos is not empty."); return WMError::WM_ERROR_INVALID_PARAM; } - return SingletonContainer::Get().GetAllMainWindowInfos(infos); + return WindowAdapterLite::GetInstance(userId_).GetAllMainWindowInfos(infos); } WMError WindowManagerLite::ClearMainSessions(const std::vector& persistentIds) @@ -847,7 +905,7 @@ WMError WindowManagerLite::ClearMainSessions(const std::vector& persist TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty."); return WMError::WM_OK; } - return SingletonContainer::Get().ClearMainSessions(persistentIds); + return WindowAdapterLite::GetInstance(userId_).ClearMainSessions(persistentIds); } WMError WindowManagerLite::ClearMainSessions(const std::vector& persistentIds, @@ -857,7 +915,7 @@ WMError WindowManagerLite::ClearMainSessions(const std::vector& persist TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty."); return WMError::WM_OK; } - return SingletonContainer::Get().ClearMainSessions(persistentIds, clearFailedIds); + return WindowAdapterLite::GetInstance(userId_).ClearMainSessions(persistentIds, clearFailedIds); } WMError WindowManagerLite::NotifyWindowStyleChange(WindowStyleType type) @@ -892,7 +950,7 @@ WMError WindowManagerLite::RegisterWindowStyleChangedListener(const sptrwindowStyleListeners_.push_back(listener); } WMError ret = WMError::WM_OK; - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -924,7 +982,7 @@ WMError WindowManagerLite::UnregisterWindowStyleChangedListener(const sptrwindowStyleListeners_.empty() && pImpl_->windowStyleListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret == WMError::WM_OK) { std::lock_guard lock(pImpl_->mutex_); @@ -956,7 +1014,7 @@ WMError WindowManagerLite::RegisterCallingWindowDisplayChangedListener( pImpl_->callingDisplayChangedListeners_.emplace_back(listener); } WMError ret = WMError::WM_OK; - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_KEYBOARD, "Register agent failed!"); @@ -991,7 +1049,7 @@ WMError WindowManagerLite::UnregisterCallingWindowDisplayChangedListener( } WMError ret = WMError::WM_OK; if (pImpl_->callingDisplayChangedListeners_.empty() && pImpl_->callingDisplayListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); if (ret == WMError::WM_OK) { std::lock_guard lock(pImpl_->mutex_); @@ -1004,7 +1062,7 @@ WMError WindowManagerLite::UnregisterCallingWindowDisplayChangedListener( WindowStyleType WindowManagerLite::GetWindowStyleType() { WindowStyleType styleType; - if (SingletonContainer::Get().GetWindowStyleType(styleType) == WMError::WM_OK) { + if (WindowAdapterLite::GetInstance(userId_).GetWindowStyleType(styleType) == WMError::WM_OK) { return styleType; } return styleType; @@ -1016,7 +1074,7 @@ WMError WindowManagerLite::TerminateSessionByPersistentId(int32_t persistentId) TLOGE(WmsLogTag::WMS_LIFE, "persistentId is invalid."); return WMError::WM_ERROR_INVALID_PARAM; } - return SingletonContainer::Get().TerminateSessionByPersistentId(persistentId); + return WindowAdapterLite::GetInstance(userId_).TerminateSessionByPersistentId(persistentId); } WMError WindowManagerLite::CloseTargetFloatWindow(const std::string& bundleName) @@ -1025,7 +1083,7 @@ WMError WindowManagerLite::CloseTargetFloatWindow(const std::string& bundleName) TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "bundleName is empty."); return WMError::WM_ERROR_INVALID_PARAM; } - return SingletonContainer::Get().CloseTargetFloatWindow(bundleName); + return WindowAdapterLite::GetInstance(userId_).CloseTargetFloatWindow(bundleName); } WMError WindowManagerLite::RegisterPiPStateChangedListener(const sptr& listener) @@ -1040,7 +1098,7 @@ WMError WindowManagerLite::RegisterPiPStateChangedListener(const sptrpipStateChangedListenerAgent_ == nullptr) { pImpl_->pipStateChangedListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = SingletonContainer::Get().RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP, pImpl_->pipStateChangedListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_PIP, "RegisterWindowManagerAgent failed!"); @@ -1076,7 +1134,7 @@ WMError WindowManagerLite::UnregisterPiPStateChangedListener(const sptrpipStateChangedListeners_.empty() && pImpl_->pipStateChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP, pImpl_->pipStateChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -1093,12 +1151,12 @@ WMError WindowManagerLite::CloseTargetPiPWindow(const std::string& bundleName) return WMError::WM_ERROR_INVALID_PARAM; } TLOGD(WmsLogTag::WMS_PIP, "bundleName:%{public}s", bundleName.c_str()); - return SingletonContainer::Get().CloseTargetPiPWindow(bundleName); + return WindowAdapterLite::GetInstance(userId_).CloseTargetPiPWindow(bundleName); } WMError WindowManagerLite::GetCurrentPiPWindowInfo(std::string& bundleName) { - return SingletonContainer::Get().GetCurrentPiPWindowInfo(bundleName); + return WindowAdapterLite::GetInstance(userId_).GetCurrentPiPWindowInfo(bundleName); } void WindowManagerLite::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) const @@ -1108,7 +1166,7 @@ void WindowManagerLite::UpdatePiPWindowStateChanged(const std::string& bundleNam WMError WindowManagerLite::GetAccessibilityWindowInfo(std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetAccessibilityWindowInfo(infos); + WMError ret = WindowAdapterLite::GetInstance(userId_).GetAccessibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window info failed"); } @@ -1125,7 +1183,7 @@ WMError WindowManagerLite::RegisterWindowUpdateListener(const sptrwindowUpdateListenerAgent_ == nullptr) { pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = SingletonContainer::Get().RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret != WMError::WM_OK) { WLOGFW("RegisterWindowManagerAgent failed!"); @@ -1156,7 +1214,7 @@ WMError WindowManagerLite::UnregisterWindowUpdateListener(const sptrwindowUpdateListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowUpdateListenerAgent_ = nullptr; @@ -1238,7 +1296,7 @@ WMError WindowManagerLite::ListWindowInfo(const WindowInfoOption& windowInfoOpti static_cast(windowInfoOption.windowInfoFilterOption), static_cast(windowInfoOption.windowInfoTypeOption), windowInfoOption.displayId, windowInfoOption.windowId); - WMError ret = SingletonContainer::Get().ListWindowInfo(windowInfoOption, infos); + WMError ret = WindowAdapterLite::GetInstance(userId_).ListWindowInfo(windowInfoOption, infos); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -1256,7 +1314,7 @@ WMError WindowManagerLite::SendPointerEventForHover(const std::shared_ptr().SendPointerEventForHover(pointerEvent); + WMError ret = WindowAdapterLite::GetInstance(userId_).SendPointerEventForHover(pointerEvent); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_EVENT, "send failed"); } -- Gitee From db8fdb10548331c9a163944b7c30d57f6aa906d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=B6=8A?= Date: Thu, 28 Aug 2025 16:34:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=9A=E5=B1=8F=E5=A4=9A=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘越 --- interfaces/innerkits/wm/window_manager.h | 29 ++- wm/src/window_manager.cpp | 226 ++++++++++++++--------- wm/src/window_manager_lite.cpp | 75 ++++---- 3 files changed, 201 insertions(+), 129 deletions(-) diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 9e9713ffed..f6fc35b1d0 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -16,19 +16,23 @@ #ifndef OHOS_ROSEN_WINDOW_MANAGER_H #define OHOS_ROSEN_WINDOW_MANAGER_H +#include #include #include #include +#include #include -#include -#include "wm_single_instance.h" -#include "wm_common.h" + #include "dm_common.h" #include "focus_change_info.h" -#include "window_visibility_info.h" -#include "window_drawing_content_info.h" + #include "window.h" +#include "window_drawing_content_info.h" #include "window_pid_visibility_info.h" +#include "window_visibility_info.h" +#include "wm_common.h" +#include "wm_single_instance.h" + namespace OHOS { namespace Rosen { @@ -612,12 +616,15 @@ public: * * @brief WindowManager used to manage window. */ -class WindowManager { +class WindowManager : public RefBase{ WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager); friend class WindowManagerAgent; friend class WMSDeathRecipient; friend class SSMDeathRecipient; public: + static sptr GetInstance(const int32_t userId); + static WMError RemoveInstanceByUserId(const int32_t userId); + /** * @brief Register WMS connection status changed listener. * @attention Callable only by u0 system user. A process only supports successful registration once. @@ -1351,8 +1358,14 @@ public: const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags); private: - WindowManager(); - ~WindowManager(); + /** + * Multi user and multi screen + */ + WindowManager(const int32_t userId = INVALID_USER_ID); + int32_t userId_; + static std::unordered_map> windowManagerMap_; + static std::mutex_ windowManagerMapMutex_; + std::recursive_mutex mutex_; class Impl; std::unique_ptr pImpl_; diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index e37e59d04f..63d29dacab 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -41,7 +41,8 @@ public: }; } -WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager) +std::unordered_map> WindowManager::windowManagerMap_ = {}; +std::mutex_ WindowManager::windowManagerMapMutex_; class WindowManager::Impl { public: @@ -531,14 +532,15 @@ void WindowManager::Impl::NotifyWMSWindowDestroyed(const WindowLifeCycleInfo& li wmsWindowDestroyedListener->OnWindowDestroyed(lifeCycleInfo, jsWindowNapiValue); } -WindowManager::WindowManager() : pImpl_(std::make_unique()) +WindowManager::WindowManager(const int32_t userId) : userId_(userId), + pImpl_(std::make_unique(mutex_)) { } int32_t WindowChecker::CheckWindowId(int32_t windowId) const { int32_t pid = INVALID_PID; - WMError ret = SingletonContainer::Get().CheckWindowId(windowId, pid); + WMError ret = WindowAdapter::GetInstance(userId_)->CheckWindowId(windowId, pid); if (ret != WMError::WM_OK) { WLOGFE("Window(%{public}d) do not allow styles to be set", windowId); } @@ -547,10 +549,63 @@ int32_t WindowChecker::CheckWindowId(int32_t windowId) const WindowManager::~WindowManager() { + TLOGI(WmsLogTag::WMS_SCB, "destroyed"); std::lock_guard lock(mutex_); destroyed_ = true; } +WindowManager& WindowManager::GetInstance() +{ + static sptr instance = nullptr; + static std::mutex mtx; + if (instance == nullptr) { + std::lock_guard lock(mtx); + if(instance == nullptr){ + instance = new WindowManager(); + } + } + return *instance; +} + +sptr WindowManager::GetInstance(const int32_t userId) +{ + /** + * Only system applications or services with a userId of 0 are allowed to communicate + * with multiple WMS-Servers and are permitted to listen for WMS connection status. + */ + sptr instance = nullptr; + int32_t clientUserId = GetUserIdByUid(getuid()); + if (clientUserId != SYSTEM_USERID || userId <= INVALID_USER_ID) { + TLOGI(WmsLogTag::WMS_MULTI_USER, "user singleton mode"); + instance = &WindowManager::GetInstance(); + return instance; + } + + //multi-instance mode + { + std:lock_guard lock(windowManagerMapMutex_); + auto iter = windowManagerMap_.find(userId); + if (iter != windowManagerMap_.end()) { + return iter->second; + } + } + TLOGI(WmsLogTag::WMS_MULTI_USER, "create new instance userId:%{public}d", userId); + instance = new WindowManager(userId); + { + std::lock_guard lock(windowManagerMapMutex_); + windowManagerMap_.insert({userId,instance}); + } + return instance; +} + +WMError WindowManager::RemoveInstanceByUserId(const int userId) +{ + TLOGI(WmsLogTag::WMS_MULTI_USER, "create new instance userId:%{public}d", userId); + std:lock_guard lock(windowManagerMapMutex_); + windowManagerMap_.erase(userId); + return WMError::OK; +} + WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr& listener) { int32_t clientUserId = GetUserIdByUid(getuid()); @@ -573,9 +628,14 @@ WMError WindowManager::RegisterWMSConnectionChangedListener(const sptrwmsConnectionChangedListener_ = listener; } - auto ret = WindowAdapter::GetInstance().RegisterWMSConnectionChangedListener( - [this](int32_t userId, int32_t screenId, bool isConnected) { - this->OnWMSConnectionChanged(userId, screenId, isConnected); + auto ret = WindowAdapter::GetInstance(userId_).RegisterWMSConnectionChangedListener( + [weakThis = wptr(this)](int32_t userId, int32_t screenId, bool isConnected) { + auto windowManager = weakThis.promote(); + if (!windowManager) { + TLOGE(WmsLogTag::WMS_SCB, "window adapter is null"); + return; + } + windowManager->OnWMSConnectionChanged(userId, screenId, isConnected); }); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_MULTI_USER, "Register failed: error = %{public}d", static_cast(ret)); @@ -588,9 +648,9 @@ WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr lock(pImpl_->listenerMutex_); + std::lock_guard lock(pImpl_->mutex_); pImpl_->wmsConnectionChangedListener_ = nullptr; - WindowAdapter::GetInstance().UnregisterWMSConnectionChangedListener(); + WindowAdapter::GetInstance(userId_).UnregisterWMSConnectionChangedListener(); return WMError::WM_OK; } @@ -646,7 +706,7 @@ WMError WindowManager::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->focusChangedListenerAgent_ = nullptr; @@ -667,7 +727,7 @@ WMError WindowManager::RegisterWindowModeChangedListener(const sptrwindowModeListenerAgent_ == nullptr) { pImpl_->windowModeListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -699,7 +759,7 @@ WMError WindowManager::UnregisterWindowModeChangedListener(const sptrwindowModeListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowModeListeners_.empty() && pImpl_->windowModeListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowModeListenerAgent_ = nullptr; @@ -720,7 +780,7 @@ WMError WindowManager::RegisterSystemBarChangedListener(const sptrsystemBarChangedListenerAgent_ == nullptr) { pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); if (ret != WMError::WM_OK) { WLOGFW("RegisterWindowManagerAgent failed!"); @@ -754,7 +814,7 @@ WMError WindowManager::UnregisterSystemBarChangedListener(const sptrsystemBarChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->systemBarChangedListenerAgent_ = nullptr; @@ -766,19 +826,19 @@ WMError WindowManager::UnregisterSystemBarChangedListener(const sptr().MinimizeAllAppWindows(displayId); + return WindowAdapter::GetInstance(userId_)->MinimizeAllAppWindows(displayId); } WMError WindowManager::ToggleShownStateForAllAppWindows() { WLOGFD("ToggleShownStateForAllAppWindows"); - return SingletonContainer::Get().ToggleShownStateForAllAppWindows(); + return WindowAdapter::GetInstance(userId_)->ToggleShownStateForAllAppWindows(); } WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode) { WLOGFD("set window layout mode: %{public}u", mode); - WMError ret = SingletonContainer::Get().SetWindowLayoutMode(mode); + WMError ret = WindowAdapter::GetInstance(userId_)->SetWindowLayoutMode(mode); if (ret != WMError::WM_OK) { WLOGFE("set layout mode failed"); } @@ -796,7 +856,7 @@ WMError WindowManager::RegisterWindowUpdateListener(const sptrwindowUpdateListenerAgent_ == nullptr) { pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret != WMError::WM_OK) { WLOGFW("RegisterWindowManagerAgent failed!"); @@ -827,7 +887,7 @@ WMError WindowManager::UnregisterWindowUpdateListener(const sptrwindowUpdateListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowUpdateListenerAgent_ = nullptr; @@ -847,7 +907,7 @@ WMError WindowManager::RegisterVisibilityChangedListener(const sptrwindowVisibilityListenerAgent_ == nullptr) { pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret != WMError::WM_OK) { @@ -879,7 +939,7 @@ WMError WindowManager::UnregisterVisibilityChangedListener(const sptrwindowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret == WMError::WM_OK) { @@ -909,7 +969,7 @@ WMError WindowManager::RegisterDisplayIdChangedListener(const sptr(windowInfoKey); } - ret = SingletonContainer::Get().RegisterWindowPropertyChangeAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowPropertyChangeAgent( WindowInfoKey::DISPLAY_ID, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "RegisterWindowPropertyChangeAgent failed!"); @@ -950,7 +1010,7 @@ WMError WindowManager::UnregisterDisplayIdChangedListener(const sptrwindowDisplayIdChangeListeners_.empty() && pImpl_->windowPropertyChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowPropertyChangeAgent(WindowInfoKey::DISPLAY_ID, + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowPropertyChangeAgent(WindowInfoKey::DISPLAY_ID, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret == WMError::WM_OK) { pImpl_->windowPropertyChangeAgent_ = nullptr; @@ -979,7 +1039,7 @@ WMError WindowManager::RegisterRectChangedListener(const sptr(windowInfoKey); } - ret = SingletonContainer::Get().RegisterWindowPropertyChangeAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowPropertyChangeAgent( WindowInfoKey::WINDOW_RECT, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "RegisterWindowPropertyChangeAgent failed!"); @@ -1020,7 +1080,7 @@ WMError WindowManager::UnregisterRectChangedListener(const sptrwindowRectChangeListeners_.empty() && pImpl_->windowPropertyChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowPropertyChangeAgent(WindowInfoKey::WINDOW_RECT, + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowPropertyChangeAgent(WindowInfoKey::WINDOW_RECT, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret == WMError::WM_OK) { pImpl_->windowPropertyChangeAgent_ = nullptr; @@ -1050,7 +1110,7 @@ WMError WindowManager::RegisterWindowModeChangedListenerForPropertyChange( } interestInfo |= static_cast(windowInfoKey); } - ret = SingletonContainer::Get().RegisterWindowPropertyChangeAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowPropertyChangeAgent( WindowInfoKey::WINDOW_MODE, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "RegisterWindowPropertyChangeAgent failed!"); @@ -1092,7 +1152,7 @@ WMError WindowManager::UnregisterWindowModeChangedListenerForPropertyChange( } WMError ret = WMError::WM_OK; if (pImpl_->windowModeChangeListeners_.empty() && pImpl_->windowPropertyChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowPropertyChangeAgent(WindowInfoKey::WINDOW_MODE, + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowPropertyChangeAgent(WindowInfoKey::WINDOW_MODE, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret == WMError::WM_OK) { pImpl_->windowPropertyChangeAgent_ = nullptr; @@ -1121,7 +1181,7 @@ WMError WindowManager::RegisterFloatingScaleChangedListener(const sptr(windowInfoKey); } - ret = SingletonContainer::Get().RegisterWindowPropertyChangeAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowPropertyChangeAgent( WindowInfoKey::FLOATING_SCALE, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "RegisterWindowPropertyChangeAgent failed!"); @@ -1162,7 +1222,7 @@ WMError WindowManager::UnregisterFloatingScaleChangedListener(const sptrfloatingScaleChangeListeners_.empty() && pImpl_->windowPropertyChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowPropertyChangeAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowPropertyChangeAgent( WindowInfoKey::FLOATING_SCALE, interestInfo, pImpl_->windowPropertyChangeAgent_); if (ret == WMError::WM_OK) { pImpl_->windowPropertyChangeAgent_ = nullptr; @@ -1182,7 +1242,7 @@ WMError WindowManager::RegisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListenerAgent_ == nullptr) { pImpl_->windowVisibilityStateListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret != WMError::WM_OK) { @@ -1214,7 +1274,7 @@ WMError WindowManager::UnregisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListeners_.empty() && pImpl_->windowVisibilityStateListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret == WMError::WM_OK) { @@ -1236,7 +1296,7 @@ WMError WindowManager::RegisterCameraFloatWindowChangedListener(const sptrcameraFloatWindowChangedListenerAgent_ == nullptr) { pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, pImpl_->cameraFloatWindowChangedListenerAgent_); if (ret != WMError::WM_OK) { @@ -1273,7 +1333,7 @@ WMError WindowManager::UnregisterCameraFloatWindowChangedListener( WMError ret = WMError::WM_OK; if (pImpl_->cameraFloatWindowChangedListeners_.empty() && pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, pImpl_->cameraFloatWindowChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -1295,7 +1355,7 @@ WMError WindowManager::RegisterWaterMarkFlagChangedListener(const sptrwaterMarkFlagChangeAgent_ == nullptr) { pImpl_->waterMarkFlagChangeAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG, pImpl_->waterMarkFlagChangeAgent_); if (ret != WMError::WM_OK) { @@ -1332,7 +1392,7 @@ WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptrwaterMarkFlagChangeListeners_.empty() && pImpl_->waterMarkFlagChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG, pImpl_->waterMarkFlagChangeAgent_); if (ret == WMError::WM_OK) { @@ -1357,7 +1417,7 @@ WMError WindowManager::RegisterGestureNavigationEnabledChangedListener( pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent(); } if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) { - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED, pImpl_->gestureNavigationEnabledAgent_); } else { @@ -1400,7 +1460,7 @@ WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener( WMError ret = WMError::WM_OK; if (pImpl_->gestureNavigationEnabledListeners_.empty() && pImpl_->gestureNavigationEnabledAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED, pImpl_->gestureNavigationEnabledAgent_); if (ret == WMError::WM_OK) { @@ -1498,7 +1558,7 @@ WMError WindowManager::RegisterWindowPidVisibilityChangedListener( pImpl_->windowPidVisibilityListenerAgent_ = sptr::MakeSptr(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY, pImpl_->windowPidVisibilityListenerAgent_); if (ret != WMError::WM_OK) { @@ -1545,7 +1605,7 @@ WMError WindowManager::UnregisterWindowPidVisibilityChangedListener( } std::unique_lock lock(pImpl_->visibilityListenerAgentListenerMutex_); if (isListenEmpty && pImpl_->windowPidVisibilityListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY, pImpl_->windowPidVisibilityListenerAgent_); if (ret == WMError::WM_OK) { @@ -1570,7 +1630,7 @@ WMError WindowManager::NotifyDisplayInfoChange(const sptr& token, void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId) { - SingletonContainer::Get().GetFocusWindowInfo(focusInfo, displayId); + WindowAdapter::GetInstance(userId_)->GetFocusWindowInfo(focusInfo, displayId); } void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const @@ -1604,7 +1664,7 @@ void WindowManager::UpdateWindowModeTypeInfo(WindowModeType type) const WMError WindowManager::GetWindowModeType(WindowModeType& windowModeType) const { - WMError ret = SingletonContainer::Get().GetWindowModeType(windowModeType); + WMError ret = WindowAdapter::GetInstance(userId_)->GetWindowModeType(windowModeType); if (ret != WMError::WM_OK) { WLOGFE("get window mode type failed"); } @@ -1638,7 +1698,7 @@ void WindowManager::UpdateWindowDrawingContentInfo( WMError WindowManager::GetAccessibilityWindowInfo(std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetAccessibilityWindowInfo(infos); + WMError ret = WindowAdapter::GetInstance(userId_)->GetAccessibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window info failed"); } @@ -1648,7 +1708,7 @@ WMError WindowManager::GetAccessibilityWindowInfo(std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetUnreliableWindowInfo(windowId, infos); + WMError ret = WindowAdapter::GetInstance(userId_)->GetUnreliableWindowInfo(windowId, infos); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "get unreliable window info failed"); } @@ -1662,7 +1722,7 @@ WMError WindowManager::ListWindowInfo(const WindowInfoOption& windowInfoOption, static_cast(windowInfoOption.windowInfoFilterOption), static_cast(windowInfoOption.windowInfoTypeOption), windowInfoOption.displayId, windowInfoOption.windowId); - WMError ret = SingletonContainer::Get().ListWindowInfo(windowInfoOption, infos); + WMError ret = WindowAdapter::GetInstance(userId_)->ListWindowInfo(windowInfoOption, infos); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -1671,7 +1731,7 @@ WMError WindowManager::ListWindowInfo(const WindowInfoOption& windowInfoOption, WMError WindowManager::GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetAllWindowLayoutInfo(displayId, infos); + WMError ret = WindowAdapter::GetInstance(userId_)->GetAllWindowLayoutInfo(displayId, infos); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -1680,17 +1740,17 @@ WMError WindowManager::GetAllWindowLayoutInfo(DisplayId displayId, std::vector().GetGlobalWindowMode(displayId, globalWinMode); + return WindowAdapter::GetInstance(userId_)->GetGlobalWindowMode(displayId, globalWinMode); } WMError WindowManager::GetTopNavDestinationName(int32_t windowId, std::string& topNavDestName) const { - return SingletonContainer::Get().GetTopNavDestinationName(windowId, topNavDestName); + return WindowAdapter::GetInstance(userId_)->GetTopNavDestinationName(windowId, topNavDestName); } WMError WindowManager::GetVisibilityWindowInfo(std::vector>& infos) const { - WMError ret = SingletonContainer::Get().GetVisibilityWindowInfo(infos); + WMError ret = WindowAdapter::GetInstance(userId_)->GetVisibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } @@ -1699,7 +1759,7 @@ WMError WindowManager::GetVisibilityWindowInfo(std::vector& infos) { - WMError ret = SingletonContainer::Get().DumpSessionAll(infos); + WMError ret = WindowAdapter::GetInstance(userId_)->DumpSessionAll(infos); if (ret != WMError::WM_OK) { WLOGFE("dump session all failed"); } @@ -1708,7 +1768,7 @@ WMError WindowManager::DumpSessionAll(std::vector& infos) WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector& infos) { - WMError ret = SingletonContainer::Get().DumpSessionWithId(persistentId, infos); + WMError ret = WindowAdapter::GetInstance(userId_)->DumpSessionWithId(persistentId, infos); if (ret != WMError::WM_OK) { WLOGFE("dump session with id failed"); } @@ -1717,7 +1777,7 @@ WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector& uiContentRemoteObj) { - WMError ret = SingletonContainer::Get().GetUIContentRemoteObj(windowId, uiContentRemoteObj); + WMError ret = WindowAdapter::GetInstance(userId_)->GetUIContentRemoteObj(windowId, uiContentRemoteObj); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to get UIContentRemoteObj. PersistentId=%{public}d; ret=%{public}u", windowId, static_cast(ret)); @@ -1727,7 +1787,7 @@ WMError WindowManager::GetUIContentRemoteObj(int32_t windowId, sptr().SetGestureNavigationEnabled(enable); + WMError ret = WindowAdapter::GetInstance(userId_)->SetGestureNavigationEnabled(enable); if (ret != WMError::WM_OK) { WLOGFE("set gesture navigation enabled failed"); } @@ -1736,7 +1796,7 @@ WMError WindowManager::SetGestureNavigationEnabled(bool enable) const WMError WindowManager::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) { - WMError ret = SingletonContainer::Get().NotifyWindowExtensionVisibilityChange(pid, uid, visible); + WMError ret = WindowAdapter::GetInstance(userId_)->NotifyWindowExtensionVisibilityChange(pid, uid, visible); if (ret != WMError::WM_OK) { WLOGFE("notify WindowExtension visibility change failed"); } @@ -1765,7 +1825,7 @@ void WindowManager::NotifyWindowPidVisibilityChanged(const sptr().RaiseWindowToTop(persistentId); + WMError ret = WindowAdapter::GetInstance(userId_)->RaiseWindowToTop(persistentId); if (ret != WMError::WM_OK) { WLOGFE("raise window to top failed"); } @@ -1789,7 +1849,7 @@ WMError WindowManager::RegisterDrawingContentChangedListener(const sptrwindowDrawingContentListenerAgent_ == nullptr) { pImpl_->windowDrawingContentListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret != WMError::WM_OK) { @@ -1821,7 +1881,7 @@ WMError WindowManager::UnregisterDrawingContentChangedListener(const sptrwindowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret == WMError::WM_OK) { @@ -1843,7 +1903,7 @@ WMError WindowManager::RegisterWindowSystemBarPropertyChangedListener( if (pImpl_->windowSystemBarPropertyChangeAgent_ == nullptr) { pImpl_->windowSystemBarPropertyChangeAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_STATUS_BAR_PROPERTY, pImpl_->windowSystemBarPropertyChangeAgent_); if (ret != WMError::WM_OK) { @@ -1878,7 +1938,7 @@ WMError WindowManager::UnregisterWindowSystemBarPropertyChangedListener( } WMError ret = WMError::WM_OK; if (pImpl_->windowSystemBarPropertyChangeAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_STATUS_BAR_PROPERTY, pImpl_->windowSystemBarPropertyChangeAgent_); if (ret == WMError::WM_OK) { @@ -1911,7 +1971,7 @@ void WindowManager::Impl::NotifyWindowSystemBarPropertyChange( WMError WindowManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) { - WMError ret = SingletonContainer::Get().ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); + WMError ret = WindowAdapter::GetInstance(userId_)->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); if (ret != WMError::WM_OK) { WLOGFE("shift application window focus failed"); } @@ -1929,7 +1989,7 @@ WMError WindowManager::RegisterVisibleWindowNumChangedListener(const sptrvisibleWindowNumChangedListenerAgent_ == nullptr) { pImpl_->visibleWindowNumChangedListenerAgent_ = new WindowManagerAgent(); } - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM, pImpl_->visibleWindowNumChangedListenerAgent_); if (ret != WMError::WM_OK) { @@ -1949,7 +2009,7 @@ WMError WindowManager::RegisterVisibleWindowNumChangedListener(const sptr& pixelMap) { - return SingletonContainer::Get().GetSnapshotByWindowId(windowId, pixelMap); + return WindowAdapter::GetInstance(userId_)->GetSnapshotByWindowId(windowId, pixelMap); } WMError WindowManager::UnregisterVisibleWindowNumChangedListener(const sptr& listener) @@ -1968,7 +2028,7 @@ WMError WindowManager::UnregisterVisibleWindowNumChangedListener(const sptrvisibleWindowNumChangedListeners_.empty() && pImpl_->visibleWindowNumChangedListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM, pImpl_->visibleWindowNumChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -2004,7 +2064,7 @@ WMError WindowManager::RegisterWindowStyleChangedListener(const sptrwindowStyleListeners_.push_back(listener); } WMError ret = WMError::WM_OK; - ret = SingletonContainer::Get().RegisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -2036,7 +2096,7 @@ WMError WindowManager::UnregisterWindowStyleChangedListener(const sptrwindowStyleListeners_.empty() && pImpl_->windowStyleListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterWindowManagerAgent( + ret = WindowAdapter::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret == WMError::WM_OK) { std::unique_lock lock(pImpl_->listenerMutex_); @@ -2049,7 +2109,7 @@ WMError WindowManager::UnregisterWindowStyleChangedListener(const sptr().GetWindowStyleType(styleType) == WMError::WM_OK) { + if (WindowAdapter::GetInstance(userId_)->GetWindowStyleType(styleType) == WMError::WM_OK) { return styleType; } return styleType; @@ -2057,7 +2117,7 @@ WindowStyleType WindowManager::GetWindowStyleType() WMError WindowManager::SkipSnapshotForAppProcess(int32_t pid, bool skip) { - WMError ret = SingletonContainer::Get().SkipSnapshotForAppProcess(pid, skip); + WMError ret = WindowAdapter::GetInstance(userId_)->SkipSnapshotForAppProcess(pid, skip); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "skip failed"); } @@ -2066,7 +2126,7 @@ WMError WindowManager::SkipSnapshotForAppProcess(int32_t pid, bool skip) WMError WindowManager::SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled) { - WMError ret = SingletonContainer::Get().SetProcessWatermark(pid, watermarkName, isEnabled); + WMError ret = WindowAdapter::GetInstance(userId_)->SetProcessWatermark(pid, watermarkName, isEnabled); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -2076,7 +2136,7 @@ WMError WindowManager::SetProcessWatermark(int32_t pid, const std::string& water WMError WindowManager::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, int32_t x, int32_t y, std::vector& windowIds) const { - WMError ret = SingletonContainer::Get().GetWindowIdsByCoordinate( + WMError ret = WindowAdapter::GetInstance(userId_)->GetWindowIdsByCoordinate( displayId, windowNumber, x, y, windowIds); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "get windowIds by coordinate failed"); @@ -2086,7 +2146,7 @@ WMError WindowManager::GetWindowIdsByCoordinate(DisplayId displayId, int32_t win WMError WindowManager::UpdateScreenLockStatusForApp(const std::string& bundleName, bool isRelease) { - WMError ret = SingletonContainer::Get().UpdateScreenLockStatusForApp(bundleName, isRelease); + WMError ret = WindowAdapter::GetInstance(userId_)->UpdateScreenLockStatusForApp(bundleName, isRelease); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "update screen lock status failed"); } @@ -2096,7 +2156,7 @@ WMError WindowManager::UpdateScreenLockStatusForApp(const std::string& bundleNam WMError WindowManager::GetDisplayIdByWindowId(const std::vector& windowIds, std::unordered_map& windowDisplayIdMap) { - WMError ret = SingletonContainer::Get().GetDisplayIdByWindowId(windowIds, windowDisplayIdMap); + WMError ret = WindowAdapter::GetInstance(userId_)->GetDisplayIdByWindowId(windowIds, windowDisplayIdMap); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -2105,7 +2165,7 @@ WMError WindowManager::GetDisplayIdByWindowId(const std::vector& windo WMError WindowManager::SetGlobalDragResizeType(DragResizeType dragResizeType) { - WMError ret = SingletonContainer::Get().SetGlobalDragResizeType(dragResizeType); + WMError ret = WindowAdapter::GetInstance(userId_)->SetGlobalDragResizeType(dragResizeType); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "failed"); } @@ -2114,7 +2174,7 @@ WMError WindowManager::SetGlobalDragResizeType(DragResizeType dragResizeType) WMError WindowManager::GetGlobalDragResizeType(DragResizeType& dragResizeType) { - WMError ret = SingletonContainer::Get().GetGlobalDragResizeType(dragResizeType); + WMError ret = WindowAdapter::GetInstance(userId_)->GetGlobalDragResizeType(dragResizeType); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "failed"); } @@ -2123,7 +2183,7 @@ WMError WindowManager::GetGlobalDragResizeType(DragResizeType& dragResizeType) WMError WindowManager::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType) { - WMError ret = SingletonContainer::Get().SetAppDragResizeType(bundleName, dragResizeType); + WMError ret = WindowAdapter::GetInstance(userId_)->SetAppDragResizeType(bundleName, dragResizeType); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "failed"); } @@ -2132,7 +2192,7 @@ WMError WindowManager::SetAppDragResizeType(const std::string& bundleName, DragR WMError WindowManager::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType) { - WMError ret = SingletonContainer::Get().GetAppDragResizeType(bundleName, dragResizeType); + WMError ret = WindowAdapter::GetInstance(userId_)->GetAppDragResizeType(bundleName, dragResizeType); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "failed"); } @@ -2141,7 +2201,7 @@ WMError WindowManager::GetAppDragResizeType(const std::string& bundleName, DragR WMError WindowManager::SetAppKeyFramePolicy(const std::string& bundleName, const KeyFramePolicy& keyFramePolicy) { - WMError ret = SingletonContainer::Get().SetAppKeyFramePolicy(bundleName, keyFramePolicy); + WMError ret = WindowAdapter::GetInstance(userId_)->SetAppKeyFramePolicy(bundleName, keyFramePolicy); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::DEFAULT, "failed"); } @@ -2150,7 +2210,7 @@ WMError WindowManager::SetAppKeyFramePolicy(const std::string& bundleName, const WMError WindowManager::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId, int32_t fingerId) { - WMError ret = SingletonContainer::Get().ShiftAppWindowPointerEvent( + WMError ret = WindowAdapter::GetInstance(userId_)->ShiftAppWindowPointerEvent( sourceWindowId, targetWindowId, fingerId); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_PC, "failed"); @@ -2160,7 +2220,7 @@ WMError WindowManager::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_ WMError WindowManager::NotifyScreenshotEvent(ScreenshotEventType type) { - WMError ret = SingletonContainer::Get().NotifyScreenshotEvent(type); + WMError ret = WindowAdapter::GetInstance(userId_)->NotifyScreenshotEvent(type); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -2171,7 +2231,7 @@ WMError WindowManager::SetStartWindowBackgroundColor( const std::string& moduleName, const std::string& abilityName, uint32_t color) { int32_t uid = static_cast(getuid()); - WMError ret = SingletonContainer::Get().SetStartWindowBackgroundColor( + WMError ret = WindowAdapter::GetInstance(userId_)->SetStartWindowBackgroundColor( moduleName, abilityName, color, uid); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_PATTERN, "failed"); @@ -2189,7 +2249,7 @@ WMError WindowManager::RequestFocus(int32_t persistentId, bool isFocused, TLOGE(WmsLogTag::WMS_FOCUS, "could not find focus reason"); return WMError::WM_ERROR_INVALID_PARAM; } - WMError ret = SingletonContainer::Get().RequestFocusStatusBySA(persistentId, + WMError ret = WindowAdapter::GetInstance(userId_)->RequestFocusStatusBySA(persistentId, isFocused, byForeground, static_cast(curReason)); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_FOCUS, "failed"); @@ -2199,7 +2259,7 @@ WMError WindowManager::RequestFocus(int32_t persistentId, bool isFocused, WMError WindowManager::MinimizeByWindowId(const std::vector& windowIds) { - WMError ret = SingletonContainer::Get().MinimizeByWindowId(windowIds); + WMError ret = WindowAdapter::GetInstance(userId_)->MinimizeByWindowId(windowIds); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_LIFE, "failed"); } @@ -2208,7 +2268,7 @@ WMError WindowManager::MinimizeByWindowId(const std::vector& windowIds) WMError WindowManager::SetForegroundWindowNum(uint32_t windowNum) { - WMError ret = SingletonContainer::Get().SetForegroundWindowNum(windowNum); + WMError ret = WindowAdapter::GetInstance(userId_)->SetForegroundWindowNum(windowNum); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_PC, "failed"); } @@ -2360,7 +2420,7 @@ WMError WindowManager::AnimateTo(int32_t windowId, WindowAnimationProperty anima { TLOGI(WmsLogTag::WMS_ANIMATION, "In, windowId: %{public}d, targetScale: %{public}f, animationOption: %{public}s", windowId, animationProperty.targetScale, animationOption.ToString().c_str()); - WMError ret = SingletonContainer::Get().AnimateTo(windowId, animationProperty, animationOption); + WMError ret = WindowAdapter::GetInstance(userId_)->AnimateTo(windowId, animationProperty, animationOption); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ANIMATION, "Failed, errorCode: %{public}d", static_cast(ret)); } @@ -2421,7 +2481,7 @@ WMError WindowManager::AddSessionBlackList( const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) { TLOGI(WmsLogTag::WMS_ATTRIBUTE, "in"); - auto ret = SingletonContainer::Get().AddSessionBlackList(bundleNames, privacyWindowTags); + auto ret = WindowAdapter::GetInstance(userId_)->AddSessionBlackList(bundleNames, privacyWindowTags); return ret; } @@ -2429,7 +2489,7 @@ WMError WindowManager::RemoveSessionBlackList( const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) { TLOGI(WmsLogTag::WMS_ATTRIBUTE, "in"); - auto ret = SingletonContainer::Get(). + auto ret = WindowAdapter::GetInstance(userId_)-> RemoveSessionBlackList(bundleNames, privacyWindowTags); return ret; } diff --git a/wm/src/window_manager_lite.cpp b/wm/src/window_manager_lite.cpp index 35bd8fbe7a..5564ca2895 100644 --- a/wm/src/window_manager_lite.cpp +++ b/wm/src/window_manager_lite.cpp @@ -417,7 +417,6 @@ WMError WindowManagerLite::RemoveInstanceByUserId(const int userId) return WMError::OK; } - WMError WindowManagerLite::RegisterFocusChangedListener(const sptr& listener) { if (listener == nullptr) { @@ -429,7 +428,7 @@ WMError WindowManagerLite::RegisterFocusChangedListener(const sptrfocusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); } if (ret != WMError::WM_OK) { @@ -462,7 +461,7 @@ WMError WindowManagerLite::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->focusChangedListenerAgent_ = nullptr; @@ -481,7 +480,7 @@ WMError WindowManagerLite::RegisterVisibilityChangedListener(const sptrwindowVisibilityListenerAgent_ == nullptr) { pImpl_->windowVisibilityListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); } @@ -514,7 +513,7 @@ WMError WindowManagerLite::UnregisterVisibilityChangedListener(const sptrwindowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret == WMError::WM_OK) { @@ -535,7 +534,7 @@ WMError WindowManagerLite::RegisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListenerAgent_ == nullptr) { pImpl_->windowVisibilityStateListenerAgent_ = new WindowManagerAgentLite(); } - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret != WMError::WM_OK) { @@ -567,7 +566,7 @@ WMError WindowManagerLite::UnregisterVisibilityStateChangedListener(const sptrwindowVisibilityStateListeners_.empty() && pImpl_->windowVisibilityStateListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityStateListenerAgent_); if (ret == WMError::WM_OK) { @@ -580,7 +579,7 @@ WMError WindowManagerLite::UnregisterVisibilityStateChangedListener(const sptrGetFocusWindowInfo(focusInfo, displayId); } void WindowManagerLite::UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const @@ -606,7 +605,7 @@ void WindowManagerLite::UpdateWindowVisibilityInfo( WMError WindowManagerLite::GetVisibilityWindowInfo(std::vector>& infos) const { - WMError ret = WindowAdapterLite::GetInstance(userId_).GetVisibilityWindowInfo(infos); + WMError ret = WindowAdapterLite::GetInstance(userId_)->GetVisibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } @@ -648,7 +647,7 @@ WMError WindowManagerLite::RegisterDrawingContentChangedListener(const sptrwindowDrawingContentListenerAgent_ == nullptr) { pImpl_->windowDrawingContentListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); } @@ -681,7 +680,7 @@ WMError WindowManagerLite::UnregisterDrawingContentChangedListener(const sptrwindowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret == WMError::WM_OK) { @@ -704,7 +703,7 @@ void WindowManagerLite::NotifyAccessibilityWindowInfo(const std::vectorGetWindowModeType(windowModeType); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } @@ -722,7 +721,7 @@ WMError WindowManagerLite::RegisterWindowModeChangedListener(const sptrwindowModeListenerAgent_ == nullptr) { pImpl_->windowModeListenerAgent_ = new (std::nothrow) WindowManagerAgentLite(); } - WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -754,7 +753,7 @@ WMError WindowManagerLite::UnregisterWindowModeChangedListener(const sptrwindowModeListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowModeListeners_.empty() && pImpl_->windowModeListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowModeListenerAgent_ = nullptr; @@ -774,7 +773,7 @@ WMError WindowManagerLite::RegisterCameraWindowChangedListener(const sptrcameraWindowChangedListenerAgent_ == nullptr) { pImpl_->cameraWindowChangedListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pImpl_->cameraWindowChangedListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_SYSTEM, "RegisterWindowManagerAgent failed!"); @@ -809,7 +808,7 @@ WMError WindowManagerLite::UnregisterCameraWindowChangedListener(const sptrcameraWindowChangedListeners_.empty() && pImpl_->cameraWindowChangedListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_WINDOW, pImpl_->cameraWindowChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -821,7 +820,7 @@ WMError WindowManagerLite::UnregisterCameraWindowChangedListener(const sptrRaiseWindowToTop(persistentId); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_SYSTEM, "raise window to top failed."); } @@ -831,12 +830,12 @@ WMError WindowManagerLite::RaiseWindowToTop(int32_t persistentId) WMError WindowManagerLite::GetMainWindowInfos(int32_t topNum, std::vector& topNInfo) { TLOGI(WmsLogTag::WMS_MAIN, "Get main window info lite"); - return WindowAdapterLite::GetInstance(userId_).GetMainWindowInfos(topNum, topNInfo); + return WindowAdapterLite::GetInstance(userId_)->GetMainWindowInfos(topNum, topNInfo); } WMError WindowManagerLite::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo) { - return WindowAdapterLite::GetInstance(userId_).GetCallingWindowInfo(callingWindowInfo); + return WindowAdapterLite::GetInstance(userId_)->GetCallingWindowInfo(callingWindowInfo); } WMError WindowManagerLite::RegisterWMSConnectionChangedListener(const sptr& listener) @@ -896,7 +895,7 @@ WMError WindowManagerLite::GetAllMainWindowInfos(std::vector& in TLOGE(WmsLogTag::WMS_MAIN, "infos is not empty."); return WMError::WM_ERROR_INVALID_PARAM; } - return WindowAdapterLite::GetInstance(userId_).GetAllMainWindowInfos(infos); + return WindowAdapterLite::GetInstance(userId_)->GetAllMainWindowInfos(infos); } WMError WindowManagerLite::ClearMainSessions(const std::vector& persistentIds) @@ -905,7 +904,7 @@ WMError WindowManagerLite::ClearMainSessions(const std::vector& persist TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty."); return WMError::WM_OK; } - return WindowAdapterLite::GetInstance(userId_).ClearMainSessions(persistentIds); + return WindowAdapterLite::GetInstance(userId_)->ClearMainSessions(persistentIds); } WMError WindowManagerLite::ClearMainSessions(const std::vector& persistentIds, @@ -915,7 +914,7 @@ WMError WindowManagerLite::ClearMainSessions(const std::vector& persist TLOGW(WmsLogTag::WMS_MAIN, "Clear main Session failed, persistentIds is empty."); return WMError::WM_OK; } - return WindowAdapterLite::GetInstance(userId_).ClearMainSessions(persistentIds, clearFailedIds); + return WindowAdapterLite::GetInstance(userId_)->ClearMainSessions(persistentIds, clearFailedIds); } WMError WindowManagerLite::NotifyWindowStyleChange(WindowStyleType type) @@ -950,7 +949,7 @@ WMError WindowManagerLite::RegisterWindowStyleChangedListener(const sptrwindowStyleListeners_.push_back(listener); } WMError ret = WMError::WM_OK; - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!"); @@ -982,7 +981,7 @@ WMError WindowManagerLite::UnregisterWindowStyleChangedListener(const sptrwindowStyleListeners_.empty() && pImpl_->windowStyleListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_); if (ret == WMError::WM_OK) { std::lock_guard lock(pImpl_->mutex_); @@ -1014,7 +1013,7 @@ WMError WindowManagerLite::RegisterCallingWindowDisplayChangedListener( pImpl_->callingDisplayChangedListeners_.emplace_back(listener); } WMError ret = WMError::WM_OK; - ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_KEYBOARD, "Register agent failed!"); @@ -1049,7 +1048,7 @@ WMError WindowManagerLite::UnregisterCallingWindowDisplayChangedListener( } WMError ret = WMError::WM_OK; if (pImpl_->callingDisplayChangedListeners_.empty() && pImpl_->callingDisplayListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CALLING_DISPLAY, pImpl_->callingDisplayListenerAgent_); if (ret == WMError::WM_OK) { std::lock_guard lock(pImpl_->mutex_); @@ -1062,7 +1061,7 @@ WMError WindowManagerLite::UnregisterCallingWindowDisplayChangedListener( WindowStyleType WindowManagerLite::GetWindowStyleType() { WindowStyleType styleType; - if (WindowAdapterLite::GetInstance(userId_).GetWindowStyleType(styleType) == WMError::WM_OK) { + if (WindowAdapterLite::GetInstance(userId_)->GetWindowStyleType(styleType) == WMError::WM_OK) { return styleType; } return styleType; @@ -1074,7 +1073,7 @@ WMError WindowManagerLite::TerminateSessionByPersistentId(int32_t persistentId) TLOGE(WmsLogTag::WMS_LIFE, "persistentId is invalid."); return WMError::WM_ERROR_INVALID_PARAM; } - return WindowAdapterLite::GetInstance(userId_).TerminateSessionByPersistentId(persistentId); + return WindowAdapterLite::GetInstance(userId_)->TerminateSessionByPersistentId(persistentId); } WMError WindowManagerLite::CloseTargetFloatWindow(const std::string& bundleName) @@ -1083,7 +1082,7 @@ WMError WindowManagerLite::CloseTargetFloatWindow(const std::string& bundleName) TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "bundleName is empty."); return WMError::WM_ERROR_INVALID_PARAM; } - return WindowAdapterLite::GetInstance(userId_).CloseTargetFloatWindow(bundleName); + return WindowAdapterLite::GetInstance(userId_)->CloseTargetFloatWindow(bundleName); } WMError WindowManagerLite::RegisterPiPStateChangedListener(const sptr& listener) @@ -1098,7 +1097,7 @@ WMError WindowManagerLite::RegisterPiPStateChangedListener(const sptrpipStateChangedListenerAgent_ == nullptr) { pImpl_->pipStateChangedListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP, pImpl_->pipStateChangedListenerAgent_); if (ret != WMError::WM_OK) { TLOGW(WmsLogTag::WMS_PIP, "RegisterWindowManagerAgent failed!"); @@ -1134,7 +1133,7 @@ WMError WindowManagerLite::UnregisterPiPStateChangedListener(const sptrpipStateChangedListeners_.empty() && pImpl_->pipStateChangedListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PIP, pImpl_->pipStateChangedListenerAgent_); if (ret == WMError::WM_OK) { @@ -1151,12 +1150,12 @@ WMError WindowManagerLite::CloseTargetPiPWindow(const std::string& bundleName) return WMError::WM_ERROR_INVALID_PARAM; } TLOGD(WmsLogTag::WMS_PIP, "bundleName:%{public}s", bundleName.c_str()); - return WindowAdapterLite::GetInstance(userId_).CloseTargetPiPWindow(bundleName); + return WindowAdapterLite::GetInstance(userId_)->CloseTargetPiPWindow(bundleName); } WMError WindowManagerLite::GetCurrentPiPWindowInfo(std::string& bundleName) { - return WindowAdapterLite::GetInstance(userId_).GetCurrentPiPWindowInfo(bundleName); + return WindowAdapterLite::GetInstance(userId_)->GetCurrentPiPWindowInfo(bundleName); } void WindowManagerLite::UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground) const @@ -1166,7 +1165,7 @@ void WindowManagerLite::UpdatePiPWindowStateChanged(const std::string& bundleNam WMError WindowManagerLite::GetAccessibilityWindowInfo(std::vector>& infos) const { - WMError ret = WindowAdapterLite::GetInstance(userId_).GetAccessibilityWindowInfo(infos); + WMError ret = WindowAdapterLite::GetInstance(userId_)->GetAccessibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window info failed"); } @@ -1183,7 +1182,7 @@ WMError WindowManagerLite::RegisterWindowUpdateListener(const sptrwindowUpdateListenerAgent_ == nullptr) { pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgentLite(); } - WMError ret = WindowAdapterLite::GetInstance(userId_).RegisterWindowManagerAgent( + WMError ret = WindowAdapterLite::GetInstance(userId_)->RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret != WMError::WM_OK) { WLOGFW("RegisterWindowManagerAgent failed!"); @@ -1214,7 +1213,7 @@ WMError WindowManagerLite::UnregisterWindowUpdateListener(const sptrwindowUpdateListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) { - ret = WindowAdapterLite::GetInstance(userId_).UnregisterWindowManagerAgent( + ret = WindowAdapterLite::GetInstance(userId_)->UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowUpdateListenerAgent_ = nullptr; @@ -1296,7 +1295,7 @@ WMError WindowManagerLite::ListWindowInfo(const WindowInfoOption& windowInfoOpti static_cast(windowInfoOption.windowInfoFilterOption), static_cast(windowInfoOption.windowInfoTypeOption), windowInfoOption.displayId, windowInfoOption.windowId); - WMError ret = WindowAdapterLite::GetInstance(userId_).ListWindowInfo(windowInfoOption, infos); + WMError ret = WindowAdapterLite::GetInstance(userId_)->ListWindowInfo(windowInfoOption, infos); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed"); } @@ -1314,7 +1313,7 @@ WMError WindowManagerLite::SendPointerEventForHover(const std::shared_ptrSendPointerEventForHover(pointerEvent); if (ret != WMError::WM_OK) { TLOGE(WmsLogTag::WMS_EVENT, "send failed"); } -- Gitee