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 #include <shared_mutex>
21
22 #include "input_manager.h"
23
24 #include "marshalling_helper.h"
25 #include "window_adapter.h"
26 #include "window_manager_agent.h"
27 #include "window_manager_hilog.h"
28 #include "window_display_change_adapter.h"
29 #include "wm_common.h"
30 #include "ws_common.h"
31
32 namespace OHOS {
33 namespace Rosen {
34 namespace {
35 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManager"};
36 struct WindowChecker : public MMI::IWindowChecker {
37 public:
38 WindowChecker() = default;
39 ~WindowChecker() = default;
40 int32_t CheckWindowId(int32_t windowId) const override;
41 };
42 }
43
44 WM_IMPLEMENT_SINGLE_INSTANCE(WindowManager)
45
46 class WindowManager::Impl {
47 public:
48 void NotifyWMSConnected(int32_t userId, int32_t screenId);
49 void NotifyWMSDisconnected(int32_t userId, int32_t screenId);
50 void NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
51 WindowType windowType, DisplayId displayId);
52 void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
53 WindowType windowType, DisplayId displayId);
54 void NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo);
55 void NotifyWindowModeChange(WindowModeType type);
56 void NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo);
57 void NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints);
58 void NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type);
59 void NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
60 void NotifyWindowVisibilityStateChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos);
61 void PackWindowChangeInfo(const std::unordered_set<WindowInfoKey>& interestInfo,
62 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos,
63 std::vector<std::unordered_map<WindowInfoKey, std::any>>& windowChangeInfos);
64 void NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>>&
65 windowDrawingContentInfos);
66 void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
67 void NotifyWaterMarkFlagChangedResult(bool showWaterMark);
68 void NotifyVisibleWindowNumChanged(const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo);
69 void NotifyGestureNavigationEnabledResult(bool enable);
70 void NotifyDisplayInfoChanged(const sptr<IRemoteObject>& token, DisplayId displayId,
71 float density, DisplayOrientation orientation);
72 void NotifyWindowStyleChange(WindowStyleType type);
73 void NotifyWindowPidVisibilityChanged(const sptr<WindowPidVisibilityInfo>& info);
74
75 static inline SingletonDelegator<WindowManager> delegator_;
76
77 std::shared_mutex listenerMutex_;
78 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener_;
79 std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
80 sptr<WindowManagerAgent> focusChangedListenerAgent_;
81 std::vector<sptr<IWindowModeChangedListener>> windowModeListeners_;
82 sptr<WindowManagerAgent> windowModeListenerAgent_;
83 std::vector<sptr<ISystemBarChangedListener>> systemBarChangedListeners_;
84 sptr<WindowManagerAgent> systemBarChangedListenerAgent_;
85 std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners_;
86 sptr<WindowManagerAgent> windowUpdateListenerAgent_;
87 std::vector<sptr<IVisibilityChangedListener>> windowVisibilityListeners_;
88 sptr<WindowManagerAgent> windowVisibilityListenerAgent_;
89 std::vector<sptr<IWindowInfoChangedListener>> windowVisibilityStateListeners_;
90 sptr<WindowManagerAgent> windowVisibilityStateListenerAgent_;
91 std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentListeners_;
92 sptr<WindowManagerAgent> windowDrawingContentListenerAgent_;
93 std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangedListeners_;
94 sptr<WindowManagerAgent> cameraFloatWindowChangedListenerAgent_;
95 std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners_;
96 sptr<WindowManagerAgent> waterMarkFlagChangeAgent_;
97 std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners_;
98 sptr<WindowManagerAgent> gestureNavigationEnabledAgent_;
99 std::vector<sptr<IVisibleWindowNumChangedListener>> visibleWindowNumChangedListeners_;
100 sptr<WindowManagerAgent> visibleWindowNumChangedListenerAgent_;
101 std::vector<sptr<IWindowStyleChangedListener>> windowStyleListeners_;
102 sptr<WindowManagerAgent> windowStyleListenerAgent_;
103 std::map<sptr<IRemoteObject>,
104 std::vector<sptr<WindowDisplayChangeAdapter>>> displayInfoChangedListeners_;
105 std::vector<sptr<IWindowPidVisibilityChangedListener>> windowPidVisibilityListeners_;
106 sptr<WindowManagerAgent> windowPidVisibilityListenerAgent_;
107 std::shared_mutex visibilityListenerAgentListenerMutex_;
108 };
109
NotifyWMSConnected(int32_t userId,int32_t screenId)110 void WindowManager::Impl::NotifyWMSConnected(int32_t userId, int32_t screenId)
111 {
112 TLOGD(WmsLogTag::WMS_MULTI_USER, "WMS connected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
113 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
114 {
115 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
116 wmsConnectionChangedListener = wmsConnectionChangedListener_;
117 }
118 if (wmsConnectionChangedListener != nullptr) {
119 wmsConnectionChangedListener->OnConnected(userId, screenId);
120 }
121 }
122
NotifyWMSDisconnected(int32_t userId,int32_t screenId)123 void WindowManager::Impl::NotifyWMSDisconnected(int32_t userId, int32_t screenId)
124 {
125 TLOGI(WmsLogTag::WMS_MULTI_USER, "WMS disconnected [userId:%{public}d; screenId:%{public}d]", userId, screenId);
126 sptr<IWMSConnectionChangedListener> wmsConnectionChangedListener;
127 {
128 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
129 wmsConnectionChangedListener = wmsConnectionChangedListener_;
130 }
131 if (wmsConnectionChangedListener != nullptr) {
132 wmsConnectionChangedListener->OnDisconnected(userId, screenId);
133 }
134 }
135
NotifyFocused(const sptr<FocusChangeInfo> & focusChangeInfo)136 void WindowManager::Impl::NotifyFocused(const sptr<FocusChangeInfo>& focusChangeInfo)
137 {
138 TLOGD(WmsLogTag::WMS_FOCUS, "NotifyFocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
139 focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
140 static_cast<uint32_t>(focusChangeInfo->windowType_));
141 std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
142 {
143 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
144 focusChangeListeners = focusChangedListeners_;
145 }
146 for (auto& listener : focusChangeListeners) {
147 listener->OnFocused(focusChangeInfo);
148 }
149 }
150
NotifyUnfocused(const sptr<FocusChangeInfo> & focusChangeInfo)151 void WindowManager::Impl::NotifyUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo)
152 {
153 TLOGD(WmsLogTag::WMS_FOCUS, "NotifyUnfocused [%{public}u; %{public}" PRIu64"; %{public}d; %{public}d; %{public}u]",
154 focusChangeInfo->windowId_, focusChangeInfo->displayId_, focusChangeInfo->pid_, focusChangeInfo->uid_,
155 static_cast<uint32_t>(focusChangeInfo->windowType_));
156 std::vector<sptr<IFocusChangedListener>> focusChangeListeners;
157 {
158 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
159 focusChangeListeners = focusChangedListeners_;
160 }
161 for (auto& listener : focusChangeListeners) {
162 listener->OnUnfocused(focusChangeInfo);
163 }
164 }
165
NotifyWindowModeChange(WindowModeType type)166 void WindowManager::Impl::NotifyWindowModeChange(WindowModeType type)
167 {
168 TLOGI(WmsLogTag::WMS_MAIN, "WindowManager::Impl UpdateWindowModeTypeInfo type: %{public}d",
169 static_cast<uint8_t>(type));
170 std::vector<sptr<IWindowModeChangedListener>> windowModeListeners;
171 {
172 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
173 windowModeListeners = windowModeListeners_;
174 }
175 for (auto &listener : windowModeListeners) {
176 listener->OnWindowModeUpdate(type);
177 }
178 }
179
NotifySystemBarChanged(DisplayId displayId,const SystemBarRegionTints & tints)180 void WindowManager::Impl::NotifySystemBarChanged(DisplayId displayId, const SystemBarRegionTints& tints)
181 {
182 for (auto tint : tints) {
183 WLOGFD("type:%{public}d, enable:%{public}d," \
184 "backgroundColor:%{public}x, contentColor:%{public}x " \
185 "region:[%{public}d, %{public}d, %{public}d, %{public}d]",
186 tint.type_, tint.prop_.enable_, tint.prop_.backgroundColor_, tint.prop_.contentColor_,
187 tint.region_.posX_, tint.region_.posY_, tint.region_.width_, tint.region_.height_);
188 }
189 std::vector<sptr<ISystemBarChangedListener>> systemBarChangeListeners;
190 {
191 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
192 systemBarChangeListeners = systemBarChangedListeners_;
193 }
194 for (auto& listener : systemBarChangeListeners) {
195 listener->OnSystemBarPropertyChange(displayId, tints);
196 }
197 }
198
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)199 void WindowManager::Impl::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
200 WindowUpdateType type)
201 {
202 if (infos.empty()) {
203 WLOGFE("infos is empty");
204 return;
205 }
206 for (auto& info : infos) {
207 if (info == nullptr) {
208 TLOGD(WmsLogTag::WMS_MAIN, "info is nullptr");
209 continue;
210 }
211 TLOGD(WmsLogTag::WMS_MAIN, "NotifyAccessibilityWindowInfo: wid[%{public}u], innerWid_[%{public}u]," \
212 "uiNodeId_[%{public}u], rect[%{public}d %{public}d %{public}d %{public}d]," \
213 "isFocused[%{public}d], isDecorEnable[%{public}d], displayId[%{public}" PRIu64"], layer[%{public}u]," \
214 "mode[%{public}u], type[%{public}u, updateType[%{public}d], bundle[%{public}s]",
215 info->wid_, info->innerWid_, info->uiNodeId_, info->windowRect_.width_, info->windowRect_.height_,
216 info->windowRect_.posX_, info->windowRect_.posY_, info->focused_, info->isDecorEnable_, info->displayId_,
217 info->layer_, info->mode_, info->type_, type, info->bundleName_.c_str());
218 for (const auto& rect : info->touchHotAreas_) {
219 TLOGD(WmsLogTag::WMS_MAIN, "window touch hot areas rect[x=%{public}d,y=%{public}d," \
220 "w=%{public}d,h=%{public}d]", rect.posX_, rect.posY_, rect.width_, rect.height_);
221 }
222 }
223
224 std::vector<sptr<IWindowUpdateListener>> windowUpdateListeners;
225 {
226 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
227 windowUpdateListeners = windowUpdateListeners_;
228 }
229 for (auto& listener : windowUpdateListeners) {
230 listener->OnWindowUpdate(infos, type);
231 }
232 }
233
NotifyWindowVisibilityInfoChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos)234 void WindowManager::Impl::NotifyWindowVisibilityInfoChanged(
235 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
236 {
237 std::vector<sptr<IVisibilityChangedListener>> visibilityChangeListeners;
238 {
239 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
240 visibilityChangeListeners = windowVisibilityListeners_;
241 }
242 for (auto& listener : visibilityChangeListeners) {
243 WLOGD("Notify WindowVisibilityInfo to caller");
244 listener->OnWindowVisibilityChanged(windowVisibilityInfos);
245 }
246 }
247
NotifyWindowVisibilityStateChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos)248 void WindowManager::Impl::NotifyWindowVisibilityStateChanged(
249 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos)
250 {
251 TLOGD(WmsLogTag::WMS_ATTRIBUTE, "in");
252 std::vector<sptr<IWindowInfoChangedListener>> windowVisibilityStateListeners;
253 {
254 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
255 windowVisibilityStateListeners = windowVisibilityStateListeners_;
256 }
257 for (auto& listener : windowVisibilityStateListeners) {
258 if (listener == nullptr) {
259 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "listener is null");
260 continue;
261 }
262 std::vector<std::unordered_map<WindowInfoKey, std::any>> windowChangeInfos;
263 PackWindowChangeInfo(listener->GetInterestInfo(), windowVisibilityInfos, windowChangeInfos);
264 TLOGD(WmsLogTag::WMS_ATTRIBUTE, "Notify WindowVisibilityState to caller, info size: %{public}zu",
265 windowChangeInfos.size());
266 listener->OnWindowInfoChanged(windowChangeInfos);
267 }
268 }
269
PackWindowChangeInfo(const std::unordered_set<WindowInfoKey> & interestInfo,const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos,std::vector<std::unordered_map<WindowInfoKey,std::any>> & windowChangeInfos)270 void WindowManager::Impl::PackWindowChangeInfo(const std::unordered_set<WindowInfoKey>& interestInfo,
271 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos,
272 std::vector<std::unordered_map<WindowInfoKey, std::any>>& windowChangeInfos)
273 {
274 for (const auto& info : windowVisibilityInfos) {
275 std::unordered_map<WindowInfoKey, std::any> windowChangeInfo;
276 if (interestInfo.find(WindowInfoKey::WINDOW_ID) != interestInfo.end()) {
277 windowChangeInfo.emplace(WindowInfoKey::WINDOW_ID, info->windowId_);
278 }
279 if (interestInfo.find(WindowInfoKey::BUNDLE_NAME) != interestInfo.end()) {
280 windowChangeInfo.emplace(WindowInfoKey::BUNDLE_NAME, info->bundleName_);
281 }
282 if (interestInfo.find(WindowInfoKey::ABILITY_NAME) != interestInfo.end()) {
283 windowChangeInfo.emplace(WindowInfoKey::ABILITY_NAME, info->abilityName_);
284 }
285 if (interestInfo.find(WindowInfoKey::APP_INDEX) != interestInfo.end()) {
286 windowChangeInfo.emplace(WindowInfoKey::APP_INDEX, info->appIndex_);
287 }
288 if (interestInfo.find(WindowInfoKey::VISIBILITY_STATE) != interestInfo.end()) {
289 windowChangeInfo.emplace(WindowInfoKey::VISIBILITY_STATE, info->visibilityState_);
290 }
291 windowChangeInfos.emplace_back(windowChangeInfo);
292 }
293 }
294
NotifyWindowDrawingContentInfoChanged(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos)295 void WindowManager::Impl::NotifyWindowDrawingContentInfoChanged(
296 const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos)
297 {
298 std::vector<sptr<IDrawingContentChangedListener>> windowDrawingContentChangeListeners;
299 {
300 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
301 windowDrawingContentChangeListeners = windowDrawingContentListeners_;
302 }
303 for (auto& listener : windowDrawingContentChangeListeners) {
304 WLOGFD("Notify windowDrawingContentInfo to caller");
305 listener->OnWindowDrawingContentChanged(windowDrawingContentInfos);
306 }
307 }
308
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing)309 void WindowManager::Impl::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing)
310 {
311 TLOGD(WmsLogTag::DEFAULT,
312 "Camera float window, accessTokenId=%{private}u, isShowing=%{public}u", accessTokenId, isShowing);
313 std::vector<sptr<ICameraFloatWindowChangedListener>> cameraFloatWindowChangeListeners;
314 {
315 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
316 cameraFloatWindowChangeListeners = cameraFloatWindowChangedListeners_;
317 }
318 for (auto& listener : cameraFloatWindowChangeListeners) {
319 listener->OnCameraFloatWindowChange(accessTokenId, isShowing);
320 }
321 }
322
NotifyWaterMarkFlagChangedResult(bool showWaterMark)323 void WindowManager::Impl::NotifyWaterMarkFlagChangedResult(bool showWaterMark)
324 {
325 WLOGFI("Notify water mark flag changed result, showWaterMark=%{public}d", showWaterMark);
326 std::vector<sptr<IWaterMarkFlagChangedListener>> waterMarkFlagChangeListeners;
327 {
328 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
329 waterMarkFlagChangeListeners = waterMarkFlagChangeListeners_;
330 }
331 for (auto& listener : waterMarkFlagChangeListeners) {
332 listener->OnWaterMarkFlagUpdate(showWaterMark);
333 }
334 }
335
NotifyGestureNavigationEnabledResult(bool enable)336 void WindowManager::Impl::NotifyGestureNavigationEnabledResult(bool enable)
337 {
338 WLOGFI("Notify gesture navigation enable result, enable=%{public}d", enable);
339 std::vector<sptr<IGestureNavigationEnabledChangedListener>> gestureNavigationEnabledListeners;
340 {
341 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
342 gestureNavigationEnabledListeners = gestureNavigationEnabledListeners_;
343 }
344 for (auto& listener : gestureNavigationEnabledListeners) {
345 listener->OnGestureNavigationEnabledUpdate(enable);
346 }
347 }
348
NotifyVisibleWindowNumChanged(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)349 void WindowManager::Impl::NotifyVisibleWindowNumChanged(
350 const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
351 {
352 std::vector<sptr<IVisibleWindowNumChangedListener>> visibleWindowNumChangedListeners;
353 {
354 std::shared_lock<std::shared_mutex> lock(listenerMutex_);
355 visibleWindowNumChangedListeners = visibleWindowNumChangedListeners_;
356 }
357 for (auto& listener : visibleWindowNumChangedListeners) {
358 if (listener == nullptr) {
359 continue;
360 }
361 listener->OnVisibleWindowNumChange(visibleWindowNumInfo);
362 }
363 }
364
NotifyDisplayInfoChanged(const sptr<IRemoteObject> & token,DisplayId displayId,float density,DisplayOrientation orientation)365 void WindowManager::Impl::NotifyDisplayInfoChanged(const sptr<IRemoteObject>& token, DisplayId displayId,
366 float density, DisplayOrientation orientation)
367 {
368 auto iter = displayInfoChangedListeners_.end();
369 std::vector<sptr<WindowDisplayChangeAdapter>> displayInfoChangedListeners;
370 {
371 std::unique_lock<std::shared_mutex> lock(listenerMutex_);
372 iter = displayInfoChangedListeners_.find(token);
373 if (iter == displayInfoChangedListeners_.end()) {
374 TLOGI(WmsLogTag::DMS, "can not find token in listener list, need not notify the change of display info");
375 return;
376 }
377 displayInfoChangedListeners = iter->second;
378 }
379
380 for (auto& listener : displayInfoChangedListeners) {
381 listener->OnDisplayInfoChange(token, displayId, density, orientation);
382 }
383 }
384
NotifyWindowStyleChange(WindowStyleType type)385 void WindowManager::Impl::NotifyWindowStyleChange(WindowStyleType type)
386 {
387 TLOGI(WmsLogTag::WMS_MAIN, "WindowStyleChange type: %{public}d",
388 static_cast<uint8_t>(type));
389 std::vector<sptr<IWindowStyleChangedListener>> windowStyleListeners;
390 {
391 std::unique_lock<std::shared_mutex> lock(listenerMutex_);
392 windowStyleListeners = windowStyleListeners_;
393 }
394 for (auto &listener : windowStyleListeners) {
395 TLOGI(WmsLogTag::WMS_MAIN, "WindowStyleChange type: %{public}d",
396 static_cast<uint8_t>(type));
397 listener->OnWindowStyleUpdate(type);
398 }
399 }
400
NotifyWindowPidVisibilityChanged(const sptr<WindowPidVisibilityInfo> & info)401 void WindowManager::Impl::NotifyWindowPidVisibilityChanged(
402 const sptr<WindowPidVisibilityInfo>& info)
403 {
404 std::vector<sptr<IWindowPidVisibilityChangedListener>> windowPidVisibilityListeners;
405 {
406 std::unique_lock<std::shared_mutex> lock(listenerMutex_);
407 windowPidVisibilityListeners = windowPidVisibilityListeners_;
408 }
409 for (auto &listener : windowPidVisibilityListeners) {
410 if (listener != nullptr) {
411 listener->NotifyWindowPidVisibilityChanged(info);
412 }
413 }
414 }
415
WindowManager()416 WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>())
417 {
418 }
419
CheckWindowId(int32_t windowId) const420 int32_t WindowChecker::CheckWindowId(int32_t windowId) const
421 {
422 int32_t pid = INVALID_PID;
423 WMError ret = SingletonContainer::Get<WindowAdapter>().CheckWindowId(windowId, pid);
424 if (ret != WMError::WM_OK) {
425 WLOGFE("Window(%{public}d) do not allow styles to be set", windowId);
426 }
427 return pid;
428 }
429
~WindowManager()430 WindowManager::~WindowManager()
431 {
432 std::lock_guard<std::recursive_mutex> lock(mutex_);
433 destroyed_ = true;
434 }
435
RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener> & listener)436 WMError WindowManager::RegisterWMSConnectionChangedListener(const sptr<IWMSConnectionChangedListener>& listener)
437 {
438 int32_t clientUserId = GetUserIdByUid(getuid());
439 if (clientUserId != SYSTEM_USERID) {
440 TLOGW(WmsLogTag::WMS_MULTI_USER, "Not u0 user, permission denied");
441 return WMError::WM_ERROR_INVALID_PERMISSION;
442 }
443 if (listener == nullptr) {
444 TLOGE(WmsLogTag::WMS_MULTI_USER, "WMS connection changed listener registered could not be null");
445 return WMError::WM_ERROR_NULLPTR;
446 }
447 TLOGD(WmsLogTag::WMS_MULTI_USER, "Register enter");
448 {
449 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
450 if (pImpl_->wmsConnectionChangedListener_) {
451 TLOGI(WmsLogTag::WMS_MULTI_USER, "wmsConnectionChangedListener is already registered, do nothing");
452 return WMError::WM_OK;
453 }
454 pImpl_->wmsConnectionChangedListener_ = listener;
455 }
456 auto ret = SingletonContainer::Get<WindowAdapter>().RegisterWMSConnectionChangedListener(
457 [this](int32_t userId, int32_t screenId, bool isConnected) {
458 this->OnWMSConnectionChanged(userId, screenId, isConnected);
459 });
460 if (ret != WMError::WM_OK) {
461 pImpl_->wmsConnectionChangedListener_ = nullptr;
462 }
463 return ret;
464 }
465
UnregisterWMSConnectionChangedListener()466 WMError WindowManager::UnregisterWMSConnectionChangedListener()
467 {
468 TLOGI(WmsLogTag::WMS_MULTI_USER, "Unregister enter");
469 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
470 pImpl_->wmsConnectionChangedListener_ = nullptr;
471 return WMError::WM_OK;
472 }
473
RegisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)474 WMError WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
475 {
476 if (listener == nullptr) {
477 WLOGFE("listener could not be null");
478 return WMError::WM_ERROR_NULLPTR;
479 }
480
481 sptr<WindowManagerAgent> focusChangedListenerAgentBack = nullptr;
482 WMError ret = WMError::WM_OK;
483 {
484 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
485 if (pImpl_->focusChangedListenerAgent_ == nullptr) {
486 pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
487 }
488 focusChangedListenerAgentBack = pImpl_->focusChangedListenerAgent_;
489 }
490 ret = WindowAdapter::GetInstance().RegisterWindowManagerAgent(
491 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, focusChangedListenerAgentBack);
492 {
493 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
494 if (ret != WMError::WM_OK) {
495 TLOGE(WmsLogTag::WMS_FOCUS, "RegisterWindowManagerAgent failed!");
496 pImpl_->focusChangedListenerAgent_ = nullptr;
497 } else {
498 auto iter = std::find(
499 pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
500 if (iter != pImpl_->focusChangedListeners_.end()) {
501 TLOGW(WmsLogTag::WMS_FOCUS, "Listener is already registered.");
502 return WMError::WM_OK;
503 }
504 pImpl_->focusChangedListeners_.push_back(listener);
505 }
506 }
507 return ret;
508 }
509
UnregisterFocusChangedListener(const sptr<IFocusChangedListener> & listener)510 WMError WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
511 {
512 if (listener == nullptr) {
513 WLOGFE("listener could not be null");
514 return WMError::WM_ERROR_NULLPTR;
515 }
516
517 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
518 auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
519 if (iter == pImpl_->focusChangedListeners_.end()) {
520 WLOGFE("could not find this listener");
521 return WMError::WM_OK;
522 }
523 pImpl_->focusChangedListeners_.erase(iter);
524 WMError ret = WMError::WM_OK;
525 if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
526 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
527 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_);
528 if (ret == WMError::WM_OK) {
529 pImpl_->focusChangedListenerAgent_ = nullptr;
530 }
531 }
532 return ret;
533 }
534
RegisterWindowModeChangedListener(const sptr<IWindowModeChangedListener> & listener)535 WMError WindowManager::RegisterWindowModeChangedListener(const sptr<IWindowModeChangedListener>& listener)
536 {
537 if (listener == nullptr) {
538 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
539 return WMError::WM_ERROR_NULLPTR;
540 }
541
542 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
543 WMError ret = WMError::WM_OK;
544 if (pImpl_->windowModeListenerAgent_ == nullptr) {
545 pImpl_->windowModeListenerAgent_ = new WindowManagerAgent();
546 }
547 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
548 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_);
549 if (ret != WMError::WM_OK) {
550 TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
551 pImpl_->windowModeListenerAgent_ = nullptr;
552 return ret;
553 }
554 auto iter = std::find(pImpl_->windowModeListeners_.begin(), pImpl_->windowModeListeners_.end(), listener);
555 if (iter != pImpl_->windowModeListeners_.end()) {
556 TLOGW(WmsLogTag::WMS_MAIN, "Listener is already registered.");
557 return WMError::WM_OK;
558 }
559 pImpl_->windowModeListeners_.push_back(listener);
560 return ret;
561 }
562
UnregisterWindowModeChangedListener(const sptr<IWindowModeChangedListener> & listener)563 WMError WindowManager::UnregisterWindowModeChangedListener(const sptr<IWindowModeChangedListener>& listener)
564 {
565 if (listener == nullptr) {
566 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
567 return WMError::WM_ERROR_NULLPTR;
568 }
569
570 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
571 auto iter = std::find(pImpl_->windowModeListeners_.begin(), pImpl_->windowModeListeners_.end(), listener);
572 if (iter == pImpl_->windowModeListeners_.end()) {
573 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
574 return WMError::WM_OK;
575 }
576 pImpl_->windowModeListeners_.erase(iter);
577 WMError ret = WMError::WM_OK;
578 if (pImpl_->windowModeListeners_.empty() && pImpl_->windowModeListenerAgent_ != nullptr) {
579 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
580 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_MODE, pImpl_->windowModeListenerAgent_);
581 if (ret == WMError::WM_OK) {
582 pImpl_->windowModeListenerAgent_ = nullptr;
583 }
584 }
585 return ret;
586 }
587
RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)588 WMError WindowManager::RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
589 {
590 if (listener == nullptr) {
591 WLOGFE("listener could not be null");
592 return WMError::WM_ERROR_NULLPTR;
593 }
594
595 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
596 WMError ret = WMError::WM_OK;
597 if (pImpl_->systemBarChangedListenerAgent_ == nullptr) {
598 pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent();
599 }
600 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
601 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
602 if (ret != WMError::WM_OK) {
603 WLOGFW("RegisterWindowManagerAgent failed!");
604 pImpl_->systemBarChangedListenerAgent_ = nullptr;
605 } else {
606 auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
607 listener);
608 if (iter != pImpl_->systemBarChangedListeners_.end()) {
609 WLOGFW("Listener is already registered.");
610 return WMError::WM_OK;
611 }
612 pImpl_->systemBarChangedListeners_.push_back(listener);
613 }
614 return ret;
615 }
616
UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener> & listener)617 WMError WindowManager::UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener)
618 {
619 if (listener == nullptr) {
620 WLOGFE("listener could not be null");
621 return WMError::WM_ERROR_NULLPTR;
622 }
623
624 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
625 auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(),
626 listener);
627 if (iter == pImpl_->systemBarChangedListeners_.end()) {
628 WLOGFE("could not find this listener");
629 return WMError::WM_OK;
630 }
631 pImpl_->systemBarChangedListeners_.erase(iter);
632 WMError ret = WMError::WM_OK;
633 if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) {
634 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
635 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_);
636 if (ret == WMError::WM_OK) {
637 pImpl_->systemBarChangedListenerAgent_ = nullptr;
638 }
639 }
640 return ret;
641 }
642
MinimizeAllAppWindows(DisplayId displayId)643 WMError WindowManager::MinimizeAllAppWindows(DisplayId displayId)
644 {
645 WLOGFD("displayId %{public}" PRIu64"", displayId);
646 return SingletonContainer::Get<WindowAdapter>().MinimizeAllAppWindows(displayId);
647 }
648
ToggleShownStateForAllAppWindows()649 WMError WindowManager::ToggleShownStateForAllAppWindows()
650 {
651 WLOGFD("ToggleShownStateForAllAppWindows");
652 return SingletonContainer::Get<WindowAdapter>().ToggleShownStateForAllAppWindows();
653 }
654
SetWindowLayoutMode(WindowLayoutMode mode)655 WMError WindowManager::SetWindowLayoutMode(WindowLayoutMode mode)
656 {
657 WLOGFD("set window layout mode: %{public}u", mode);
658 WMError ret = SingletonContainer::Get<WindowAdapter>().SetWindowLayoutMode(mode);
659 if (ret != WMError::WM_OK) {
660 WLOGFE("set layout mode failed");
661 }
662 return ret;
663 }
664
RegisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)665 WMError WindowManager::RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener)
666 {
667 if (listener == nullptr) {
668 WLOGFE("listener could not be null");
669 return WMError::WM_ERROR_NULLPTR;
670 }
671 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
672 WMError ret = WMError::WM_OK;
673 if (pImpl_->windowUpdateListenerAgent_ == nullptr) {
674 pImpl_->windowUpdateListenerAgent_ = new WindowManagerAgent();
675 }
676 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
677 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
678 if (ret != WMError::WM_OK) {
679 WLOGFW("RegisterWindowManagerAgent failed!");
680 pImpl_->windowUpdateListenerAgent_ = nullptr;
681 } else {
682 auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
683 if (iter != pImpl_->windowUpdateListeners_.end()) {
684 WLOGI("Listener is already registered.");
685 return WMError::WM_OK;
686 }
687 pImpl_->windowUpdateListeners_.emplace_back(listener);
688 }
689 return ret;
690 }
691
UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener> & listener)692 WMError WindowManager::UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener)
693 {
694 if (listener == nullptr) {
695 WLOGFE("listener could not be null");
696 return WMError::WM_ERROR_NULLPTR;
697 }
698 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
699 auto iter = std::find(pImpl_->windowUpdateListeners_.begin(), pImpl_->windowUpdateListeners_.end(), listener);
700 if (iter == pImpl_->windowUpdateListeners_.end()) {
701 WLOGFE("could not find this listener");
702 return WMError::WM_OK;
703 }
704 pImpl_->windowUpdateListeners_.erase(iter);
705 WMError ret = WMError::WM_OK;
706 if (pImpl_->windowUpdateListeners_.empty() && pImpl_->windowUpdateListenerAgent_ != nullptr) {
707 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
708 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE, pImpl_->windowUpdateListenerAgent_);
709 if (ret == WMError::WM_OK) {
710 pImpl_->windowUpdateListenerAgent_ = nullptr;
711 }
712 }
713 return ret;
714 }
715
RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)716 WMError WindowManager::RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
717 {
718 if (listener == nullptr) {
719 WLOGFE("listener could not be null");
720 return WMError::WM_ERROR_NULLPTR;
721 }
722 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
723 WMError ret = WMError::WM_OK;
724 if (pImpl_->windowVisibilityListenerAgent_ == nullptr) {
725 pImpl_->windowVisibilityListenerAgent_ = new WindowManagerAgent();
726 }
727 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
728 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
729 pImpl_->windowVisibilityListenerAgent_);
730 if (ret != WMError::WM_OK) {
731 WLOGFW("RegisterWindowManagerAgent failed!");
732 pImpl_->windowVisibilityListenerAgent_ = nullptr;
733 } else {
734 auto iter = std::find(pImpl_->windowVisibilityListeners_.begin(), pImpl_->windowVisibilityListeners_.end(),
735 listener);
736 if (iter != pImpl_->windowVisibilityListeners_.end()) {
737 WLOGFW("Listener is already registered.");
738 return WMError::WM_OK;
739 }
740 pImpl_->windowVisibilityListeners_.emplace_back(listener);
741 }
742 return ret;
743 }
744
UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener> & listener)745 WMError WindowManager::UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener)
746 {
747 if (listener == nullptr) {
748 WLOGFE("listener could not be null");
749 return WMError::WM_ERROR_NULLPTR;
750 }
751 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
752 pImpl_->windowVisibilityListeners_.erase(std::remove_if(pImpl_->windowVisibilityListeners_.begin(),
753 pImpl_->windowVisibilityListeners_.end(), [listener](sptr<IVisibilityChangedListener> registeredListener) {
754 return registeredListener == listener;
755 }), pImpl_->windowVisibilityListeners_.end());
756
757 WMError ret = WMError::WM_OK;
758 if (pImpl_->windowVisibilityListeners_.empty() && pImpl_->windowVisibilityListenerAgent_ != nullptr) {
759 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
760 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
761 pImpl_->windowVisibilityListenerAgent_);
762 if (ret == WMError::WM_OK) {
763 pImpl_->windowVisibilityListenerAgent_ = nullptr;
764 }
765 }
766 return ret;
767 }
768
RegisterVisibilityStateChangedListener(const sptr<IWindowInfoChangedListener> & listener)769 WMError WindowManager::RegisterVisibilityStateChangedListener(const sptr<IWindowInfoChangedListener>& listener)
770 {
771 if (listener == nullptr) {
772 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "listener is null");
773 return WMError::WM_ERROR_NULLPTR;
774 }
775 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
776 WMError ret = WMError::WM_OK;
777 if (pImpl_->windowVisibilityStateListenerAgent_ == nullptr) {
778 pImpl_->windowVisibilityStateListenerAgent_ = new WindowManagerAgent();
779 }
780 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
781 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
782 pImpl_->windowVisibilityStateListenerAgent_);
783 if (ret != WMError::WM_OK) {
784 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "RegisterWindowManagerAgent failed!");
785 pImpl_->windowVisibilityStateListenerAgent_ = nullptr;
786 } else {
787 auto iter = std::find(pImpl_->windowVisibilityStateListeners_.begin(),
788 pImpl_->windowVisibilityStateListeners_.end(), listener);
789 if (iter != pImpl_->windowVisibilityStateListeners_.end()) {
790 TLOGW(WmsLogTag::WMS_ATTRIBUTE, "Listener is already registered.");
791 return WMError::WM_OK;
792 }
793 pImpl_->windowVisibilityStateListeners_.emplace_back(listener);
794 }
795 return ret;
796 }
797
UnregisterVisibilityStateChangedListener(const sptr<IWindowInfoChangedListener> & listener)798 WMError WindowManager::UnregisterVisibilityStateChangedListener(const sptr<IWindowInfoChangedListener>& listener)
799 {
800 if (listener == nullptr) {
801 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "listener is null");
802 return WMError::WM_ERROR_NULLPTR;
803 }
804 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
805 pImpl_->windowVisibilityStateListeners_.erase(std::remove_if(pImpl_->windowVisibilityStateListeners_ .begin(),
806 pImpl_->windowVisibilityStateListeners_.end(), [listener](sptr<IWindowInfoChangedListener> registeredListener) {
807 return registeredListener == listener;
808 }), pImpl_->windowVisibilityStateListeners_.end());
809
810 WMError ret = WMError::WM_OK;
811 if (pImpl_->windowVisibilityStateListeners_.empty() && pImpl_->windowVisibilityStateListenerAgent_ != nullptr) {
812 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
813 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
814 pImpl_->windowVisibilityStateListenerAgent_);
815 if (ret == WMError::WM_OK) {
816 pImpl_->windowVisibilityStateListenerAgent_ = nullptr;
817 }
818 }
819 return ret;
820 }
821
RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)822 WMError WindowManager::RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener)
823 {
824 if (listener == nullptr) {
825 WLOGFE("listener could not be null");
826 return WMError::WM_ERROR_NULLPTR;
827 }
828
829 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
830 WMError ret = WMError::WM_OK;
831 if (pImpl_->cameraFloatWindowChangedListenerAgent_ == nullptr) {
832 pImpl_->cameraFloatWindowChangedListenerAgent_ = new WindowManagerAgent();
833 }
834 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
835 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
836 pImpl_->cameraFloatWindowChangedListenerAgent_);
837 if (ret != WMError::WM_OK) {
838 WLOGFW("RegisterWindowManagerAgent failed!");
839 pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
840 } else {
841 auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
842 pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
843 if (iter != pImpl_->cameraFloatWindowChangedListeners_.end()) {
844 WLOGFW("Listener is already registered.");
845 return WMError::WM_OK;
846 }
847 pImpl_->cameraFloatWindowChangedListeners_.push_back(listener);
848 }
849 return ret;
850 }
851
UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener> & listener)852 WMError WindowManager::UnregisterCameraFloatWindowChangedListener(
853 const sptr<ICameraFloatWindowChangedListener>& listener)
854 {
855 if (listener == nullptr) {
856 WLOGFE("listener could not be null");
857 return WMError::WM_ERROR_NULLPTR;
858 }
859
860 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
861 auto iter = std::find(pImpl_->cameraFloatWindowChangedListeners_.begin(),
862 pImpl_->cameraFloatWindowChangedListeners_.end(), listener);
863 if (iter == pImpl_->cameraFloatWindowChangedListeners_.end()) {
864 WLOGFE("could not find this listener");
865 return WMError::WM_OK;
866 }
867 pImpl_->cameraFloatWindowChangedListeners_.erase(iter);
868 WMError ret = WMError::WM_OK;
869 if (pImpl_->cameraFloatWindowChangedListeners_.empty() &&
870 pImpl_->cameraFloatWindowChangedListenerAgent_ != nullptr) {
871 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
872 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
873 pImpl_->cameraFloatWindowChangedListenerAgent_);
874 if (ret == WMError::WM_OK) {
875 pImpl_->cameraFloatWindowChangedListenerAgent_ = nullptr;
876 }
877 }
878 return ret;
879 }
880
RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)881 WMError WindowManager::RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
882 {
883 if (listener == nullptr) {
884 WLOGFE("listener could not be null");
885 return WMError::WM_ERROR_NULLPTR;
886 }
887
888 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
889 WMError ret = WMError::WM_OK;
890 if (pImpl_->waterMarkFlagChangeAgent_ == nullptr) {
891 pImpl_->waterMarkFlagChangeAgent_ = new WindowManagerAgent();
892 }
893 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
894 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
895 pImpl_->waterMarkFlagChangeAgent_);
896 if (ret != WMError::WM_OK) {
897 WLOGFW("RegisterWindowManagerAgent failed!");
898 pImpl_->waterMarkFlagChangeAgent_ = nullptr;
899 } else {
900 auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
901 pImpl_->waterMarkFlagChangeListeners_.end(), listener);
902 if (iter != pImpl_->waterMarkFlagChangeListeners_.end()) {
903 WLOGFW("Listener is already registered.");
904 return WMError::WM_OK;
905 }
906 pImpl_->waterMarkFlagChangeListeners_.push_back(listener);
907 }
908 WLOGFD("Try to registerWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
909 return ret;
910 }
911
UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener> & listener)912 WMError WindowManager::UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener)
913 {
914 if (listener == nullptr) {
915 WLOGFE("listener could not be null");
916 return WMError::WM_ERROR_NULLPTR;
917 }
918
919 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
920 auto iter = std::find(pImpl_->waterMarkFlagChangeListeners_.begin(),
921 pImpl_->waterMarkFlagChangeListeners_.end(), listener);
922 if (iter == pImpl_->waterMarkFlagChangeListeners_.end()) {
923 WLOGFE("could not find this listener");
924 return WMError::WM_OK;
925 }
926 pImpl_->waterMarkFlagChangeListeners_.erase(iter);
927 WMError ret = WMError::WM_OK;
928 if (pImpl_->waterMarkFlagChangeListeners_.empty() &&
929 pImpl_->waterMarkFlagChangeAgent_ != nullptr) {
930 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
931 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WATER_MARK_FLAG,
932 pImpl_->waterMarkFlagChangeAgent_);
933 if (ret == WMError::WM_OK) {
934 pImpl_->waterMarkFlagChangeAgent_ = nullptr;
935 }
936 }
937 WLOGFD("Try to unregisterWaterMarkFlagChangedListener && result : %{public}u", static_cast<uint32_t>(ret));
938 return ret;
939 }
940
RegisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)941 WMError WindowManager::RegisterGestureNavigationEnabledChangedListener(
942 const sptr<IGestureNavigationEnabledChangedListener>& listener)
943 {
944 if (listener == nullptr) {
945 WLOGFE("listener could not be null");
946 return WMError::WM_ERROR_NULLPTR;
947 }
948
949 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
950 WMError ret = WMError::WM_OK;
951 if (pImpl_->gestureNavigationEnabledAgent_ == nullptr) {
952 pImpl_->gestureNavigationEnabledAgent_ = new (std::nothrow)WindowManagerAgent();
953 }
954 if (pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
955 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
956 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
957 pImpl_->gestureNavigationEnabledAgent_);
958 } else {
959 WLOGFE("Create windowManagerAgent object failed!");
960 ret = WMError::WM_ERROR_NULLPTR;
961 }
962 if (ret != WMError::WM_OK) {
963 WLOGFE("RegisterWindowManagerAgent failed!");
964 pImpl_->gestureNavigationEnabledAgent_ = nullptr;
965 } else {
966 auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
967 pImpl_->gestureNavigationEnabledListeners_.end(), listener);
968 if (iter != pImpl_->gestureNavigationEnabledListeners_.end()) {
969 WLOGFW("Listener is already registered.");
970 return WMError::WM_OK;
971 }
972 pImpl_->gestureNavigationEnabledListeners_.push_back(listener);
973 }
974 WLOGFD("Try to registerGestureNavigationEnabledChangedListener and result is %{public}u",
975 static_cast<uint32_t>(ret));
976 return ret;
977 }
978
UnregisterGestureNavigationEnabledChangedListener(const sptr<IGestureNavigationEnabledChangedListener> & listener)979 WMError WindowManager::UnregisterGestureNavigationEnabledChangedListener(
980 const sptr<IGestureNavigationEnabledChangedListener>& listener)
981 {
982 if (listener == nullptr) {
983 WLOGFE("listener could not be null");
984 return WMError::WM_ERROR_NULLPTR;
985 }
986
987 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
988 auto iter = std::find(pImpl_->gestureNavigationEnabledListeners_.begin(),
989 pImpl_->gestureNavigationEnabledListeners_.end(), listener);
990 if (iter == pImpl_->gestureNavigationEnabledListeners_.end()) {
991 WLOGFE("could not find this listener");
992 return WMError::WM_ERROR_INVALID_PARAM;
993 }
994 pImpl_->gestureNavigationEnabledListeners_.erase(iter);
995 WMError ret = WMError::WM_OK;
996 if (pImpl_->gestureNavigationEnabledListeners_.empty() &&
997 pImpl_->gestureNavigationEnabledAgent_ != nullptr) {
998 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
999 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_GESTURE_NAVIGATION_ENABLED,
1000 pImpl_->gestureNavigationEnabledAgent_);
1001 if (ret == WMError::WM_OK) {
1002 pImpl_->gestureNavigationEnabledAgent_ = nullptr;
1003 }
1004 }
1005 WLOGFD("Try to unregisterGestureNavigationEnabledChangedListener and result is %{public}u",
1006 static_cast<uint32_t>(ret));
1007 return ret;
1008 }
1009
RegisterDisplayInfoChangedListener(const sptr<IRemoteObject> & token,const sptr<IDisplayInfoChangedListener> & listener)1010 WMError WindowManager::RegisterDisplayInfoChangedListener(const sptr<IRemoteObject>& token,
1011 const sptr<IDisplayInfoChangedListener>& listener)
1012 {
1013 if (token == nullptr) {
1014 TLOGE(WmsLogTag::DMS, "ability token could not be null");
1015 return WMError::WM_ERROR_NULLPTR;
1016 }
1017
1018 if (listener == nullptr) {
1019 TLOGE(WmsLogTag::DMS, "listener could not be null");
1020 return WMError::WM_ERROR_NULLPTR;
1021 }
1022
1023 sptr<WindowDisplayChangeAdapter> listenerAdapter = new (std::nothrow) WindowDisplayChangeAdapter(token, listener);
1024 if (listenerAdapter == nullptr) {
1025 TLOGE(WmsLogTag::DMS, "create listener adapter failed.");
1026 return WMError::WM_ERROR_NO_MEM;
1027 }
1028 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1029 auto iter = pImpl_->displayInfoChangedListeners_.find(token);
1030 if (iter == pImpl_->displayInfoChangedListeners_.end()) {
1031 pImpl_->displayInfoChangedListeners_.insert({token, {listenerAdapter}});
1032 } else {
1033 auto listerneIter = std::find_if(iter->second.begin(), iter->second.end(),
1034 [&listener](const sptr<WindowDisplayChangeAdapter>& item) {
1035 return listener == item->GetListener();
1036 });
1037 if (listerneIter != iter->second.end()) {
1038 TLOGW(WmsLogTag::DMS, "listener is already registered.");
1039 } else {
1040 iter->second.push_back(listenerAdapter);
1041 }
1042 }
1043 TLOGD(WmsLogTag::DMS, "try to registerDisplayInfoChangedListener success");
1044 return WMError::WM_OK;
1045 }
1046
UnregisterDisplayInfoChangedListener(const sptr<IRemoteObject> & token,const sptr<IDisplayInfoChangedListener> & listener)1047 WMError WindowManager::UnregisterDisplayInfoChangedListener(const sptr<IRemoteObject>& token,
1048 const sptr<IDisplayInfoChangedListener>& listener)
1049 {
1050 if (token == nullptr) {
1051 TLOGE(WmsLogTag::DMS, "ability token could not be null");
1052 return WMError::WM_ERROR_NULLPTR;
1053 }
1054
1055 if (listener == nullptr) {
1056 TLOGE(WmsLogTag::DMS, "listener could not be null");
1057 return WMError::WM_ERROR_NULLPTR;
1058 }
1059
1060 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1061 auto iter = pImpl_->displayInfoChangedListeners_.find(token);
1062 if (iter == pImpl_->displayInfoChangedListeners_.end()) {
1063 TLOGW(WmsLogTag::DMS, "can not find the ability token");
1064 } else {
1065 auto listerneIter = std::find_if(iter->second.begin(), iter->second.end(),
1066 [&listener](sptr<WindowDisplayChangeAdapter>& item) {
1067 return listener == item->GetListener();
1068 });
1069 if (listerneIter == iter->second.end()) {
1070 TLOGW(WmsLogTag::DMS, "can not find the listener.");
1071 } else {
1072 iter->second.erase(listerneIter);
1073 if (iter->second.empty()) {
1074 pImpl_->displayInfoChangedListeners_.erase(iter);
1075 }
1076 }
1077 }
1078 TLOGD(WmsLogTag::DMS, "try to unregisterDisplayInfoChangedListener success");
1079 return WMError::WM_OK;
1080 }
1081
RegisterWindowPidVisibilityChangedListener(const sptr<IWindowPidVisibilityChangedListener> & listener)1082 WMError WindowManager::RegisterWindowPidVisibilityChangedListener(
1083 const sptr<IWindowPidVisibilityChangedListener>& listener)
1084 {
1085 if (listener == nullptr) {
1086 TLOGE(WmsLogTag::WMS_LIFE, "listener could not be null");
1087 return WMError::WM_ERROR_NULLPTR;
1088 }
1089 WMError ret = WMError::WM_OK;
1090 {
1091 std::unique_lock<std::shared_mutex> lock(pImpl_->visibilityListenerAgentListenerMutex_);
1092 if (pImpl_->windowPidVisibilityListenerAgent_ == nullptr) {
1093 pImpl_->windowPidVisibilityListenerAgent_ = sptr<WindowManagerAgent>::MakeSptr();
1094 }
1095 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1096 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY,
1097 pImpl_->windowPidVisibilityListenerAgent_);
1098 if (ret != WMError::WM_OK) {
1099 TLOGE(WmsLogTag::WMS_LIFE, "RegisterWindowManagerAgent failed!");
1100 pImpl_->windowPidVisibilityListenerAgent_ = nullptr;
1101 }
1102 }
1103 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1104 if (ret == WMError::WM_OK) {
1105 auto iter = std::find(pImpl_->windowPidVisibilityListeners_.begin(),
1106 pImpl_->windowPidVisibilityListeners_.end(), listener);
1107 if (iter != pImpl_->windowPidVisibilityListeners_.end()) {
1108 WLOGI("Listener is already registered.");
1109 return WMError::WM_OK;
1110 }
1111 pImpl_->windowPidVisibilityListeners_.emplace_back(listener);
1112 }
1113 return ret;
1114 }
1115
UnregisterWindowPidVisibilityChangedListener(const sptr<IWindowPidVisibilityChangedListener> & listener)1116 WMError WindowManager::UnregisterWindowPidVisibilityChangedListener(
1117 const sptr<IWindowPidVisibilityChangedListener>& listener)
1118 {
1119 if (listener == nullptr) {
1120 TLOGE(WmsLogTag::WMS_LIFE, "listener could not be null");
1121 return WMError::WM_ERROR_NULLPTR;
1122 }
1123 bool isListenEmpty = true;
1124 {
1125 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1126 auto iter = std::find(pImpl_->windowPidVisibilityListeners_.begin(),
1127 pImpl_->windowPidVisibilityListeners_.end(), listener);
1128 if (iter == pImpl_->windowPidVisibilityListeners_.end()) {
1129 TLOGE(WmsLogTag::WMS_LIFE, "could not find this listener");
1130 return WMError::WM_OK;
1131 }
1132 pImpl_->windowPidVisibilityListeners_.erase(iter);
1133 isListenEmpty = pImpl_->windowPidVisibilityListeners_.empty();
1134 }
1135 WMError ret = WMError::WM_OK;
1136 if (!isListenEmpty) {
1137 return ret;
1138 }
1139 std::unique_lock<std::shared_mutex> lock(pImpl_->visibilityListenerAgentListenerMutex_);
1140 if (isListenEmpty && pImpl_->windowPidVisibilityListenerAgent_ != nullptr) {
1141 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1142 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_PID_VISIBILITY,
1143 pImpl_->windowPidVisibilityListenerAgent_);
1144 if (ret == WMError::WM_OK) {
1145 pImpl_->windowPidVisibilityListenerAgent_ = nullptr;
1146 }
1147 }
1148 return ret;
1149 }
1150
NotifyDisplayInfoChange(const sptr<IRemoteObject> & token,DisplayId displayId,float density,DisplayOrientation orientation)1151 WMError WindowManager::NotifyDisplayInfoChange(const sptr<IRemoteObject>& token, DisplayId displayId,
1152 float density, DisplayOrientation orientation)
1153 {
1154 TLOGD(WmsLogTag::DMS, "notify display info change, displayid=%{public}" PRIu64 ", density=%{public}f, "
1155 "orientation=%{public}d", displayId, density, orientation);
1156 if (token == nullptr) {
1157 TLOGE(WmsLogTag::DMS, "notify display info change failed, token is nullptr");
1158 return WMError::WM_ERROR_INVALID_PARAM;
1159 }
1160 pImpl_->NotifyDisplayInfoChanged(token, displayId, density, orientation);
1161 return WMError::WM_OK;
1162 }
1163
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)1164 void WindowManager::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
1165 {
1166 SingletonContainer::Get<WindowAdapter>().GetFocusWindowInfo(focusInfo, displayId);
1167 }
1168
OnWMSConnectionChanged(int32_t userId,int32_t screenId,bool isConnected) const1169 void WindowManager::OnWMSConnectionChanged(int32_t userId, int32_t screenId, bool isConnected) const
1170 {
1171 if (isConnected) {
1172 pImpl_->NotifyWMSConnected(userId, screenId);
1173 } else {
1174 pImpl_->NotifyWMSDisconnected(userId, screenId);
1175 }
1176 }
1177
UpdateFocusChangeInfo(const sptr<FocusChangeInfo> & focusChangeInfo,bool focused) const1178 void WindowManager::UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const
1179 {
1180 if (focusChangeInfo == nullptr) {
1181 WLOGFE("focusChangeInfo is nullptr.");
1182 return;
1183 }
1184 TLOGD(WmsLogTag::WMS_FOCUS, "window focus change: %{public}d, id: %{public}u", focused, focusChangeInfo->windowId_);
1185 if (focused) {
1186 pImpl_->NotifyFocused(focusChangeInfo);
1187 } else {
1188 pImpl_->NotifyUnfocused(focusChangeInfo);
1189 }
1190 }
1191
UpdateWindowModeTypeInfo(WindowModeType type) const1192 void WindowManager::UpdateWindowModeTypeInfo(WindowModeType type) const
1193 {
1194 pImpl_->NotifyWindowModeChange(type);
1195 }
1196
1197
GetWindowModeType(WindowModeType & windowModeType) const1198 WMError WindowManager::GetWindowModeType(WindowModeType& windowModeType) const
1199 {
1200 WMError ret = SingletonContainer::Get<WindowAdapter>().GetWindowModeType(windowModeType);
1201 if (ret != WMError::WM_OK) {
1202 WLOGFE("get window mode type failed");
1203 }
1204 return ret;
1205 }
1206
UpdateSystemBarRegionTints(DisplayId displayId,const SystemBarRegionTints & tints) const1207 void WindowManager::UpdateSystemBarRegionTints(DisplayId displayId,
1208 const SystemBarRegionTints& tints) const
1209 {
1210 pImpl_->NotifySystemBarChanged(displayId, tints);
1211 }
1212
NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type) const1213 void WindowManager::NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
1214 WindowUpdateType type) const
1215 {
1216 pImpl_->NotifyAccessibilityWindowInfo(infos, type);
1217 }
1218
UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfos) const1219 void WindowManager::UpdateWindowVisibilityInfo(
1220 const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const
1221 {
1222 pImpl_->NotifyWindowVisibilityInfoChanged(windowVisibilityInfos);
1223 pImpl_->NotifyWindowVisibilityStateChanged(windowVisibilityInfos);
1224 }
1225
UpdateWindowDrawingContentInfo(const std::vector<sptr<WindowDrawingContentInfo>> & windowDrawingContentInfos) const1226 void WindowManager::UpdateWindowDrawingContentInfo(
1227 const std::vector<sptr<WindowDrawingContentInfo>>& windowDrawingContentInfos) const
1228 {
1229 pImpl_->NotifyWindowDrawingContentInfoChanged(windowDrawingContentInfos);
1230 }
1231
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos) const1232 WMError WindowManager::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const
1233 {
1234 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAccessibilityWindowInfo(infos);
1235 if (ret != WMError::WM_OK) {
1236 WLOGFE("get window info failed");
1237 }
1238 return ret;
1239 }
1240
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos) const1241 WMError WindowManager::GetUnreliableWindowInfo(int32_t windowId,
1242 std::vector<sptr<UnreliableWindowInfo>>& infos) const
1243 {
1244 WMError ret = SingletonContainer::Get<WindowAdapter>().GetUnreliableWindowInfo(windowId, infos);
1245 if (ret != WMError::WM_OK) {
1246 TLOGE(WmsLogTag::DEFAULT, "get unreliable window info failed");
1247 }
1248 return ret;
1249 }
1250
ListWindowInfo(const WindowInfoOption & windowInfoOption,std::vector<sptr<WindowInfo>> & infos) const1251 WMError WindowManager::ListWindowInfo(const WindowInfoOption& windowInfoOption,
1252 std::vector<sptr<WindowInfo>>& infos) const
1253 {
1254 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "windowInfoOption: %{public}u %{public}u %{public}" PRIu64" %{public}d",
1255 static_cast<WindowInfoFilterOptionDataType>(windowInfoOption.windowInfoFilterOption),
1256 static_cast<WindowInfoTypeOptionDataType>(windowInfoOption.windowInfoTypeOption),
1257 windowInfoOption.displayId, windowInfoOption.windowId);
1258 WMError ret = SingletonContainer::Get<WindowAdapter>().ListWindowInfo(windowInfoOption, infos);
1259 if (ret != WMError::WM_OK) {
1260 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed");
1261 }
1262 return ret;
1263 }
1264
GetAllWindowLayoutInfo(DisplayId displayId,std::vector<sptr<WindowLayoutInfo>> & infos) const1265 WMError WindowManager::GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos) const
1266 {
1267 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAllWindowLayoutInfo(displayId, infos);
1268 if (ret != WMError::WM_OK) {
1269 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed");
1270 }
1271 return ret;
1272 }
1273
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos) const1274 WMError WindowManager::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const
1275 {
1276 WMError ret = SingletonContainer::Get<WindowAdapter>().GetVisibilityWindowInfo(infos);
1277 if (ret != WMError::WM_OK) {
1278 WLOGFE("get window visibility info failed");
1279 }
1280 return ret;
1281 }
1282
DumpSessionAll(std::vector<std::string> & infos)1283 WMError WindowManager::DumpSessionAll(std::vector<std::string>& infos)
1284 {
1285 WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionAll(infos);
1286 if (ret != WMError::WM_OK) {
1287 WLOGFE("dump session all failed");
1288 }
1289 return ret;
1290 }
1291
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)1292 WMError WindowManager::DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos)
1293 {
1294 WMError ret = SingletonContainer::Get<WindowAdapter>().DumpSessionWithId(persistentId, infos);
1295 if (ret != WMError::WM_OK) {
1296 WLOGFE("dump session with id failed");
1297 }
1298 return ret;
1299 }
1300
GetUIContentRemoteObj(int32_t windowId,sptr<IRemoteObject> & uiContentRemoteObj)1301 WMError WindowManager::GetUIContentRemoteObj(int32_t windowId, sptr<IRemoteObject>& uiContentRemoteObj)
1302 {
1303 WMError ret = SingletonContainer::Get<WindowAdapter>().GetUIContentRemoteObj(windowId, uiContentRemoteObj);
1304 if (ret != WMError::WM_OK) {
1305 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to get UIContentRemoteObj. PersistentId=%{public}d; ret=%{public}u",
1306 windowId, static_cast<uint32_t>(ret));
1307 }
1308 return ret;
1309 }
1310
SetGestureNavigationEnabled(bool enable) const1311 WMError WindowManager::SetGestureNavigationEnabled(bool enable) const
1312 {
1313 WMError ret = SingletonContainer::Get<WindowAdapter>().SetGestureNavigationEnabled(enable);
1314 if (ret != WMError::WM_OK) {
1315 WLOGFE("set gesture navigation enabled failed");
1316 }
1317 return ret;
1318 }
1319
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)1320 WMError WindowManager::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
1321 {
1322 WMError ret = SingletonContainer::Get<WindowAdapter>().NotifyWindowExtensionVisibilityChange(pid, uid, visible);
1323 if (ret != WMError::WM_OK) {
1324 WLOGFE("notify WindowExtension visibility change failed");
1325 }
1326 return ret;
1327 }
1328
UpdateCameraFloatWindowStatus(uint32_t accessTokenId,bool isShowing) const1329 void WindowManager::UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const
1330 {
1331 pImpl_->UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
1332 }
1333
NotifyWaterMarkFlagChangedResult(bool showWaterMark) const1334 void WindowManager::NotifyWaterMarkFlagChangedResult(bool showWaterMark) const
1335 {
1336 pImpl_->NotifyWaterMarkFlagChangedResult(showWaterMark);
1337 }
1338
NotifyGestureNavigationEnabledResult(bool enable) const1339 void WindowManager::NotifyGestureNavigationEnabledResult(bool enable) const
1340 {
1341 pImpl_->NotifyGestureNavigationEnabledResult(enable);
1342 }
1343
NotifyWindowPidVisibilityChanged(const sptr<WindowPidVisibilityInfo> & info) const1344 void WindowManager::NotifyWindowPidVisibilityChanged(const sptr<WindowPidVisibilityInfo>& info) const
1345 {
1346 pImpl_->NotifyWindowPidVisibilityChanged(info);
1347 }
1348
RaiseWindowToTop(int32_t persistentId)1349 WMError WindowManager::RaiseWindowToTop(int32_t persistentId)
1350 {
1351 WMError ret = SingletonContainer::Get<WindowAdapter>().RaiseWindowToTop(persistentId);
1352 if (ret != WMError::WM_OK) {
1353 WLOGFE("raise window to top failed");
1354 }
1355 return ret;
1356 }
1357
NotifyWindowStyleChange(WindowStyleType type)1358 WMError WindowManager::NotifyWindowStyleChange(WindowStyleType type)
1359 {
1360 pImpl_->NotifyWindowStyleChange(type);
1361 return WMError::WM_OK;
1362 }
1363
RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)1364 WMError WindowManager::RegisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
1365 {
1366 if (listener == nullptr) {
1367 WLOGFE("listener could not be null");
1368 return WMError::WM_ERROR_NULLPTR;
1369 }
1370 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1371 WMError ret = WMError::WM_OK;
1372 if (pImpl_->windowDrawingContentListenerAgent_ == nullptr) {
1373 pImpl_->windowDrawingContentListenerAgent_ = new WindowManagerAgent();
1374 }
1375 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1376 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
1377 pImpl_->windowDrawingContentListenerAgent_);
1378 if (ret != WMError::WM_OK) {
1379 WLOGFW("RegisterWindowManagerAgent failed!");
1380 pImpl_->windowDrawingContentListenerAgent_ = nullptr;
1381 } else {
1382 auto iter = std::find(pImpl_->windowDrawingContentListeners_.begin(),
1383 pImpl_->windowDrawingContentListeners_.end(), listener);
1384 if (iter != pImpl_->windowDrawingContentListeners_.end()) {
1385 WLOGFW("Listener is already registered.");
1386 return WMError::WM_OK;
1387 }
1388 pImpl_->windowDrawingContentListeners_.emplace_back(listener);
1389 }
1390 return ret;
1391 }
1392
UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener> & listener)1393 WMError WindowManager::UnregisterDrawingContentChangedListener(const sptr<IDrawingContentChangedListener>& listener)
1394 {
1395 if (listener == nullptr) {
1396 WLOGFE("listener could not be null");
1397 return WMError::WM_ERROR_NULLPTR;
1398 }
1399 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1400 pImpl_->windowDrawingContentListeners_.erase(std::remove_if(pImpl_->windowDrawingContentListeners_.begin(),
1401 pImpl_->windowDrawingContentListeners_.end(),
1402 [listener](sptr<IDrawingContentChangedListener> registeredListener) { return registeredListener == listener; }),
1403 pImpl_->windowDrawingContentListeners_.end());
1404
1405 WMError ret = WMError::WM_OK;
1406 if (pImpl_->windowDrawingContentListeners_.empty() && pImpl_->windowDrawingContentListenerAgent_ != nullptr) {
1407 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1408 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_DRAWING_STATE,
1409 pImpl_->windowDrawingContentListenerAgent_);
1410 if (ret == WMError::WM_OK) {
1411 pImpl_->windowDrawingContentListenerAgent_ = nullptr;
1412 }
1413 }
1414 return ret;
1415 }
1416
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)1417 WMError WindowManager::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
1418 {
1419 WMError ret = SingletonContainer::Get<WindowAdapter>().ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1420 if (ret != WMError::WM_OK) {
1421 WLOGFE("shift application window focus failed");
1422 }
1423 return ret;
1424 }
1425
RegisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener> & listener)1426 WMError WindowManager::RegisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener>& listener)
1427 {
1428 if (listener == nullptr) {
1429 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1430 return WMError::WM_ERROR_NULLPTR;
1431 }
1432 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1433 WMError ret = WMError::WM_OK;
1434 if (pImpl_->visibleWindowNumChangedListenerAgent_ == nullptr) {
1435 pImpl_->visibleWindowNumChangedListenerAgent_ = new WindowManagerAgent();
1436 }
1437 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1438 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM,
1439 pImpl_->visibleWindowNumChangedListenerAgent_);
1440 if (ret != WMError::WM_OK) {
1441 TLOGE(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
1442 pImpl_->visibleWindowNumChangedListenerAgent_ = nullptr;
1443 } else {
1444 auto iter = std::find(pImpl_->visibleWindowNumChangedListeners_.begin(),
1445 pImpl_->visibleWindowNumChangedListeners_.end(), listener);
1446 if (iter != pImpl_->visibleWindowNumChangedListeners_.end()) {
1447 TLOGE(WmsLogTag::WMS_MAIN, "Listener is already registered.");
1448 return WMError::WM_OK;
1449 }
1450 pImpl_->visibleWindowNumChangedListeners_.emplace_back(listener);
1451 }
1452 return ret;
1453 }
1454
GetSnapshotByWindowId(int32_t windowId,std::shared_ptr<Media::PixelMap> & pixelMap)1455 WMError WindowManager::GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap)
1456 {
1457 return SingletonContainer::Get<WindowAdapter>().GetSnapshotByWindowId(windowId, pixelMap);
1458 }
1459
UnregisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener> & listener)1460 WMError WindowManager::UnregisterVisibleWindowNumChangedListener(const sptr<IVisibleWindowNumChangedListener>& listener)
1461 {
1462 if (listener == nullptr) {
1463 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1464 return WMError::WM_ERROR_NULLPTR;
1465 }
1466 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1467 auto iter = std::find(pImpl_->visibleWindowNumChangedListeners_.begin(),
1468 pImpl_->visibleWindowNumChangedListeners_.end(), listener);
1469 if (iter == pImpl_->visibleWindowNumChangedListeners_.end()) {
1470 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
1471 return WMError::WM_OK;
1472 }
1473
1474 WMError ret = WMError::WM_OK;
1475 if (pImpl_->visibleWindowNumChangedListeners_.empty() && pImpl_->visibleWindowNumChangedListenerAgent_ != nullptr) {
1476 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1477 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_VISIBLE_WINDOW_NUM,
1478 pImpl_->visibleWindowNumChangedListenerAgent_);
1479 if (ret == WMError::WM_OK) {
1480 pImpl_->visibleWindowNumChangedListenerAgent_ = nullptr;
1481 }
1482 }
1483 return ret;
1484 }
1485
UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo> & visibleWindowNumInfo)1486 void WindowManager::UpdateVisibleWindowNum(const std::vector<VisibleWindowNumInfo>& visibleWindowNumInfo)
1487 {
1488 pImpl_->NotifyVisibleWindowNumChanged(visibleWindowNumInfo);
1489 }
1490
1491
RegisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener> & listener)1492 WMError WindowManager::RegisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener>& listener)
1493 {
1494 TLOGI(WmsLogTag::WMS_MAIN, "start register");
1495 if (listener == nullptr) {
1496 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1497 return WMError::WM_ERROR_NULLPTR;
1498 }
1499 {
1500 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1501 if (pImpl_->windowStyleListenerAgent_ == nullptr) {
1502 pImpl_->windowStyleListenerAgent_ = new WindowManagerAgent();
1503 }
1504 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1505 if (iter != pImpl_->windowStyleListeners_.end()) {
1506 TLOGW(WmsLogTag::WMS_MAIN, "Listener is already registered.");
1507 return WMError::WM_OK;
1508 }
1509 pImpl_->windowStyleListeners_.push_back(listener);
1510 }
1511 WMError ret = WMError::WM_OK;
1512 ret = SingletonContainer::Get<WindowAdapter>().RegisterWindowManagerAgent(
1513 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_);
1514 if (ret != WMError::WM_OK) {
1515 TLOGW(WmsLogTag::WMS_MAIN, "RegisterWindowManagerAgent failed!");
1516 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1517 pImpl_->windowStyleListenerAgent_ = nullptr;
1518 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1519 if (iter != pImpl_->windowStyleListeners_.end()) {
1520 pImpl_->windowStyleListeners_.erase(iter);
1521 }
1522 }
1523 return ret;
1524 }
1525
UnregisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener> & listener)1526 WMError WindowManager::UnregisterWindowStyleChangedListener(const sptr<IWindowStyleChangedListener>& listener)
1527 {
1528 TLOGI(WmsLogTag::WMS_MAIN, "start unregister");
1529 if (listener == nullptr) {
1530 TLOGE(WmsLogTag::WMS_MAIN, "listener could not be null");
1531 return WMError::WM_ERROR_NULLPTR;
1532 }
1533 {
1534 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1535 auto iter = std::find(pImpl_->windowStyleListeners_.begin(), pImpl_->windowStyleListeners_.end(), listener);
1536 if (iter == pImpl_->windowStyleListeners_.end()) {
1537 TLOGE(WmsLogTag::WMS_MAIN, "could not find this listener");
1538 return WMError::WM_OK;
1539 }
1540 pImpl_->windowStyleListeners_.erase(iter);
1541 }
1542 WMError ret = WMError::WM_OK;
1543 if (pImpl_->windowStyleListeners_.empty() && pImpl_->windowStyleListenerAgent_ != nullptr) {
1544 ret = SingletonContainer::Get<WindowAdapter>().UnregisterWindowManagerAgent(
1545 WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_WINDOW_STYLE, pImpl_->windowStyleListenerAgent_);
1546 if (ret == WMError::WM_OK) {
1547 std::unique_lock<std::shared_mutex> lock(pImpl_->listenerMutex_);
1548 pImpl_->windowStyleListenerAgent_ = nullptr;
1549 }
1550 }
1551 return ret;
1552 }
1553
GetWindowStyleType()1554 WindowStyleType WindowManager::GetWindowStyleType()
1555 {
1556 WindowStyleType styleType;
1557 if (SingletonContainer::Get<WindowAdapter>().GetWindowStyleType(styleType) == WMError::WM_OK) {
1558 return styleType;
1559 }
1560 return styleType;
1561 }
1562
SkipSnapshotForAppProcess(int32_t pid,bool skip)1563 WMError WindowManager::SkipSnapshotForAppProcess(int32_t pid, bool skip)
1564 {
1565 WMError ret = SingletonContainer::Get<WindowAdapter>().SkipSnapshotForAppProcess(pid, skip);
1566 if (ret != WMError::WM_OK) {
1567 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "skip failed");
1568 }
1569 return ret;
1570 }
1571
SetProcessWatermark(int32_t pid,const std::string & watermarkName,bool isEnabled)1572 WMError WindowManager::SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled)
1573 {
1574 WMError ret = SingletonContainer::Get<WindowAdapter>().SetProcessWatermark(pid, watermarkName, isEnabled);
1575 if (ret != WMError::WM_OK) {
1576 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed");
1577 }
1578 return ret;
1579 }
1580
GetWindowIdsByCoordinate(DisplayId displayId,int32_t windowNumber,int32_t x,int32_t y,std::vector<int32_t> & windowIds) const1581 WMError WindowManager::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
1582 int32_t x, int32_t y, std::vector<int32_t>& windowIds) const
1583 {
1584 WMError ret = SingletonContainer::Get<WindowAdapter>().GetWindowIdsByCoordinate(
1585 displayId, windowNumber, x, y, windowIds);
1586 if (ret != WMError::WM_OK) {
1587 TLOGE(WmsLogTag::DEFAULT, "get windowIds by coordinate failed");
1588 }
1589 return ret;
1590 }
1591
UpdateScreenLockStatusForApp(const std::string & bundleName,bool isRelease)1592 WMError WindowManager::UpdateScreenLockStatusForApp(const std::string& bundleName, bool isRelease)
1593 {
1594 WMError ret = SingletonContainer::Get<WindowAdapter>().UpdateScreenLockStatusForApp(bundleName, isRelease);
1595 if (ret != WMError::WM_OK) {
1596 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "update screen lock status failed");
1597 }
1598 return ret;
1599 }
1600
GetDisplayIdByWindowId(const std::vector<uint64_t> & windowIds,std::unordered_map<uint64_t,DisplayId> & windowDisplayIdMap)1601 WMError WindowManager::GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
1602 std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap)
1603 {
1604 WMError ret = SingletonContainer::Get<WindowAdapter>().GetDisplayIdByWindowId(windowIds, windowDisplayIdMap);
1605 if (ret != WMError::WM_OK) {
1606 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "failed");
1607 }
1608 return ret;
1609 }
1610
SetGlobalDragResizeType(DragResizeType dragResizeType)1611 WMError WindowManager::SetGlobalDragResizeType(DragResizeType dragResizeType)
1612 {
1613 WMError ret = SingletonContainer::Get<WindowAdapter>().SetGlobalDragResizeType(dragResizeType);
1614 if (ret != WMError::WM_OK) {
1615 TLOGE(WmsLogTag::DEFAULT, "failed");
1616 }
1617 return ret;
1618 }
1619
GetGlobalDragResizeType(DragResizeType & dragResizeType)1620 WMError WindowManager::GetGlobalDragResizeType(DragResizeType& dragResizeType)
1621 {
1622 WMError ret = SingletonContainer::Get<WindowAdapter>().GetGlobalDragResizeType(dragResizeType);
1623 if (ret != WMError::WM_OK) {
1624 TLOGE(WmsLogTag::DEFAULT, "failed");
1625 }
1626 return ret;
1627 }
1628
SetAppDragResizeType(const std::string & bundleName,DragResizeType dragResizeType)1629 WMError WindowManager::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType)
1630 {
1631 WMError ret = SingletonContainer::Get<WindowAdapter>().SetAppDragResizeType(bundleName, dragResizeType);
1632 if (ret != WMError::WM_OK) {
1633 TLOGE(WmsLogTag::DEFAULT, "failed");
1634 }
1635 return ret;
1636 }
1637
GetAppDragResizeType(const std::string & bundleName,DragResizeType & dragResizeType)1638 WMError WindowManager::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType)
1639 {
1640 WMError ret = SingletonContainer::Get<WindowAdapter>().GetAppDragResizeType(bundleName, dragResizeType);
1641 if (ret != WMError::WM_OK) {
1642 TLOGE(WmsLogTag::DEFAULT, "failed");
1643 }
1644 return ret;
1645 }
1646
ShiftAppWindowPointerEvent(int32_t sourceWindowId,int32_t targetWindowId)1647 WMError WindowManager::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId)
1648 {
1649 WMError ret = SingletonContainer::Get<WindowAdapter>().ShiftAppWindowPointerEvent(
1650 sourceWindowId, targetWindowId);
1651 if (ret != WMError::WM_OK) {
1652 TLOGE(WmsLogTag::WMS_PC, "failed");
1653 }
1654 return ret;
1655 }
1656
RequestFocus(int32_t persistentId,bool isFocused,bool byForeground,WindowFocusChangeReason reason)1657 WMError WindowManager::RequestFocus(int32_t persistentId, bool isFocused,
1658 bool byForeground, WindowFocusChangeReason reason)
1659 {
1660 int32_t curReason = static_cast<int32_t>(reason);
1661 int32_t reasonStart = static_cast<int32_t>(FocusChangeReason::DEFAULT);
1662 int32_t reasonEnd = static_cast<int32_t>(FocusChangeReason::MAX);
1663 if (curReason < reasonStart || curReason > reasonEnd) {
1664 TLOGE(WmsLogTag::WMS_FOCUS, "could not find focus reason");
1665 return WMError::WM_ERROR_INVALID_PARAM;
1666 }
1667 WMError ret = SingletonContainer::Get<WindowAdapter>().RequestFocusStatusBySA(persistentId,
1668 isFocused, byForeground, static_cast<FocusChangeReason>(curReason));
1669 if (ret != WMError::WM_OK) {
1670 TLOGE(WmsLogTag::WMS_FOCUS, "failed");
1671 }
1672 return ret;
1673 }
1674
MinimizeByWindowId(const std::vector<int32_t> & windowIds)1675 WMError WindowManager::MinimizeByWindowId(const std::vector<int32_t>& windowIds)
1676 {
1677 WMError ret = SingletonContainer::Get<WindowAdapter>().MinimizeByWindowId(windowIds);
1678 if (ret != WMError::WM_OK) {
1679 TLOGE(WmsLogTag::WMS_LIFE, "failed");
1680 }
1681 return ret;
1682 }
1683
ProcessRegisterWindowInfoChangeCallback(WindowInfoKey observedInfo,const sptr<IWindowInfoChangedListener> & listener)1684 WMError WindowManager::ProcessRegisterWindowInfoChangeCallback(WindowInfoKey observedInfo,
1685 const sptr<IWindowInfoChangedListener>& listener)
1686 {
1687 switch (observedInfo) {
1688 case WindowInfoKey::VISIBILITY_STATE :
1689 return RegisterVisibilityStateChangedListener(listener);
1690 default:
1691 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Invalid observedInfo: %{public}d", static_cast<uint32_t>(observedInfo));
1692 return WMError::WM_ERROR_INVALID_PARAM;
1693 }
1694 }
1695
ProcessUnregisterWindowInfoChangeCallback(WindowInfoKey observedInfo,const sptr<IWindowInfoChangedListener> & listener)1696 WMError WindowManager::ProcessUnregisterWindowInfoChangeCallback(WindowInfoKey observedInfo,
1697 const sptr<IWindowInfoChangedListener>& listener)
1698 {
1699 switch (observedInfo) {
1700 case WindowInfoKey::VISIBILITY_STATE :
1701 return UnregisterVisibilityStateChangedListener(listener);
1702 default:
1703 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Invalid observedInfo: %{public}d", static_cast<uint32_t>(observedInfo));
1704 return WMError::WM_ERROR_INVALID_PARAM;
1705 }
1706 }
1707
RegisterWindowInfoChangeCallback(const std::unordered_set<WindowInfoKey> & observedInfo,const sptr<IWindowInfoChangedListener> & listener)1708 WMError WindowManager::RegisterWindowInfoChangeCallback(const std::unordered_set<WindowInfoKey>& observedInfo,
1709 const sptr<IWindowInfoChangedListener>& listener)
1710 {
1711 std::ostringstream observedInfoForLog;
1712 observedInfoForLog << "ObservedInfo: ";
1713 auto ret = WMError::WM_OK;
1714 for (const auto& info : observedInfo) {
1715 observedInfoForLog << static_cast<uint32_t>(info) << ", ";
1716 if (listener->GetInterestInfo().find(info) == listener->GetInterestInfo().end()) {
1717 listener->AddInterestInfo(info);
1718 }
1719 ret = ProcessRegisterWindowInfoChangeCallback(info, listener);
1720 if (ret != WMError::WM_OK) {
1721 observedInfoForLog << "failed";
1722 break;
1723 }
1724 }
1725 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "%{public}s", observedInfoForLog.str().c_str());
1726 return ret;
1727 }
1728
UnregisterWindowInfoChangeCallback(const std::unordered_set<WindowInfoKey> & observedInfo,const sptr<IWindowInfoChangedListener> & listener)1729 WMError WindowManager::UnregisterWindowInfoChangeCallback(const std::unordered_set<WindowInfoKey>& observedInfo,
1730 const sptr<IWindowInfoChangedListener>& listener)
1731 {
1732 std::ostringstream observedInfoForLog;
1733 observedInfoForLog << "ObservedInfo: ";
1734 auto ret = WMError::WM_OK;
1735 for (const auto& info : observedInfo) {
1736 observedInfoForLog << static_cast<uint32_t>(info) << ", ";
1737 if (listener->GetInterestInfo().find(info) == listener->GetInterestInfo().end()) {
1738 listener->AddInterestInfo(info);
1739 }
1740 ret = ProcessUnregisterWindowInfoChangeCallback(info, listener);
1741 if (ret != WMError::WM_OK) {
1742 observedInfoForLog << "failed";
1743 break;
1744 }
1745 }
1746 TLOGI(WmsLogTag::WMS_ATTRIBUTE, "%{public}s", observedInfoForLog.str().c_str());
1747 return ret;
1748 }
1749 } // namespace Rosen
1750 } // namespace OHOS
1751