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 "window_display_change_adapter.h"
28 #include "wm_common.h"
29
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManager"};
34 struct WindowChecker : public MMI::IWindowChecker {
35 public:
36 WindowChecker() = default;
37 ~WindowChecker() = default;
38 int32_t CheckWindowId(int32_t windowId) const override;
39 };
40 }
41
42 WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager)
43
44 class WindowManager::Impl {
45 public:
Impl(std::recursive_mutex & mutex)46 explicit Impl(std::recursive_mutex& mutex) : mutex_(mutex) {}
47 void NotifyWMSConnected(int32_t userId, int32_t screenId);
48 void NotifyWMSDisconnected(int32_t userId, int32_t screenId);
49 void NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
50 WindowType windowType, DisplayId displayId);
51 void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
52 WindowType windowType, DisplayId displayId);
53 void NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo);
54 void NotifyWindowModeChange(WindowModeType type);
55 void NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo);
56 void NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints);
57 void NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type);
58 void NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
59 void NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>>&
60 windowDrawingContentInfos);
61 void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
62 void NotifyWaterMarkFlagChangedResult(bool showWaterMark);
63 void NotifyVisibleWindowNumChanged(const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo);
64 void NotifyGestureNavigationEnabledResult(bool enable);
65 void NotifyDisplayInfoChanged(const sptr<IRemoteObject>& token, DisplayId displayId,
66 float density, DisplayOrientation orientation);
67 void NotifyWindowStyleChange(WindowStyleType type);
68
69 static inline SingletonDelegator<WindowManager> delegator_;
70
71 std::recursive_mutex& mutex_;
72 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener_;
73 std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
74 sptr<WindowManagerAgent> focusChangedListenerAgent_;
75 std::vector<sptr<IWindowModeChangedListener>> windowModeListeners_;
76 sptr<WindowManagerAgent> windowModeListenerAgent_;
77 std::vector<sptr<ISystemBarChangedListener>> systemBarChangedListeners_;
78 sptr<WindowManagerAgent> systemBarChangedListenerAgent_;
79 std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners_;
80 sptr<WindowManagerAgent> windowUpdateListenerAgent_;
81 std::vector<sptr<IVisibilityChangedListener>> windowVisibilityListeners_;
82 sptr<WindowManagerAgent> windowVisibilityListenerAgent_;
83 std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentListeners_;
84 sptr<WindowManagerAgent> windowDrawingContentListenerAgent_;
85 std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangedListeners_;
86 sptr<WindowManagerAgent> cameraFloatWindowChangedListenerAgent_;
87 std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners_;
88 sptr<WindowManagerAgent> waterMarkFlagChangeAgent_;
89 std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners_;
90 sptr<WindowManagerAgent> gestureNavigationEnabledAgent_;
91 std::vector<sptr<IVisibleWindowNumChangedListener>> visibleWindowNumChangedListeners_;
92 sptr<WindowManagerAgent> visibleWindowNumChangedListenerAgent_;
93 std::vector<sptr<IWindowStyleChangedListener>> windowStyleListeners_;
94 sptr<WindowManagerAgent> windowStyleListenerAgent_;
95 std::map<sptr<IRemoteObject>,
96 std::vector<sptr<WindowDisplayChangeAdapter>>> displayInfoChangedListeners_;
97 };
98
NotifyWMSConnected(int32_t userId,int32_t screenId)99 void WindowManager::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId)
100 {
101 TLOGI(WmsLogTag::WMS_MULTI_USER, "WMS connected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
102 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
103 {
104 std::lock_guard<std::recursive_mutex> lock(mutex_);
105 wmsConnectionChangedListener = wmsConnectionChangedListener_;
106 }
107 if (wmsConnectionChangedListener != nullptr) {
108 wmsConnectionChangedListener->OnConnected(userId, screenId);
109 }
110 }
111
NotifyWMSDisconnected(int32_t userId,int32_t screenId)112 void WindowManager::Impl::NotifyWMSDisconnected(int32_t userId, int32_t screenId)
113 {
114 TLOGI(WmsLogTag::WMS_MULTI_USER, "WMS disconnected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
115 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
116 {
117 std::lock_guard<std::recursive_mutex> lock(mutex_);
118 wmsConnectionChangedListener = wmsConnectionChangedListener_;
119 }
120 if (wmsConnectionChangedListener != nullptr) {
121 wmsConnectionChangedListener->OnDisconnected(userId, screenId);
122 }
123 }
124
NotifyFocused(const sptr<FocusChangeInfo> & focusChangeInfo)125 void WindowManager::Impl::NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo)
126 {
127 TLOGD(WmsLogTag::WMS_FOCUS, "NotifyFocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
128 focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
129 static_cast<uint32_t>(focusChangeInfo->windowType_));
130 std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
131 {
132 std::lock_guard<std::recursive_mutex> lock(mutex_);
133 focusChangeListeners = focusChangedListeners_;
134 }
135 WLOGFD("NotifyFocused listeners: %{public}zu", focusChangeListeners.size());
136 for (auto& listener : focusChangeListeners) {
137 listener->OnFocused(focusChangeInfo);
138 }
139 }
140
NotifyUnfocused(const sptr<FocusChangeInfo> & focusChangeInfo)141 void WindowManager::Impl::NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo)
142 {
143 TLOGD(WmsLogTag::WMS_FOCUS, "NotifyUnfocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
144 focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
145 static_cast<uint32_t>(focusChangeInfo->windowType_));
146 std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
147 {
148 std::lock_guard<std::recursive_mutex> lock(mutex_);
149 focusChangeListeners = focusChangedListeners_;
150 }
151 WLOGFD("NotifyUnfocused listeners: %{public}zu", focusChangeListeners.size());
152 for (auto& listener : focusChangeListeners) {
153 listener->OnUnfocused(focusChangeInfo);
154 }
155 }
156
NotifyWindowModeChange(WindowModeType type)157 void WindowManager::Impl::NotifyWindowModeChange(WindowModeType type)
158 {
159 TLOGI(WmsLogTag::WMS_MAIN, "WindowManager::Impl UpdateWindowModeTypeInfo type: %{public}d",
160 static_cast<uint8_t>(type));
161 std::vector<sptr<IWindowModeChangedListener>> windowModeListeners;
162 {
163 std::lock_guard<std::recursive_mutex> lock(mutex_);
164 windowModeListeners = windowModeListeners_;
165 }
166 for (auto &listener : windowModeListeners) {
167 listener->OnWindowModeUpdate(type);
168 }
169 }
170
NotifySystemBarChanged(DisplayId displayId,const SystemBarRegionTints & tints)171 void WindowManager::Impl::NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints)
172 {
173 for (auto tint : tints) {
174 WLOGFD("type:%{public}d, enable:%{public}d," \
175 "backgroundColor:%{public}x, contentColor:%{public}x " \
176 "region:[%{public}d, %{public}d, %{public}d, %{public}d]",
177 tint.type_, tint.prop_.enable_, tint.prop_.backgroundColor_, tint.prop_.contentColor_,
178 tint.region_.posX_, tint.region_.posY_, tint.region_.width_, tint.region_.height_);
179 }
180 std::vector<sptr<ISystemBarChangedListener>> systemBarChangeListeners;
181 {
182 std::lock_guard<std::recursive_mutex> lock(mutex_);
183 systemBarChangeListeners = systemBarChangedListeners_;
184 }
185 for (auto& listener : systemBarChangeListeners) {
186 listener->OnSystemBarPropertyChange(displayId, tints);
187 }
188 }
189
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)190 void WindowManager::Impl::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
191 WindowUpdateType type)
192 {
193 if (infos.empty()) {
194 WLOGFE("infos is empty");
195 return;
196 }
197 for (auto& info : infos) {
198 if (info == nullptr) {
199 TLOGD(WmsLogTag::WMS_MAIN, "info is nullptr");
200 continue;
201 }
202 TLOGD(WmsLogTag::WMS_MAIN, "NotifyAccessibilityWindowInfo: wid[%{public}u], innerWid_[%{public}u]," \
203 "uiNodeId_[%{public}u], rect[%{public}d %{public}d %{public}d %{public}d]," \
204 "isFocused[%{public}d], isDecorEnable[%{public}d], displayId[%{public}" PRIu64"], layer[%{public}u]," \
205 "mode[%{public}u], type[%{public}u, updateType[%{public}d], bundle[%{public}s]",
206 info->wid_, info->innerWid_, info->uiNodeId_, info->windowRect_.width_, info->windowRect_.height_,
207 info->windowRect_.posX_, info->windowRect_.posY_, info->focused_, info->isDecorEnable_, info->displayId_,
208 info->layer_, info->mode_, info->type_, type, info->bundleName_.c_str());
209 for (const auto& rect : info->touchHotAreas_) {
210 TLOGD(WmsLogTag::WMS_MAIN, "window touch hot areas rect[x=%{public}d,y=%{public}d," \
211 "w=%{public}d,h=%{public}d]", rect.posX_, rect.posY_, rect.width_, rect.height_);
212 }
213 }
214
215 std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners;
216 {
217 std::lock_guard<std::recursive_mutex> lock(mutex_);
218 windowUpdateListeners = windowUpdateListeners_;
219 }
220 for (auto& listener : windowUpdateListeners) {
221 listener->OnWindowUpdate(infos, type);
222 }
223 }
224
NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos)225 void WindowManager::Impl::NotifyWindowVisibilityInfoChanged(
226 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
227 {
228 std::vector<sptr<IVisibilityChangedListener>> visibilityChangeListeners;
229 {
230 std::lock_guard<std::recursive_mutex> lock(mutex_);
231 visibilityChangeListeners = windowVisibilityListeners_;
232 }
233 for (auto& listener : visibilityChangeListeners) {
234 WLOGD("Notify WindowVisibilityInfo to caller");
235 listener->OnWindowVisibilityChanged(windowVisibilityInfos);
236 }
237 }
238
NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos)239 void WindowManager::Impl::NotifyWindowDrawingContentInfoChanged(
240 const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos)
241 {
242 std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentChangeListeners;
243 {
244 std::lock_guard<std::recursive_mutex> lock(mutex_);
245 windowDrawingContentChangeListeners = windowDrawingContentListeners_;
246 }
247 for (auto& listener : windowDrawingContentChangeListeners) {
248 WLOGFD("Notify windowDrawingContentInfo to caller");
249 listener->OnWindowDrawingContentChanged(windowDrawingContentInfos);
250 }
251 }
252
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)253 void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
254 {
255 TLOGD(WmsLogTag::DEFAULT,
256 "Camera float window, accessTokenId = %{private}u, isShowing = %{public}u", accessTokenId, isShowing);
257 std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangeListeners;
258 {
259 std::lock_guard<std::recursive_mutex> lock(mutex_);
260 cameraFloatWindowChangeListeners = cameraFloatWindowChangedListeners_;
261 }
262 for (auto& listener : cameraFloatWindowChangeListeners) {
263 listener->OnCameraFloatWindowChange(accessTokenId, isShowing);
264 }
265 }
266
NotifyWaterMarkFlagChangedResult(bool showWaterMark)267 void WindowManager::Impl::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
268 {
269 WLOGFI("Notify water mark flag changed result, showWaterMark = %{public}d", showWaterMark);
270 std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners;
271 {
272 std::lock_guard<std::recursive_mutex> lock(mutex_);
273 waterMarkFlagChangeListeners = waterMarkFlagChangeListeners_;
274 }
275 for (auto& listener : waterMarkFlagChangeListeners) {
276 listener->OnWaterMarkFlagUpdate(showWaterMark);
277 }
278 }
279
NotifyGestureNavigationEnabledResult(bool enable)280 void WindowManager::Impl::NotifyGestureNavigationEnabledResult(bool enable)
281 {
282 WLOGFI("Notify gesture navigation enable result, enable = %{public}d", enable);
283 std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners;
284 {
285 std::lock_guard<std::recursive_mutex> lock(mutex_);
286 gestureNavigationEnabledListeners = gestureNavigationEnabledListeners_;
287 }
288 for (auto& listener : gestureNavigationEnabledListeners) {
289 listener->OnGestureNavigationEnabledUpdate(enable);
290 }
291 }
292
NotifyVisibleWindowNumChanged(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)293 void WindowManager::Impl::NotifyVisibleWindowNumChanged(
294 const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
295 {
296 std::vector<sptr<IVisibleWindowNumChangedListener>> visibleWindowNumChangedListeners;
297 {
298 std::lock_guard<std::recursive_mutex> lock(mutex_);
299 visibleWindowNumChangedListeners = visibleWindowNumChangedListeners_;
300 }
301 for (auto& listener : visibleWindowNumChangedListeners) {
302 if (listener == nullptr) {
303 continue;
304 }
305 listener->OnVisibleWindowNumChange(visibleWindowNumInfo);
306 }
307 }
308
NotifyDisplayInfoChanged(const sptr<IRemoteObject> & token,DisplayId displayId,float density,DisplayOrientation orientation)309 void WindowManager::Impl::NotifyDisplayInfoChanged(const sptr<IRemoteObject>& token, DisplayId displayId,
310 float density, DisplayOrientation orientation)
311 {
312 auto iter = displayInfoChangedListeners_.end();
313 std::vector<sptr<WindowDisplayChangeAdapter>> displayInfoChangedListeners;
314 {
315 std::lock_guard<std::recursive_mutex> lock(mutex_);
316 iter = displayInfoChangedListeners_.find(token);
317 if (iter == displayInfoChangedListeners_.end()) {
318 TLOGI(WmsLogTag::DMS, "can not find token in listener list, need not notify the change of display info");
319 return;
320 }
321 displayInfoChangedListeners = iter->second;
322 }
323
324 for (auto& listener : displayInfoChangedListeners) {
325 listener->OnDisplayInfoChange(token, displayId, density, orientation);
326 }
327 }
328
NotifyWindowStyleChange(WindowStyleType type)329 void WindowManager::Impl::NotifyWindowStyleChange(WindowStyleType type)
330 {
331 TLOGI(WmsLogTag::WMS_MAIN, "WindowStyleChange type: %{public}d",
332 static_cast<uint8_t>(type));
333 std::vector<sptr<IWindowStyleChangedListener>> windowStyleListeners;
334 {
335 std::lock_guard<std::recursive_mutex> lock(mutex_);
336 windowStyleListeners = windowStyleListeners_;
337 }
338 for (auto &listener : windowStyleListeners) {
339 TLOGI(WmsLogTag::WMS_MAIN, "WindowStyleChange type: %{public}d",
340 static_cast<uint8_t>(type));
341 listener->OnWindowStyleUpdate(type);
342 }
343 }
344
WindowManager()345 WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>(mutex_))
346 {
347 }
348
CheckWindowId(int32_t windowId) const349 int32_t WindowChecker::CheckWindowId(int32_t windowId) const
350 {
351 int32_t pid = INVALID_PID;
352 WMError ret = SingletonContainer::Get<WindowAdapter>().CheckWindowId(windowId, pid);
353 if (ret != WMError::WM_OK) {
354 WLOGFE("Window(%{public}d) do not allow styles to be set", windowId);
355 }
356 return pid;
357 }
358
~WindowManager()359 WindowManager::~WindowManager()
360 {
361 std::lock_guard<std::recursive_mutex> lock(mutex_);
362 destroyed_ = true;
363 }
364
RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener> & listener)365 WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener>& listener)
366 {
367 int32_t clientUserId = GetUserIdByUid(getuid());
368 if (clientUserId != SYSTEM_USERID) {
369 TLOGW(WmsLogTag::WMS_MULTI_USER, "Not u0 user, permission denied");
370 return WMError::WM_ERROR_INVALID_PERMISSION;
371 }
372 if (listener == nullptr) {
373 TLOGE(WmsLogTag::WMS_MULTI_USER, "WMS connection changed listener registered could not be null");
374 return WMError::WM_ERROR_NULLPTR;
375 }
376 TLOGI(WmsLogTag::WMS_MULTI_USER, "Register enter");
377 {
378 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
379 if (pImpl_->wmsConnectionChangedListener_) {
380 TLOGI(WmsLogTag::WMS_MULTI_USER, "wmsConnectionChangedListener is already registered, do nothing");
381 return WMError::WM_OK;
382 }
383 pImpl_->wmsConnectionChangedListener_ = listener;
384 }
385 auto ret = SingletonContainer::Get<WindowAdapter>().RegisterWMSConnectionChangedListener(
386 [this](int32_t userId, int32_t screenId, bool isConnected) {
387 this->OnWMSConnectionChanged(userId, screenId, isConnected);
388 });
389 if (ret != WMError::WM_OK) {
390 pImpl_->wmsConnectionChangedListener_ = nullptr;
391 }
392 return ret;
393 }
394
UnregisterWMSConnectionChangedListener()395 WMError WindowManager::UnregisterWMSConnectionChangedListener()
396 {
397 TLOGI(WmsLogTag::WMS_MULTI_USER, "Unregister enter");
398 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
399 pImpl_->wmsConnectionChangedListener_ = nullptr;
400 return WMError::WM_OK;
401 }
402
RegisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)403 WMError WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
404 {
405 if (listener == nullptr) {
406 WLOGFE("listener could not be null");
407 return WMError::WM_ERROR_NULLPTR;
408 }
409
410 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
411 WMError ret = WMError::WM_OK;
412 if (pImpl_->focusChangedListenerAgent_ == nullptr) {
413 pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
414 }
415 ret = WindowAdapter::GetInstance().RegisterWindowManagerAgent(
416 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
417 if (ret != WMError::WM_OK) {
418 WLOGFW("RegisterWindowManagerAgent failed!");
419 pImpl_->focusChangedListenerAgent_ = nullptr;
420 } else {
421 auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
422 if (iter != pImpl_->focusChangedListeners_.end()) {
423 WLOGFW("Listener is already registered.");
424 return WMError::WM_OK;
425 }
426 pImpl_->focusChangedListeners_.push_back(listener);
427 }
428 return ret;
429 }
430
UnregisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)431 WMError WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
432 {
433 if (listener == nullptr) {
434 WLOGFE("listener could not be null");
435 return WMError::WM_ERROR_NULLPTR;
436 }
437
438 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
439 auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
440 if (iter == pImpl_->focusChangedListeners_.end()) {
441 WLOGFE("could not find this listener");
442 return WMError::WM_OK;
443 }
444 pImpl_->focusChangedListeners_.erase(iter);
445 WMError ret = WMError::WM_OK;
446 if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
447 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
448 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
449 if (ret == WMError::WM_OK) {
450 pImpl_->focusChangedListenerAgent_ = nullptr;
451 }
452 }
453 return ret;
454 }
455
RegisterWindowModeChangedListener(const sptr<IWindowModeChangedListener> & listener)456 WMError WindowManager::RegisterWindowModeChangedListener(const sptr<IWindowModeChangedListener>& listener)
457 {
458 if (listener == nullptr) {
459 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
460 return WMError::WM_ERROR_NULLPTR;
461 }
462
463 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
464 WMError ret = WMError::WM_OK;
465 if (pImpl_->windowModeListenerAgent_ == nullptr) {
466 pImpl_->windowModeListenerAgent_ = new WindowManagerAgent();
467 }
468 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
469 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_);
470 if (ret != WMError::WM_OK) {
471 TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
472 pImpl_->windowModeListenerAgent_ = nullptr;
473 return ret;
474 }
475 auto iter = std::find(pImpl_->windowModeListeners_.begin(), pImpl_->windowModeListeners_.end(), listener);
476 if (iter != pImpl_->windowModeListeners_.end()) {
477 TLOGW(WmsLogTag::WMS_MAIN, "Listener is already registered.");
478 return WMError::WM_OK;
479 }
480 pImpl_->windowModeListeners_.push_back(listener);
481 return ret;
482 }
483
UnregisterWindowModeChangedListener(const sptr<IWindowModeChangedListener> & listener)484 WMError WindowManager::UnregisterWindowModeChangedListener(const sptr<IWindowModeChangedListener>& listener)
485 {
486 if (listener == nullptr) {
487 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
488 return WMError::WM_ERROR_NULLPTR;
489 }
490
491 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
492 auto iter = std::find(pImpl_->windowModeListeners_.begin(), pImpl_->windowModeListeners_.end(), listener);
493 if (iter == pImpl_->windowModeListeners_.end()) {
494 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
495 return WMError::WM_OK;
496 }
497 pImpl_->windowModeListeners_.erase(iter);
498 WMError ret = WMError::WM_OK;
499 if (pImpl_->windowModeListeners_.empty() && pImpl_->windowModeListenerAgent_ != nullptr) {
500 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
501 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_);
502 if (ret == WMError::WM_OK) {
503 pImpl_->windowModeListenerAgent_ = nullptr;
504 }
505 }
506 return ret;
507 }
508
RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)509 WMError WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
510 {
511 if (listener == nullptr) {
512 WLOGFE("listener could not be null");
513 return WMError::WM_ERROR_NULLPTR;
514 }
515
516 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
517 WMError ret = WMError::WM_OK;
518 if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
519 pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
520 }
521 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
522 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
523 if (ret != WMError::WM_OK) {
524 WLOGFW("RegisterWindowManagerAgent failed!");
525 pImpl_->systemBarChangedListenerAgent_ = nullptr;
526 } else {
527 auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
528 listener);
529 if (iter != pImpl_->systemBarChangedListeners_.end()) {
530 WLOGFW("Listener is already registered.");
531 return WMError::WM_OK;
532 }
533 pImpl_->systemBarChangedListeners_.push_back(listener);
534 }
535 return ret;
536 }
537
UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)538 WMError WindowManager::UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& 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 auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
547 listener);
548 if (iter == pImpl_->systemBarChangedListeners_.end()) {
549 WLOGFE("could not find this listener");
550 return WMError::WM_OK;
551 }
552 pImpl_->systemBarChangedListeners_.erase(iter);
553 WMError ret = WMError::WM_OK;
554 if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) {
555 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
556 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
557 if (ret == WMError::WM_OK) {
558 pImpl_->systemBarChangedListenerAgent_ = nullptr;
559 }
560 }
561 return ret;
562 }
563
MinimizeAllAppWindows(DisplayId displayId)564 WMError WindowManager::MinimizeAllAppWindows(DisplayId displayId)
565 {
566 WLOGFD("displayId %{public}" PRIu64"", displayId);
567 return SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(displayId);
568 }
569
ToggleShownStateForAllAppWindows()570 WMError WindowManager::ToggleShownStateForAllAppWindows()
571 {
572 WLOGFD("ToggleShownStateForAllAppWindows");
573 return SingletonContainer::Get<WindowAdapter>().ToggleShownStateForAllAppWindows();
574 }
575
SetWindowLayoutMode(WindowLayoutMode mode)576 WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode)
577 {
578 WLOGFD("set window layout mode: %{public}u", mode);
579 WMError ret = SingletonContainer::Get<WindowAdapter>().SetWindowLayoutMode(mode);
580 if (ret != WMError::WM_OK) {
581 WLOGFE("set layout mode failed");
582 }
583 return ret;
584 }
585
RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)586 WMError WindowManager::RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> &listener)
587 {
588 if (listener == nullptr) {
589 WLOGFE("listener could not be null");
590 return WMError::WM_ERROR_NULLPTR;
591 }
592 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
593 WMError ret = WMError::WM_OK;
594 if (pImpl_->windowUpdateListenerAgent_ == nullptr) {
595 pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent();
596 }
597 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
598 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
599 if (ret != WMError::WM_OK) {
600 WLOGFW("RegisterWindowManagerAgent failed!");
601 pImpl_->windowUpdateListenerAgent_ = nullptr;
602 } else {
603 auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
604 if (iter != pImpl_->windowUpdateListeners_.end()) {
605 WLOGI("Listener is already registered.");
606 return WMError::WM_OK;
607 }
608 pImpl_->windowUpdateListeners_.emplace_back(listener);
609 }
610 return ret;
611 }
612
UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)613 WMError WindowManager::UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener)
614 {
615 if (listener == nullptr) {
616 WLOGFE("listener could not be null");
617 return WMError::WM_ERROR_NULLPTR;
618 }
619 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
620 auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
621 if (iter == pImpl_->windowUpdateListeners_.end()) {
622 WLOGFE("could not find this listener");
623 return WMError::WM_OK;
624 }
625 pImpl_->windowUpdateListeners_.erase(iter);
626 WMError ret = WMError::WM_OK;
627 if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) {
628 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
629 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
630 if (ret == WMError::WM_OK) {
631 pImpl_->windowUpdateListenerAgent_ = nullptr;
632 }
633 }
634 return ret;
635 }
636
RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)637 WMError WindowManager::RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
638 {
639 if (listener == nullptr) {
640 WLOGFE("listener could not be null");
641 return WMError::WM_ERROR_NULLPTR;
642 }
643 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
644 WMError ret = WMError::WM_OK;
645 if (pImpl_->windowVisibilityListenerAgent_ == nullptr) {
646 pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent();
647 }
648 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
649 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
650 pImpl_->windowVisibilityListenerAgent_);
651 if (ret != WMError::WM_OK) {
652 WLOGFW("RegisterWindowManagerAgent failed!");
653 pImpl_->windowVisibilityListenerAgent_ = nullptr;
654 } else {
655 auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(),
656 listener);
657 if (iter != pImpl_->windowVisibilityListeners_.end()) {
658 WLOGFW("Listener is already registered.");
659 return WMError::WM_OK;
660 }
661 pImpl_->windowVisibilityListeners_.emplace_back(listener);
662 }
663 return ret;
664 }
665
UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)666 WMError WindowManager::UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
667 {
668 if (listener == nullptr) {
669 WLOGFE("listener could not be null");
670 return WMError::WM_ERROR_NULLPTR;
671 }
672 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
673 pImpl_->windowVisibilityListeners_.erase(std::remove_if(pImpl_->windowVisibilityListeners_.begin(),
674 pImpl_->windowVisibilityListeners_.end(), [listener](sptr<IVisibilityChangedListener> registeredListener) {
675 return registeredListener == listener;
676 }), pImpl_->windowVisibilityListeners_.end());
677
678 WMError ret = WMError::WM_OK;
679 if (pImpl_->windowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) {
680 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
681 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
682 pImpl_->windowVisibilityListenerAgent_);
683 if (ret == WMError::WM_OK) {
684 pImpl_->windowVisibilityListenerAgent_ = nullptr;
685 }
686 }
687 return ret;
688 }
689
RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)690 WMError WindowManager::RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener)
691 {
692 if (listener == nullptr) {
693 WLOGFE("listener could not be null");
694 return WMError::WM_ERROR_NULLPTR;
695 }
696
697 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
698 WMError ret = WMError::WM_OK;
699 if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) {
700 pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent();
701 }
702 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
703 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
704 pImpl_->cameraFloatWindowChangedListenerAgent_);
705 if (ret != WMError::WM_OK) {
706 WLOGFW("RegisterWindowManagerAgent failed!");
707 pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
708 } else {
709 auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
710 pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
711 if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) {
712 WLOGFW("Listener is already registered.");
713 return WMError::WM_OK;
714 }
715 pImpl_->cameraFloatWindowChangedListeners_.push_back(listener);
716 }
717 return ret;
718 }
719
UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)720 WMError WindowManager::UnregisterCameraFloatWindowChangedListener(
721 const sptr<ICameraFloatWindowChangedListener>& listener)
722 {
723 if (listener == nullptr) {
724 WLOGFE("listener could not be null");
725 return WMError::WM_ERROR_NULLPTR;
726 }
727
728 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
729 auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
730 pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
731 if (iter == pImpl_->cameraFloatWindowChangedListeners_.end()) {
732 WLOGFE("could not find this listener");
733 return WMError::WM_OK;
734 }
735 pImpl_->cameraFloatWindowChangedListeners_.erase(iter);
736 WMError ret = WMError::WM_OK;
737 if (pImpl_->cameraFloatWindowChangedListeners_.empty() &&
738 pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) {
739 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
740 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
741 pImpl_->cameraFloatWindowChangedListenerAgent_);
742 if (ret == WMError::WM_OK) {
743 pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
744 }
745 }
746 return ret;
747 }
748
RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)749 WMError WindowManager::RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
750 {
751 if (listener == nullptr) {
752 WLOGFE("listener could not be null");
753 return WMError::WM_ERROR_NULLPTR;
754 }
755
756 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
757 WMError ret = WMError::WM_OK;
758 if (pImpl_->waterMarkFlagChangeAgent_ == nullptr) {
759 pImpl_->waterMarkFlagChangeAgent_ = new WindowManagerAgent();
760 }
761 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
762 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
763 pImpl_->waterMarkFlagChangeAgent_);
764 if (ret != WMError::WM_OK) {
765 WLOGFW("RegisterWindowManagerAgent failed!");
766 pImpl_->waterMarkFlagChangeAgent_ = nullptr;
767 } else {
768 auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
769 pImpl_->waterMarkFlagChangeListeners_.end(), listener);
770 if (iter != pImpl_->waterMarkFlagChangeListeners_.end()) {
771 WLOGFW("Listener is already registered.");
772 return WMError::WM_OK;
773 }
774 pImpl_->waterMarkFlagChangeListeners_.push_back(listener);
775 }
776 WLOGFD("Try to registerWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
777 return ret;
778 }
779
UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)780 WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
781 {
782 if (listener == nullptr) {
783 WLOGFE("listener could not be null");
784 return WMError::WM_ERROR_NULLPTR;
785 }
786
787 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
788 auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
789 pImpl_->waterMarkFlagChangeListeners_.end(), listener);
790 if (iter == pImpl_->waterMarkFlagChangeListeners_.end()) {
791 WLOGFE("could not find this listener");
792 return WMError::WM_OK;
793 }
794 pImpl_->waterMarkFlagChangeListeners_.erase(iter);
795 WMError ret = WMError::WM_OK;
796 if (pImpl_->waterMarkFlagChangeListeners_.empty() &&
797 pImpl_->waterMarkFlagChangeAgent_ != nullptr) {
798 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
799 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
800 pImpl_->waterMarkFlagChangeAgent_);
801 if (ret == WMError::WM_OK) {
802 pImpl_->waterMarkFlagChangeAgent_ = nullptr;
803 }
804 }
805 WLOGFD("Try to unregisterWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
806 return ret;
807 }
808
RegisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)809 WMError WindowManager::RegisterGestureNavigationEnabledChangedListener(
810 const sptr<IGestureNavigationEnabledChangedListener>& listener)
811 {
812 if (listener == nullptr) {
813 WLOGFE("listener could not be null");
814 return WMError::WM_ERROR_NULLPTR;
815 }
816
817 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
818 WMError ret = WMError::WM_OK;
819 if (pImpl_->gestureNavigationEnabledAgent_ == nullptr) {
820 pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent();
821 }
822 if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
823 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
824 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
825 pImpl_->gestureNavigationEnabledAgent_);
826 } else {
827 WLOGFE("Create windowManagerAgent object failed!");
828 ret = WMError::WM_ERROR_NULLPTR;
829 }
830 if (ret != WMError::WM_OK) {
831 WLOGFE("RegisterWindowManagerAgent failed!");
832 pImpl_->gestureNavigationEnabledAgent_ = nullptr;
833 } else {
834 auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
835 pImpl_->gestureNavigationEnabledListeners_.end(), listener);
836 if (iter != pImpl_->gestureNavigationEnabledListeners_.end()) {
837 WLOGFW("Listener is already registered.");
838 return WMError::WM_OK;
839 }
840 pImpl_->gestureNavigationEnabledListeners_.push_back(listener);
841 }
842 WLOGFD("Try to registerGestureNavigationEnabledChangedListener and result is %{public}u",
843 static_cast<uint32_t>(ret));
844 return ret;
845 }
846
UnregisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)847 WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener(
848 const sptr<IGestureNavigationEnabledChangedListener>& listener)
849 {
850 if (listener == nullptr) {
851 WLOGFE("listener could not be null");
852 return WMError::WM_ERROR_NULLPTR;
853 }
854
855 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
856 auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
857 pImpl_->gestureNavigationEnabledListeners_.end(), listener);
858 if (iter == pImpl_->gestureNavigationEnabledListeners_.end()) {
859 WLOGFE("could not find this listener");
860 return WMError::WM_ERROR_INVALID_PARAM;
861 }
862 pImpl_->gestureNavigationEnabledListeners_.erase(iter);
863 WMError ret = WMError::WM_OK;
864 if (pImpl_->gestureNavigationEnabledListeners_.empty() &&
865 pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
866 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
867 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
868 pImpl_->gestureNavigationEnabledAgent_);
869 if (ret == WMError::WM_OK) {
870 pImpl_->gestureNavigationEnabledAgent_ = nullptr;
871 }
872 }
873 WLOGFD("Try to unregisterGestureNavigationEnabledChangedListener and result is %{public}u",
874 static_cast<uint32_t>(ret));
875 return ret;
876 }
877
RegisterDisplayInfoChangedListener(const sptr<IRemoteObject> & token,const sptr<IDisplayInfoChangedListener> & listener)878 WMError WindowManager::RegisterDisplayInfoChangedListener(const sptr<IRemoteObject>& token,
879 const sptr<IDisplayInfoChangedListener>& listener)
880 {
881 if (token == nullptr) {
882 TLOGE(WmsLogTag::DMS, "ability token could not be null");
883 return WMError::WM_ERROR_NULLPTR;
884 }
885
886 if (listener == nullptr) {
887 TLOGE(WmsLogTag::DMS, "listener could not be null");
888 return WMError::WM_ERROR_NULLPTR;
889 }
890
891 sptr<WindowDisplayChangeAdapter> listenerAdapter = new (std::nothrow) WindowDisplayChangeAdapter(token, listener);
892 if (listenerAdapter == nullptr) {
893 TLOGE(WmsLogTag::DMS, "create listener adapter failed.");
894 return WMError::WM_ERROR_NO_MEM;
895 }
896 std::lock_guard<std::recursive_mutex> lock(mutex_);
897 auto iter = pImpl_->displayInfoChangedListeners_.find(token);
898 if (iter == pImpl_->displayInfoChangedListeners_.end()) {
899 pImpl_->displayInfoChangedListeners_.insert({token, {listenerAdapter}});
900 } else {
901 auto listerneIter = std::find_if(iter->second.begin(), iter->second.end(),
902 [&listener](const sptr<WindowDisplayChangeAdapter>& item) {
903 return listener == item->GetListener();
904 });
905 if (listerneIter != iter->second.end()) {
906 TLOGW(WmsLogTag::DMS, "listener is already registered.");
907 } else {
908 iter->second.push_back(listenerAdapter);
909 }
910 }
911 TLOGD(WmsLogTag::DMS, "try to registerDisplayInfoChangedListener success");
912 return WMError::WM_OK;
913 }
914
UnregisterDisplayInfoChangedListener(const sptr<IRemoteObject> & token,const sptr<IDisplayInfoChangedListener> & listener)915 WMError WindowManager::UnregisterDisplayInfoChangedListener(const sptr<IRemoteObject>& token,
916 const sptr<IDisplayInfoChangedListener>& listener)
917 {
918 if (token == nullptr) {
919 TLOGE(WmsLogTag::DMS, "ability token could not be null");
920 return WMError::WM_ERROR_NULLPTR;
921 }
922
923 if (listener == nullptr) {
924 TLOGE(WmsLogTag::DMS, "listener could not be null");
925 return WMError::WM_ERROR_NULLPTR;
926 }
927
928 std::lock_guard<std::recursive_mutex> lock(mutex_);
929 auto iter = pImpl_->displayInfoChangedListeners_.find(token);
930 if (iter == pImpl_->displayInfoChangedListeners_.end()) {
931 TLOGW(WmsLogTag::DMS, "can not find the ability token");
932 } else {
933 auto listerneIter = std::find_if(iter->second.begin(), iter->second.end(),
934 [&listener](sptr<WindowDisplayChangeAdapter>& item) {
935 return listener == item->GetListener();
936 });
937 if (listerneIter == iter->second.end()) {
938 TLOGW(WmsLogTag::DMS, "can not find the listener.");
939 } else {
940 iter->second.erase(listerneIter);
941 if (iter->second.empty()) {
942 pImpl_->displayInfoChangedListeners_.erase(iter);
943 }
944 }
945 }
946 TLOGD(WmsLogTag::DMS, "try to unregisterDisplayInfoChangedListener success");
947 return WMError::WM_OK;
948 }
949
NotifyDisplayInfoChange(const sptr<IRemoteObject> & token,DisplayId displayId,float density,DisplayOrientation orientation)950 WMError WindowManager::NotifyDisplayInfoChange(const sptr<IRemoteObject>& token, DisplayId displayId,
951 float density, DisplayOrientation orientation)
952 {
953 TLOGD(WmsLogTag::DMS, "notify display info change, displayid = %{public}" PRIu64", density=%{public}f," \
954 "orientation = %{public}d", displayId, density, orientation);
955 if (token == nullptr) {
956 TLOGE(WmsLogTag::DMS, "notify display info change failed, token is nullptr");
957 return WMError::WM_ERROR_INVALID_PARAM;
958 }
959 pImpl_->NotifyDisplayInfoChanged(token, displayId, density, orientation);
960 return WMError::WM_OK;
961 }
962
GetFocusWindowInfo(FocusChangeInfo & focusInfo)963 void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
964 {
965 SingletonContainer::Get<WindowAdapter>().GetFocusWindowInfo(focusInfo);
966 }
967
OnWMSConnectionChanged(int32_t userId,int32_t screenId,bool isConnected) const968 void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const
969 {
970 if (isConnected) {
971 pImpl_->NotifyWMSConnected(userId, screenId);
972 } else {
973 pImpl_->NotifyWMSDisconnected(userId, screenId);
974 }
975 }
976
UpdateFocusChangeInfo(const sptr<FocusChangeInfo> & focusChangeInfo,bool focused) const977 void WindowManager::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const
978 {
979 if (focusChangeInfo == nullptr) {
980 WLOGFE("focusChangeInfo is nullptr.");
981 return;
982 }
983 TLOGD(WmsLogTag::WMS_FOCUS, "window focus change: %{public}d, id: %{public}u", focused, focusChangeInfo->windowId_);
984 if (focused) {
985 pImpl_->NotifyFocused(focusChangeInfo);
986 } else {
987 pImpl_->NotifyUnfocused(focusChangeInfo);
988 }
989 }
990
UpdateWindowModeTypeInfo(WindowModeType type) const991 void WindowManager::UpdateWindowModeTypeInfo(WindowModeType type) const
992 {
993 pImpl_->NotifyWindowModeChange(type);
994 }
995
GetWindowModeType(WindowModeType & windowModeType) const996 WMError WindowManager::GetWindowModeType(WindowModeType& windowModeType) const
997 {
998 WMError ret = SingletonContainer::Get<WindowAdapter>().GetWindowModeType(windowModeType);
999 if (ret != WMError::WM_OK) {
1000 WLOGFE("get window mode type failed");
1001 }
1002 return ret;
1003 }
1004
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints) const1005 void WindowManager::UpdateSystemBarRegionTints(DisplayId displayId,
1006 const SystemBarRegionTints& tints) const
1007 {
1008 pImpl_->NotifySystemBarChanged(displayId, tints);
1009 }
1010
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type) const1011 void WindowManager::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
1012 WindowUpdateType type) const
1013 {
1014 pImpl_->NotifyAccessibilityWindowInfo(infos, type);
1015 }
1016
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos) const1017 void WindowManager::UpdateWindowVisibilityInfo(
1018 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const
1019 {
1020 pImpl_->NotifyWindowVisibilityInfoChanged(windowVisibilityInfos);
1021 }
1022
UpdateWindowDrawingContentInfo(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos) const1023 void WindowManager::UpdateWindowDrawingContentInfo(
1024 const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos) const
1025 {
1026 pImpl_->NotifyWindowDrawingContentInfoChanged(windowDrawingContentInfos);
1027 }
1028
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos) const1029 WMError WindowManager::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const
1030 {
1031 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAccessibilityWindowInfo(infos);
1032 if (ret != WMError::WM_OK) {
1033 WLOGFE("get window info failed");
1034 }
1035 return ret;
1036 }
1037
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos) const1038 WMError WindowManager::GetUnreliableWindowInfo(int32_t windowId,
1039 std::vector<sptr<UnreliableWindowInfo>>& infos) const
1040 {
1041 WMError ret = SingletonContainer::Get<WindowAdapter>().GetUnreliableWindowInfo(windowId, infos);
1042 if (ret != WMError::WM_OK) {
1043 TLOGE(WmsLogTag::DEFAULT, "get unreliable window info failed");
1044 }
1045 return ret;
1046 }
1047
GetAllWindowLayoutInfo(DisplayId displayId,std::vector<sptr<WindowLayoutInfo>> & infos) const1048 WMError WindowManager::GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos) const
1049 {
1050 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAllWindowLayoutInfo(displayId, infos);
1051 if (ret != WMError::WM_OK) {
1052 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed");
1053 }
1054 return ret;
1055 }
1056
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos) const1057 WMError WindowManager::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const
1058 {
1059 WMError ret = SingletonContainer::Get<WindowAdapter>().GetVisibilityWindowInfo(infos);
1060 if (ret != WMError::WM_OK) {
1061 WLOGFE("get window visibility info failed");
1062 }
1063 return ret;
1064 }
1065
DumpSessionAll(std::vector<std::string> & infos)1066 WMError WindowManager::DumpSessionAll(std::vector<std::string> &infos)
1067 {
1068 WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionAll(infos);
1069 if (ret != WMError::WM_OK) {
1070 WLOGFE("dump session all failed");
1071 }
1072 return ret;
1073 }
1074
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)1075 WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos)
1076 {
1077 WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionWithId(persistentId, infos);
1078 if (ret != WMError::WM_OK) {
1079 WLOGFE("dump session with id failed");
1080 }
1081 return ret;
1082 }
1083
GetUIContentRemoteObj(int32_t windowId,sptr<IRemoteObject> & uiContentRemoteObj)1084 WMError WindowManager::GetUIContentRemoteObj(int32_t windowId, sptr<IRemoteObject>& uiContentRemoteObj)
1085 {
1086 WMError ret = SingletonContainer::Get<WindowAdapter>().GetUIContentRemoteObj(windowId, uiContentRemoteObj);
1087 if (ret != WMError::WM_OK) {
1088 TLOGE(WmsLogTag::DEFAULT, "Failed to get UIContentRemoteObj. PersistentId=%{public}d; ret=%{public}u",
1089 windowId, static_cast<uint32_t>(ret));
1090 }
1091 return ret;
1092 }
1093
SetGestureNavigaionEnabled(bool enable) const1094 WMError WindowManager::SetGestureNavigaionEnabled(bool enable) const
1095 {
1096 WMError ret = SingletonContainer::Get<WindowAdapter>().SetGestureNavigaionEnabled(enable);
1097 if (ret != WMError::WM_OK) {
1098 WLOGFE("set gesture navigaion enabled failed");
1099 }
1100 return ret;
1101 }
1102
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)1103 WMError WindowManager::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
1104 {
1105 WMError ret = SingletonContainer::Get<WindowAdapter>().NotifyWindowExtensionVisibilityChange(pid, uid, visible);
1106 if (ret != WMError::WM_OK) {
1107 WLOGFE("notify WindowExtension visibility change failed");
1108 }
1109 return ret;
1110 }
1111
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing) const1112 void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const
1113 {
1114 pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
1115 }
1116
NotifyWaterMarkFlagChangedResult(bool showWaterMark) const1117 void WindowManager::NotifyWaterMarkFlagChangedResult(bool showWaterMark) const
1118 {
1119 pImpl_->NotifyWaterMarkFlagChangedResult(showWaterMark);
1120 }
1121
NotifyGestureNavigationEnabledResult(bool enable) const1122 void WindowManager::NotifyGestureNavigationEnabledResult(bool enable) const
1123 {
1124 pImpl_->NotifyGestureNavigationEnabledResult(enable);
1125 }
1126
RaiseWindowToTop(int32_t persistentId)1127 WMError WindowManager::RaiseWindowToTop(int32_t persistentId)
1128 {
1129 WMError ret = SingletonContainer::Get<WindowAdapter>().RaiseWindowToTop(persistentId);
1130 if (ret != WMError::WM_OK) {
1131 WLOGFE("raise window to top failed");
1132 }
1133 return ret;
1134 }
1135
NotifyWindowStyleChange(WindowStyleType type)1136 WMError WindowManager::NotifyWindowStyleChange(WindowStyleType type)
1137 {
1138 pImpl_->NotifyWindowStyleChange(type);
1139 return WMError::WM_OK;
1140 }
1141
RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)1142 WMError WindowManager::RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
1143 {
1144 if (listener == nullptr) {
1145 WLOGFE("listener could not be null");
1146 return WMError::WM_ERROR_NULLPTR;
1147 }
1148 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
1149 WMError ret = WMError::WM_OK;
1150 if (pImpl_->windowDrawingContentListenerAgent_ == nullptr) {
1151 pImpl_->windowDrawingContentListenerAgent_ = new WindowManagerAgent();
1152 }
1153 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1154 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
1155 pImpl_->windowDrawingContentListenerAgent_);
1156 if (ret != WMError::WM_OK) {
1157 WLOGFW("RegisterWindowManagerAgent failed!");
1158 pImpl_->windowDrawingContentListenerAgent_ = nullptr;
1159 } else {
1160 auto iter = std::find(pImpl_->windowDrawingContentListeners_.begin(),
1161 pImpl_->windowDrawingContentListeners_.end(), listener);
1162 if (iter != pImpl_->windowDrawingContentListeners_.end()) {
1163 WLOGFW("Listener is already registered.");
1164 return WMError::WM_OK;
1165 }
1166 pImpl_->windowDrawingContentListeners_.emplace_back(listener);
1167 }
1168 return ret;
1169 }
1170
UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)1171 WMError WindowManager::UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
1172 {
1173 if (listener == nullptr) {
1174 WLOGFE("listener could not be null");
1175 return WMError::WM_ERROR_NULLPTR;
1176 }
1177 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
1178 pImpl_->windowDrawingContentListeners_.erase(std::remove_if(pImpl_->windowDrawingContentListeners_.begin(),
1179 pImpl_->windowDrawingContentListeners_.end(),
1180 [listener](sptr<IDrawingContentChangedListener> registeredListener) { return registeredListener == listener; }),
1181 pImpl_->windowDrawingContentListeners_.end());
1182
1183 WMError ret = WMError::WM_OK;
1184 if (pImpl_->windowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) {
1185 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1186 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
1187 pImpl_->windowDrawingContentListenerAgent_);
1188 if (ret == WMError::WM_OK) {
1189 pImpl_->windowDrawingContentListenerAgent_ = nullptr;
1190 }
1191 }
1192 return ret;
1193 }
1194
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)1195 WMError WindowManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
1196 {
1197 WMError ret = SingletonContainer::Get<WindowAdapter>().ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1198 if (ret != WMError::WM_OK) {
1199 WLOGFE("shift application window focus failed");
1200 }
1201 return ret;
1202 }
1203
RegisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener> & listener)1204 WMError WindowManager::RegisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener>& listener)
1205 {
1206 if (listener == nullptr) {
1207 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1208 return WMError::WM_ERROR_NULLPTR;
1209 }
1210 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
1211 WMError ret = WMError::WM_OK;
1212 if (pImpl_->visibleWindowNumChangedListenerAgent_ == nullptr) {
1213 pImpl_->visibleWindowNumChangedListenerAgent_ = new WindowManagerAgent();
1214 }
1215 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1216 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM,
1217 pImpl_->visibleWindowNumChangedListenerAgent_);
1218 if (ret != WMError::WM_OK) {
1219 TLOGE(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
1220 pImpl_->visibleWindowNumChangedListenerAgent_ = nullptr;
1221 } else {
1222 auto iter = std::find(pImpl_->visibleWindowNumChangedListeners_.begin(),
1223 pImpl_->visibleWindowNumChangedListeners_.end(), listener);
1224 if (iter != pImpl_->visibleWindowNumChangedListeners_.end()) {
1225 TLOGE(WmsLogTag::WMS_MAIN, "Listener is already registered.");
1226 return WMError::WM_OK;
1227 }
1228 pImpl_->visibleWindowNumChangedListeners_.emplace_back(listener);
1229 }
1230 return ret;
1231 }
1232
GetSnapshotByWindowId(int32_t windowId,std::shared_ptr<Media::PixelMap> & pixelMap)1233 WMError WindowManager::GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap)
1234 {
1235 return SingletonContainer::Get<WindowAdapter>().GetSnapshotByWindowId(windowId, pixelMap);
1236 }
1237
UnregisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener> & listener)1238 WMError WindowManager::UnregisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener>& listener)
1239 {
1240 if (listener == nullptr) {
1241 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1242 return WMError::WM_ERROR_NULLPTR;
1243 }
1244 std::lock_guard<std::recursive_mutex> lock(pImpl_->mutex_);
1245 auto iter = std::find(pImpl_->visibleWindowNumChangedListeners_.begin(),
1246 pImpl_->visibleWindowNumChangedListeners_.end(), listener);
1247 if (iter == pImpl_->visibleWindowNumChangedListeners_.end()) {
1248 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
1249 return WMError::WM_OK;
1250 }
1251
1252 WMError ret = WMError::WM_OK;
1253 if (pImpl_->visibleWindowNumChangedListeners_.empty() && pImpl_->visibleWindowNumChangedListenerAgent_ != nullptr) {
1254 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1255 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM,
1256 pImpl_->visibleWindowNumChangedListenerAgent_);
1257 if (ret == WMError::WM_OK) {
1258 pImpl_->visibleWindowNumChangedListenerAgent_ = nullptr;
1259 }
1260 }
1261 return ret;
1262 }
1263
UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)1264 void WindowManager::UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
1265 {
1266 pImpl_->NotifyVisibleWindowNumChanged(visibleWindowNumInfo);
1267 }
1268
1269
RegisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener> & listener)1270 WMError WindowManager::RegisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener>& listener)
1271 {
1272 TLOGI(WmsLogTag::WMS_MAIN, "start register");
1273 if (listener == nullptr) {
1274 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1275 return WMError::WM_ERROR_NULLPTR;
1276 }
1277 {
1278 std::lock_guard<std::recursive_mutex> lock(mutex_);
1279 if (pImpl_->windowStyleListenerAgent_ == nullptr) {
1280 pImpl_->windowStyleListenerAgent_ = new WindowManagerAgent();
1281 }
1282 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1283 if (iter != pImpl_->windowStyleListeners_.end()) {
1284 TLOGW(WmsLogTag::WMS_MAIN, "Listener is already registered.");
1285 return WMError::WM_OK;
1286 }
1287 pImpl_->windowStyleListeners_.push_back(listener);
1288 }
1289 WMError ret = WMError::WM_OK;
1290 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1291 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_);
1292 if (ret != WMError::WM_OK) {
1293 TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
1294 std::lock_guard<std::recursive_mutex> lock(mutex_);
1295 pImpl_->windowStyleListenerAgent_ = nullptr;
1296 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1297 if (iter != pImpl_->windowStyleListeners_.end()) {
1298 pImpl_->windowStyleListeners_.erase(iter);
1299 }
1300 }
1301 return ret;
1302 }
1303
UnregisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener> & listener)1304 WMError WindowManager::UnregisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener>& listener)
1305 {
1306 TLOGI(WmsLogTag::WMS_MAIN, "start unregister");
1307 if (listener == nullptr) {
1308 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1309 return WMError::WM_ERROR_NULLPTR;
1310 }
1311 {
1312 std::lock_guard<std::recursive_mutex> lock(mutex_);
1313 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1314 if (iter == pImpl_->windowStyleListeners_.end()) {
1315 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
1316 return WMError::WM_OK;
1317 }
1318 pImpl_->windowStyleListeners_.erase(iter);
1319 }
1320 WMError ret = WMError::WM_OK;
1321 if (pImpl_->windowStyleListeners_.empty() && pImpl_->windowStyleListenerAgent_ != nullptr) {
1322 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1323 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_);
1324 if (ret == WMError::WM_OK) {
1325 std::lock_guard<std::recursive_mutex> lock(mutex_);
1326 pImpl_->windowStyleListenerAgent_ = nullptr;
1327 }
1328 }
1329 return ret;
1330 }
1331
GetWindowStyleType()1332 WindowStyleType WindowManager::GetWindowStyleType()
1333 {
1334 WindowStyleType styleType;
1335 if (SingletonContainer::Get<WindowAdapter>().GetWindowStyleType(styleType) == WMError::WM_OK) {
1336 return styleType;
1337 }
1338 return styleType;
1339 }
1340
GetWindowIdsByCoordinate(DisplayId displayId,int32_t windowNumber,int32_t x,int32_t y,std::vector<int32_t> & windowIds) const1341 WMError WindowManager::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
1342 int32_t x, int32_t y, std::vector<int32_t>& windowIds) const
1343 {
1344 WMError ret = SingletonContainer::Get<WindowAdapter>().GetWindowIdsByCoordinate(
1345 displayId, windowNumber, x, y, windowIds);
1346 if (ret != WMError::WM_OK) {
1347 TLOGE(WmsLogTag::DEFAULT, "get windowIds by coordinate failed");
1348 }
1349 return ret;
1350 }
1351
ReleaseForegroundSessionScreenLock()1352 WMError WindowManager::ReleaseForegroundSessionScreenLock()
1353 {
1354 WMError ret = SingletonContainer::Get<WindowAdapter>().ReleaseForegroundSessionScreenLock();
1355 if (ret != WMError::WM_OK) {
1356 TLOGE(WmsLogTag::DEFAULT, "release screen lock failed");
1357 }
1358 return ret;
1359 }
1360
GetDisplayIdByWindowId(const std::vector<uint64_t> & windowIds,std::unordered_map<uint64_t,DisplayId> & windowDisplayIdMap)1361 WMError WindowManager::GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
1362 std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap)
1363 {
1364 WMError ret = SingletonContainer::Get<WindowAdapter>().GetDisplayIdByWindowId(windowIds, windowDisplayIdMap);
1365 if (ret != WMError::WM_OK) {
1366 TLOGE(WmsLogTag::DEFAULT, "failed");
1367 }
1368 return ret;
1369 }
1370
SetGlobalDragResizeType(DragResizeType dragResizeType)1371 WMError WindowManager::SetGlobalDragResizeType(DragResizeType dragResizeType)
1372 {
1373 WMError ret = SingletonContainer::Get<WindowAdapter>().SetGlobalDragResizeType(dragResizeType);
1374 if (ret != WMError::WM_OK) {
1375 TLOGE(WmsLogTag::DEFAULT, "failed");
1376 }
1377 return ret;
1378 }
1379
GetGlobalDragResizeType(DragResizeType & dragResizeType)1380 WMError WindowManager::GetGlobalDragResizeType(DragResizeType& dragResizeType)
1381 {
1382 WMError ret = SingletonContainer::Get<WindowAdapter>().GetGlobalDragResizeType(dragResizeType);
1383 if (ret != WMError::WM_OK) {
1384 TLOGE(WmsLogTag::DEFAULT, "failed");
1385 }
1386 return ret;
1387 }
1388
SetAppDragResizeType(const std::string & bundleName,DragResizeType dragResizeType)1389 WMError WindowManager::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType)
1390 {
1391 WMError ret = SingletonContainer::Get<WindowAdapter>().SetAppDragResizeType(bundleName, dragResizeType);
1392 if (ret != WMError::WM_OK) {
1393 TLOGE(WmsLogTag::DEFAULT, "failed");
1394 }
1395 return ret;
1396 }
1397
GetAppDragResizeType(const std::string & bundleName,DragResizeType & dragResizeType)1398 WMError WindowManager::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType)
1399 {
1400 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAppDragResizeType(bundleName, dragResizeType);
1401 if (ret != WMError::WM_OK) {
1402 TLOGE(WmsLogTag::DEFAULT, "failed");
1403 }
1404 return ret;
1405 }
1406
ShiftAppWindowPointerEvent(int32_t sourceWindowId,int32_t targetWindowId)1407 WMError WindowManager::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId)
1408 {
1409 WMError ret = SingletonContainer::Get<WindowAdapter>().ShiftAppWindowPointerEvent(
1410 sourceWindowId, targetWindowId);
1411 if (ret != WMError::WM_OK) {
1412 TLOGE(WmsLogTag::WMS_PC, "failed");
1413 }
1414 return ret;
1415 }
1416 } // namespace Rosen
1417 } // namespace OHOS
1418