/* * Copyright (c) 2021-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.h" #include #include #include "input_manager.h" #include "marshalling_helper.h" #include "window_adapter.h" #include "window_manager_agent.h" #include "window_manager_hilog.h" #include "wm_common.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManager"}; struct WindowChecker : public MMI::IWindowChecker { public: WindowChecker() = default; ~WindowChecker() = default; int32_t CheckWindowId(int32_t windowId) const override; }; } WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager) class WindowManager::Impl { public: explicit Impl(std::recursive_mutex& mutex) : mutex_(mutex) {} void NotifyWMSConnected(int32_t userId, int32_t screenId); void NotifyWMSDisconnected(int32_t userId, int32_t screenId); void NotifyFocused(uint32_t windowId, const sptr& abilityToken, WindowType windowType, DisplayId displayId); void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, WindowType windowType, DisplayId displayId); void NotifyFocused(const sptr& focusChangeInfo); void NotifyUnfocused(const sptr& focusChangeInfo); void NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints); void NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type); void NotifyWindowVisibilityInfoChanged(const std::vector>& windowVisibilityInfos); void NotifyWindowDrawingContentInfoChanged(const std::vector>& windowDrawingContentInfos); void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing); void NotifyWaterMarkFlagChangedResult(bool showWaterMark); void NotifyGestureNavigationEnabledResult(bool enable); static inline SingletonDelegator delegator_; std::recursive_mutex& mutex_; sptr wmsConnectionChangedListener_; std::vector> focusChangedListeners_; sptr focusChangedListenerAgent_; std::vector> systemBarChangedListeners_; sptr systemBarChangedListenerAgent_; std::vector> windowUpdateListeners_; sptr windowUpdateListenerAgent_; std::vector> windowVisibilityListeners_; sptr windowVisibilityListenerAgent_; std::vector> windowDrawingContentListeners_; sptr windowDrawingContentListenerAgent_; std::vector> cameraFloatWindowChangedListeners_; sptr cameraFloatWindowChangedListenerAgent_; std::vector> waterMarkFlagChangeListeners_; sptr waterMarkFlagChangeAgent_; std::vector> gestureNavigationEnabledListeners_; sptr gestureNavigationEnabledAgent_; }; void WindowManager::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId) { WLOGFI("NotifyWMSConnected [userId:%{public}d; screenId:%{public}d]", userId, screenId); sptr wmsConnectionChangedListener; { std::lock_guard lock(mutex_); wmsConnectionChangedListener = wmsConnectionChangedListener_; } if (wmsConnectionChangedListener != nullptr) { wmsConnectionChangedListener->OnConnected(userId, screenId); } } void WindowManager::Impl::NotifyWMSDisconnected(int32_t userId, int32_t screenId) { WLOGFI("NotifyWMSDisconnected [userId:%{public}d; screenId:%{public}d]", userId, screenId); sptr wmsConnectionChangedListener; { std::lock_guard lock(mutex_); wmsConnectionChangedListener = wmsConnectionChangedListener_; } if (wmsConnectionChangedListener != nullptr) { wmsConnectionChangedListener->OnDisconnected(userId, screenId); } } void WindowManager::Impl::NotifyFocused(const sptr& focusChangeInfo) { WLOGFD("[WMSFocus]NotifyFocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]", focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_, static_cast(focusChangeInfo->windowType_)); std::vector> focusChangeListeners; { std::lock_guard lock(mutex_); focusChangeListeners = focusChangedListeners_; } for (auto& listener : focusChangeListeners) { listener->OnFocused(focusChangeInfo); } } void WindowManager::Impl::NotifyUnfocused(const sptr& focusChangeInfo) { WLOGFD("[WMSFocus]NotifyUnfocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]", focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_, static_cast(focusChangeInfo->windowType_)); std::vector> focusChangeListeners; { std::lock_guard lock(mutex_); focusChangeListeners = focusChangedListeners_; } for (auto& listener : focusChangeListeners) { listener->OnUnfocused(focusChangeInfo); } } void WindowManager::Impl::NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints) { for (auto tint : tints) { WLOGFD("type:%{public}d, enable:%{public}d," \ "backgroundColor:%{public}x, contentColor:%{public}x " \ "region:[%{public}d, %{public}d, %{public}d, %{public}d]", tint.type_, tint.prop_.enable_, tint.prop_.backgroundColor_, tint.prop_.contentColor_, tint.region_.posX_, tint.region_.posY_, tint.region_.width_, tint.region_.height_); } std::vector> systemBarChangeListeners; { std::lock_guard lock(mutex_); systemBarChangeListeners = systemBarChangedListeners_; } for (auto& listener : systemBarChangeListeners) { listener->OnSystemBarPropertyChange(displayId, tints); } } void WindowManager::Impl::NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type) { if (infos.empty()) { WLOGFE("infos is empty"); return; } for (auto& info : infos) { WLOGFD("NotifyAccessibilityWindowInfo: wid[%{public}u], innerWid_[%{public}u], uiNodeId_[%{public}u]," \ "rect[%{public}d %{public}d %{public}d %{public}d]," \ "isFocused[%{public}d], isDecorEnable[%{public}d], displayId[%{public}" PRIu64"], layer[%{public}u]," \ "mode[%{public}u], type[%{public}u, updateType[%{public}d]", info->wid_, info->innerWid_, info->uiNodeId_, info->windowRect_.width_, info->windowRect_.height_, info->windowRect_.posX_, info->windowRect_.posY_, info->focused_, info->isDecorEnable_, info->displayId_, info->layer_, info->mode_, info->type_, type); } std::vector> windowUpdateListeners; { std::lock_guard lock(mutex_); windowUpdateListeners = windowUpdateListeners_; } for (auto& listener : windowUpdateListeners) { listener->OnWindowUpdate(infos, type); } } void WindowManager::Impl::NotifyWindowVisibilityInfoChanged( const std::vector>& windowVisibilityInfos) { std::vector> visibilityChangeListeners; { std::lock_guard lock(mutex_); visibilityChangeListeners = windowVisibilityListeners_; } for (auto& listener : visibilityChangeListeners) { WLOGI("Notify WindowVisibilityInfo to caller"); listener->OnWindowVisibilityChanged(windowVisibilityInfos); } } void WindowManager::Impl::NotifyWindowDrawingContentInfoChanged( const std::vector>& windowDrawingContentInfos) { std::vector> windowDrawingContentChangeListeners; { std::lock_guard lock(mutex_); windowDrawingContentChangeListeners = windowDrawingContentListeners_; } for (auto& listener : windowDrawingContentChangeListeners) { WLOGFD("Notify windowDrawingContentInfo to caller"); listener->OnWindowDrawingContentChanged(windowDrawingContentInfos); } } void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) { WLOGFD("Camera float window, accessTokenId = %{public}u, isShowing = %{public}u", accessTokenId, isShowing); std::vector> cameraFloatWindowChangeListeners; { std::lock_guard lock(mutex_); cameraFloatWindowChangeListeners = cameraFloatWindowChangedListeners_; } for (auto& listener : cameraFloatWindowChangeListeners) { listener->OnCameraFloatWindowChange(accessTokenId, isShowing); } } void WindowManager::Impl::NotifyWaterMarkFlagChangedResult(bool showWaterMark) { WLOGFI("Notify water mark flag changed result, showWaterMark = %{public}d", showWaterMark); std::vector> waterMarkFlagChangeListeners; { std::lock_guard lock(mutex_); waterMarkFlagChangeListeners = waterMarkFlagChangeListeners_; } for (auto& listener : waterMarkFlagChangeListeners) { listener->OnWaterMarkFlagUpdate(showWaterMark); } } void WindowManager::Impl::NotifyGestureNavigationEnabledResult(bool enable) { WLOGFI("Notify gesture navigation enable result, enable = %{public}d", enable); std::vector> gestureNavigationEnabledListeners; { std::lock_guard lock(mutex_); gestureNavigationEnabledListeners = gestureNavigationEnabledListeners_; } for (auto& listener : gestureNavigationEnabledListeners) { listener->OnGestureNavigationEnabledUpdate(enable); } } WindowManager::WindowManager() : pImpl_(std::make_unique(mutex_)) { auto windowChecker = std::make_shared(); MMI::InputManager::GetInstance()->SetWindowCheckerHandler(windowChecker); } int32_t WindowChecker::CheckWindowId(int32_t windowId) const { int32_t pid = INVALID_PID; WMError ret = SingletonContainer::Get().CheckWindowId(windowId, pid); if (ret != WMError::WM_OK) { WLOGFE("Window(%{public}d) do not allow styles to be set", windowId); } return pid; } WindowManager::~WindowManager() { std::lock_guard lock(mutex_); destroyed_ = true; } WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("WMS connection changed listener registered could not be null"); return WMError::WM_ERROR_NULLPTR; } WLOGFI("RegisterWMSConnectionChangedListener in"); { std::lock_guard lock(pImpl_->mutex_); if (pImpl_->wmsConnectionChangedListener_) { WLOGFI("wmsConnectionChangedListener is already registered, do nothing"); return WMError::WM_OK; } pImpl_->wmsConnectionChangedListener_ = listener; } return SingletonContainer::Get().RegisterWMSConnectionChangedListener( std::bind(&WindowManager::OnWMSConnectionChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } WMError WindowManager::UnregisterWMSConnectionChangedListener() { WLOGFI("UnregisterWMSConnectionChangedListener in"); std::lock_guard lock(pImpl_->mutex_); pImpl_->wmsConnectionChangedListener_ = nullptr; return WMError::WM_OK; } WMError WindowManager::RegisterFocusChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->focusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->focusChangedListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener); if (iter != pImpl_->focusChangedListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->focusChangedListeners_.push_back(listener); } return ret; } WMError WindowManager::UnregisterFocusChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener); if (iter == pImpl_->focusChangedListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_OK; } pImpl_->focusChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->focusChangedListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::RegisterSystemBarChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->systemBarChangedListenerAgent_ == nullptr) { pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->systemBarChangedListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(), listener); if (iter != pImpl_->systemBarChangedListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->systemBarChangedListeners_.push_back(listener); } return ret; } WMError WindowManager::UnregisterSystemBarChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(), listener); if (iter == pImpl_->systemBarChangedListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_OK; } pImpl_->systemBarChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->systemBarChangedListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::MinimizeAllAppWindows(DisplayId displayId) { WLOGFD("displayId %{public}" PRIu64"", displayId); return SingletonContainer::Get().MinimizeAllAppWindows(displayId); } WMError WindowManager::ToggleShownStateForAllAppWindows() { WLOGFD("ToggleShownStateForAllAppWindows"); return SingletonContainer::Get().ToggleShownStateForAllAppWindows(); } WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode) { WLOGFD("set window layout mode: %{public}u", mode); WMError ret = SingletonContainer::Get().SetWindowLayoutMode(mode); if (ret != WMError::WM_OK) { WLOGFE("set layout mode failed"); } return ret; } WMError WindowManager::RegisterWindowUpdateListener(const sptr &listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->windowUpdateListenerAgent_ == nullptr) { pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->windowUpdateListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener); if (iter != pImpl_->windowUpdateListeners_.end()) { WLOGI("Listener is already registered."); return WMError::WM_OK; } pImpl_->windowUpdateListeners_.emplace_back(listener); } return ret; } WMError WindowManager::UnregisterWindowUpdateListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener); if (iter == pImpl_->windowUpdateListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_OK; } pImpl_->windowUpdateListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowUpdateListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::RegisterVisibilityChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->windowVisibilityListenerAgent_ == nullptr) { pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->windowVisibilityListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(), listener); if (iter != pImpl_->windowVisibilityListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->windowVisibilityListeners_.emplace_back(listener); } return ret; } WMError WindowManager::UnregisterVisibilityChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); pImpl_->windowVisibilityListeners_.erase(std::remove_if(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(), [listener](sptr registeredListener) { return registeredListener == listener; }), pImpl_->windowVisibilityListeners_.end()); WMError ret = WMError::WM_OK; if (pImpl_->windowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY, pImpl_->windowVisibilityListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowVisibilityListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::RegisterCameraFloatWindowChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) { pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, pImpl_->cameraFloatWindowChangedListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(), pImpl_->cameraFloatWindowChangedListeners_.end(), listener); if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->cameraFloatWindowChangedListeners_.push_back(listener); } return ret; } WMError WindowManager::UnregisterCameraFloatWindowChangedListener( const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(), pImpl_->cameraFloatWindowChangedListeners_.end(), listener); if (iter == pImpl_->cameraFloatWindowChangedListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_OK; } pImpl_->cameraFloatWindowChangedListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->cameraFloatWindowChangedListeners_.empty() && pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT, pImpl_->cameraFloatWindowChangedListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::RegisterWaterMarkFlagChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->waterMarkFlagChangeAgent_ == nullptr) { pImpl_->waterMarkFlagChangeAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG, pImpl_->waterMarkFlagChangeAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->waterMarkFlagChangeAgent_ = nullptr; } else { auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(), pImpl_->waterMarkFlagChangeListeners_.end(), listener); if (iter != pImpl_->waterMarkFlagChangeListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->waterMarkFlagChangeListeners_.push_back(listener); } WLOGFD("Try to registerWaterMarkFlagChangedListener && result : %{public}u", static_cast(ret)); return ret; } WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(), pImpl_->waterMarkFlagChangeListeners_.end(), listener); if (iter == pImpl_->waterMarkFlagChangeListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_OK; } pImpl_->waterMarkFlagChangeListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->waterMarkFlagChangeListeners_.empty() && pImpl_->waterMarkFlagChangeAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG, pImpl_->waterMarkFlagChangeAgent_); if (ret == WMError::WM_OK) { pImpl_->waterMarkFlagChangeAgent_ = nullptr; } } WLOGFD("Try to unregisterWaterMarkFlagChangedListener && result : %{public}u", static_cast(ret)); return ret; } WMError WindowManager::RegisterGestureNavigationEnabledChangedListener( const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->gestureNavigationEnabledAgent_ == nullptr) { pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent(); } if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) { ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED, pImpl_->gestureNavigationEnabledAgent_); } else { WLOGFE("Create windowManagerAgent object failed!"); ret = WMError::WM_ERROR_NULLPTR; } if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFE("RegisterWindowManagerAgent failed!"); pImpl_->gestureNavigationEnabledAgent_ = nullptr; } else { auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(), pImpl_->gestureNavigationEnabledListeners_.end(), listener); if (iter != pImpl_->gestureNavigationEnabledListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->gestureNavigationEnabledListeners_.push_back(listener); } WLOGFD("Try to registerGestureNavigationEnabledChangedListener and result is %{public}u", static_cast(ret)); return ret; } WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener( const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(), pImpl_->gestureNavigationEnabledListeners_.end(), listener); if (iter == pImpl_->gestureNavigationEnabledListeners_.end()) { WLOGFE("could not find this listener"); return WMError::WM_ERROR_INVALID_PARAM; } pImpl_->gestureNavigationEnabledListeners_.erase(iter); WMError ret = WMError::WM_OK; if (pImpl_->gestureNavigationEnabledListeners_.empty() && pImpl_->gestureNavigationEnabledAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED, pImpl_->gestureNavigationEnabledAgent_); if (ret == WMError::WM_OK) { pImpl_->gestureNavigationEnabledAgent_ = nullptr; } } WLOGFD("Try to unregisterGestureNavigationEnabledChangedListener and result is %{public}u", static_cast(ret)); return ret; } void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo) { SingletonContainer::Get().GetFocusWindowInfo(focusInfo); } void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const { if (isConnected) { pImpl_->NotifyWMSConnected(userId, screenId); } else { pImpl_->NotifyWMSDisconnected(userId, screenId); } } void WindowManager::UpdateFocusChangeInfo(const sptr& focusChangeInfo, bool focused) const { if (focusChangeInfo == nullptr) { WLOGFE("focusChangeInfo is nullptr."); return; } WLOGFD("[WMSFocus]window focus change: %{public}d, id: %{public}u", focused, focusChangeInfo->windowId_); if (focused) { pImpl_->NotifyFocused(focusChangeInfo); } else { pImpl_->NotifyUnfocused(focusChangeInfo); } } void WindowManager::UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) const { pImpl_->NotifySystemBarChanged(displayId, tints); } void WindowManager::NotifyAccessibilityWindowInfo(const std::vector>& infos, WindowUpdateType type) const { pImpl_->NotifyAccessibilityWindowInfo(infos, type); } void WindowManager::UpdateWindowVisibilityInfo( const std::vector>& windowVisibilityInfos) const { pImpl_->NotifyWindowVisibilityInfoChanged(windowVisibilityInfos); } void WindowManager::UpdateWindowDrawingContentInfo( const std::vector>& windowDrawingContentInfos) const { pImpl_->NotifyWindowDrawingContentInfoChanged(windowDrawingContentInfos); } WMError WindowManager::GetAccessibilityWindowInfo(std::vector>& infos) const { WMError ret = SingletonContainer::Get().GetAccessibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window info failed"); } return ret; } WMError WindowManager::GetVisibilityWindowInfo(std::vector>& infos) const { WMError ret = SingletonContainer::Get().GetVisibilityWindowInfo(infos); if (ret != WMError::WM_OK) { WLOGFE("get window visibility info failed"); } return ret; } WMError WindowManager::DumpSessionAll(std::vector &infos) { WMError ret = SingletonContainer::Get().DumpSessionAll(infos); if (ret != WMError::WM_OK) { WLOGFE("dump session all failed"); } return ret; } WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector &infos) { WMError ret = SingletonContainer::Get().DumpSessionWithId(persistentId, infos); if (ret != WMError::WM_OK) { WLOGFE("dump session with id failed"); } return ret; } WMError WindowManager::SetGestureNavigaionEnabled(bool enable) const { WMError ret = SingletonContainer::Get().SetGestureNavigaionEnabled(enable); if (ret != WMError::WM_OK) { WLOGFE("set gesture navigaion enabled failed"); } return ret; } WMError WindowManager::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) { WMError ret = SingletonContainer::Get().NotifyWindowExtensionVisibilityChange(pid, uid, visible); if (ret != WMError::WM_OK) { WLOGFE("notify WindowExtension visibility change failed"); } return ret; } void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const { pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing); } void WindowManager::NotifyWaterMarkFlagChangedResult(bool showWaterMark) const { pImpl_->NotifyWaterMarkFlagChangedResult(showWaterMark); } void WindowManager::NotifyGestureNavigationEnabledResult(bool enable) const { pImpl_->NotifyGestureNavigationEnabledResult(enable); } WMError WindowManager::RaiseWindowToTop(int32_t persistentId) { WMError ret = SingletonContainer::Get().RaiseWindowToTop(persistentId); if (ret != WMError::WM_OK) { WLOGFE("raise window to top failed"); } return ret; } WMError WindowManager::RegisterDrawingContentChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); WMError ret = WMError::WM_OK; if (pImpl_->windowDrawingContentListenerAgent_ == nullptr) { pImpl_->windowDrawingContentListenerAgent_ = new WindowManagerAgent(); } ret = SingletonContainer::Get().RegisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) { WLOGFW("RegisterWindowManagerAgent failed!"); pImpl_->windowDrawingContentListenerAgent_ = nullptr; } else { auto iter = std::find(pImpl_->windowDrawingContentListeners_.begin(), pImpl_->windowDrawingContentListeners_.end(), listener); if (iter != pImpl_->windowDrawingContentListeners_.end()) { WLOGFW("Listener is already registered."); return WMError::WM_OK; } pImpl_->windowDrawingContentListeners_.emplace_back(listener); } return ret; } WMError WindowManager::UnregisterDrawingContentChangedListener(const sptr& listener) { if (listener == nullptr) { WLOGFE("listener could not be null"); return WMError::WM_ERROR_NULLPTR; } std::lock_guard lock(pImpl_->mutex_); pImpl_->windowDrawingContentListeners_.erase(std::remove_if(pImpl_->windowDrawingContentListeners_.begin(), pImpl_->windowDrawingContentListeners_.end(), [listener](sptr registeredListener) { return registeredListener == listener; }), pImpl_->windowDrawingContentListeners_.end()); WMError ret = WMError::WM_OK; if (pImpl_->windowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) { ret = SingletonContainer::Get().UnregisterWindowManagerAgent( WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE, pImpl_->windowDrawingContentListenerAgent_); if (ret == WMError::WM_OK) { pImpl_->windowDrawingContentListenerAgent_ = nullptr; } } return ret; } WMError WindowManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) { WMError ret = SingletonContainer::Get().ShiftAppWindowFocus(sourcePersistentId, targetPersistentId); if (ret != WMError::WM_OK) { WLOGFE("shift application window focus failed"); } return ret; } } // namespace Rosen } // namespace OHOS