• 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 "zidl/window_manager_proxy.h"
17 #include <ipc_types.h>
18 #include <key_event.h>
19 #include <rs_iwindow_animation_controller.h>
20 #include <rs_window_animation_target.h>
21 
22 #include "marshalling_helper.h"
23 #include "window_manager_hilog.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 namespace {
28     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerProxy"};
29 }
30 
31 
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId,sptr<IRemoteObject> token)32 WMError WindowManagerProxy::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
33     const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token)
34 {
35     MessageParcel data;
36     MessageParcel reply;
37     MessageOption option;
38     if (!data.WriteInterfaceToken(GetDescriptor())) {
39         WLOGFE("WriteInterfaceToken failed");
40         return WMError::WM_ERROR_IPC_FAILED;
41     }
42 
43     if (!data.WriteRemoteObject(window->AsObject())) {
44         WLOGFE("Write IWindow failed");
45         return WMError::WM_ERROR_IPC_FAILED;
46     }
47 
48     if (!data.WriteParcelable(property.GetRefPtr())) {
49         WLOGFE("Write windowProperty failed");
50         return WMError::WM_ERROR_IPC_FAILED;
51     }
52 
53     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
54         WLOGFE("Write windowProperty failed");
55         return WMError::WM_ERROR_IPC_FAILED;
56     }
57     if (token != nullptr) {
58         if (!data.WriteRemoteObject(token)) {
59             WLOGFE("Write abilityToken failed");
60             return WMError::WM_ERROR_IPC_FAILED;
61         }
62     }
63 
64     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_CREATE_WINDOW),
65         data, reply, option) != ERR_NONE) {
66         return WMError::WM_ERROR_IPC_FAILED;
67     }
68     windowId = reply.ReadUint32();
69     int32_t ret = reply.ReadInt32();
70     property->SetWindowFlags(reply.ReadUint32());
71     property->SetApiCompatibleVersion(reply.ReadUint32());
72     return static_cast<WMError>(ret);
73 }
74 
AddWindow(sptr<WindowProperty> & property)75 WMError WindowManagerProxy::AddWindow(sptr<WindowProperty>& property)
76 {
77     MessageParcel data;
78     MessageParcel reply;
79     MessageOption option;
80     if (!data.WriteInterfaceToken(GetDescriptor())) {
81         WLOGFE("WriteInterfaceToken failed");
82         return WMError::WM_ERROR_IPC_FAILED;
83     }
84 
85     if (!data.WriteParcelable(property.GetRefPtr())) {
86         WLOGFE("Write windowProperty failed");
87         return WMError::WM_ERROR_IPC_FAILED;
88     }
89 
90     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ADD_WINDOW),
91         data, reply, option) != ERR_NONE) {
92         return WMError::WM_ERROR_IPC_FAILED;
93     }
94 
95     int32_t ret = reply.ReadInt32();
96     return static_cast<WMError>(ret);
97 }
98 
RemoveWindow(uint32_t windowId,bool isFromInnerkits)99 WMError WindowManagerProxy::RemoveWindow(uint32_t windowId, bool isFromInnerkits)
100 {
101     MessageParcel data;
102     MessageParcel reply;
103     MessageOption option;
104     if (!data.WriteInterfaceToken(GetDescriptor())) {
105         WLOGFE("WriteInterfaceToken failed");
106         return WMError::WM_ERROR_IPC_FAILED;
107     }
108 
109     if (!data.WriteUint32(windowId)) {
110         WLOGFE("Write windowId failed");
111         return WMError::WM_ERROR_IPC_FAILED;
112     }
113 
114     if (!data.WriteBool(isFromInnerkits)) {
115         WLOGFE("Write isFromInnerkits failed");
116         return WMError::WM_ERROR_IPC_FAILED;
117     }
118 
119     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REMOVE_WINDOW),
120         data, reply, option) != ERR_NONE) {
121         return WMError::WM_ERROR_IPC_FAILED;
122     }
123 
124     int32_t ret = reply.ReadInt32();
125     return static_cast<WMError>(ret);
126 }
127 
DestroyWindow(uint32_t windowId,bool)128 WMError WindowManagerProxy::DestroyWindow(uint32_t windowId, bool /* onlySelf */)
129 {
130     MessageParcel data;
131     MessageParcel reply;
132     MessageOption option;
133     if (!data.WriteInterfaceToken(GetDescriptor())) {
134         WLOGFE("WriteInterfaceToken failed");
135         return WMError::WM_ERROR_IPC_FAILED;
136     }
137 
138     if (!data.WriteUint32(windowId)) {
139         WLOGFE("Write windowId failed");
140         return WMError::WM_ERROR_IPC_FAILED;
141     }
142 
143     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DESTROY_WINDOW),
144         data, reply, option) != ERR_NONE) {
145         return WMError::WM_ERROR_IPC_FAILED;
146     }
147 
148     int32_t ret = reply.ReadInt32();
149     return static_cast<WMError>(ret);
150 }
151 
RequestFocus(uint32_t windowId)152 WMError WindowManagerProxy::RequestFocus(uint32_t windowId)
153 {
154     MessageParcel data;
155     MessageParcel reply;
156     MessageOption option;
157     if (!data.WriteInterfaceToken(GetDescriptor())) {
158         WLOGFE("WriteInterfaceToken failed");
159         return WMError::WM_ERROR_IPC_FAILED;
160     }
161 
162     if (!data.WriteUint32(windowId)) {
163         WLOGFE("Write windowId failed");
164         return WMError::WM_ERROR_IPC_FAILED;
165     }
166     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REQUEST_FOCUS),
167         data, reply, option) != ERR_NONE) {
168         return WMError::WM_ERROR_IPC_FAILED;
169     }
170 
171     int32_t ret = reply.ReadInt32();
172     return static_cast<WMError>(ret);
173 }
174 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType type)175 AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type)
176 {
177     MessageParcel data;
178     MessageParcel reply;
179     MessageOption option;
180 
181     AvoidArea avoidArea;
182     if (!data.WriteInterfaceToken(GetDescriptor())) {
183         WLOGFE("WriteInterfaceToken failed");
184         return avoidArea;
185     }
186 
187     if (!data.WriteUint32(windowId)) {
188         WLOGFE("Write windowId failed");
189         return avoidArea;
190     }
191 
192     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
193         WLOGFE("Write AvoidAreaType failed");
194         return avoidArea;
195     }
196 
197     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_AVOID_AREA),
198         data, reply, option) != ERR_NONE) {
199         return avoidArea;
200     }
201     sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
202     if (area == nullptr) {
203         return avoidArea;
204     }
205     return *area;
206 }
207 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)208 WMError WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
209     const sptr<IWindowManagerAgent>& windowManagerAgent)
210 {
211     MessageParcel data;
212     MessageParcel reply;
213     MessageOption option;
214     if (!data.WriteInterfaceToken(GetDescriptor())) {
215         WLOGFE("WriteInterfaceToken failed");
216         return WMError::WM_ERROR_IPC_FAILED;
217     }
218 
219     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
220         WLOGFE("Write type failed");
221         return WMError::WM_ERROR_IPC_FAILED;
222     }
223 
224     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
225         WLOGFE("Write IWindowManagerAgent failed");
226         return WMError::WM_ERROR_IPC_FAILED;
227     }
228 
229     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
230         data, reply, option) != ERR_NONE) {
231         WLOGFE("SendRequest failed");
232         return WMError::WM_ERROR_IPC_FAILED;
233     }
234 
235     return static_cast<WMError>(reply.ReadInt32());
236 }
237 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)238 WMError WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
239     const sptr<IWindowManagerAgent>& windowManagerAgent)
240 {
241     MessageParcel data;
242     MessageParcel reply;
243     MessageOption option;
244     if (!data.WriteInterfaceToken(GetDescriptor())) {
245         WLOGFE("WriteInterfaceToken failed");
246         return WMError::WM_ERROR_IPC_FAILED;
247     }
248 
249     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
250         WLOGFE("Write type failed");
251         return WMError::WM_ERROR_IPC_FAILED;
252     }
253 
254     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
255         WLOGFE("Write IWindowManagerAgent failed");
256         return WMError::WM_ERROR_IPC_FAILED;
257     }
258 
259     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
260         data, reply, option) != ERR_NONE) {
261         WLOGFE("SendRequest failed");
262         return WMError::WM_ERROR_IPC_FAILED;
263     }
264 
265     return static_cast<WMError>(reply.ReadInt32());
266 }
267 
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)268 WMError WindowManagerProxy::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
269 {
270     MessageParcel data;
271     MessageParcel reply;
272     MessageOption option;
273 
274     if (controller == nullptr) {
275         WLOGFE("RSWindowAnimation Failed to set window animation controller, controller is null!");
276         return WMError::WM_ERROR_IPC_FAILED;
277     }
278 
279     if (!data.WriteInterfaceToken(GetDescriptor())) {
280         WLOGFE("RSWindowAnimation Failed to WriteInterfaceToken!");
281         return WMError::WM_ERROR_IPC_FAILED;
282     }
283 
284     if (!data.WriteRemoteObject(controller->AsObject())) {
285         WLOGFE("RSWindowAnimation Failed to write controller!");
286         return WMError::WM_ERROR_IPC_FAILED;
287     }
288 
289     auto error = Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER),
290         data, reply, option);
291     if (error != ERR_NONE) {
292         WLOGFE("RSWindowAnimation Send request error: %{public}d", error);
293         return WMError::WM_ERROR_IPC_FAILED;
294     }
295 
296     int32_t ret = reply.ReadInt32();
297     return static_cast<WMError>(ret);
298 }
299 
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)300 void WindowManagerProxy::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
301     sptr<MoveDragProperty>& moveDragProperty)
302 {
303     MessageParcel data;
304     MessageParcel reply;
305     MessageOption option;
306     if (!data.WriteInterfaceToken(GetDescriptor())) {
307         WLOGFE("WriteInterfaceToken failed");
308         return;
309     }
310     if (!data.WriteUint32(windowId)) {
311         WLOGFE("Write windowId failed");
312         return;
313     }
314     if (!data.WriteParcelable(windowProperty.GetRefPtr())) {
315         WLOGFE("Failed to write windowProperty!");
316         return;
317     }
318     if (!data.WriteParcelable(moveDragProperty.GetRefPtr())) {
319         WLOGFE("Failed to write moveDragProperty!");
320         return;
321     }
322     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG),
323         data, reply, option) != ERR_NONE) {
324         WLOGFE("SendRequest failed");
325     }
326 }
327 
ProcessPointDown(uint32_t windowId,bool isPointDown)328 void WindowManagerProxy::ProcessPointDown(uint32_t windowId, bool isPointDown)
329 {
330     MessageParcel data;
331     MessageParcel reply;
332     MessageOption option;
333     if (!data.WriteInterfaceToken(GetDescriptor())) {
334         WLOGFE("WriteInterfaceToken failed");
335         return;
336     }
337     if (!data.WriteUint32(windowId)) {
338         WLOGFE("Write windowId failed");
339         return;
340     }
341     if (!data.WriteBool(isPointDown)) {
342         WLOGFE("Write isPointDown failed");
343         return;
344     }
345     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN),
346         data, reply, option) != ERR_NONE) {
347         WLOGFE("SendRequest failed");
348     }
349 }
350 
ProcessPointUp(uint32_t windowId)351 void WindowManagerProxy::ProcessPointUp(uint32_t windowId)
352 {
353     MessageParcel data;
354     MessageParcel reply;
355     MessageOption option;
356     if (!data.WriteInterfaceToken(GetDescriptor())) {
357         WLOGFE("WriteInterfaceToken failed");
358         return;
359     }
360     if (!data.WriteUint32(windowId)) {
361         WLOGFE("Write windowId failed");
362         return;
363     }
364     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP),
365         data, reply, option) != ERR_NONE) {
366         WLOGFE("SendRequest failed");
367     }
368 }
369 
MinimizeAllAppWindows(DisplayId displayId)370 WMError WindowManagerProxy::MinimizeAllAppWindows(DisplayId displayId)
371 {
372     MessageParcel data;
373     MessageParcel reply;
374     MessageOption option;
375     if (!data.WriteInterfaceToken(GetDescriptor())) {
376         WLOGFE("WriteInterfaceToken failed");
377         return WMError::WM_ERROR_IPC_FAILED;
378     }
379     if (!data.WriteUint64(displayId)) {
380         WLOGFE("Write displayId failed");
381         return WMError::WM_ERROR_IPC_FAILED;
382     }
383     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS),
384         data, reply, option) != ERR_NONE) {
385         WLOGFE("SendRequest failed");
386         return WMError::WM_ERROR_IPC_FAILED;
387     }
388 
389     int32_t ret;
390     if (!reply.ReadInt32(ret)) {
391         return WMError::WM_ERROR_IPC_FAILED;
392     }
393 
394     WLOGFE("MinimizeAllAppWindows: %{public}u", ret);
395     return static_cast<WMError>(ret);
396 }
397 
ToggleShownStateForAllAppWindows()398 WMError WindowManagerProxy::ToggleShownStateForAllAppWindows()
399 {
400     MessageParcel data;
401     MessageParcel reply;
402     MessageOption option;
403     if (!data.WriteInterfaceToken(GetDescriptor())) {
404         WLOGFE("WriteInterfaceToken failed");
405         return WMError::WM_ERROR_IPC_FAILED;
406     }
407     if (Remote()->SendRequest(
408         static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS),
409         data, reply, option) != ERR_NONE) {
410         WLOGFE("SendRequest failed");
411         return WMError::WM_ERROR_IPC_FAILED;
412     }
413     int32_t ret;
414     if (!reply.ReadInt32(ret)) {
415         return WMError::WM_ERROR_IPC_FAILED;
416     }
417     return static_cast<WMError>(ret);
418 }
419 
SetWindowLayoutMode(WindowLayoutMode mode)420 WMError WindowManagerProxy::SetWindowLayoutMode(WindowLayoutMode mode)
421 {
422     MessageParcel data;
423     MessageParcel reply;
424     MessageOption option;
425     if (!data.WriteInterfaceToken(GetDescriptor())) {
426         WLOGFE("WriteInterfaceToken failed");
427         return WMError::WM_ERROR_IPC_FAILED;
428     }
429     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
430         WLOGFE("Write mode failed");
431         return WMError::WM_ERROR_IPC_FAILED;
432     }
433     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE),
434         data, reply, option) != ERR_NONE) {
435         return WMError::WM_ERROR_IPC_FAILED;
436     }
437 
438     int32_t ret = reply.ReadInt32();
439     return static_cast<WMError>(ret);
440 }
441 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)442 WMError WindowManagerProxy::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
443     bool isAsyncTask)
444 {
445     MessageParcel data;
446     MessageParcel reply;
447     MessageOption option;
448     if (!data.WriteInterfaceToken(GetDescriptor())) {
449         WLOGFE("WriteInterfaceToken failed");
450         return WMError::WM_ERROR_IPC_FAILED;
451     }
452 
453     if (!data.WriteUint32(static_cast<uint32_t>(action))) {
454         WLOGFE("Write PropertyChangeAction failed");
455         return WMError::WM_ERROR_IPC_FAILED;
456     }
457 
458     if (!windowProperty->Write(data, action)) {
459         WLOGFE("Write windowProperty failed");
460         return WMError::WM_ERROR_IPC_FAILED;
461     }
462 
463     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY),
464         data, reply, option) != ERR_NONE) {
465         return WMError::WM_ERROR_IPC_FAILED;
466     }
467 
468     int32_t ret = reply.ReadInt32();
469     return static_cast<WMError>(ret);
470 }
471 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)472 WMError WindowManagerProxy::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
473 {
474     MessageParcel data;
475     if (!data.WriteInterfaceToken(GetDescriptor())) {
476         WLOGFE("WriteInterfaceToken failed");
477         return WMError::WM_ERROR_IPC_FAILED;
478     }
479     if (!data.WriteUint32(windowId)) {
480         WLOGFE("Write mainWinId failed");
481         return WMError::WM_ERROR_IPC_FAILED;
482     }
483     if (!data.WriteUint32(static_cast<uint32_t>(gravity))) {
484         WLOGFE("Write mainWinId failed");
485         return WMError::WM_ERROR_IPC_FAILED;
486     }
487     if (!data.WriteUint32(percent)) {
488         WLOGFE("Write mainWinId failed");
489         return WMError::WM_ERROR_IPC_FAILED;
490     }
491 
492     MessageParcel reply;
493     MessageOption option;
494     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY),
495         data, reply, option) != ERR_NONE) {
496         return WMError::WM_ERROR_IPC_FAILED;
497     }
498 
499     int32_t ret = reply.ReadInt32();
500     return static_cast<WMError>(ret);
501 }
502 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)503 WMError WindowManagerProxy::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
504 {
505     MessageParcel data;
506     MessageParcel reply;
507     MessageOption option;
508     if (!data.WriteInterfaceToken(GetDescriptor())) {
509         WLOGFE("WriteInterfaceToken failed");
510         return WMError::WM_ERROR_IPC_FAILED;
511     }
512 
513     if (!data.WriteUint32(mainWinId)) {
514         WLOGFE("Write mainWinId failed");
515         return WMError::WM_ERROR_IPC_FAILED;
516     }
517 
518     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
519         data, reply, option) != ERR_NONE) {
520         return WMError::WM_ERROR_IPC_FAILED;
521     }
522     topWinId = reply.ReadUint32();
523     int32_t ret = reply.ReadInt32();
524     return static_cast<WMError>(ret);
525 }
526 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)527 WMError WindowManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
528 {
529     MessageParcel data;
530     MessageParcel reply;
531     MessageOption option;
532     if (!data.WriteInterfaceToken(GetDescriptor())) {
533         WLOGFE("WriteInterfaceToken failed");
534         return WMError::WM_ERROR_IPC_FAILED;
535     }
536     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID),
537         data, reply, option) != ERR_NONE) {
538         return WMError::WM_ERROR_IPC_FAILED;
539     }
540     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
541         WLOGFE("read accessibility window infos failed");
542         return WMError::WM_ERROR_IPC_FAILED;
543     }
544     return static_cast<WMError>(reply.ReadInt32());
545 }
546 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)547 WMError WindowManagerProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
548 {
549     MessageParcel data;
550     MessageParcel reply;
551     MessageOption option;
552     if (!data.WriteInterfaceToken(GetDescriptor())) {
553         WLOGFE("WriteInterfaceToken failed");
554         return WMError::WM_ERROR_IPC_FAILED;
555     }
556     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID),
557         data, reply, option) != ERR_NONE) {
558         return WMError::WM_ERROR_IPC_FAILED;
559     }
560     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
561         WLOGFE("read visibility window infos failed");
562         return WMError::WM_ERROR_IPC_FAILED;
563     }
564     return static_cast<WMError>(reply.ReadInt32());
565 }
566 
GetSystemConfig(SystemConfig & systemConfig)567 WMError WindowManagerProxy::GetSystemConfig(SystemConfig& systemConfig)
568 {
569     MessageParcel data;
570     MessageParcel reply;
571     MessageOption option;
572     if (!data.WriteInterfaceToken(GetDescriptor())) {
573         WLOGFE("WriteInterfaceToken failed");
574         return WMError::WM_ERROR_IPC_FAILED;
575     }
576     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG),
577         data, reply, option) != ERR_NONE) {
578         return WMError::WM_ERROR_IPC_FAILED;
579     }
580     sptr<SystemConfig> config = reply.ReadParcelable<SystemConfig>();
581     systemConfig = *config;
582     int32_t ret = reply.ReadInt32();
583     return static_cast<WMError>(ret);
584 }
585 
NotifyWindowTransition(sptr<WindowTransitionInfo> & from,sptr<WindowTransitionInfo> & to,bool isFromClient)586 WMError WindowManagerProxy::NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
587     bool isFromClient)
588 {
589     MessageParcel data;
590     MessageParcel reply;
591     MessageOption option;
592 
593     if (!data.WriteInterfaceToken(GetDescriptor())) {
594         WLOGFE("Failed to WriteInterfaceToken!");
595         return WMError::WM_ERROR_IPC_FAILED;
596     }
597 
598     if (!data.WriteParcelable(from)) {
599         WLOGFE("Failed to write from ability window info!");
600         return WMError::WM_ERROR_IPC_FAILED;
601     }
602 
603     if (!data.WriteParcelable(to)) {
604         WLOGFE("Failed to write to ability window info!");
605         return WMError::WM_ERROR_IPC_FAILED;
606     }
607 
608     if (!data.WriteBool(isFromClient)) {
609         WLOGFE("Failed to write to isFromClient!");
610         return WMError::WM_ERROR_IPC_FAILED;
611     }
612     auto error = Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION),
613         data, reply, option);
614     if (error != ERR_NONE) {
615         WLOGFE("Send request error: %{public}d", static_cast<uint32_t>(error));
616         return WMError::WM_ERROR_IPC_FAILED;
617     }
618     auto ret = static_cast<WMError>(reply.ReadInt32());
619     return ret;
620 }
621 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)622 WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
623 {
624     MessageParcel data;
625     MessageParcel reply;
626     MessageOption option;
627 
628     if (!data.WriteInterfaceToken(GetDescriptor())) {
629         WLOGFE("WriteInterfaceToken failed");
630         return WMError::WM_ERROR_IPC_FAILED;
631     }
632     if (!data.WriteUint64(displayId)) {
633         WLOGFE("Write displayId failed");
634         return WMError::WM_ERROR_IPC_FAILED;
635     }
636     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
637         data, reply, option) != ERR_NONE) {
638         return WMError::WM_ERROR_IPC_FAILED;
639     }
640 
641     auto ret = static_cast<WMError>(reply.ReadInt32());
642     if (ret == WMError::WM_OK) {
643         hotZones.fullscreen_.posX_ = reply.ReadInt32();
644         hotZones.fullscreen_.posY_ = reply.ReadInt32();
645         hotZones.fullscreen_.width_ = reply.ReadUint32();
646         hotZones.fullscreen_.height_ = reply.ReadUint32();
647 
648         hotZones.primary_.posX_ = reply.ReadInt32();
649         hotZones.primary_.posY_ = reply.ReadInt32();
650         hotZones.primary_.width_ = reply.ReadUint32();
651         hotZones.primary_.height_ = reply.ReadUint32();
652 
653         hotZones.secondary_.posX_ = reply.ReadInt32();
654         hotZones.secondary_.posY_ = reply.ReadInt32();
655         hotZones.secondary_.width_ = reply.ReadUint32();
656         hotZones.secondary_.height_ = reply.ReadUint32();
657     }
658     return ret;
659 }
660 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)661 void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
662     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
663 {
664     MessageParcel data;
665     MessageParcel reply;
666     MessageOption option;
667     if (!data.WriteInterfaceToken(GetDescriptor())) {
668         WLOGFE("WriteInterfaceToken failed");
669         return;
670     }
671 
672     if (!data.WriteUInt32Vector(windowIds)) {
673         WLOGFE("Write windowIds failed");
674         return;
675     }
676 
677     if (!data.WriteBool(isAnimated)) {
678         WLOGFE("Write isAnimated failed");
679         return;
680     }
681     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK),
682         data, reply, option) != ERR_NONE) {
683         WLOGFE("Send request error");
684         return;
685     }
686     ;
687     if (reply.ReadBool()) {
688         sptr<IRemoteObject> finishCallbackObject = reply.ReadRemoteObject();
689         finishCallback = iface_cast<RSIWindowAnimationFinishedCallback>(finishCallbackObject);
690     } else {
691         finishCallback = nullptr;
692     }
693     return;
694 }
695 
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)696 WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
697 {
698     MessageParcel data;
699     MessageParcel reply;
700     MessageOption option;
701 
702     if (!data.WriteInterfaceToken(GetDescriptor())) {
703         WLOGFE("WriteInterfaceToken failed");
704         return WMError::WM_ERROR_IPC_FAILED;
705     }
706     if (!data.WriteUint32(windowId)) {
707         WLOGFE("Write windowId failed");
708         return WMError::WM_ERROR_IPC_FAILED;
709     }
710     if (!data.WriteBool(haveListener)) {
711         WLOGFE("Write avoid area listener failed");
712         return WMError::WM_ERROR_IPC_FAILED;
713     }
714     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
715         data, reply, option) != ERR_NONE) {
716         return WMError::WM_ERROR_IPC_FAILED;
717     }
718     return static_cast<WMError>(reply.ReadInt32());
719 }
720 
UpdateRsTree(uint32_t windowId,bool isAdd)721 WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd)
722 {
723     MessageParcel data;
724     MessageParcel reply;
725     MessageOption option(MessageOption::TF_ASYNC);
726 
727     if (!data.WriteInterfaceToken(GetDescriptor())) {
728         WLOGFE("WriteInterfaceToken failed");
729         return WMError::WM_ERROR_IPC_FAILED;
730     }
731     if (!data.WriteUint32(windowId)) {
732         WLOGFE("Write windowId failed");
733         return WMError::WM_ERROR_IPC_FAILED;
734     }
735     if (!data.WriteBool(isAdd)) {
736         WLOGFE("Write avoid area listener failed");
737         return WMError::WM_ERROR_IPC_FAILED;
738     }
739     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE),
740         data, reply, option) != ERR_NONE) {
741         return WMError::WM_ERROR_IPC_FAILED;
742     }
743     return static_cast<WMError>(reply.ReadInt32());
744 }
745 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)746 WMError WindowManagerProxy::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
747 {
748     MessageParcel data;
749     MessageParcel reply;
750     MessageOption option;
751     if (!data.WriteInterfaceToken(GetDescriptor())) {
752         WLOGFE("WriteInterfaceToken failed");
753         return WMError::WM_ERROR_IPC_FAILED;
754     }
755     if (!data.WriteUint32(windowId)) {
756         WLOGFE("Write windowId failed");
757         return WMError::WM_ERROR_IPC_FAILED;
758     }
759     if (targetToken != nullptr) {
760         if (!data.WriteRemoteObject(targetToken)) {
761             WLOGFE("Write targetToken failed");
762             return WMError::WM_ERROR_IPC_FAILED;
763         }
764     }
765     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
766         data, reply, option) != ERR_NONE) {
767         return WMError::WM_ERROR_IPC_FAILED;
768     }
769 
770     int32_t ret = reply.ReadInt32();
771     return static_cast<WMError>(ret);
772 }
773 
SetAnchorAndScale(int32_t x,int32_t y,float scale)774 void WindowManagerProxy::SetAnchorAndScale(int32_t x, int32_t y, float scale)
775 {
776     MessageParcel data;
777     MessageParcel reply;
778     MessageOption option;
779     if (!data.WriteInterfaceToken(GetDescriptor())) {
780         WLOGFE("WriteInterfaceToken failed");
781         return;
782     }
783     if (!data.WriteInt32(x)) {
784         WLOGFE("Write anchor x failed");
785         return;
786     }
787     if (!data.WriteInt32(y)) {
788         WLOGFE("Write anchor y failed");
789         return;
790     }
791     if (!data.WriteFloat(scale)) {
792         WLOGFE("Write scale failed");
793         return;
794     }
795     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE),
796         data, reply, option) != ERR_NONE) {
797         WLOGFE("SendRequest failed");
798     }
799 }
800 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)801 void WindowManagerProxy::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
802 {
803     MessageParcel data;
804     MessageParcel reply;
805     MessageOption option;
806     if (!data.WriteInterfaceToken(GetDescriptor())) {
807         WLOGFE("WriteInterfaceToken failed");
808         return;
809     }
810     if (!data.WriteInt32(deltaX)) {
811         WLOGFE("Write anchor delatX failed");
812         return;
813     }
814     if (!data.WriteInt32(deltaY)) {
815         WLOGFE("Write anchor deltaY failed");
816         return;
817     }
818     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET),
819         data, reply, option) != ERR_NONE) {
820         WLOGFE("SendRequest failed");
821     }
822 }
823 
OffWindowZoom()824 void WindowManagerProxy::OffWindowZoom()
825 {
826     MessageParcel data;
827     MessageParcel reply;
828     MessageOption option;
829     if (!data.WriteInterfaceToken(GetDescriptor())) {
830         WLOGFE("WriteInterfaceToken failed");
831         return;
832     }
833     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM),
834         data, reply, option) != ERR_NONE) {
835         WLOGFE("SendRequest failed");
836     }
837 }
838 
RaiseToAppTop(uint32_t windowId)839 WmErrorCode WindowManagerProxy::RaiseToAppTop(uint32_t windowId)
840 {
841     MessageParcel data;
842     MessageParcel reply;
843     MessageOption option;
844     if (!data.WriteInterfaceToken(GetDescriptor())) {
845         WLOGFE("WriteInterfaceToken failed");
846         return WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY;
847     }
848 
849     if (!data.WriteUint32(windowId)) {
850         WLOGFE("Write anchor delatX failed");
851         return WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY;
852     }
853 
854     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER),
855         data, reply, option) != ERR_NONE) {
856         WLOGFE("SendRequest failed");
857         return WmErrorCode::WM_ERROR_SYSTEM_ABNORMALLY;
858     }
859     return WmErrorCode::WM_OK;
860 }
861 
GetSnapshot(int32_t windowId)862 std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowId)
863 {
864     MessageParcel data;
865     MessageParcel reply;
866     MessageOption option;
867 
868     Media::InitializationOptions opts;
869     opts.size.width = 200;  // 200:default width
870     opts.size.height = 300; // 300:default height
871     std::shared_ptr<Media::PixelMap> pixelMap(Media::PixelMap::Create(opts).release());
872     if (!data.WriteInterfaceToken(GetDescriptor())) {
873         WLOGFE("WriteInterfaceToken failed");
874         return pixelMap;
875     }
876     if (!data.WriteUint32(windowId)) {
877         WLOGFE("Write windowId failed");
878         return pixelMap;
879     }
880     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SNAPSHOT),
881         data, reply, option) != ERR_NONE) {
882         return pixelMap;
883     }
884 
885     std::shared_ptr<Media::PixelMap> map(reply.ReadParcelable<Media::PixelMap>());
886     if (map == nullptr) {
887         return pixelMap;
888     }
889     return map;
890 }
891 
SetGestureNavigaionEnabled(bool enable)892 WMError WindowManagerProxy::SetGestureNavigaionEnabled(bool enable)
893 {
894     MessageParcel data;
895     MessageParcel reply;
896     MessageOption option;
897     if (!data.WriteInterfaceToken(GetDescriptor())) {
898         WLOGFE("WriteInterfaceToken failed");
899         return WMError::WM_ERROR_IPC_FAILED;
900     }
901 
902     if (!data.WriteBool(enable)) {
903         WLOGFE("Write anchor delatX failed");
904         return WMError::WM_ERROR_IPC_FAILED;
905     }
906 
907     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED),
908         data, reply, option) != ERR_NONE) {
909         WLOGFE("SendRequest failed");
910         return WMError::WM_ERROR_IPC_FAILED;
911     }
912     int32_t ret = reply.ReadInt32();
913     return static_cast<WMError>(ret);
914 }
915 
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)916 void WindowManagerProxy::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
917 {
918     MessageParcel data;
919     MessageParcel reply;
920     MessageOption option(MessageOption::TF_ASYNC);
921     if (!data.WriteInterfaceToken(GetDescriptor())) {
922         WLOGFE("WriteInterfaceToken failed");
923         return;
924     }
925     if (!data.WriteUint32(windowId)) {
926         WLOGFE("Write anchor delatX failed");
927         return;
928     }
929     if (!event->WriteToParcel(data)) {
930         WLOGFE("Write event faild");
931         return;
932     }
933     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT),
934         data, reply, option) != ERR_NONE) {
935         WLOGFE("SendRequest failed");
936         return;
937     }
938 }
939 
NotifyDumpInfoResult(const std::vector<std::string> & info)940 void WindowManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
941 {
942     MessageParcel data;
943     MessageParcel reply;
944     MessageOption option(MessageOption::TF_ASYNC);
945     if (!data.WriteInterfaceToken(GetDescriptor())) {
946         WLOGFE("WriteInterfaceToken pfailed");
947         return;
948     }
949     if (!data.WriteStringVector(info)) {
950         WLOGFE("Write info failed");
951         return;
952     }
953     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
954         data, reply, option) != ERR_NONE) {
955         WLOGFE("SendRequest failed");
956         return;
957     }
958 }
959 
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)960 WMError WindowManagerProxy::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
961     std::vector<sptr<RSWindowAnimationTarget>>& targets)
962 {
963     MessageParcel data;
964     MessageParcel reply;
965     MessageOption option;
966     if (!data.WriteInterfaceToken(GetDescriptor())) {
967         WLOGFE("write interfaceToken failed");
968         return WMError::WM_ERROR_IPC_FAILED;
969     }
970     if (!data.WriteUInt32Vector(missionIds)) {
971         WLOGFE("Write missionIds failed");
972         return WMError::WM_ERROR_IPC_FAILED;
973     }
974     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS),
975         data, reply, option) != ERR_NONE) {
976         return WMError::WM_ERROR_IPC_FAILED;
977     }
978     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<RSWindowAnimationTarget>(reply, targets)) {
979         WLOGFE("read window animation targets failed");
980         return WMError::WM_ERROR_IPC_FAILED;
981     }
982     return static_cast<WMError>(reply.ReadInt32());
983 }
984 
SetMaximizeMode(MaximizeMode maximizeMode)985 void WindowManagerProxy::SetMaximizeMode(MaximizeMode maximizeMode)
986 {
987     MessageParcel data;
988     MessageOption option;
989     MessageParcel reply;
990     if (!data.WriteInterfaceToken(GetDescriptor())) {
991         WLOGFE("WriteInterfaceToken failed!");
992         return;
993     }
994     if (!data.WriteInt32(static_cast<uint32_t>(maximizeMode))) {
995         WLOGFE("Write maximizeMode failed");
996         return;
997     }
998     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_MAXIMIZE_MODE),
999         data, reply, option) != ERR_NONE) {
1000         WLOGFE("SendRequest failed");
1001     }
1002 }
1003 
GetMaximizeMode()1004 MaximizeMode WindowManagerProxy::GetMaximizeMode()
1005 {
1006     MessageParcel data;
1007     MessageParcel reply;
1008     MessageOption option;
1009     if (!data.WriteInterfaceToken(GetDescriptor())) {
1010         WLOGFE("WriteInterfaceToken failed");
1011         return MaximizeMode::MODE_FULL_FILL;
1012     }
1013 
1014     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_MAXIMIZE_MODE),
1015         data, reply, option) != ERR_NONE) {
1016         WLOGFE("SendRequest failed");
1017         return MaximizeMode::MODE_FULL_FILL;
1018     }
1019     int32_t ret = reply.ReadInt32();
1020     return static_cast<MaximizeMode>(ret);
1021 }
1022 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)1023 void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
1024 {
1025     MessageParcel data;
1026     MessageParcel reply;
1027     MessageOption option;
1028     if (!data.WriteInterfaceToken(GetDescriptor())) {
1029         WLOGFE("WriteInterfaceToken failed");
1030         return;
1031     }
1032 
1033     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO),
1034         data, reply, option) != ERR_NONE) {
1035         WLOGFE("SendRequest failed");
1036         return;
1037     }
1038     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
1039     focusInfo = *info;
1040 }
1041 } // namespace Rosen
1042 } // namespace OHOS
1043