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