• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "window_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 
RequestFocus(uint32_t windowId)106 WMError WindowAdapter::RequestFocus(uint32_t windowId)
107 {
108     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
109 
110     auto wmsProxy = GetWindowManagerServiceProxy();
111     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
112     return wmsProxy->RequestFocus(windowId);
113 }
114 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)115 WMError WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type,
116     const sptr<IWindowManagerAgent>& windowManagerAgent)
117 {
118     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
119 
120     auto wmsProxy = GetWindowManagerServiceProxy();
121     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
122 
123     {
124         std::lock_guard<std::mutex> lock(mutex_);
125         if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
126             windowManagerAgentMap_[type] = std::set<sptr<IWindowManagerAgent>>();
127         }
128         windowManagerAgentMap_[type].insert(windowManagerAgent);
129     }
130 
131     return wmsProxy->RegisterWindowManagerAgent(type, windowManagerAgent);
132 }
133 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)134 WMError WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type,
135     const sptr<IWindowManagerAgent>& windowManagerAgent)
136 {
137     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
138 
139     auto wmsProxy = GetWindowManagerServiceProxy();
140     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
141     auto ret = wmsProxy->UnregisterWindowManagerAgent(type, windowManagerAgent);
142 
143     std::lock_guard<std::mutex> lock(mutex_);
144     if (windowManagerAgentMap_.find(type) == windowManagerAgentMap_.end()) {
145         WLOGFW("WindowManagerAgentType = %{public}d not found", type);
146         return ret;
147     }
148 
149     auto& agentSet = windowManagerAgentMap_[type];
150     auto agent = std::find(agentSet.begin(), agentSet.end(), windowManagerAgent);
151     if (agent == agentSet.end()) {
152         WLOGFW("Cannot find agent,  type = %{public}d", type);
153         return ret;
154     }
155     agentSet.erase(agent);
156 
157     return ret;
158 }
159 
CheckWindowId(int32_t windowId,int32_t & pid)160 WMError WindowAdapter::CheckWindowId(int32_t windowId, int32_t& pid)
161 {
162     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
163 
164     auto wmsProxy = GetWindowManagerServiceProxy();
165     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
166     return wmsProxy->CheckWindowId(windowId, pid);
167 }
168 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)169 WMError WindowAdapter::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
170 {
171     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
172 
173     auto wmsProxy = GetWindowManagerServiceProxy();
174     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
175     return wmsProxy->GetAccessibilityWindowInfo(infos);
176 }
177 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)178 WMError WindowAdapter::GetUnreliableWindowInfo(int32_t windowId,
179     std::vector<sptr<UnreliableWindowInfo>>& infos)
180 {
181     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
182 
183     auto wmsProxy = GetWindowManagerServiceProxy();
184     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
185     return wmsProxy->GetUnreliableWindowInfo(windowId, infos);
186 }
187 
GetAllWindowLayoutInfo(DisplayId displayId,std::vector<sptr<WindowLayoutInfo>> & infos)188 WMError WindowAdapter::GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos)
189 {
190     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
191     auto wmsProxy = GetWindowManagerServiceProxy();
192     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
193     return wmsProxy->GetAllWindowLayoutInfo(displayId, infos);
194 }
195 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)196 WMError WindowAdapter::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
197 {
198     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
199 
200     auto wmsProxy = GetWindowManagerServiceProxy();
201     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
202     return wmsProxy->GetVisibilityWindowInfo(infos);
203 }
204 
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)205 WMError WindowAdapter::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
206 {
207     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
208 
209     auto wmsProxy = GetWindowManagerServiceProxy();
210     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
211     return wmsProxy->SetWindowAnimationController(controller);
212 }
213 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType type,AvoidArea & avoidArea)214 WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidArea)
215 {
216     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
217 
218     auto wmsProxy = GetWindowManagerServiceProxy();
219     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
220     avoidArea = wmsProxy->GetAvoidAreaByType(windowId, type);
221     return WMError::WM_OK;
222 }
223 
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)224 void WindowAdapter::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
225     sptr<MoveDragProperty>& moveDragProperty)
226 {
227     INIT_PROXY_CHECK_RETURN();
228 
229     auto wmsProxy = GetWindowManagerServiceProxy();
230     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
231     wmsProxy->NotifyServerReadyToMoveOrDrag(windowId, windowProperty, moveDragProperty);
232 }
233 
ProcessPointDown(uint32_t windowId,bool isPointDown)234 void WindowAdapter::ProcessPointDown(uint32_t windowId, bool isPointDown)
235 {
236     INIT_PROXY_CHECK_RETURN();
237 
238     auto wmsProxy = GetWindowManagerServiceProxy();
239     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
240     wmsProxy->ProcessPointDown(windowId, isPointDown);
241 }
242 
ProcessPointUp(uint32_t windowId)243 void WindowAdapter::ProcessPointUp(uint32_t windowId)
244 {
245     INIT_PROXY_CHECK_RETURN();
246 
247     auto wmsProxy = GetWindowManagerServiceProxy();
248     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
249     wmsProxy->ProcessPointUp(windowId);
250 }
251 
MinimizeAllAppWindows(DisplayId displayId)252 WMError WindowAdapter::MinimizeAllAppWindows(DisplayId displayId)
253 {
254     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
255 
256     auto wmsProxy = GetWindowManagerServiceProxy();
257     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
258     return wmsProxy->MinimizeAllAppWindows(displayId);
259 }
260 
ToggleShownStateForAllAppWindows()261 WMError WindowAdapter::ToggleShownStateForAllAppWindows()
262 {
263     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
264 
265     auto wmsProxy = GetWindowManagerServiceProxy();
266     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
267     return wmsProxy->ToggleShownStateForAllAppWindows();
268 }
269 
GetSystemConfig(SystemConfig & systemConfig)270 WMError WindowAdapter::GetSystemConfig(SystemConfig& systemConfig)
271 {
272     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
273 
274     auto wmsProxy = GetWindowManagerServiceProxy();
275     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
276     return wmsProxy->GetSystemConfig(systemConfig);
277 }
278 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)279 WMError WindowAdapter::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
280 {
281     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
282 
283     auto wmsProxy = GetWindowManagerServiceProxy();
284     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
285     return wmsProxy->GetModeChangeHotZones(displayId, hotZones);
286 }
287 
InitWMSProxy()288 bool WindowAdapter::InitWMSProxy()
289 {
290     std::lock_guard<std::mutex> lock(mutex_);
291     if (!isProxyValid_) {
292         sptr<ISystemAbilityManager> systemAbilityManager =
293             SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
294         if (!systemAbilityManager) {
295             WLOGFE("Failed to get system ability mgr.");
296             return false;
297         }
298 
299         sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(WINDOW_MANAGER_SERVICE_ID);
300         if (!remoteObject) {
301             WLOGFE("Failed to get window manager service.");
302             return false;
303         }
304 
305         windowManagerServiceProxy_ = iface_cast<IWindowManager>(remoteObject);
306         if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
307             WLOGFE("Failed to get system window manager services");
308             return false;
309         }
310 
311         wmsDeath_ = new WMSDeathRecipient();
312         if (!wmsDeath_) {
313             WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
314             return false;
315         }
316         if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) {
317             WLOGFE("Failed to add death recipient");
318             return false;
319         }
320         isProxyValid_ = true;
321     }
322     return true;
323 }
324 
RegisterSessionRecoverCallbackFunc(int32_t persistentId,const SessionRecoverCallbackFunc & callbackFunc)325 void WindowAdapter::RegisterSessionRecoverCallbackFunc(
326     int32_t persistentId, const SessionRecoverCallbackFunc& callbackFunc)
327 {
328     TLOGI(WmsLogTag::WMS_RECOVER, "persistentId = %{public}d", persistentId);
329     std::lock_guard<std::mutex> lock(mutex_);
330     sessionRecoverCallbackFuncMap_[persistentId] = callbackFunc;
331 }
332 
GetSnapshotByWindowId(int32_t windowId,std::shared_ptr<Media::PixelMap> & pixelMap)333 WMError WindowAdapter::GetSnapshotByWindowId(int32_t windowId, std::shared_ptr<Media::PixelMap>& pixelMap)
334 {
335     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_IPC_FAILED);
336 
337     auto wmsProxy = GetWindowManagerServiceProxy();
338     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_IPC_FAILED);
339     return wmsProxy->GetSnapshotByWindowId(windowId, pixelMap);
340 }
341 
UnregisterSessionRecoverCallbackFunc(int32_t persistentId)342 void WindowAdapter::UnregisterSessionRecoverCallbackFunc(int32_t persistentId)
343 {
344     std::lock_guard<std::mutex> lock(mutex_);
345     auto it = sessionRecoverCallbackFuncMap_.find(persistentId);
346     if (it != sessionRecoverCallbackFuncMap_.end()) {
347         sessionRecoverCallbackFuncMap_.erase(it);
348     }
349 }
350 
RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc & callbackFunc)351 WMError WindowAdapter::RegisterWMSConnectionChangedListener(const WMSConnectionChangedCallbackFunc& callbackFunc)
352 {
353     WLOGFI("RegisterWMSConnectionChangedListener in");
354     return SessionManager::GetInstance().RegisterWMSConnectionChangedListener(callbackFunc);
355 }
356 
WindowManagerAndSessionRecover()357 void WindowAdapter::WindowManagerAndSessionRecover()
358 {
359     ClearWindowAdapter();
360     if (!InitSSMProxy()) {
361         TLOGE(WmsLogTag::WMS_RECOVER, "InitSSMProxy failed");
362         return;
363     }
364 
365     ReregisterWindowManagerAgent();
366 
367     std::map<int32_t, SessionRecoverCallbackFunc> sessionRecoverCallbackFuncMap;
368     {
369         std::lock_guard<std::mutex> lock(mutex_);
370         sessionRecoverCallbackFuncMap = sessionRecoverCallbackFuncMap_;
371     }
372     for (const auto& it : sessionRecoverCallbackFuncMap) {
373         TLOGD(WmsLogTag::WMS_RECOVER, "Session recover callback, persistentId = %{public}" PRId32, it.first);
374         auto ret = it.second();
375         if (ret != WMError::WM_OK) {
376             TLOGE(WmsLogTag::WMS_RECOVER, "Session recover callback, persistentId = %{public}" PRId32 " is error",
377                 it.first);
378             return;
379         }
380     }
381 }
382 
ReregisterWindowManagerAgent()383 void WindowAdapter::ReregisterWindowManagerAgent()
384 {
385     std::lock_guard<std::mutex> lock(mutex_);
386     if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
387         TLOGE(WmsLogTag::WMS_RECOVER, "proxy is null");
388         return;
389     }
390     for (const auto& it : windowManagerAgentMap_) {
391         TLOGI(WmsLogTag::WMS_RECOVER, "Window manager agent type = %{public}" PRIu32 ", size = %{public}" PRIu64,
392             it.first, static_cast<uint64_t>(it.second.size()));
393         for (auto& agent : it.second) {
394             if (windowManagerServiceProxy_->RegisterWindowManagerAgent(it.first, agent) != WMError::WM_OK) {
395                 TLOGE(WmsLogTag::WMS_RECOVER, "failed");
396             }
397         }
398     }
399 }
400 
OnUserSwitch()401 void WindowAdapter::OnUserSwitch()
402 {
403     TLOGI(WmsLogTag::WMS_MULTI_USER, "User switched");
404     ClearWindowAdapter();
405     InitSSMProxy();
406     ReregisterWindowManagerAgent();
407 }
408 
InitSSMProxy()409 bool WindowAdapter::InitSSMProxy()
410 {
411     std::lock_guard<std::mutex> lock(mutex_);
412     if (!isProxyValid_) {
413         windowManagerServiceProxy_ = SessionManager::GetInstance().GetSceneSessionManagerProxy();
414         if (!windowManagerServiceProxy_ || !windowManagerServiceProxy_->AsObject()) {
415             WLOGFE("Failed to get system scene session manager services");
416             return false;
417         }
418         wmsDeath_ = new (std::nothrow) WMSDeathRecipient();
419         if (!wmsDeath_) {
420             WLOGFE("Failed to create death Recipient ptr WMSDeathRecipient");
421             return false;
422         }
423         sptr<IRemoteObject> remoteObject = windowManagerServiceProxy_->AsObject();
424         if (remoteObject->IsProxyObject() && !remoteObject->AddDeathRecipient(wmsDeath_)) {
425             WLOGFE("Failed to add death recipient");
426             return false;
427         }
428         if (!recoverInitialized_) {
429             SessionManager::GetInstance().RegisterWindowManagerRecoverCallbackFunc(
430                 [this] { this->WindowManagerAndSessionRecover(); });
431             recoverInitialized_ = true;
432         }
433         // U0 system user needs to subscribe OnUserSwitch event
434         int32_t clientUserId = GetUserIdByUid(getuid());
435         if (clientUserId == SYSTEM_USERID && !isRegisteredUserSwitchListener_) {
436             SessionManager::GetInstance().RegisterUserSwitchListener([this]() { this->OnUserSwitch(); });
437             isRegisteredUserSwitchListener_ = true;
438         }
439         isProxyValid_ = true;
440     }
441     return true;
442 }
443 
ClearWindowAdapter()444 void WindowAdapter::ClearWindowAdapter()
445 {
446     std::lock_guard<std::mutex> lock(mutex_);
447     if ((windowManagerServiceProxy_ != nullptr) && (windowManagerServiceProxy_->AsObject() != nullptr)) {
448         windowManagerServiceProxy_->AsObject()->RemoveDeathRecipient(wmsDeath_);
449     }
450     isProxyValid_ = false;
451     windowManagerServiceProxy_ = nullptr;
452 }
453 
OnRemoteDied(const wptr<IRemoteObject> & wptrDeath)454 void WMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
455 {
456     if (wptrDeath == nullptr) {
457         WLOGFE("wptrDeath is null");
458         return;
459     }
460 
461     sptr<IRemoteObject> object = wptrDeath.promote();
462     if (!object) {
463         WLOGFE("object is null");
464         return;
465     }
466     WLOGI("wms OnRemoteDied");
467     SingletonContainer::Get<WindowAdapter>().ClearWindowAdapter();
468 }
469 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)470 WMError WindowAdapter::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
471 {
472     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
473 
474     auto wmsProxy = GetWindowManagerServiceProxy();
475     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
476     return wmsProxy->GetTopWindowId(mainWinId, topWinId);
477 }
478 
GetParentMainWindowId(int32_t windowId,int32_t & mainWindowId)479 WMError WindowAdapter::GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId)
480 {
481     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
482 
483     auto wmsProxy = GetWindowManagerServiceProxy();
484     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
485     return wmsProxy->GetParentMainWindowId(windowId, mainWindowId);
486 }
487 
SetWindowLayoutMode(WindowLayoutMode mode)488 WMError WindowAdapter::SetWindowLayoutMode(WindowLayoutMode mode)
489 {
490     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
491 
492     auto wmsProxy = GetWindowManagerServiceProxy();
493     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
494     return wmsProxy->SetWindowLayoutMode(mode);
495 }
496 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action)497 WMError WindowAdapter::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action)
498 {
499     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
500 
501     auto wmsProxy = GetWindowManagerServiceProxy();
502     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
503     return wmsProxy->UpdateProperty(windowProperty, action);
504 }
505 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)506 WMError WindowAdapter::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
507 {
508     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
509 
510     auto wmsProxy = GetWindowManagerServiceProxy();
511     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
512     return wmsProxy->SetWindowGravity(windowId, gravity, percent);
513 }
514 
NotifyWindowTransition(sptr<WindowTransitionInfo> from,sptr<WindowTransitionInfo> to)515 WMError WindowAdapter::NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to)
516 {
517     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
518 
519     auto wmsProxy = GetWindowManagerServiceProxy();
520     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
521     return wmsProxy->NotifyWindowTransition(from, to, true);
522 }
523 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)524 void WindowAdapter::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
525     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
526 {
527     INIT_PROXY_CHECK_RETURN();
528 
529     auto wmsProxy = GetWindowManagerServiceProxy();
530     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
531     wmsProxy->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
532 }
533 
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)534 WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
535 {
536     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
537 
538     auto wmsProxy = GetWindowManagerServiceProxy();
539     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
540     return wmsProxy->UpdateAvoidAreaListener(windowId, haveListener);
541 }
542 
UpdateRsTree(uint32_t windowId,bool isAdd)543 WMError WindowAdapter::UpdateRsTree(uint32_t windowId, bool isAdd)
544 {
545     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
546 
547     auto wmsProxy = GetWindowManagerServiceProxy();
548     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
549     return wmsProxy->UpdateRsTree(windowId, isAdd);
550 }
551 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)552 WMError WindowAdapter::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
553 {
554     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
555 
556     auto wmsProxy = GetWindowManagerServiceProxy();
557     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
558     return wmsProxy->BindDialogTarget(windowId, targetToken);
559 }
560 
SetAnchorAndScale(int32_t x,int32_t y,float scale)561 void WindowAdapter::SetAnchorAndScale(int32_t x, int32_t y, float scale)
562 {
563     INIT_PROXY_CHECK_RETURN();
564 
565     auto wmsProxy = GetWindowManagerServiceProxy();
566     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
567     wmsProxy->SetAnchorAndScale(x, y, scale);
568 }
569 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)570 void WindowAdapter::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
571 {
572     INIT_PROXY_CHECK_RETURN();
573 
574     auto wmsProxy = GetWindowManagerServiceProxy();
575     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
576     wmsProxy->SetAnchorOffset(deltaX, deltaY);
577 }
578 
OffWindowZoom()579 void WindowAdapter::OffWindowZoom()
580 {
581     INIT_PROXY_CHECK_RETURN();
582 
583     auto wmsProxy = GetWindowManagerServiceProxy();
584     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
585     wmsProxy->OffWindowZoom();
586 }
587 
588 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)589 WMError WindowAdapter::RaiseToAppTop(uint32_t windowId)
590 {
591     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
592 
593     auto wmsProxy = GetWindowManagerServiceProxy();
594     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
595     return wmsProxy->RaiseToAppTop(windowId);
596 }
597 
GetSnapshot(int32_t windowId)598 std::shared_ptr<Media::PixelMap> WindowAdapter::GetSnapshot(int32_t windowId)
599 {
600     INIT_PROXY_CHECK_RETURN(nullptr);
601 
602     auto wmsProxy = GetWindowManagerServiceProxy();
603     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, nullptr);
604     return wmsProxy->GetSnapshot(windowId);
605 }
606 
SetGestureNavigaionEnabled(bool enable)607 WMError WindowAdapter::SetGestureNavigaionEnabled(bool enable)
608 {
609     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
610 
611     auto wmsProxy = GetWindowManagerServiceProxy();
612     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
613     return wmsProxy->SetGestureNavigaionEnabled(enable);
614 }
615 
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)616 void WindowAdapter::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
617 {
618     INIT_PROXY_CHECK_RETURN();
619 
620     auto wmsProxy = GetWindowManagerServiceProxy();
621     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
622     wmsProxy->DispatchKeyEvent(windowId, event);
623 }
624 
NotifyDumpInfoResult(const std::vector<std::string> & info)625 void WindowAdapter::NotifyDumpInfoResult(const std::vector<std::string>& info)
626 {
627     INIT_PROXY_CHECK_RETURN();
628 
629     auto wmsProxy = GetWindowManagerServiceProxy();
630     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
631     wmsProxy->NotifyDumpInfoResult(info);
632 }
633 
DumpSessionAll(std::vector<std::string> & infos)634 WMError WindowAdapter::DumpSessionAll(std::vector<std::string>& infos)
635 {
636     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
637 
638     auto wmsProxy = GetWindowManagerServiceProxy();
639     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
640     return static_cast<WMError>(wmsProxy->DumpSessionAll(infos));
641 }
642 
DumpSessionWithId(int32_t persistentId,std::vector<std::string> & infos)643 WMError WindowAdapter::DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos)
644 {
645     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
646 
647     auto wmsProxy = GetWindowManagerServiceProxy();
648     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
649     return static_cast<WMError>(wmsProxy->DumpSessionWithId(persistentId, infos));
650 }
651 
GetUIContentRemoteObj(int32_t persistentId,sptr<IRemoteObject> & uiContentRemoteObj)652 WMError WindowAdapter::GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj)
653 {
654     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
655 
656     auto wmsProxy = GetWindowManagerServiceProxy();
657     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
658     return static_cast<WMError>(wmsProxy->GetUIContentRemoteObj(persistentId, uiContentRemoteObj));
659 }
660 
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)661 WMError WindowAdapter::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
662     std::vector<sptr<RSWindowAnimationTarget>>& targets)
663 {
664     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
665 
666     auto wmsProxy = GetWindowManagerServiceProxy();
667     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
668     return wmsProxy->GetWindowAnimationTargets(missionIds, targets);
669 }
670 
SetMaximizeMode(MaximizeMode maximizeMode)671 void WindowAdapter::SetMaximizeMode(MaximizeMode maximizeMode)
672 {
673     INIT_PROXY_CHECK_RETURN();
674 
675     auto wmsProxy = GetWindowManagerServiceProxy();
676     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
677     wmsProxy->SetMaximizeMode(maximizeMode);
678 }
679 
GetMaximizeMode()680 MaximizeMode WindowAdapter::GetMaximizeMode()
681 {
682     INIT_PROXY_CHECK_RETURN(MaximizeMode::MODE_FULL_FILL);
683 
684     auto wmsProxy = GetWindowManagerServiceProxy();
685     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, MaximizeMode::MODE_FULL_FILL);
686     return wmsProxy->GetMaximizeMode();
687 }
688 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)689 void WindowAdapter::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
690 {
691     INIT_PROXY_CHECK_RETURN();
692 
693     auto wmsProxy = GetWindowManagerServiceProxy();
694     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
695     wmsProxy->GetFocusWindowInfo(focusInfo);
696 }
697 
UpdateSessionAvoidAreaListener(int32_t & persistentId,bool haveListener)698 WMError WindowAdapter::UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener)
699 {
700     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
701 
702     auto wmsProxy = GetWindowManagerServiceProxy();
703     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
704     return static_cast<WMError>(wmsProxy->UpdateSessionAvoidAreaListener(persistentId, haveListener));
705 }
706 
UpdateSessionTouchOutsideListener(int32_t & persistentId,bool haveListener)707 WMError WindowAdapter::UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener)
708 {
709     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
710 
711     auto wmsProxy = GetWindowManagerServiceProxy();
712     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
713     return static_cast<WMError>(
714         wmsProxy->UpdateSessionTouchOutsideListener(persistentId, haveListener));
715 }
716 
NotifyWindowExtensionVisibilityChange(int32_t pid,int32_t uid,bool visible)717 WMError WindowAdapter::NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible)
718 {
719     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
720 
721     auto wmsProxy = GetWindowManagerServiceProxy();
722     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
723     return static_cast<WMError>(wmsProxy->NotifyWindowExtensionVisibilityChange(pid, uid, visible));
724 }
725 
RaiseWindowToTop(int32_t persistentId)726 WMError WindowAdapter::RaiseWindowToTop(int32_t persistentId)
727 {
728     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
729 
730     auto wmsProxy = GetWindowManagerServiceProxy();
731     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
732     return static_cast<WMError>(wmsProxy->RaiseWindowToTop(persistentId));
733 }
734 
UpdateSessionWindowVisibilityListener(int32_t persistentId,bool haveListener)735 WMError WindowAdapter::UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener)
736 {
737     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
738 
739     auto wmsProxy = GetWindowManagerServiceProxy();
740     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
741     WSError ret = wmsProxy->UpdateSessionWindowVisibilityListener(persistentId, haveListener);
742     return static_cast<WMError>(ret);
743 }
744 
ShiftAppWindowFocus(int32_t sourcePersistentId,int32_t targetPersistentId)745 WMError WindowAdapter::ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId)
746 {
747     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
748 
749     auto wmsProxy = GetWindowManagerServiceProxy();
750     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
751     return static_cast<WMError>(
752         wmsProxy->ShiftAppWindowFocus(sourcePersistentId, targetPersistentId));
753 }
754 
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)755 void WindowAdapter::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
756     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
757     sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
758     SystemSessionConfig& systemConfig, sptr<IRemoteObject> token)
759 {
760     INIT_PROXY_CHECK_RETURN();
761 
762     auto wmsProxy = GetWindowManagerServiceProxy();
763     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
764     wmsProxy->CreateAndConnectSpecificSession(sessionStage, eventChannel,
765         surfaceNode, property, persistentId, session, systemConfig, token);
766 }
767 
RecoverAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,sptr<ISession> & session,sptr<IRemoteObject> token)768 void WindowAdapter::RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
769     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
770     sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token)
771 {
772     INIT_PROXY_CHECK_RETURN();
773     TLOGI(WmsLogTag::WMS_RECOVER, "called");
774 
775     auto wmsProxy = GetWindowManagerServiceProxy();
776     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
777     wmsProxy->RecoverAndConnectSpecificSession(
778         sessionStage, eventChannel, surfaceNode, property, session, token);
779 }
780 
DestroyAndDisconnectSpecificSession(const int32_t persistentId)781 WMError WindowAdapter::DestroyAndDisconnectSpecificSession(const int32_t persistentId)
782 {
783     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
784 
785     auto wmsProxy = GetWindowManagerServiceProxy();
786     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
787     return static_cast<WMError>(wmsProxy->DestroyAndDisconnectSpecificSession(persistentId));
788 }
789 
DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,const sptr<IRemoteObject> & callback)790 WMError WindowAdapter::DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,
791     const sptr<IRemoteObject>& callback)
792 {
793     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
794 
795     auto wmsProxy = GetWindowManagerServiceProxy();
796     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
797     return static_cast<WMError>(
798         wmsProxy->DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback));
799 }
800 
RecoverAndReconnectSceneSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<ISession> & session,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)801 WMError WindowAdapter::RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
802     const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
803     sptr<ISession>& session, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
804 {
805     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
806     TLOGI(WmsLogTag::WMS_RECOVER, "called");
807 
808     auto wmsProxy = GetWindowManagerServiceProxy();
809     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
810     auto ret = wmsProxy->RecoverAndReconnectSceneSession(
811         sessionStage, eventChannel, surfaceNode, session, property, token);
812     if (ret != WSError::WS_OK) {
813         TLOGE(WmsLogTag::WMS_RECOVER, "failed, ret = %{public}d", ret);
814         return WMError::WM_DO_NOTHING;
815     }
816     return WMError::WM_OK;
817 }
818 
SetSessionGravity(int32_t persistentId,SessionGravity gravity,uint32_t percent)819 WMError WindowAdapter::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent)
820 {
821     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
822 
823     auto wmsProxy = GetWindowManagerServiceProxy();
824     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
825     return static_cast<WMError>(wmsProxy->SetSessionGravity(persistentId, gravity, percent));
826 }
827 
BindDialogSessionTarget(uint64_t persistentId,sptr<IRemoteObject> targetToken)828 WMError WindowAdapter::BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken)
829 {
830     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
831 
832     auto wmsProxy = GetWindowManagerServiceProxy();
833     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
834     return static_cast<WMError>(wmsProxy->BindDialogSessionTarget(persistentId, targetToken));
835 }
836 
RequestFocusStatus(int32_t persistentId,bool isFocused)837 WMError WindowAdapter::RequestFocusStatus(int32_t persistentId, bool isFocused)
838 {
839     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
840 
841     auto wmsProxy = GetWindowManagerServiceProxy();
842     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
843     return static_cast<WMError>(wmsProxy->RequestFocusStatus(persistentId, isFocused));
844 }
845 
AddExtensionWindowStageToSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,uint64_t surfaceNodeId,bool isConstrainedModal)846 void WindowAdapter::AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage,
847     const sptr<IRemoteObject>& token, uint64_t surfaceNodeId, bool isConstrainedModal)
848 {
849     INIT_PROXY_CHECK_RETURN();
850 
851     auto wmsProxy = GetWindowManagerServiceProxy();
852     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
853     wmsProxy->AddExtensionWindowStageToSCB(sessionStage, token, surfaceNodeId, isConstrainedModal);
854 }
855 
RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage> & sessionStage,const sptr<IRemoteObject> & token,bool isConstrainedModal)856 void WindowAdapter::RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage,
857     const sptr<IRemoteObject>& token, bool isConstrainedModal)
858 {
859     INIT_PROXY_CHECK_RETURN();
860 
861     auto wmsProxy = GetWindowManagerServiceProxy();
862     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
863     wmsProxy->RemoveExtensionWindowStageFromSCB(sessionStage, token, isConstrainedModal);
864 }
865 
ProcessModalExtensionPointDown(const sptr<IRemoteObject> & token,int32_t posX,int32_t posY)866 void WindowAdapter::ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY)
867 {
868     INIT_PROXY_CHECK_RETURN();
869 
870     auto wmsProxy = GetWindowManagerServiceProxy();
871     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
872     wmsProxy->ProcessModalExtensionPointDown(token, posX, posY);
873 }
874 
UpdateModalExtensionRect(const sptr<IRemoteObject> & token,Rect rect)875 void WindowAdapter::UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect)
876 {
877     INIT_PROXY_CHECK_RETURN();
878 
879     auto wmsProxy = GetWindowManagerServiceProxy();
880     CHECK_PROXY_RETURN_IF_NULL(wmsProxy);
881     wmsProxy->UpdateModalExtensionRect(token, rect);
882 }
883 
AddOrRemoveSecureSession(int32_t persistentId,bool shouldHide)884 WMError WindowAdapter::AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide)
885 {
886     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
887 
888     auto wmsProxy = GetWindowManagerServiceProxy();
889     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
890     return static_cast<WMError>(wmsProxy->AddOrRemoveSecureSession(persistentId, shouldHide));
891 }
892 
UpdateExtWindowFlags(const sptr<IRemoteObject> & token,uint32_t extWindowFlags,uint32_t extWindowActions)893 WMError WindowAdapter::UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags,
894     uint32_t extWindowActions)
895 {
896     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
897 
898     auto wmsProxy = GetWindowManagerServiceProxy();
899     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
900     return static_cast<WMError>(wmsProxy->UpdateExtWindowFlags(token, extWindowFlags, extWindowActions));
901 }
902 
GetHostWindowRect(int32_t hostWindowId,Rect & rect)903 WMError WindowAdapter::GetHostWindowRect(int32_t hostWindowId, Rect& rect)
904 {
905     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
906 
907     auto wmsProxy = GetWindowManagerServiceProxy();
908     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
909     return static_cast<WMError>(wmsProxy->GetHostWindowRect(hostWindowId, rect));
910 }
911 
GetFreeMultiWindowEnableState(bool & enable)912 WMError WindowAdapter::GetFreeMultiWindowEnableState(bool& enable)
913 {
914     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
915 
916     auto wmsProxy = GetWindowManagerServiceProxy();
917     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
918     return static_cast<WMError>(wmsProxy->GetFreeMultiWindowEnableState(enable));
919 }
920 
GetCallingWindowWindowStatus(int32_t persistentId,WindowStatus & windowStatus)921 WMError WindowAdapter::GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus)
922 {
923     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
924 
925     auto wmsProxy = GetWindowManagerServiceProxy();
926     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
927     return static_cast<WMError>(wmsProxy->GetCallingWindowWindowStatus(persistentId, windowStatus));
928 }
929 
GetCallingWindowRect(int32_t persistentId,Rect & rect)930 WMError WindowAdapter::GetCallingWindowRect(int32_t persistentId, Rect& rect)
931 {
932     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
933 
934     auto wmsProxy = GetWindowManagerServiceProxy();
935     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
936     return static_cast<WMError>(wmsProxy->GetCallingWindowRect(persistentId, rect));
937 }
938 
GetWindowModeType(WindowModeType & windowModeType)939 WMError WindowAdapter::GetWindowModeType(WindowModeType& windowModeType)
940 {
941     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
942 
943     WLOGFD("get window mode type");
944     auto wmsProxy = GetWindowManagerServiceProxy();
945     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
946     return wmsProxy->GetWindowModeType(windowModeType);
947 }
948 
GetWindowStyleType(WindowStyleType & windowStyleType)949 WMError WindowAdapter::GetWindowStyleType(WindowStyleType& windowStyleType)
950 {
951     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
952     auto wmsProxy = GetWindowManagerServiceProxy();
953     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
954     return wmsProxy->GetWindowStyleType(windowStyleType);
955 }
956 
GetWindowIdsByCoordinate(DisplayId displayId,int32_t windowNumber,int32_t x,int32_t y,std::vector<int32_t> & windowIds)957 WMError WindowAdapter::GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
958     int32_t x, int32_t y, std::vector<int32_t>& windowIds)
959 {
960     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
961     auto wmsProxy = GetWindowManagerServiceProxy();
962     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
963     return wmsProxy->GetWindowIdsByCoordinate(displayId, windowNumber, x, y, windowIds);
964 }
965 
GetWindowManagerServiceProxy() const966 sptr<IWindowManager> WindowAdapter::GetWindowManagerServiceProxy() const
967 {
968     std::lock_guard<std::mutex> lock(mutex_);
969     return windowManagerServiceProxy_;
970 }
971 
ReleaseForegroundSessionScreenLock()972 WMError WindowAdapter::ReleaseForegroundSessionScreenLock()
973 {
974     INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING);
975     auto wmsProxy = GetWindowManagerServiceProxy();
976     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING);
977     return wmsProxy->ReleaseForegroundSessionScreenLock();
978 }
979 
IsWindowRectAutoSave(const std::string & key,bool & enabled)980 WMError WindowAdapter::IsWindowRectAutoSave(const std::string& key, bool& enabled)
981 {
982     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
983     auto wmsProxy = GetWindowManagerServiceProxy();
984     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
985     return wmsProxy->IsWindowRectAutoSave(key, enabled);
986 }
987 
GetDisplayIdByWindowId(const std::vector<uint64_t> & windowIds,std::unordered_map<uint64_t,DisplayId> & windowDisplayIdMap)988 WMError WindowAdapter::GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
989     std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap)
990 {
991     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
992     auto wmsProxy = GetWindowManagerServiceProxy();
993     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
994     return wmsProxy->GetDisplayIdByWindowId(windowIds, windowDisplayIdMap);
995 }
996 
IsPcWindow(bool & isPcWindow)997 WMError WindowAdapter::IsPcWindow(bool& isPcWindow)
998 {
999     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1000     auto wmsProxy = GetWindowManagerServiceProxy();
1001     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1002     return wmsProxy->IsPcWindow(isPcWindow);
1003 }
1004 
IsPcOrPadFreeMultiWindowMode(bool & isPcOrPadFreeMultiWindowMode)1005 WMError WindowAdapter::IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode)
1006 {
1007     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1008     auto wmsProxy = GetWindowManagerServiceProxy();
1009     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1010     return wmsProxy->IsPcOrPadFreeMultiWindowMode(isPcOrPadFreeMultiWindowMode);
1011 }
1012 
ShiftAppWindowPointerEvent(int32_t sourceWindowId,int32_t targetWindowId)1013 WMError WindowAdapter::ShiftAppWindowPointerEvent(int32_t sourceWindowId, int32_t targetWindowId)
1014 {
1015     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1016     auto wmsProxy = GetWindowManagerServiceProxy();
1017     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1018     return wmsProxy->ShiftAppWindowPointerEvent(sourceWindowId, targetWindowId);
1019 }
1020 
SetGlobalDragResizeType(DragResizeType dragResizeType)1021 WMError WindowAdapter::SetGlobalDragResizeType(DragResizeType dragResizeType)
1022 {
1023     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1024     auto wmsProxy = GetWindowManagerServiceProxy();
1025     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1026     return wmsProxy->SetGlobalDragResizeType(dragResizeType);
1027 }
1028 
GetGlobalDragResizeType(DragResizeType & dragResizeType)1029 WMError WindowAdapter::GetGlobalDragResizeType(DragResizeType& dragResizeType)
1030 {
1031     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1032     auto wmsProxy = GetWindowManagerServiceProxy();
1033     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1034     return wmsProxy->GetGlobalDragResizeType(dragResizeType);
1035 }
1036 
SetAppDragResizeType(const std::string & bundleName,DragResizeType dragResizeType)1037 WMError WindowAdapter::SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType)
1038 {
1039     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1040     auto wmsProxy = GetWindowManagerServiceProxy();
1041     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1042     return wmsProxy->SetAppDragResizeType(bundleName, dragResizeType);
1043 }
1044 
GetAppDragResizeType(const std::string & bundleName,DragResizeType & dragResizeType)1045 WMError WindowAdapter::GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType)
1046 {
1047     INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
1048     auto wmsProxy = GetWindowManagerServiceProxy();
1049     CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_ERROR_SAMGR);
1050     return wmsProxy->GetAppDragResizeType(bundleName, dragResizeType);
1051 }
1052 } // namespace Rosen
1053 } // namespace OHOS
1054