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_adapter.h"
17 #include <iservice_registry.h>
18 #include <key_event.h>
19 #include <system_ability_definition.h>
20 #include <rs_window_animation_target.h>
21 #include "window_manager.h"
22 #include "window_manager_proxy.h"
23 #include "window_manager_hilog.h"
24 #include "wm_common.h"
25 #include "scene_board_judgement.h"
26 #include "session_manager.h"
27 #include "focus_change_info.h"
28 #include <unistd.h>
29 #include "window_session_impl.h"
30
31 namespace OHOS {
32 namespace Rosen {
33 namespace {
34 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAdapter"};
35 }
WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapter)36 WM_IMPLEMENT_SINGLE_INSTANCE(WindowAdapter)
37
38 #define INIT_PROXY_CHECK_RETURN(ret) \
39 do { \
40 if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { \
41 if (!InitSSMProxy()) { \
42 WLOGFE("InitSSMProxy failed!"); \
43 return ret; \
44 } \
45 } else { \
46 if (!InitWMSProxy()) { \
47 WLOGFE("InitWMSProxy failed!"); \
48 return ret; \
49 } \
50 } \
51 } while (false)
52
53 #define CHECK_PROXY_RETURN_ERROR_IF_NULL(proxy, ret) \
54 do { \
55 if ((proxy) == nullptr) { \
56 TLOGE(WmsLogTag::DEFAULT, "window manager proxy is nullptr"); \
57 return ret; \
58 } \
59 } while (false)
60
61 #define CHECK_PROXY_RETURN_IF_NULL(proxy) \
62 do { \
63 if ((proxy) == nullptr) { \
64 TLOGE(WmsLogTag::DEFAULT, "window manager proxy is nullptr"); \
65 return; \
66 } \
67 } while (false)
68
69 WMError WindowAdapter::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty,
70 std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId, const sptr<IRemoteObject>& token)
71 {
72 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
73
74 auto wmsProxy = GetWindowManagerServiceProxy();
75 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
76 return wmsProxy->CreateWindow(window, windowProperty, surfaceNode, windowId, token);
77 }
78
AddWindow(sptr<WindowProperty> & windowProperty)79 WMError WindowAdapter::AddWindow(sptr<WindowProperty>& windowProperty)
80 {
81 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
82
83 auto wmsProxy = GetWindowManagerServiceProxy();
84 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
85 return wmsProxy->AddWindow(windowProperty);
86 }
87
RemoveWindow(uint32_t windowId,bool isFromInnerkits)88 WMError WindowAdapter::RemoveWindow(uint32_t windowId, bool isFromInnerkits)
89 {
90 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
91
92 auto wmsProxy = GetWindowManagerServiceProxy();
93 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
94 return wmsProxy->RemoveWindow(windowId, isFromInnerkits);
95 }
96
DestroyWindow(uint32_t windowId)97 WMError WindowAdapter::DestroyWindow(uint32_t windowId)
98 {
99 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
100
101 auto wmsProxy = GetWindowManagerServiceProxy();
102 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
103 return wmsProxy->DestroyWindow(windowId);
104 }
105
SetParentWindow(int32_t subWindowId,int32_t newParentWindowId)106 WMError WindowAdapter::SetParentWindow(int32_t subWindowId, int32_t newParentWindowId)
107 {
108 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
109 auto wmsProxy = GetWindowManagerServiceProxy();
110 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
111 return wmsProxy->SetParentWindow(subWindowId, newParentWindowId);
112 }
113
RequestFocus(uint32_t windowId)114 WMError WindowAdapter::RequestFocus(uint32_t windowId)
115 {
116 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
117
118 auto wmsProxy = GetWindowManagerServiceProxy();
119 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
120 return wmsProxy->RequestFocus(windowId);
121 }
122
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)123 WMError WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type,
124 const sptr<IWindowManagerAgent>& windowManagerAgent)
125 {
126 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
127
128 auto wmsProxy = GetWindowManagerServiceProxy();
129 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
130
131 {
132 std::lock_guard<std::mutex> lock(mutex_);
133 if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
134 windowManagerAgentMap_[type] = std::set<sptr<IWindowManagerAgent>>();
135 }
136 windowManagerAgentMap_[type].insert(windowManagerAgent);
137 }
138
139 return wmsProxy->RegisterWindowManagerAgent(type, windowManagerAgent);
140 }
141
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)142 WMError WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type,
143 const sptr<IWindowManagerAgent>& windowManagerAgent)
144 {
145 TLOGD(WmsLogTag::DEFAULT, "called, type: %{public}d", type);
146 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
147
148 auto wmsProxy = GetWindowManagerServiceProxy();
149 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
150 auto ret = wmsProxy->UnregisterWindowManagerAgent(type, windowManagerAgent);
151
152 std::lock_guard<std::mutex> lock(mutex_);
153 if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
154 WLOGFW("WindowManagerAgentType=%{public}d not found", type);
155 return ret;
156 }
157
158 auto& agentSet = windowManagerAgentMap_[type];
159 auto agent = std::find(agentSet.begin(), agentSet.end(), windowManagerAgent);
160 if (agent == agentSet.end()) {
161 WLOGFW("Cannot find agent, type=%{public}d", type);
162 return ret;
163 }
164 agentSet.erase(agent);
165 TLOGD(WmsLogTag::DEFAULT, "success, type: %{public}d", type);
166
167 return ret;
168 }
169
RegisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey,uint32_t interestInfo,const sptr<IWindowManagerAgent> & windowManagerAgent)170 WMError WindowAdapter::RegisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey,
171 uint32_t interestInfo, const sptr<IWindowManagerAgent>& windowManagerAgent)
172 {
173 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
174
175 auto wmsProxy = GetWindowManagerServiceProxy();
176 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
177
178 {
179 std::lock_guard<std::mutex> lock(mutex_);
180 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PROPERTY;
181 if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
182 windowManagerAgentMap_[type] = std::set<sptr<IWindowManagerAgent>>();
183 }
184 windowManagerAgentMap_[type].insert(windowManagerAgent);
185 }
186
187 observedFlags_ |= static_cast<uint32_t>(windowInfoKey);
188 interestedFlags_ |= interestInfo;
189
190 return wmsProxy->RegisterWindowPropertyChangeAgent(windowInfoKey, interestInfo, windowManagerAgent);
191 }
192
UnregisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey,uint32_t interestInfo,const sptr<IWindowManagerAgent> & windowManagerAgent)193 WMError WindowAdapter::UnregisterWindowPropertyChangeAgent(WindowInfoKey windowInfoKey,
194 uint32_t interestInfo, const sptr<IWindowManagerAgent>& windowManagerAgent)
195 {
196 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
197
198 auto wmsProxy = GetWindowManagerServiceProxy();
199 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
200 auto ret = wmsProxy->UnregisterWindowPropertyChangeAgent(windowInfoKey, interestInfo, windowManagerAgent);
201
202 observedFlags_ &= ~(static_cast<uint32_t>(windowInfoKey));
203 interestedFlags_ &= ~interestInfo;
204
205 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_PROPERTY;
206 std::lock_guard<std::mutex> lock(mutex_);
207 if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
208 TLOGW(WmsLogTag::WMS_ATTRIBUTE, "WINDOW_MANAGER_AGENT_TYPE_PROPERTY not found");
209 return ret;
210 }
211
212 auto& agentSet = windowManagerAgentMap_[type];
213 auto agent = std::find(agentSet.begin(), agentSet.end(), windowManagerAgent);
214 if (agent == agentSet.end()) {
215 TLOGW(WmsLogTag::WMS_ATTRIBUTE, "Cannot find WINDOW_MANAGER_AGENT_TYPE_PROPERTY");
216 return ret;
217 }
218 agentSet.erase(agent);
219
220 return ret;
221 }
222
CheckWindowId(int32_t windowId,int32_t & pid)223 WMError WindowAdapter::CheckWindowId(int32_t windowId, int32_t& pid)
224 {
225 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
226
227 auto wmsProxy = GetWindowManagerServiceProxy();
228 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
229 return wmsProxy->CheckWindowId(windowId, pid);
230 }
231
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)232 WMError WindowAdapter::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
233 {
234 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
235
236 auto wmsProxy = GetWindowManagerServiceProxy();
237 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
238 return wmsProxy->GetAccessibilityWindowInfo(infos);
239 }
240
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)241 WMError WindowAdapter::GetUnreliableWindowInfo(int32_t windowId,
242 std::vector<sptr<UnreliableWindowInfo>>& infos)
243 {
244 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
245
246 auto wmsProxy = GetWindowManagerServiceProxy();
247 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
248 return wmsProxy->GetUnreliableWindowInfo(windowId, infos);
249 }
250
ListWindowInfo(const WindowInfoOption & windowInfoOption,std::vector<sptr<WindowInfo>> & infos)251 WMError WindowAdapter::ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector<sptr<WindowInfo>>& infos)
252 {
253 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
254 auto wmsProxy = GetWindowManagerServiceProxy();
255 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
256 return wmsProxy->ListWindowInfo(windowInfoOption, infos);
257 }
258
GetAllWindowLayoutInfo(DisplayId displayId,std::vector<sptr<WindowLayoutInfo>> & infos)259 WMError WindowAdapter::GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos)
260 {
261 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
262 auto wmsProxy = GetWindowManagerServiceProxy();
263 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
264 return wmsProxy->GetAllWindowLayoutInfo(displayId, infos);
265 }
266
GetGlobalWindowMode(DisplayId displayId,GlobalWindowMode & globalWinMode)267 WMError WindowAdapter::GetGlobalWindowMode(DisplayId displayId, GlobalWindowMode& globalWinMode)
268 {
269 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
270 auto wmsProxy = GetWindowManagerServiceProxy();
271 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
272 return wmsProxy->GetGlobalWindowMode(displayId, globalWinMode);
273 }
274
GetTopNavDestinationName(int32_t windowId,std::string & topNavDestName)275 WMError WindowAdapter::GetTopNavDestinationName(int32_t windowId, std::string& topNavDestName)
276 {
277 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
278 auto wmsProxy = GetWindowManagerServiceProxy();
279 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
280 return wmsProxy->GetTopNavDestinationName(windowId, topNavDestName);
281 }
282
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)283 WMError WindowAdapter::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
284 {
285 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
286
287 auto wmsProxy = GetWindowManagerServiceProxy();
288 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
289 return wmsProxy->GetVisibilityWindowInfo(infos);
290 }
291
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)292 WMError WindowAdapter::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
293 {
294 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
295
296 auto wmsProxy = GetWindowManagerServiceProxy();
297 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
298 return wmsProxy->SetWindowAnimationController(controller);
299 }
300
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType type,AvoidArea & avoidArea,const Rect & rect)301 WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidArea, const Rect& rect)
302 {
303 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
304
305 auto wmsProxy = GetWindowManagerServiceProxy();
306 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
307 avoidArea = wmsProxy->GetAvoidAreaByType(windowId, type, rect);
308 return WMError::WM_OK;
309 }
310
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)311 void WindowAdapter::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
312 sptr<MoveDragProperty>& moveDragProperty)
313 {
314 INIT_PROXY_CHECK_RETURN();
315
316 auto wmsProxy = GetWindowManagerServiceProxy();
317 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
318 wmsProxy->NotifyServerReadyToMoveOrDrag(windowId, windowProperty, moveDragProperty);
319 }
320
ProcessPointDown(uint32_t windowId,bool isPointDown)321 void WindowAdapter::ProcessPointDown(uint32_t windowId, bool isPointDown)
322 {
323 INIT_PROXY_CHECK_RETURN();
324
325 auto wmsProxy = GetWindowManagerServiceProxy();
326 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
327 wmsProxy->ProcessPointDown(windowId, isPointDown);
328 }
329
ProcessPointUp(uint32_t windowId)330 void WindowAdapter::ProcessPointUp(uint32_t windowId)
331 {
332 INIT_PROXY_CHECK_RETURN();
333
334 auto wmsProxy = GetWindowManagerServiceProxy();
335 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
336 wmsProxy->ProcessPointUp(windowId);
337 }
338
MinimizeAllAppWindows(DisplayId displayId)339 WMError WindowAdapter::MinimizeAllAppWindows(DisplayId displayId)
340 {
341 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
342
343 auto wmsProxy = GetWindowManagerServiceProxy();
344 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
345 return wmsProxy->MinimizeAllAppWindows(displayId);
346 }
347
ToggleShownStateForAllAppWindows()348 WMError WindowAdapter::ToggleShownStateForAllAppWindows()
349 {
350 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
351
352 auto wmsProxy = GetWindowManagerServiceProxy();
353 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
354 return wmsProxy->ToggleShownStateForAllAppWindows();
355 }
356
GetSystemConfig(SystemConfig & systemConfig)357 WMError WindowAdapter::GetSystemConfig(SystemConfig& systemConfig)
358 {
359 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
360
361 auto wmsProxy = GetWindowManagerServiceProxy();
362 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
363 return wmsProxy->GetSystemConfig(systemConfig);
364 }
365
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)366 WMError WindowAdapter::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
367 {
368 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
369
370 auto wmsProxy = GetWindowManagerServiceProxy();
371 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
372 return wmsProxy->GetModeChangeHotZones(displayId, hotZones);
373 }
374
InitWMSProxy()375 bool WindowAdapter::InitWMSProxy()
376 {
377 std::lock_guard<std::mutex> lock(mutex_);
378 if (!isProxyValid_) {
379 sptr<ISystemAbilityManager> systemAbilityManager =
380 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
381 if (!systemAbilityManager) {
382 WLOGFE("Failed to get system ability mgr.");
383 return false;
384 }
385
386 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID);
387 if (!remoteObject) {
388 WLOGFE("Failed to get window manager service.");
389 return false;
390 }
391
392 windowManagerServiceProxy_ = iface_cast<IWindowManager>(remoteObject);
393 if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
394 WLOGFE("Failed to get system window manager services");
395 return false;
396 }
397
398 wmsDeath_ = new WMSDeathRecipient();
399 if (!wmsDeath_) {
400 WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
401 return false;
402 }
403 if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) {
404 WLOGFE("Failed to add death recipient");
405 return false;
406 }
407 isProxyValid_ = true;
408 }
409 return true;
410 }
411
RegisterSessionRecoverCallbackFunc(int32_t persistentId,const SessionRecoverCallbackFunc & callbackFunc)412 void WindowAdapter::RegisterSessionRecoverCallbackFunc(
413 int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc)
414 {
415 TLOGI(WmsLogTag::WMS_RECOVER, "persistentId=%{public}d", persistentId);
416 std::lock_guard<std::mutex> lock(mutex_);
417 sessionRecoverCallbackFuncMap_[persistentId] = callbackFunc;
418 }
419
RegisterUIEffectRecoverCallbackFunc(int32_t id,const UIEffectRecoverCallbackFunc & callbackFunc)420 void WindowAdapter::RegisterUIEffectRecoverCallbackFunc(int32_t id,
421 const UIEffectRecoverCallbackFunc& callbackFunc)
422 {
423 std::lock_guard<std::mutex> lock(effectMutex_);
424 uiEffectRecoverCallbackFuncMap_[id] = callbackFunc;
425 }
UnregisterUIEffectRecoverCallbackFunc(int32_t id)426 void WindowAdapter::UnregisterUIEffectRecoverCallbackFunc(int32_t id)
427 {
428 std::lock_guard<std::mutex> lock(effectMutex_);
429 uiEffectRecoverCallbackFuncMap_.erase(id);
430 }
431
GetSnapshotByWindowId(int32_t windowId,std::shared_ptr<Media::PixelMap> & pixelMap)432 WMError WindowAdapter::GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap)
433 {
434 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_IPC_FAILED);
435
436 auto wmsProxy = GetWindowManagerServiceProxy();
437 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_IPC_FAILED);
438 return wmsProxy->GetSnapshotByWindowId(windowId, pixelMap);
439 }
440
UnregisterSessionRecoverCallbackFunc(int32_t persistentId)441 void WindowAdapter::UnregisterSessionRecoverCallbackFunc(int32_t persistentId)
442 {
443 std::lock_guard<std::mutex> lock(mutex_);
444 auto it = sessionRecoverCallbackFuncMap_.find(persistentId);
445 if (it != sessionRecoverCallbackFuncMap_.end()) {
446 sessionRecoverCallbackFuncMap_.erase(it);
447 }
448 }
449
RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc & callbackFunc)450 WMError WindowAdapter::RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc)
451 {
452 TLOGI(WmsLogTag::WMS_MULTI_USER, "RegisterWMSConnectionChangedListener in");
453 return SessionManager::GetInstance().RegisterWMSConnectionChangedListener(callbackFunc);
454 }
455
UnregisterWMSConnectionChangedListener()456 WMError WindowAdapter::UnregisterWMSConnectionChangedListener()
457 {
458 TLOGI(WmsLogTag::WMS_MULTI_USER, "unregister wms connection changed listener");
459 return SessionManager::GetInstance().UnregisterWMSConnectionChangedListener();
460 }
461
WindowManagerAndSessionRecover()462 void WindowAdapter::WindowManagerAndSessionRecover()
463 {
464 ClearWindowAdapter();
465 if (!InitSSMProxy()) {
466 TLOGE(WmsLogTag::WMS_RECOVER, "InitSSMProxy failed");
467 return;
468 }
469
470 ReregisterWindowManagerAgent();
471 RecoverWindowPropertyChangeFlag();
472
473 std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap;
474 {
475 std::lock_guard<std::mutex> lock(mutex_);
476 sessionRecoverCallbackFuncMap = sessionRecoverCallbackFuncMap_;
477 }
478 for (const auto& it : sessionRecoverCallbackFuncMap) {
479 TLOGD(WmsLogTag::WMS_RECOVER, "Session recover callback, persistentId=%{public}" PRId32, it.first);
480 auto ret = it.second();
481 if (ret != WMError::WM_OK) {
482 TLOGE(WmsLogTag::WMS_RECOVER, "Session recover callback, persistentId=%{public}" PRId32 " is error",
483 it.first);
484 }
485 }
486 std::map<int32_t, UIEffectRecoverCallbackFunc> uiEffectRecoverCallbackFuncMap;
487 {
488 std::lock_guard<std::mutex> lock(effectMutex_);
489 uiEffectRecoverCallbackFuncMap = uiEffectRecoverCallbackFuncMap_;
490 }
491 for (const auto& it : uiEffectRecoverCallbackFuncMap) {
492 TLOGD(WmsLogTag::WMS_RECOVER, "ui effect recover callback, id: %{public}d", it.first);
493 auto ret = it.second();
494 if (ret != WMError::WM_OK) {
495 TLOGE(WmsLogTag::WMS_RECOVER, "ui effect create failed, id: %{public}d, reason %{public}d", it.first, ret);
496 }
497 }
498 }
499
RecoverWindowPropertyChangeFlag()500 WMError WindowAdapter::RecoverWindowPropertyChangeFlag()
501 {
502 std::lock_guard<std::mutex> lock(mutex_);
503 if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
504 TLOGE(WmsLogTag::WMS_RECOVER, "proxy is null");
505 return WMError::WM_ERROR_NULLPTR;
506 }
507 auto ret = windowManagerServiceProxy_->RecoverWindowPropertyChangeFlag(observedFlags_, interestedFlags_);
508 if (ret != WMError::WM_OK) {
509 TLOGE(WmsLogTag::WMS_RECOVER, "failed, ret=%{public}d", static_cast<int32_t>(ret));
510 }
511 return ret;
512 }
513
ReregisterWindowManagerAgent()514 void WindowAdapter::ReregisterWindowManagerAgent()
515 {
516 std::lock_guard<std::mutex> lock(mutex_);
517 if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
518 TLOGE(WmsLogTag::WMS_RECOVER, "proxy is null");
519 return;
520 }
521 for (const auto& it : windowManagerAgentMap_) {
522 TLOGI(WmsLogTag::WMS_RECOVER, "Window manager agent type=%{public}" PRIu32 ", size=%{public}" PRIu64,
523 it.first, static_cast<uint64_t>(it.second.size()));
524 for (auto& agent : it.second) {
525 if (windowManagerServiceProxy_->RegisterWindowManagerAgent(it.first, agent) != WMError::WM_OK) {
526 TLOGE(WmsLogTag::WMS_RECOVER, "failed");
527 }
528 }
529 }
530 }
531
OnUserSwitch()532 void WindowAdapter::OnUserSwitch()
533 {
534 TLOGI(WmsLogTag::WMS_MULTI_USER, "User switched");
535 ClearWindowAdapter();
536 InitSSMProxy();
537 ReregisterWindowManagerAgent();
538 }
539
InitSSMProxy()540 bool WindowAdapter::InitSSMProxy()
541 {
542 std::lock_guard<std::mutex> lock(mutex_);
543 if (!isProxyValid_) {
544 windowManagerServiceProxy_ = SessionManager::GetInstance().GetSceneSessionManagerProxy();
545 if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
546 WLOGFE("Failed to get system scene session manager services");
547 return false;
548 }
549 wmsDeath_ = new (std::nothrow) WMSDeathRecipient();
550 if (!wmsDeath_) {
551 WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
552 return false;
553 }
554 sptr<IRemoteObject> remoteObject = windowManagerServiceProxy_->AsObject();
555 if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) {
556 WLOGFE("Failed to add death recipient");
557 return false;
558 }
559 if (!recoverInitialized_) {
560 SessionManager::GetInstance().RegisterWindowManagerRecoverCallbackFunc(
561 [this] { this->WindowManagerAndSessionRecover(); });
562 recoverInitialized_ = true;
563 }
564 // U0 system user needs to subscribe OnUserSwitch event
565 int32_t clientUserId = GetUserIdByUid(getuid());
566 if (clientUserId == SYSTEM_USERID && !isRegisteredUserSwitchListener_) {
567 SessionManager::GetInstance().RegisterUserSwitchListener([this]() { this->OnUserSwitch(); });
568 isRegisteredUserSwitchListener_ = true;
569 }
570 isProxyValid_ = true;
571 }
572 return true;
573 }
574
ClearWindowAdapter()575 void WindowAdapter::ClearWindowAdapter()
576 {
577 std::lock_guard<std::mutex> lock(mutex_);
578 if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) {
579 windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_);
580 }
581 isProxyValid_ = false;
582 windowManagerServiceProxy_ = nullptr;
583 }
584
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)585 void WMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
586 {
587 if (wptrDeath == nullptr) {
588 WLOGFE("wptrDeath is null");
589 return;
590 }
591
592 sptr<IRemoteObject> object = wptrDeath.promote();
593 if (!object) {
594 WLOGFE("object is null");
595 return;
596 }
597 WLOGI("wms OnRemoteDied");
598 SingletonContainer::Get<WindowAdapter>().ClearWindowAdapter();
599 }
600
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)601 WMError WindowAdapter::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
602 {
603 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
604
605 auto wmsProxy = GetWindowManagerServiceProxy();
606 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
607 return wmsProxy->GetTopWindowId(mainWinId, topWinId);
608 }
609
GetParentMainWindowId(int32_t windowId,int32_t & mainWindowId)610 WMError WindowAdapter::GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId)
611 {
612 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
613
614 auto wmsProxy = GetWindowManagerServiceProxy();
615 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
616 return wmsProxy->GetParentMainWindowId(windowId, mainWindowId);
617 }
618
SetWindowLayoutMode(WindowLayoutMode mode)619 WMError WindowAdapter::SetWindowLayoutMode(WindowLayoutMode mode)
620 {
621 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
622
623 auto wmsProxy = GetWindowManagerServiceProxy();
624 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
625 return wmsProxy->SetWindowLayoutMode(mode);
626 }
627
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action)628 WMError WindowAdapter::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action)
629 {
630 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
631
632 auto wmsProxy = GetWindowManagerServiceProxy();
633 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
634 return wmsProxy->UpdateProperty(windowProperty, action);
635 }
636
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)637 WMError WindowAdapter::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
638 {
639 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
640
641 auto wmsProxy = GetWindowManagerServiceProxy();
642 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
643 return wmsProxy->SetWindowGravity(windowId, gravity, percent);
644 }
645
NotifyWindowTransition(sptr<WindowTransitionInfo> from,sptr<WindowTransitionInfo> to)646 WMError WindowAdapter::NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to)
647 {
648 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
649
650 auto wmsProxy = GetWindowManagerServiceProxy();
651 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
652 return wmsProxy->NotifyWindowTransition(from, to, true);
653 }
654
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)655 void WindowAdapter::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
656 sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
657 {
658 INIT_PROXY_CHECK_RETURN();
659
660 auto wmsProxy = GetWindowManagerServiceProxy();
661 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
662 wmsProxy->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
663 }
664
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)665 WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
666 {
667 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
668
669 auto wmsProxy = GetWindowManagerServiceProxy();
670 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
671 return wmsProxy->UpdateAvoidAreaListener(windowId, haveListener);
672 }
673
UpdateRsTree(uint32_t windowId,bool isAdd)674 WMError WindowAdapter::UpdateRsTree(uint32_t windowId, bool isAdd)
675 {
676 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
677
678 auto wmsProxy = GetWindowManagerServiceProxy();
679 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
680 return wmsProxy->UpdateRsTree(windowId, isAdd);
681 }
682
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)683 WMError WindowAdapter::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
684 {
685 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
686
687 auto wmsProxy = GetWindowManagerServiceProxy();
688 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
689 return wmsProxy->BindDialogTarget(windowId, targetToken);
690 }
691
SetAnchorAndScale(int32_t x,int32_t y,float scale)692 void WindowAdapter::SetAnchorAndScale(int32_t x, int32_t y, float scale)
693 {
694 INIT_PROXY_CHECK_RETURN();
695
696 auto wmsProxy = GetWindowManagerServiceProxy();
697 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
698 wmsProxy->SetAnchorAndScale(x, y, scale);
699 }
700
SetAnchorOffset(int32_t deltaX,int32_t deltaY)701 void WindowAdapter::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
702 {
703 INIT_PROXY_CHECK_RETURN();
704
705 auto wmsProxy = GetWindowManagerServiceProxy();
706 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
707 wmsProxy->SetAnchorOffset(deltaX, deltaY);
708 }
709
OffWindowZoom()710 void WindowAdapter::OffWindowZoom()
711 {
712 INIT_PROXY_CHECK_RETURN();
713
714 auto wmsProxy = GetWindowManagerServiceProxy();
715 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
716 wmsProxy->OffWindowZoom();
717 }
718
719 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)720 WMError WindowAdapter::RaiseToAppTop(uint32_t windowId)
721 {
722 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
723
724 auto wmsProxy = GetWindowManagerServiceProxy();
725 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
726 return wmsProxy->RaiseToAppTop(windowId);
727 }
728
GetSnapshot(int32_t windowId)729 std::shared_ptr<Media::PixelMap> WindowAdapter::GetSnapshot(int32_t windowId)
730 {
731 INIT_PROXY_CHECK_RETURN(nullptr);
732
733 auto wmsProxy = GetWindowManagerServiceProxy();
734 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, nullptr);
735 return wmsProxy->GetSnapshot(windowId);
736 }
737
SetGestureNavigationEnabled(bool enable)738 WMError WindowAdapter::SetGestureNavigationEnabled(bool enable)
739 {
740 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
741
742 auto wmsProxy = GetWindowManagerServiceProxy();
743 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
744 return wmsProxy->SetGestureNavigationEnabled(enable);
745 }
746
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)747 void WindowAdapter::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
748 {
749 INIT_PROXY_CHECK_RETURN();
750
751 auto wmsProxy = GetWindowManagerServiceProxy();
752 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
753 wmsProxy->DispatchKeyEvent(windowId, event);
754 }
755
NotifyDumpInfoResult(const std::vector<std::string> & info)756 void WindowAdapter::NotifyDumpInfoResult(const std::vector<std::string>& info)
757 {
758 INIT_PROXY_CHECK_RETURN();
759
760 auto wmsProxy = GetWindowManagerServiceProxy();
761 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
762 wmsProxy->NotifyDumpInfoResult(info);
763 }
764
DumpSessionAll(std::vector<std::string> & infos)765 WMError WindowAdapter::DumpSessionAll(std::vector<std::string>& infos)
766 {
767 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
768
769 auto wmsProxy = GetWindowManagerServiceProxy();
770 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
771 return static_cast<WMError>(wmsProxy->DumpSessionAll(infos));
772 }
773
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)774 WMError WindowAdapter::DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos)
775 {
776 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
777
778 auto wmsProxy = GetWindowManagerServiceProxy();
779 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
780 return static_cast<WMError>(wmsProxy->DumpSessionWithId(persistentId, infos));
781 }
782
GetUIContentRemoteObj(int32_t persistentId,sptr<IRemoteObject> & uiContentRemoteObj)783 WMError WindowAdapter::GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj)
784 {
785 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
786
787 auto wmsProxy = GetWindowManagerServiceProxy();
788 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
789 return static_cast<WMError>(wmsProxy->GetUIContentRemoteObj(persistentId, uiContentRemoteObj));
790 }
791
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)792 WMError WindowAdapter::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
793 std::vector<sptr<RSWindowAnimationTarget>>& targets)
794 {
795 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
796
797 auto wmsProxy = GetWindowManagerServiceProxy();
798 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
799 return wmsProxy->GetWindowAnimationTargets(missionIds, targets);
800 }
801
SetMaximizeMode(MaximizeMode maximizeMode)802 void WindowAdapter::SetMaximizeMode(MaximizeMode maximizeMode)
803 {
804 INIT_PROXY_CHECK_RETURN();
805
806 auto wmsProxy = GetWindowManagerServiceProxy();
807 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
808 wmsProxy->SetMaximizeMode(maximizeMode);
809 }
810
GetMaximizeMode()811 MaximizeMode WindowAdapter::GetMaximizeMode()
812 {
813 INIT_PROXY_CHECK_RETURN(MaximizeMode::MODE_FULL_FILL);
814
815 auto wmsProxy = GetWindowManagerServiceProxy();
816 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, MaximizeMode::MODE_FULL_FILL);
817 return wmsProxy->GetMaximizeMode();
818 }
819
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)820 void WindowAdapter::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
821 {
822 INIT_PROXY_CHECK_RETURN();
823
824 auto wmsProxy = GetWindowManagerServiceProxy();
825 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
826 if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
827 wmsProxy->GetFocusWindowInfo(focusInfo, displayId);
828 } else {
829 wmsProxy->GetFocusWindowInfo(focusInfo);
830 }
831 }
832
UpdateSessionAvoidAreaListener(int32_t persistentId,bool haveListener)833 WMError WindowAdapter::UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener)
834 {
835 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
836
837 auto wmsProxy = GetWindowManagerServiceProxy();
838 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
839 return static_cast<WMError>(wmsProxy->UpdateSessionAvoidAreaListener(persistentId, haveListener));
840 }
841
UpdateSessionTouchOutsideListener(int32_t & persistentId,bool haveListener)842 WMError WindowAdapter::UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener)
843 {
844 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
845
846 auto wmsProxy = GetWindowManagerServiceProxy();
847 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
848 return static_cast<WMError>(
849 wmsProxy->UpdateSessionTouchOutsideListener(persistentId, haveListener));
850 }
851
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)852 WMError WindowAdapter::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
853 {
854 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
855
856 auto wmsProxy = GetWindowManagerServiceProxy();
857 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
858 return static_cast<WMError>(wmsProxy->NotifyWindowExtensionVisibilityChange(pid, uid, visible));
859 }
860
RaiseWindowToTop(int32_t persistentId)861 WMError WindowAdapter::RaiseWindowToTop(int32_t persistentId)
862 {
863 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
864
865 auto wmsProxy = GetWindowManagerServiceProxy();
866 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
867 return static_cast<WMError>(wmsProxy->RaiseWindowToTop(persistentId));
868 }
869
UpdateSessionWindowVisibilityListener(int32_t persistentId,bool haveListener)870 WMError WindowAdapter::UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener)
871 {
872 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
873
874 auto wmsProxy = GetWindowManagerServiceProxy();
875 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
876 WSError ret = wmsProxy->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
877 return static_cast<WMError>(ret);
878 }
879
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)880 WMError WindowAdapter::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
881 {
882 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
883
884 auto wmsProxy = GetWindowManagerServiceProxy();
885 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
886 return static_cast<WMError>(
887 wmsProxy->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId));
888 }
889
CreateAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,int32_t & persistentId,sptr<ISession> & session,SystemSessionConfig & systemConfig,sptr<IRemoteObject> token)890 void WindowAdapter::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
891 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
892 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
893 SystemSessionConfig& systemConfig, sptr<IRemoteObject> token)
894 {
895 INIT_PROXY_CHECK_RETURN();
896
897 auto wmsProxy = GetWindowManagerServiceProxy();
898 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
899 wmsProxy->CreateAndConnectSpecificSession(sessionStage, eventChannel,
900 surfaceNode, property, persistentId, session, systemConfig, token);
901 }
902
RecoverAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,sptr<ISession> & session,sptr<IRemoteObject> token)903 void WindowAdapter::RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
904 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
905 sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token)
906 {
907 INIT_PROXY_CHECK_RETURN();
908 TLOGI(WmsLogTag::WMS_RECOVER, "called");
909
910 auto wmsProxy = GetWindowManagerServiceProxy();
911 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
912 wmsProxy->RecoverAndConnectSpecificSession(
913 sessionStage, eventChannel, surfaceNode, property, session, token);
914 }
915
DestroyAndDisconnectSpecificSession(const int32_t persistentId)916 WMError WindowAdapter::DestroyAndDisconnectSpecificSession(const int32_t persistentId)
917 {
918 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
919
920 auto wmsProxy = GetWindowManagerServiceProxy();
921 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
922 return static_cast<WMError>(wmsProxy->DestroyAndDisconnectSpecificSession(persistentId));
923 }
924
DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,const sptr<IRemoteObject> & callback)925 WMError WindowAdapter::DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,
926 const sptr<IRemoteObject>& callback)
927 {
928 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
929
930 auto wmsProxy = GetWindowManagerServiceProxy();
931 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
932 return static_cast<WMError>(
933 wmsProxy->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback));
934 }
935
RecoverAndReconnectSceneSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<ISession> & session,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)936 WMError WindowAdapter::RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
937 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
938 sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
939 {
940 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
941 TLOGI(WmsLogTag::WMS_RECOVER, "called");
942
943 auto wmsProxy = GetWindowManagerServiceProxy();
944 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
945 auto ret = wmsProxy->RecoverAndReconnectSceneSession(
946 sessionStage, eventChannel, surfaceNode, session, property, token);
947 if (ret != WSError::WS_OK) {
948 TLOGE(WmsLogTag::WMS_RECOVER, "failed, ret=%{public}d", ret);
949 return WMError::WM_DO_NOTHING;
950 }
951 return WMError::WM_OK;
952 }
953
SetSessionGravity(int32_t persistentId,SessionGravity gravity,uint32_t percent)954 WMError WindowAdapter::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent)
955 {
956 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
957
958 auto wmsProxy = GetWindowManagerServiceProxy();
959 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
960 return static_cast<WMError>(wmsProxy->SetSessionGravity(persistentId, gravity, percent));
961 }
962
BindDialogSessionTarget(uint64_t persistentId,sptr<IRemoteObject> targetToken)963 WMError WindowAdapter::BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken)
964 {
965 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
966
967 auto wmsProxy = GetWindowManagerServiceProxy();
968 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
969 return static_cast<WMError>(wmsProxy->BindDialogSessionTarget(persistentId, targetToken));
970 }
971
RequestFocusStatus(int32_t persistentId,bool isFocused)972 WMError WindowAdapter::RequestFocusStatus(int32_t persistentId, bool isFocused)
973 {
974 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
975
976 auto wmsProxy = GetWindowManagerServiceProxy();
977 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
978 return static_cast<WMError>(wmsProxy->RequestFocusStatus(persistentId, isFocused));
979 }
980
RequestFocusStatusBySA(int32_t persistentId,bool isFocused,bool byForeground,FocusChangeReason reason)981 WMError WindowAdapter::RequestFocusStatusBySA(int32_t persistentId, bool isFocused,
982 bool byForeground, FocusChangeReason reason)
983 {
984 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
985 auto wmsProxy = GetWindowManagerServiceProxy();
986 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
987 return wmsProxy->RequestFocusStatusBySA(persistentId, isFocused, byForeground, reason);
988 }
989
AddExtensionWindowStageToSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,uint64_t surfaceNodeId,bool isConstrainedModal)990 void WindowAdapter::AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage,
991 const sptr<IRemoteObject>& token, uint64_t surfaceNodeId, bool isConstrainedModal)
992 {
993 INIT_PROXY_CHECK_RETURN();
994
995 auto wmsProxy = GetWindowManagerServiceProxy();
996 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
997 wmsProxy->AddExtensionWindowStageToSCB(sessionStage, token, surfaceNodeId, isConstrainedModal);
998 }
999
RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,bool isConstrainedModal)1000 void WindowAdapter::RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage,
1001 const sptr<IRemoteObject>& token, bool isConstrainedModal)
1002 {
1003 INIT_PROXY_CHECK_RETURN();
1004
1005 auto wmsProxy = GetWindowManagerServiceProxy();
1006 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
1007 wmsProxy->RemoveExtensionWindowStageFromSCB(sessionStage, token, isConstrainedModal);
1008 }
1009
ProcessModalExtensionPointDown(const sptr<IRemoteObject> & token,int32_t posX,int32_t posY)1010 void WindowAdapter::ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY)
1011 {
1012 INIT_PROXY_CHECK_RETURN();
1013
1014 auto wmsProxy = GetWindowManagerServiceProxy();
1015 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
1016 wmsProxy->ProcessModalExtensionPointDown(token, posX, posY);
1017 }
1018
UpdateModalExtensionRect(const sptr<IRemoteObject> & token,Rect rect)1019 void WindowAdapter::UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect)
1020 {
1021 INIT_PROXY_CHECK_RETURN();
1022
1023 auto wmsProxy = GetWindowManagerServiceProxy();
1024 CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
1025 wmsProxy->UpdateModalExtensionRect(token, rect);
1026 }
1027
AddOrRemoveSecureSession(int32_t persistentId,bool shouldHide)1028 WMError WindowAdapter::AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide)
1029 {
1030 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1031
1032 auto wmsProxy = GetWindowManagerServiceProxy();
1033 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1034 return static_cast<WMError>(wmsProxy->AddOrRemoveSecureSession(persistentId, shouldHide));
1035 }
1036
UpdateExtWindowFlags(const sptr<IRemoteObject> & token,uint32_t extWindowFlags,uint32_t extWindowActions)1037 WMError WindowAdapter::UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags,
1038 uint32_t extWindowActions)
1039 {
1040 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1041
1042 auto wmsProxy = GetWindowManagerServiceProxy();
1043 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1044 return static_cast<WMError>(wmsProxy->UpdateExtWindowFlags(token, extWindowFlags, extWindowActions));
1045 }
1046
GetHostWindowRect(int32_t hostWindowId,Rect & rect)1047 WMError WindowAdapter::GetHostWindowRect(int32_t hostWindowId, Rect& rect)
1048 {
1049 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1050
1051 auto wmsProxy = GetWindowManagerServiceProxy();
1052 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1053 return static_cast<WMError>(wmsProxy->GetHostWindowRect(hostWindowId, rect));
1054 }
1055
GetHostGlobalScaledRect(int32_t hostWindowId,Rect & globalScaledRect)1056 WMError WindowAdapter::GetHostGlobalScaledRect(int32_t hostWindowId, Rect& globalScaledRect)
1057 {
1058 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1059
1060 auto wmsProxy = GetWindowManagerServiceProxy();
1061 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1062 return static_cast<WMError>(wmsProxy->GetHostGlobalScaledRect(hostWindowId, globalScaledRect));
1063 }
1064
GetFreeMultiWindowEnableState(bool & enable)1065 WMError WindowAdapter::GetFreeMultiWindowEnableState(bool& enable)
1066 {
1067 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1068
1069 auto wmsProxy = GetWindowManagerServiceProxy();
1070 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1071 return static_cast<WMError>(wmsProxy->GetFreeMultiWindowEnableState(enable));
1072 }
1073
GetCallingWindowWindowStatus(int32_t persistentId,WindowStatus & windowStatus)1074 WMError WindowAdapter::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus)
1075 {
1076 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1077
1078 auto wmsProxy = GetWindowManagerServiceProxy();
1079 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1080 return static_cast<WMError>(wmsProxy->GetCallingWindowWindowStatus(persistentId, windowStatus));
1081 }
1082
GetCallingWindowRect(int32_t persistentId,Rect & rect)1083 WMError WindowAdapter::GetCallingWindowRect(int32_t persistentId, Rect& rect)
1084 {
1085 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1086
1087 auto wmsProxy = GetWindowManagerServiceProxy();
1088 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1089 return static_cast<WMError>(wmsProxy->GetCallingWindowRect(persistentId, rect));
1090 }
1091
GetWindowModeType(WindowModeType & windowModeType)1092 WMError WindowAdapter::GetWindowModeType(WindowModeType& windowModeType)
1093 {
1094 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1095
1096 WLOGFD("get window mode type");
1097 auto wmsProxy = GetWindowManagerServiceProxy();
1098 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1099 return wmsProxy->GetWindowModeType(windowModeType);
1100 }
1101
GetWindowStyleType(WindowStyleType & windowStyleType)1102 WMError WindowAdapter::GetWindowStyleType(WindowStyleType& windowStyleType)
1103 {
1104 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1105 auto wmsProxy = GetWindowManagerServiceProxy();
1106 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1107 return wmsProxy->GetWindowStyleType(windowStyleType);
1108 }
1109
GetWindowIdsByCoordinate(DisplayId displayId,int32_t windowNumber,int32_t x,int32_t y,std::vector<int32_t> & windowIds)1110 WMError WindowAdapter::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
1111 int32_t x, int32_t y, std::vector<int32_t>& windowIds)
1112 {
1113 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1114 auto wmsProxy = GetWindowManagerServiceProxy();
1115 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1116 return wmsProxy->GetWindowIdsByCoordinate(displayId, windowNumber, x, y, windowIds);
1117 }
1118
GetWindowManagerServiceProxy() const1119 sptr<IWindowManager> WindowAdapter::GetWindowManagerServiceProxy() const
1120 {
1121 std::lock_guard<std::mutex> lock(mutex_);
1122 return windowManagerServiceProxy_;
1123 }
1124
SkipSnapshotForAppProcess(int32_t pid,bool skip)1125 WMError WindowAdapter::SkipSnapshotForAppProcess(int32_t pid, bool skip)
1126 {
1127 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1128 auto wmsProxy = GetWindowManagerServiceProxy();
1129 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1130 return wmsProxy->SkipSnapshotForAppProcess(pid, skip);
1131 }
1132
SetProcessWatermark(int32_t pid,const std::string & watermarkName,bool isEnabled)1133 WMError WindowAdapter::SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled)
1134 {
1135 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1136 auto wmsProxy = GetWindowManagerServiceProxy();
1137 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1138 return wmsProxy->SetProcessWatermark(pid, watermarkName, isEnabled);
1139 }
1140
UpdateScreenLockStatusForApp(const std::string & bundleName,bool isRelease)1141 WMError WindowAdapter::UpdateScreenLockStatusForApp(const std::string& bundleName, bool isRelease)
1142 {
1143 INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
1144 auto wmsProxy = GetWindowManagerServiceProxy();
1145 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1146 return wmsProxy->UpdateScreenLockStatusForApp(bundleName, isRelease);
1147 }
1148
IsPcWindow(bool & isPcWindow)1149 WMError WindowAdapter::IsPcWindow(bool& isPcWindow)
1150 {
1151 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1152 auto wmsProxy = GetWindowManagerServiceProxy();
1153 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1154 return wmsProxy->IsPcWindow(isPcWindow);
1155 }
1156
IsFreeMultiWindowMode(bool & isFreeMultiWindow)1157 WMError WindowAdapter::IsFreeMultiWindowMode(bool& isFreeMultiWindow)
1158 {
1159 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1160 auto wmsProxy = GetWindowManagerServiceProxy();
1161 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1162 return wmsProxy->IsFreeMultiWindow(isFreeMultiWindow);
1163 }
1164
IsPcOrPadFreeMultiWindowMode(bool & isPcOrPadFreeMultiWindowMode)1165 WMError WindowAdapter::IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode)
1166 {
1167 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1168 auto wmsProxy = GetWindowManagerServiceProxy();
1169 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1170 return wmsProxy->IsPcOrPadFreeMultiWindowMode(isPcOrPadFreeMultiWindowMode);
1171 }
1172
IsWindowRectAutoSave(const std::string & key,bool & enabled,int persistentId)1173 WMError WindowAdapter::IsWindowRectAutoSave(const std::string& key, bool& enabled, int persistentId)
1174 {
1175 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1176 auto wmsProxy = GetWindowManagerServiceProxy();
1177 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1178 return wmsProxy->IsWindowRectAutoSave(key, enabled, persistentId);
1179 }
1180
SetImageForRecent(uint32_t imgResourceId,ImageFit imageFit,int32_t persistentId)1181 WMError WindowAdapter::SetImageForRecent(uint32_t imgResourceId, ImageFit imageFit, int32_t persistentId)
1182 {
1183 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1184 auto wmsProxy = GetWindowManagerServiceProxy();
1185 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1186 return wmsProxy->SetImageForRecent(imgResourceId, imageFit, persistentId);
1187 }
1188
ShiftAppWindowPointerEvent(int32_t sourceWindowId,int32_t targetWindowId,int32_t fingerId)1189 WMError WindowAdapter::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId, int32_t fingerId)
1190 {
1191 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1192 auto wmsProxy = GetWindowManagerServiceProxy();
1193 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1194 return wmsProxy->ShiftAppWindowPointerEvent(sourceWindowId, targetWindowId, fingerId);
1195 }
1196
NotifyScreenshotEvent(ScreenshotEventType type)1197 WMError WindowAdapter::NotifyScreenshotEvent(ScreenshotEventType type)
1198 {
1199 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1200 auto wmsProxy = GetWindowManagerServiceProxy();
1201 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1202 return wmsProxy->NotifyScreenshotEvent(type);
1203 }
1204
SetStartWindowBackgroundColor(const std::string & moduleName,const std::string & abilityName,uint32_t color,int32_t uid)1205 WMError WindowAdapter::SetStartWindowBackgroundColor(
1206 const std::string& moduleName, const std::string& abilityName, uint32_t color, int32_t uid)
1207 {
1208 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1209 auto wmsProxy = GetWindowManagerServiceProxy();
1210 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1211 return wmsProxy->SetStartWindowBackgroundColor(moduleName, abilityName, color, uid);
1212 }
1213
GetDisplayIdByWindowId(const std::vector<uint64_t> & windowIds,std::unordered_map<uint64_t,DisplayId> & windowDisplayIdMap)1214 WMError WindowAdapter::GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
1215 std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap)
1216 {
1217 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1218 auto wmsProxy = GetWindowManagerServiceProxy();
1219 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1220 return wmsProxy->GetDisplayIdByWindowId(windowIds, windowDisplayIdMap);
1221 }
1222
SetGlobalDragResizeType(DragResizeType dragResizeType)1223 WMError WindowAdapter::SetGlobalDragResizeType(DragResizeType dragResizeType)
1224 {
1225 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1226 auto wmsProxy = GetWindowManagerServiceProxy();
1227 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1228 return wmsProxy->SetGlobalDragResizeType(dragResizeType);
1229 }
1230
GetGlobalDragResizeType(DragResizeType & dragResizeType)1231 WMError WindowAdapter::GetGlobalDragResizeType(DragResizeType& dragResizeType)
1232 {
1233 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1234 auto wmsProxy = GetWindowManagerServiceProxy();
1235 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1236 return wmsProxy->GetGlobalDragResizeType(dragResizeType);
1237 }
1238
SetAppDragResizeType(const std::string & bundleName,DragResizeType dragResizeType)1239 WMError WindowAdapter::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType)
1240 {
1241 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1242 auto wmsProxy = GetWindowManagerServiceProxy();
1243 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1244 return wmsProxy->SetAppDragResizeType(bundleName, dragResizeType);
1245 }
1246
GetAppDragResizeType(const std::string & bundleName,DragResizeType & dragResizeType)1247 WMError WindowAdapter::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType)
1248 {
1249 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1250 auto wmsProxy = GetWindowManagerServiceProxy();
1251 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1252 return wmsProxy->GetAppDragResizeType(bundleName, dragResizeType);
1253 }
1254
SetAppKeyFramePolicy(const std::string & bundleName,const KeyFramePolicy & keyFramePolicy)1255 WMError WindowAdapter::SetAppKeyFramePolicy(const std::string& bundleName, const KeyFramePolicy& keyFramePolicy)
1256 {
1257 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1258 auto wmsProxy = GetWindowManagerServiceProxy();
1259 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1260 return wmsProxy->SetAppKeyFramePolicy(bundleName, keyFramePolicy);
1261 }
1262
NotifyWatchGestureConsumeResult(int32_t keyCode,bool isConsumed)1263 WMError WindowAdapter::NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed)
1264 {
1265 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1266 auto wmsProxy = GetWindowManagerServiceProxy();
1267 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1268 return wmsProxy->NotifyWatchGestureConsumeResult(keyCode, isConsumed);
1269 }
1270
NotifyWatchFocusActiveChange(bool isActive)1271 WMError WindowAdapter::NotifyWatchFocusActiveChange(bool isActive)
1272 {
1273 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1274 auto wmsProxy = GetWindowManagerServiceProxy();
1275 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1276 return wmsProxy->NotifyWatchFocusActiveChange(isActive);
1277 }
1278
MinimizeByWindowId(const std::vector<int32_t> & windowIds)1279 WMError WindowAdapter::MinimizeByWindowId(const std::vector<int32_t>& windowIds)
1280 {
1281 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1282 auto wmsProxy = GetWindowManagerServiceProxy();
1283 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1284 return wmsProxy->MinimizeByWindowId(windowIds);
1285 }
1286
SetForegroundWindowNum(uint32_t windowNum)1287 WMError WindowAdapter::SetForegroundWindowNum(uint32_t windowNum)
1288 {
1289 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1290 auto wmsProxy = GetWindowManagerServiceProxy();
1291 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1292 return wmsProxy->SetForegroundWindowNum(windowNum);
1293 }
1294
UseImplicitAnimation(int32_t hostWindowId,bool useImplicit)1295 WMError WindowAdapter::UseImplicitAnimation(int32_t hostWindowId, bool useImplicit)
1296 {
1297 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1298 auto wmsProxy = GetWindowManagerServiceProxy();
1299 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
1300 return static_cast<WMError>(wmsProxy->UseImplicitAnimation(hostWindowId, useImplicit));
1301 }
1302
AnimateTo(int32_t windowId,const WindowAnimationProperty & animationProperty,const WindowAnimationOption & animationOption)1303 WMError WindowAdapter::AnimateTo(int32_t windowId, const WindowAnimationProperty& animationProperty,
1304 const WindowAnimationOption& animationOption)
1305 {
1306 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1307 auto wmsProxy = GetWindowManagerServiceProxy();
1308 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1309 return wmsProxy->AnimateTo(windowId, animationProperty, animationOption);
1310 }
1311
CreateUIEffectController(const sptr<IUIEffectControllerClient> & controllerClient,sptr<IUIEffectController> & controller,int32_t & controllerId)1312 WMError WindowAdapter::CreateUIEffectController(const sptr<IUIEffectControllerClient>& controllerClient,
1313 sptr<IUIEffectController>& controller, int32_t& controllerId)
1314 {
1315 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1316 auto wmsProxy = GetWindowManagerServiceProxy();
1317 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1318 return wmsProxy->CreateUIEffectController(controllerClient, controller, controllerId);
1319 }
1320
AddSessionBlackList(const std::unordered_set<std::string> & bundleNames,const std::unordered_set<std::string> & privacyWindowTags)1321 WMError WindowAdapter::AddSessionBlackList(
1322 const std::unordered_set<std::string>& bundleNames, const std::unordered_set<std::string>& privacyWindowTags)
1323 {
1324 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1325 auto wmsProxy = GetWindowManagerServiceProxy();
1326 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1327 return wmsProxy->AddSessionBlackList(bundleNames, privacyWindowTags);
1328 }
1329
RemoveSessionBlackList(const std::unordered_set<std::string> & bundleNames,const std::unordered_set<std::string> & privacyWindowTags)1330 WMError WindowAdapter::RemoveSessionBlackList(
1331 const std::unordered_set<std::string>& bundleNames, const std::unordered_set<std::string>& privacyWindowTags)
1332 {
1333 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1334 auto wmsProxy = GetWindowManagerServiceProxy();
1335 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1336 return wmsProxy->RemoveSessionBlackList(bundleNames, privacyWindowTags);
1337 }
1338
GetPiPSettingSwitchStatus(bool & switchStatus)1339 WMError WindowAdapter::GetPiPSettingSwitchStatus(bool& switchStatus)
1340 {
1341 INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1342 auto wmsProxy = GetWindowManagerServiceProxy();
1343 CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1344 return wmsProxy->GetPiPSettingSwitchStatus(switchStatus);
1345 }
1346 } // namespace Rosen
1347 } // namespace OHOS
1348