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