• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "window_manager.h"
17 
18 #include <algorithm>
19 #include <cinttypes>
20 
21 #include "input_manager.h"
22 
23 #include "marshalling_helper.h"
24 #include "window_adapter.h"
25 #include "window_manager_agent.h"
26 #include "window_manager_hilog.h"
27 #include "wm_common.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManager"};
33 struct WindowChecker : public MMI::IWindowChecker {
34 public:
35     WindowChecker() = default;
36     ~WindowChecker() = default;
37     int32_t CheckWindowId(int32_t windowId) const override;
38 };
39 }
40 
41 WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager)
42 
43 class WindowManager::Impl {
44 public:
Impl(std::recursive_mutex & mutex)45     explicit Impl(std::recursive_mutex& mutex) : mutex_(mutex) {}
46     void NotifyWMSConnected(int32_t userId, int32_t screenId);
47     void NotifyWMSDisconnected(int32_t userId, int32_t screenId);
48     void NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
49         WindowType windowType, DisplayId displayId);
50     void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
51         WindowType windowType, DisplayId displayId);
52     void NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo);
53     void NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo);
54     void NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints);
55     void NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type);
56     void NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
57     void NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>>&
58         windowDrawingContentInfos);
59     void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
60     void NotifyWaterMarkFlagChangedResult(bool showWaterMark);
61     void NotifyGestureNavigationEnabledResult(bool enable);
62 
63     static inline SingletonDelegator<WindowManager> delegator_;
64 
65     std::recursive_mutex& mutex_;
66     sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener_;
67     std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
68     sptr<WindowManagerAgent> focusChangedListenerAgent_;
69     std::vector<sptr<ISystemBarChangedListener>> systemBarChangedListeners_;
70     sptr<WindowManagerAgent> systemBarChangedListenerAgent_;
71     std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners_;
72     sptr<WindowManagerAgent> windowUpdateListenerAgent_;
73     std::vector<sptr<IVisibilityChangedListener>> windowVisibilityListeners_;
74     sptr<WindowManagerAgent> windowVisibilityListenerAgent_;
75     std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentListeners_;
76     sptr<WindowManagerAgent> windowDrawingContentListenerAgent_;
77     std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangedListeners_;
78     sptr<WindowManagerAgent> cameraFloatWindowChangedListenerAgent_;
79     std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners_;
80     sptr<WindowManagerAgent> waterMarkFlagChangeAgent_;
81     std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners_;
82     sptr<WindowManagerAgent> gestureNavigationEnabledAgent_;
83 };
84 
NotifyWMSConnected(int32_t userId,int32_t screenId)85 void WindowManager::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId)
86 {
87     WLOGFI("NotifyWMSConnected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
88     sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
89     {
90         std::lock_guard<std::recursive_mutex> lock(mutex_);
91         wmsConnectionChangedListener = wmsConnectionChangedListener_;
92     }
93     if (wmsConnectionChangedListener != nullptr) {
94         wmsConnectionChangedListener->OnConnected(userId, screenId);
95     }
96 }
97 
NotifyWMSDisconnected(int32_t userId,int32_t screenId)98 void WindowManager::Impl::NotifyWMSDisconnected(int32_t userId, int32_t screenId)
99 {
100     WLOGFI("NotifyWMSDisconnected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
101     sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
102     {
103         std::lock_guard<std::recursive_mutex> lock(mutex_);
104         wmsConnectionChangedListener = wmsConnectionChangedListener_;
105     }
106     if (wmsConnectionChangedListener != nullptr) {
107         wmsConnectionChangedListener->OnDisconnected(userId, screenId);
108     }
109 }
110 
NotifyFocused(const sptr<FocusChangeInfo> & focusChangeInfo)111 void WindowManager::Impl::NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo)
112 {
113     WLOGFD("[WMSFocus]NotifyFocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
114         focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
115         static_cast<uint32_t>(focusChangeInfo->windowType_));
116     std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
117     {
118         std::lock_guard<std::recursive_mutex> lock(mutex_);
119         focusChangeListeners = focusChangedListeners_;
120     }
121     for (auto& listener : focusChangeListeners) {
122         listener->OnFocused(focusChangeInfo);
123     }
124 }
125 
NotifyUnfocused(const sptr<FocusChangeInfo> & focusChangeInfo)126 void WindowManager::Impl::NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo)
127 {
128     WLOGFD("[WMSFocus]NotifyUnfocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
129         focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
130         static_cast<uint32_t>(focusChangeInfo->windowType_));
131     std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
132     {
133         std::lock_guard<std::recursive_mutex> lock(mutex_);
134         focusChangeListeners = focusChangedListeners_;
135     }
136     for (auto& listener : focusChangeListeners) {
137         listener->OnUnfocused(focusChangeInfo);
138     }
139 }
140 
NotifySystemBarChanged(DisplayId displayId,const SystemBarRegionTints & tints)141 void WindowManager::Impl::NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints)
142 {
143     for (auto tint : tints) {
144         WLOGFD("type:%{public}d, enable:%{public}d," \
145             "backgroundColor:%{public}x, contentColor:%{public}x " \
146             "region:[%{public}d, %{public}d, %{public}d, %{public}d]",
147             tint.type_, tint.prop_.enable_, tint.prop_.backgroundColor_, tint.prop_.contentColor_,
148             tint.region_.posX_, tint.region_.posY_, tint.region_.width_, tint.region_.height_);
149     }
150     std::vector<sptr<ISystemBarChangedListener>> systemBarChangeListeners;
151     {
152         std::lock_guard<std::recursive_mutex> lock(mutex_);
153         systemBarChangeListeners = systemBarChangedListeners_;
154     }
155     for (auto& listener : systemBarChangeListeners) {
156         listener->OnSystemBarPropertyChange(displayId, tints);
157     }
158 }
159 
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)160 void WindowManager::Impl::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
161     WindowUpdateType type)
162 {
163     if (infos.empty()) {
164         WLOGFE("infos is empty");
165         return;
166     }
167     for (auto& info : infos) {
168         WLOGFD("NotifyAccessibilityWindowInfo: wid[%{public}u], innerWid_[%{public}u], uiNodeId_[%{public}u]," \
169             "rect[%{public}d %{public}d %{public}d %{public}d]," \
170             "isFocused[%{public}d], isDecorEnable[%{public}d], displayId[%{public}" PRIu64"], layer[%{public}u]," \
171             "mode[%{public}u], type[%{public}u, updateType[%{public}d]",
172             info->wid_, info->innerWid_, info->uiNodeId_, info->windowRect_.width_, info->windowRect_.height_,
173             info->windowRect_.posX_, info->windowRect_.posY_, info->focused_, info->isDecorEnable_, info->displayId_,
174             info->layer_, info->mode_, info->type_, type);
175     }
176 
177     std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners;
178     {
179         std::lock_guard<std::recursive_mutex> lock(mutex_);
180         windowUpdateListeners = windowUpdateListeners_;
181     }
182     for (auto& listener : windowUpdateListeners) {
183         listener->OnWindowUpdate(infos, type);
184     }
185 }
186 
NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos)187 void WindowManager::Impl::NotifyWindowVisibilityInfoChanged(
188     const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
189 {
190     std::vector<sptr<IVisibilityChangedListener>> visibilityChangeListeners;
191     {
192         std::lock_guard<std::recursive_mutex> lock(mutex_);
193         visibilityChangeListeners = windowVisibilityListeners_;
194     }
195     for (auto& listener : visibilityChangeListeners) {
196         WLOGI("Notify WindowVisibilityInfo to caller");
197         listener->OnWindowVisibilityChanged(windowVisibilityInfos);
198     }
199 }
200 
NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos)201 void WindowManager::Impl::NotifyWindowDrawingContentInfoChanged(
202     const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos)
203 {
204     std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentChangeListeners;
205     {
206         std::lock_guard<std::recursive_mutex> lock(mutex_);
207         windowDrawingContentChangeListeners = windowDrawingContentListeners_;
208     }
209     for (auto& listener : windowDrawingContentChangeListeners) {
210         WLOGFD("Notify windowDrawingContentInfo to caller");
211         listener->OnWindowDrawingContentChanged(windowDrawingContentInfos);
212     }
213 }
214 
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)215 void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
216 {
217     WLOGFD("Camera float window, accessTokenId = %{public}u, isShowing = %{public}u", accessTokenId, isShowing);
218     std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangeListeners;
219     {
220         std::lock_guard<std::recursive_mutex> lock(mutex_);
221         cameraFloatWindowChangeListeners = cameraFloatWindowChangedListeners_;
222     }
223     for (auto& listener : cameraFloatWindowChangeListeners) {
224         listener->OnCameraFloatWindowChange(accessTokenId, isShowing);
225     }
226 }
227 
NotifyWaterMarkFlagChangedResult(bool showWaterMark)228 void WindowManager::Impl::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
229 {
230     WLOGFI("Notify water mark flag changed result, showWaterMark = %{public}d", showWaterMark);
231     std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners;
232     {
233         std::lock_guard<std::recursive_mutex> lock(mutex_);
234         waterMarkFlagChangeListeners = waterMarkFlagChangeListeners_;
235     }
236     for (auto& listener : waterMarkFlagChangeListeners) {
237         listener->OnWaterMarkFlagUpdate(showWaterMark);
238     }
239 }
240 
NotifyGestureNavigationEnabledResult(bool enable)241 void WindowManager::Impl::NotifyGestureNavigationEnabledResult(bool enable)
242 {
243     WLOGFI("Notify gesture navigation enable result, enable = %{public}d", enable);
244     std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners;
245     {
246         std::lock_guard<std::recursive_mutex> lock(mutex_);
247         gestureNavigationEnabledListeners = gestureNavigationEnabledListeners_;
248     }
249     for (auto& listener : gestureNavigationEnabledListeners) {
250         listener->OnGestureNavigationEnabledUpdate(enable);
251     }
252 }
253 
WindowManager()254 WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>(mutex_))
255 {
256     auto windowChecker = std::make_shared<WindowChecker>();
257     MMI::InputManager::GetInstance()->SetWindowCheckerHandler(windowChecker);
258 }
259 
CheckWindowId(int32_t windowId) const260 int32_t WindowChecker::CheckWindowId(int32_t windowId) const
261 {
262     int32_t pid = INVALID_PID;
263     WMError ret = SingletonContainer::Get<WindowAdapter>().CheckWindowId(windowId, pid);
264     if (ret != WMError::WM_OK) {
265         WLOGFE("Window(%{public}d) do not allow styles to be set", windowId);
266     }
267     return pid;
268 }
269 
~WindowManager()270 WindowManager::~WindowManager()
271 {
272     std::lock_guard<std::recursive_mutex> lock(mutex_);
273     destroyed_ = true;
274 }
275 
RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener> & listener)276 WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener>& listener)
277 {
278     if (listener == nullptr) {
279         WLOGFE("WMS connection changed listener registered could not be null");
280         return WMError::WM_ERROR_NULLPTR;
281     }
282     WLOGFI("RegisterWMSConnectionChangedListener in");
283     {
284         std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
285         if (pImpl_->wmsConnectionChangedListener_) {
286             WLOGFI("wmsConnectionChangedListener is already registered, do nothing");
287             return WMError::WM_OK;
288         }
289         pImpl_->wmsConnectionChangedListener_ = listener;
290     }
291     return SingletonContainer::Get<WindowAdapter>().RegisterWMSConnectionChangedListener(
292         std::bind(&WindowManager::OnWMSConnectionChanged, this, std::placeholders::_1, std::placeholders::_2,
293             std::placeholders::_3));
294 }
295 
UnregisterWMSConnectionChangedListener()296 WMError WindowManager::UnregisterWMSConnectionChangedListener()
297 {
298     WLOGFI("UnregisterWMSConnectionChangedListener in");
299     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
300     pImpl_->wmsConnectionChangedListener_ = nullptr;
301     return WMError::WM_OK;
302 }
303 
RegisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)304 WMError WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
305 {
306     if (listener == nullptr) {
307         WLOGFE("listener could not be null");
308         return WMError::WM_ERROR_NULLPTR;
309     }
310 
311     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
312     WMError ret = WMError::WM_OK;
313     if (pImpl_->focusChangedListenerAgent_ == nullptr) {
314         pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
315     }
316     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
317         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
318     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
319         WLOGFW("RegisterWindowManagerAgent failed!");
320         pImpl_->focusChangedListenerAgent_ = nullptr;
321     } else {
322         auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
323         if (iter != pImpl_->focusChangedListeners_.end()) {
324             WLOGFW("Listener is already registered.");
325             return WMError::WM_OK;
326         }
327         pImpl_->focusChangedListeners_.push_back(listener);
328     }
329     return ret;
330 }
331 
UnregisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)332 WMError WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
333 {
334     if (listener == nullptr) {
335         WLOGFE("listener could not be null");
336         return WMError::WM_ERROR_NULLPTR;
337     }
338 
339     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
340     auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
341     if (iter == pImpl_->focusChangedListeners_.end()) {
342         WLOGFE("could not find this listener");
343         return WMError::WM_OK;
344     }
345     pImpl_->focusChangedListeners_.erase(iter);
346     WMError ret = WMError::WM_OK;
347     if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
348         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
349             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
350         if (ret == WMError::WM_OK) {
351             pImpl_->focusChangedListenerAgent_ = nullptr;
352         }
353     }
354     return ret;
355 }
356 
RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)357 WMError WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
358 {
359     if (listener == nullptr) {
360         WLOGFE("listener could not be null");
361         return WMError::WM_ERROR_NULLPTR;
362     }
363 
364     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
365     WMError ret = WMError::WM_OK;
366     if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
367         pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
368     }
369     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
370         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
371     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
372         WLOGFW("RegisterWindowManagerAgent failed!");
373         pImpl_->systemBarChangedListenerAgent_ = nullptr;
374     } else {
375         auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
376             listener);
377         if (iter != pImpl_->systemBarChangedListeners_.end()) {
378             WLOGFW("Listener is already registered.");
379             return WMError::WM_OK;
380         }
381         pImpl_->systemBarChangedListeners_.push_back(listener);
382     }
383     return ret;
384 }
385 
UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)386 WMError WindowManager::UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
387 {
388     if (listener == nullptr) {
389         WLOGFE("listener could not be null");
390         return WMError::WM_ERROR_NULLPTR;
391     }
392 
393     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
394     auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
395         listener);
396     if (iter == pImpl_->systemBarChangedListeners_.end()) {
397         WLOGFE("could not find this listener");
398         return WMError::WM_OK;
399     }
400     pImpl_->systemBarChangedListeners_.erase(iter);
401     WMError ret = WMError::WM_OK;
402     if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) {
403         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
404             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
405         if (ret == WMError::WM_OK) {
406             pImpl_->systemBarChangedListenerAgent_ = nullptr;
407         }
408     }
409     return ret;
410 }
411 
MinimizeAllAppWindows(DisplayId displayId)412 WMError WindowManager::MinimizeAllAppWindows(DisplayId displayId)
413 {
414     WLOGFD("displayId %{public}" PRIu64"", displayId);
415     return SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(displayId);
416 }
417 
ToggleShownStateForAllAppWindows()418 WMError WindowManager::ToggleShownStateForAllAppWindows()
419 {
420     WLOGFD("ToggleShownStateForAllAppWindows");
421     return SingletonContainer::Get<WindowAdapter>().ToggleShownStateForAllAppWindows();
422 }
423 
SetWindowLayoutMode(WindowLayoutMode mode)424 WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode)
425 {
426     WLOGFD("set window layout mode: %{public}u", mode);
427     WMError ret  = SingletonContainer::Get<WindowAdapter>().SetWindowLayoutMode(mode);
428     if (ret != WMError::WM_OK) {
429         WLOGFE("set layout mode failed");
430     }
431     return ret;
432 }
433 
RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)434 WMError WindowManager::RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> &listener)
435 {
436     if (listener == nullptr) {
437         WLOGFE("listener could not be null");
438         return WMError::WM_ERROR_NULLPTR;
439     }
440     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
441     WMError ret = WMError::WM_OK;
442     if (pImpl_->windowUpdateListenerAgent_ == nullptr) {
443         pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent();
444     }
445     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
446         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
447     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
448         WLOGFW("RegisterWindowManagerAgent failed!");
449         pImpl_->windowUpdateListenerAgent_ = nullptr;
450     } else {
451         auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
452         if (iter != pImpl_->windowUpdateListeners_.end()) {
453             WLOGI("Listener is already registered.");
454             return WMError::WM_OK;
455         }
456         pImpl_->windowUpdateListeners_.emplace_back(listener);
457     }
458     return ret;
459 }
460 
UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)461 WMError WindowManager::UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener)
462 {
463     if (listener == nullptr) {
464         WLOGFE("listener could not be null");
465         return WMError::WM_ERROR_NULLPTR;
466     }
467     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
468     auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
469     if (iter == pImpl_->windowUpdateListeners_.end()) {
470         WLOGFE("could not find this listener");
471         return WMError::WM_OK;
472     }
473     pImpl_->windowUpdateListeners_.erase(iter);
474     WMError ret = WMError::WM_OK;
475     if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) {
476         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
477             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
478         if (ret == WMError::WM_OK) {
479             pImpl_->windowUpdateListenerAgent_ = nullptr;
480         }
481     }
482     return ret;
483 }
484 
RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)485 WMError WindowManager::RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
486 {
487     if (listener == nullptr) {
488         WLOGFE("listener could not be null");
489         return WMError::WM_ERROR_NULLPTR;
490     }
491     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
492     WMError ret = WMError::WM_OK;
493     if (pImpl_->windowVisibilityListenerAgent_ == nullptr) {
494         pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent();
495     }
496     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
497         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
498         pImpl_->windowVisibilityListenerAgent_);
499     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
500         WLOGFW("RegisterWindowManagerAgent failed!");
501         pImpl_->windowVisibilityListenerAgent_ = nullptr;
502     } else {
503         auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(),
504             listener);
505         if (iter != pImpl_->windowVisibilityListeners_.end()) {
506             WLOGFW("Listener is already registered.");
507             return WMError::WM_OK;
508         }
509         pImpl_->windowVisibilityListeners_.emplace_back(listener);
510     }
511     return ret;
512 }
513 
UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)514 WMError WindowManager::UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
515 {
516     if (listener == nullptr) {
517         WLOGFE("listener could not be null");
518         return WMError::WM_ERROR_NULLPTR;
519     }
520     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
521     pImpl_->windowVisibilityListeners_.erase(std::remove_if(pImpl_->windowVisibilityListeners_.begin(),
522         pImpl_->windowVisibilityListeners_.end(), [listener](sptr<IVisibilityChangedListener> registeredListener) {
523             return registeredListener == listener;
524         }), pImpl_->windowVisibilityListeners_.end());
525 
526     WMError ret = WMError::WM_OK;
527     if (pImpl_->windowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) {
528         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
529             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
530             pImpl_->windowVisibilityListenerAgent_);
531         if (ret == WMError::WM_OK) {
532             pImpl_->windowVisibilityListenerAgent_ = nullptr;
533         }
534     }
535     return ret;
536 }
537 
RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)538 WMError WindowManager::RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener)
539 {
540     if (listener == nullptr) {
541         WLOGFE("listener could not be null");
542         return WMError::WM_ERROR_NULLPTR;
543     }
544 
545     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
546     WMError ret = WMError::WM_OK;
547     if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) {
548         pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent();
549     }
550     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
551         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
552         pImpl_->cameraFloatWindowChangedListenerAgent_);
553     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
554         WLOGFW("RegisterWindowManagerAgent failed!");
555         pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
556     } else {
557         auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
558             pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
559         if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) {
560             WLOGFW("Listener is already registered.");
561             return WMError::WM_OK;
562         }
563         pImpl_->cameraFloatWindowChangedListeners_.push_back(listener);
564     }
565     return ret;
566 }
567 
UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)568 WMError WindowManager::UnregisterCameraFloatWindowChangedListener(
569     const sptr<ICameraFloatWindowChangedListener>& listener)
570 {
571     if (listener == nullptr) {
572         WLOGFE("listener could not be null");
573         return WMError::WM_ERROR_NULLPTR;
574     }
575 
576     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
577     auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
578         pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
579     if (iter == pImpl_->cameraFloatWindowChangedListeners_.end()) {
580         WLOGFE("could not find this listener");
581         return WMError::WM_OK;
582     }
583     pImpl_->cameraFloatWindowChangedListeners_.erase(iter);
584     WMError ret = WMError::WM_OK;
585     if (pImpl_->cameraFloatWindowChangedListeners_.empty() &&
586         pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) {
587         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
588             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
589             pImpl_->cameraFloatWindowChangedListenerAgent_);
590         if (ret == WMError::WM_OK) {
591             pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
592         }
593     }
594     return ret;
595 }
596 
RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)597 WMError WindowManager::RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
598 {
599     if (listener == nullptr) {
600         WLOGFE("listener could not be null");
601         return WMError::WM_ERROR_NULLPTR;
602     }
603 
604     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
605     WMError ret = WMError::WM_OK;
606     if (pImpl_->waterMarkFlagChangeAgent_ == nullptr) {
607         pImpl_->waterMarkFlagChangeAgent_ = new WindowManagerAgent();
608     }
609     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
610         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
611         pImpl_->waterMarkFlagChangeAgent_);
612     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
613         WLOGFW("RegisterWindowManagerAgent failed!");
614         pImpl_->waterMarkFlagChangeAgent_ = nullptr;
615     } else {
616         auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
617             pImpl_->waterMarkFlagChangeListeners_.end(), listener);
618         if (iter != pImpl_->waterMarkFlagChangeListeners_.end()) {
619             WLOGFW("Listener is already registered.");
620             return WMError::WM_OK;
621         }
622         pImpl_->waterMarkFlagChangeListeners_.push_back(listener);
623     }
624     WLOGFD("Try to registerWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
625     return ret;
626 }
627 
UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)628 WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
629 {
630     if (listener == nullptr) {
631         WLOGFE("listener could not be null");
632         return WMError::WM_ERROR_NULLPTR;
633     }
634 
635     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
636     auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
637         pImpl_->waterMarkFlagChangeListeners_.end(), listener);
638     if (iter == pImpl_->waterMarkFlagChangeListeners_.end()) {
639         WLOGFE("could not find this listener");
640         return WMError::WM_OK;
641     }
642     pImpl_->waterMarkFlagChangeListeners_.erase(iter);
643     WMError ret = WMError::WM_OK;
644     if (pImpl_->waterMarkFlagChangeListeners_.empty() &&
645         pImpl_->waterMarkFlagChangeAgent_ != nullptr) {
646         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
647             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
648             pImpl_->waterMarkFlagChangeAgent_);
649         if (ret == WMError::WM_OK) {
650             pImpl_->waterMarkFlagChangeAgent_ = nullptr;
651         }
652     }
653     WLOGFD("Try to unregisterWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
654     return ret;
655 }
656 
RegisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)657 WMError WindowManager::RegisterGestureNavigationEnabledChangedListener(
658     const sptr<IGestureNavigationEnabledChangedListener>& listener)
659 {
660     if (listener == nullptr) {
661         WLOGFE("listener could not be null");
662         return WMError::WM_ERROR_NULLPTR;
663     }
664 
665     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
666     WMError ret = WMError::WM_OK;
667     if (pImpl_->gestureNavigationEnabledAgent_ == nullptr) {
668         pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent();
669     }
670     if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
671         ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
672             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
673             pImpl_->gestureNavigationEnabledAgent_);
674     } else {
675         WLOGFE("Create windowManagerAgent object failed!");
676         ret = WMError::WM_ERROR_NULLPTR;
677     }
678     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
679         WLOGFE("RegisterWindowManagerAgent failed!");
680         pImpl_->gestureNavigationEnabledAgent_ = nullptr;
681     } else {
682         auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
683             pImpl_->gestureNavigationEnabledListeners_.end(), listener);
684         if (iter != pImpl_->gestureNavigationEnabledListeners_.end()) {
685             WLOGFW("Listener is already registered.");
686             return WMError::WM_OK;
687         }
688         pImpl_->gestureNavigationEnabledListeners_.push_back(listener);
689     }
690     WLOGFD("Try to registerGestureNavigationEnabledChangedListener and result is %{public}u",
691         static_cast<uint32_t>(ret));
692     return ret;
693 }
694 
UnregisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)695 WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener(
696     const sptr<IGestureNavigationEnabledChangedListener>& listener)
697 {
698     if (listener == nullptr) {
699         WLOGFE("listener could not be null");
700         return WMError::WM_ERROR_NULLPTR;
701     }
702 
703     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
704     auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
705         pImpl_->gestureNavigationEnabledListeners_.end(), listener);
706     if (iter == pImpl_->gestureNavigationEnabledListeners_.end()) {
707         WLOGFE("could not find this listener");
708         return WMError::WM_ERROR_INVALID_PARAM;
709     }
710     pImpl_->gestureNavigationEnabledListeners_.erase(iter);
711     WMError ret = WMError::WM_OK;
712     if (pImpl_->gestureNavigationEnabledListeners_.empty() &&
713         pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
714         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
715             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
716             pImpl_->gestureNavigationEnabledAgent_);
717         if (ret == WMError::WM_OK) {
718             pImpl_->gestureNavigationEnabledAgent_ = nullptr;
719         }
720     }
721     WLOGFD("Try to unregisterGestureNavigationEnabledChangedListener and result is %{public}u",
722         static_cast<uint32_t>(ret));
723     return ret;
724 }
725 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)726 void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
727 {
728     SingletonContainer::Get<WindowAdapter>().GetFocusWindowInfo(focusInfo);
729 }
730 
OnWMSConnectionChanged(int32_t userId,int32_t screenId,bool isConnected) const731 void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const
732 {
733     if (isConnected) {
734         pImpl_->NotifyWMSConnected(userId, screenId);
735     } else {
736         pImpl_->NotifyWMSDisconnected(userId, screenId);
737     }
738 }
739 
UpdateFocusChangeInfo(const sptr<FocusChangeInfo> & focusChangeInfo,bool focused) const740 void WindowManager::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const
741 {
742     if (focusChangeInfo == nullptr) {
743         WLOGFE("focusChangeInfo is nullptr.");
744         return;
745     }
746     WLOGFD("[WMSFocus]window focus change: %{public}d, id: %{public}u", focused, focusChangeInfo->windowId_);
747     if (focused) {
748         pImpl_->NotifyFocused(focusChangeInfo);
749     } else {
750         pImpl_->NotifyUnfocused(focusChangeInfo);
751     }
752 }
753 
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints) const754 void WindowManager::UpdateSystemBarRegionTints(DisplayId displayId,
755     const SystemBarRegionTints& tints) const
756 {
757     pImpl_->NotifySystemBarChanged(displayId, tints);
758 }
759 
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type) const760 void WindowManager::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
761     WindowUpdateType type) const
762 {
763     pImpl_->NotifyAccessibilityWindowInfo(infos, type);
764 }
765 
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos) const766 void WindowManager::UpdateWindowVisibilityInfo(
767     const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const
768 {
769     pImpl_->NotifyWindowVisibilityInfoChanged(windowVisibilityInfos);
770 }
771 
UpdateWindowDrawingContentInfo(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos) const772 void WindowManager::UpdateWindowDrawingContentInfo(
773     const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos) const
774 {
775     pImpl_->NotifyWindowDrawingContentInfoChanged(windowDrawingContentInfos);
776 }
777 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos) const778 WMError WindowManager::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const
779 {
780     WMError ret = SingletonContainer::Get<WindowAdapter>().GetAccessibilityWindowInfo(infos);
781     if (ret != WMError::WM_OK) {
782         WLOGFE("get window info failed");
783     }
784     return ret;
785 }
786 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos) const787 WMError WindowManager::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const
788 {
789     WMError ret = SingletonContainer::Get<WindowAdapter>().GetVisibilityWindowInfo(infos);
790     if (ret != WMError::WM_OK) {
791         WLOGFE("get window visibility info failed");
792     }
793     return ret;
794 }
795 
DumpSessionAll(std::vector<std::string> & infos)796 WMError WindowManager::DumpSessionAll(std::vector<std::string> &infos)
797 {
798     WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionAll(infos);
799     if (ret != WMError::WM_OK) {
800         WLOGFE("dump session all failed");
801     }
802     return ret;
803 }
804 
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)805 WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos)
806 {
807     WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionWithId(persistentId, infos);
808     if (ret != WMError::WM_OK) {
809         WLOGFE("dump session with id failed");
810     }
811     return ret;
812 }
813 
SetGestureNavigaionEnabled(bool enable) const814 WMError WindowManager::SetGestureNavigaionEnabled(bool enable) const
815 {
816     WMError ret = SingletonContainer::Get<WindowAdapter>().SetGestureNavigaionEnabled(enable);
817     if (ret != WMError::WM_OK) {
818         WLOGFE("set gesture navigaion enabled failed");
819     }
820     return ret;
821 }
822 
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)823 WMError WindowManager::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
824 {
825     WMError ret = SingletonContainer::Get<WindowAdapter>().NotifyWindowExtensionVisibilityChange(pid, uid, visible);
826     if (ret != WMError::WM_OK) {
827         WLOGFE("notify WindowExtension visibility change failed");
828     }
829     return ret;
830 }
831 
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing) const832 void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const
833 {
834     pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
835 }
836 
NotifyWaterMarkFlagChangedResult(bool showWaterMark) const837 void WindowManager::NotifyWaterMarkFlagChangedResult(bool showWaterMark) const
838 {
839     pImpl_->NotifyWaterMarkFlagChangedResult(showWaterMark);
840 }
841 
NotifyGestureNavigationEnabledResult(bool enable) const842 void WindowManager::NotifyGestureNavigationEnabledResult(bool enable) const
843 {
844     pImpl_->NotifyGestureNavigationEnabledResult(enable);
845 }
846 
RaiseWindowToTop(int32_t persistentId)847 WMError WindowManager::RaiseWindowToTop(int32_t persistentId)
848 {
849     WMError ret = SingletonContainer::Get<WindowAdapter>().RaiseWindowToTop(persistentId);
850     if (ret != WMError::WM_OK) {
851         WLOGFE("raise window to top failed");
852     }
853     return ret;
854 }
855 
RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)856 WMError WindowManager::RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
857 {
858     if (listener == nullptr) {
859         WLOGFE("listener could not be null");
860         return WMError::WM_ERROR_NULLPTR;
861     }
862     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
863     WMError ret = WMError::WM_OK;
864     if (pImpl_->windowDrawingContentListenerAgent_ == nullptr) {
865         pImpl_->windowDrawingContentListenerAgent_ = new WindowManagerAgent();
866     }
867     ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
868         WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
869         pImpl_->windowDrawingContentListenerAgent_);
870     if (ret != WMError::WM_OK && ret != WMError::WM_ERROR_REPEAT_OPERATION) {
871         WLOGFW("RegisterWindowManagerAgent failed!");
872         pImpl_->windowDrawingContentListenerAgent_ = nullptr;
873     } else {
874         auto iter = std::find(pImpl_->windowDrawingContentListeners_.begin(),
875             pImpl_->windowDrawingContentListeners_.end(), listener);
876         if (iter != pImpl_->windowDrawingContentListeners_.end()) {
877             WLOGFW("Listener is already registered.");
878             return WMError::WM_OK;
879         }
880         pImpl_->windowDrawingContentListeners_.emplace_back(listener);
881     }
882     return ret;
883 }
884 
UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)885 WMError WindowManager::UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
886 {
887     if (listener == nullptr) {
888         WLOGFE("listener could not be null");
889         return WMError::WM_ERROR_NULLPTR;
890     }
891     std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
892     pImpl_->windowDrawingContentListeners_.erase(std::remove_if(pImpl_->windowDrawingContentListeners_.begin(),
893         pImpl_->windowDrawingContentListeners_.end(),
894         [listener](sptr<IDrawingContentChangedListener> registeredListener) { return registeredListener == listener; }),
895         pImpl_->windowDrawingContentListeners_.end());
896 
897     WMError ret = WMError::WM_OK;
898     if (pImpl_->windowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) {
899         ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
900             WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
901             pImpl_->windowDrawingContentListenerAgent_);
902         if (ret == WMError::WM_OK) {
903             pImpl_->windowDrawingContentListenerAgent_ = nullptr;
904         }
905     }
906     return ret;
907 }
908 
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)909 WMError WindowManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
910 {
911     WMError ret = SingletonContainer::Get<WindowAdapter>().ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
912     if (ret != WMError::WM_OK) {
913         WLOGFE("shift application window focus failed");
914     }
915     return ret;
916 }
917 
918 } // namespace Rosen
919 } // namespace OHOS
920