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     sptr<IRemoteObject> remote = Remote();
65     if (remote == nullptr) {
66         WLOGFE("remote is null");
67         return WMError::WM_ERROR_IPC_FAILED;
68     }
69     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_CREATE_WINDOW),
70         data, reply, option) != ERR_NONE) {
71         return WMError::WM_ERROR_IPC_FAILED;
72     }
73     windowId = reply.ReadUint32();
74     int32_t ret = reply.ReadInt32();
75     property->SetWindowFlags(reply.ReadUint32());
76     property->SetApiCompatibleVersion(reply.ReadUint32());
77     return static_cast<WMError>(ret);
78 }
79 
AddWindow(sptr<WindowProperty> & property)80 WMError WindowManagerProxy::AddWindow(sptr<WindowProperty>& property)
81 {
82     MessageParcel data;
83     MessageParcel reply;
84     MessageOption option;
85     if (!data.WriteInterfaceToken(GetDescriptor())) {
86         WLOGFE("WriteInterfaceToken failed");
87         return WMError::WM_ERROR_IPC_FAILED;
88     }
89 
90     if (!data.WriteParcelable(property.GetRefPtr())) {
91         WLOGFE("Write windowProperty failed");
92         return WMError::WM_ERROR_IPC_FAILED;
93     }
94 
95     sptr<IRemoteObject> remote = Remote();
96     if (remote == nullptr) {
97         WLOGFE("remote is null");
98         return WMError::WM_ERROR_IPC_FAILED;
99     }
100     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ADD_WINDOW),
101         data, reply, option) != ERR_NONE) {
102         return WMError::WM_ERROR_IPC_FAILED;
103     }
104 
105     int32_t ret = reply.ReadInt32();
106     return static_cast<WMError>(ret);
107 }
108 
RemoveWindow(uint32_t windowId,bool isFromInnerkits)109 WMError WindowManagerProxy::RemoveWindow(uint32_t windowId, bool isFromInnerkits)
110 {
111     MessageParcel data;
112     MessageParcel reply;
113     MessageOption option;
114     if (!data.WriteInterfaceToken(GetDescriptor())) {
115         WLOGFE("WriteInterfaceToken failed");
116         return WMError::WM_ERROR_IPC_FAILED;
117     }
118 
119     if (!data.WriteUint32(windowId)) {
120         WLOGFE("Write windowId failed");
121         return WMError::WM_ERROR_IPC_FAILED;
122     }
123 
124     if (!data.WriteBool(isFromInnerkits)) {
125         WLOGFE("Write isFromInnerkits failed");
126         return WMError::WM_ERROR_IPC_FAILED;
127     }
128 
129     sptr<IRemoteObject> remote = Remote();
130     if (remote == nullptr) {
131         WLOGFE("remote is null");
132         return WMError::WM_ERROR_IPC_FAILED;
133     }
134     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REMOVE_WINDOW),
135         data, reply, option) != ERR_NONE) {
136         return WMError::WM_ERROR_IPC_FAILED;
137     }
138 
139     int32_t ret = reply.ReadInt32();
140     return static_cast<WMError>(ret);
141 }
142 
DestroyWindow(uint32_t windowId,bool)143 WMError WindowManagerProxy::DestroyWindow(uint32_t windowId, bool /* onlySelf */)
144 {
145     MessageParcel data;
146     MessageParcel reply;
147     MessageOption option;
148     if (!data.WriteInterfaceToken(GetDescriptor())) {
149         WLOGFE("WriteInterfaceToken failed");
150         return WMError::WM_ERROR_IPC_FAILED;
151     }
152 
153     if (!data.WriteUint32(windowId)) {
154         WLOGFE("Write windowId failed");
155         return WMError::WM_ERROR_IPC_FAILED;
156     }
157 
158     sptr<IRemoteObject> remote = Remote();
159     if (remote == nullptr) {
160         WLOGFE("remote is null");
161         return WMError::WM_ERROR_IPC_FAILED;
162     }
163     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DESTROY_WINDOW),
164         data, reply, option) != ERR_NONE) {
165         return WMError::WM_ERROR_IPC_FAILED;
166     }
167 
168     int32_t ret = reply.ReadInt32();
169     return static_cast<WMError>(ret);
170 }
171 
RequestFocus(uint32_t windowId)172 WMError WindowManagerProxy::RequestFocus(uint32_t windowId)
173 {
174     MessageParcel data;
175     MessageParcel reply;
176     MessageOption option;
177     if (!data.WriteInterfaceToken(GetDescriptor())) {
178         WLOGFE("WriteInterfaceToken failed");
179         return WMError::WM_ERROR_IPC_FAILED;
180     }
181 
182     if (!data.WriteUint32(windowId)) {
183         WLOGFE("Write windowId failed");
184         return WMError::WM_ERROR_IPC_FAILED;
185     }
186     sptr<IRemoteObject> remote = Remote();
187     if (remote == nullptr) {
188         WLOGFE("remote is null");
189         return WMError::WM_ERROR_IPC_FAILED;
190     }
191     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REQUEST_FOCUS),
192         data, reply, option) != ERR_NONE) {
193         return WMError::WM_ERROR_IPC_FAILED;
194     }
195 
196     int32_t ret = reply.ReadInt32();
197     return static_cast<WMError>(ret);
198 }
199 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType type)200 AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type)
201 {
202     MessageParcel data;
203     MessageParcel reply;
204     MessageOption option;
205 
206     AvoidArea avoidArea;
207     if (!data.WriteInterfaceToken(GetDescriptor())) {
208         WLOGFE("WriteInterfaceToken failed");
209         return avoidArea;
210     }
211 
212     if (!data.WriteUint32(windowId)) {
213         WLOGFE("Write windowId failed");
214         return avoidArea;
215     }
216 
217     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
218         WLOGFE("Write AvoidAreaType failed");
219         return avoidArea;
220     }
221 
222     sptr<IRemoteObject> remote = Remote();
223     if (remote == nullptr) {
224         WLOGFE("remote is null");
225         return avoidArea;
226     }
227     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_AVOID_AREA),
228         data, reply, option) != ERR_NONE) {
229         return avoidArea;
230     }
231     sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
232     if (area == nullptr) {
233         return avoidArea;
234     }
235     return *area;
236 }
237 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)238 WMError WindowManagerProxy::RegisterWindowManagerAgent(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     sptr<IRemoteObject> remote = Remote();
260     if (remote == nullptr) {
261         WLOGFE("remote is null");
262         return WMError::WM_ERROR_IPC_FAILED;
263     }
264     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
265         data, reply, option) != ERR_NONE) {
266         WLOGFE("SendRequest failed");
267         return WMError::WM_ERROR_IPC_FAILED;
268     }
269 
270     return static_cast<WMError>(reply.ReadInt32());
271 }
272 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)273 WMError WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
274     const sptr<IWindowManagerAgent>& windowManagerAgent)
275 {
276     MessageParcel data;
277     MessageParcel reply;
278     MessageOption option;
279     if (!data.WriteInterfaceToken(GetDescriptor())) {
280         WLOGFE("WriteInterfaceToken failed");
281         return WMError::WM_ERROR_IPC_FAILED;
282     }
283 
284     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
285         WLOGFE("Write type failed");
286         return WMError::WM_ERROR_IPC_FAILED;
287     }
288 
289     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
290         WLOGFE("Write IWindowManagerAgent failed");
291         return WMError::WM_ERROR_IPC_FAILED;
292     }
293 
294     sptr<IRemoteObject> remote = Remote();
295     if (remote == nullptr) {
296         WLOGFE("remote is null");
297         return WMError::WM_ERROR_IPC_FAILED;
298     }
299     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
300         data, reply, option) != ERR_NONE) {
301         WLOGFE("SendRequest failed");
302         return WMError::WM_ERROR_IPC_FAILED;
303     }
304 
305     return static_cast<WMError>(reply.ReadInt32());
306 }
307 
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)308 WMError WindowManagerProxy::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
309 {
310     MessageParcel data;
311     MessageParcel reply;
312     MessageOption option;
313 
314     if (controller == nullptr) {
315         WLOGFE("RSWindowAnimation Failed to set window animation controller, controller is null!");
316         return WMError::WM_ERROR_IPC_FAILED;
317     }
318 
319     if (!data.WriteInterfaceToken(GetDescriptor())) {
320         WLOGFE("RSWindowAnimation Failed to WriteInterfaceToken!");
321         return WMError::WM_ERROR_IPC_FAILED;
322     }
323 
324     if (!data.WriteRemoteObject(controller->AsObject())) {
325         WLOGFE("RSWindowAnimation Failed to write controller!");
326         return WMError::WM_ERROR_IPC_FAILED;
327     }
328 
329     sptr<IRemoteObject> remote = Remote();
330     if (remote == nullptr) {
331         WLOGFE("remote is null");
332         return WMError::WM_ERROR_IPC_FAILED;
333     }
334     auto error = remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER),
335         data, reply, option);
336     if (error != ERR_NONE) {
337         WLOGFE("RSWindowAnimation Send request error: %{public}d", error);
338         return WMError::WM_ERROR_IPC_FAILED;
339     }
340 
341     int32_t ret = reply.ReadInt32();
342     return static_cast<WMError>(ret);
343 }
344 
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)345 void WindowManagerProxy::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
346     sptr<MoveDragProperty>& moveDragProperty)
347 {
348     MessageParcel data;
349     MessageParcel reply;
350     MessageOption option;
351     if (!data.WriteInterfaceToken(GetDescriptor())) {
352         WLOGFE("WriteInterfaceToken failed");
353         return;
354     }
355     if (!data.WriteUint32(windowId)) {
356         WLOGFE("Write windowId failed");
357         return;
358     }
359     if (!data.WriteParcelable(windowProperty.GetRefPtr())) {
360         WLOGFE("Failed to write windowProperty!");
361         return;
362     }
363     if (!data.WriteParcelable(moveDragProperty.GetRefPtr())) {
364         WLOGFE("Failed to write moveDragProperty!");
365         return;
366     }
367 
368     sptr<IRemoteObject> remote = Remote();
369     if (remote == nullptr) {
370         WLOGFE("remote is null");
371         return;
372     }
373     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG),
374         data, reply, option) != ERR_NONE) {
375         WLOGFE("SendRequest failed");
376     }
377 }
378 
ProcessPointDown(uint32_t windowId,bool isPointDown)379 void WindowManagerProxy::ProcessPointDown(uint32_t windowId, bool isPointDown)
380 {
381     MessageParcel data;
382     MessageParcel reply;
383     MessageOption option;
384     if (!data.WriteInterfaceToken(GetDescriptor())) {
385         WLOGFE("WriteInterfaceToken failed");
386         return;
387     }
388     if (!data.WriteUint32(windowId)) {
389         WLOGFE("Write windowId failed");
390         return;
391     }
392     if (!data.WriteBool(isPointDown)) {
393         WLOGFE("Write isPointDown failed");
394         return;
395     }
396 
397     sptr<IRemoteObject> remote = Remote();
398     if (remote == nullptr) {
399         WLOGFE("remote is null");
400         return;
401     }
402     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN),
403         data, reply, option) != ERR_NONE) {
404         WLOGFE("SendRequest failed");
405     }
406 }
407 
ProcessPointUp(uint32_t windowId)408 void WindowManagerProxy::ProcessPointUp(uint32_t windowId)
409 {
410     MessageParcel data;
411     MessageParcel reply;
412     MessageOption option;
413     if (!data.WriteInterfaceToken(GetDescriptor())) {
414         WLOGFE("WriteInterfaceToken failed");
415         return;
416     }
417     if (!data.WriteUint32(windowId)) {
418         WLOGFE("Write windowId failed");
419         return;
420     }
421     sptr<IRemoteObject> remote = Remote();
422     if (remote == nullptr) {
423         WLOGFE("remote is null");
424         return;
425     }
426     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP),
427         data, reply, option) != ERR_NONE) {
428         WLOGFE("SendRequest failed");
429     }
430 }
431 
MinimizeAllAppWindows(DisplayId displayId)432 WMError WindowManagerProxy::MinimizeAllAppWindows(DisplayId displayId)
433 {
434     MessageParcel data;
435     MessageParcel reply;
436     MessageOption option;
437     if (!data.WriteInterfaceToken(GetDescriptor())) {
438         WLOGFE("WriteInterfaceToken failed");
439         return WMError::WM_ERROR_IPC_FAILED;
440     }
441     if (!data.WriteUint64(displayId)) {
442         WLOGFE("Write displayId failed");
443         return WMError::WM_ERROR_IPC_FAILED;
444     }
445     sptr<IRemoteObject> remote = Remote();
446     if (remote == nullptr) {
447         WLOGFE("remote is null");
448         return WMError::WM_ERROR_IPC_FAILED;
449     }
450     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS),
451         data, reply, option) != ERR_NONE) {
452         WLOGFE("SendRequest failed");
453         return WMError::WM_ERROR_IPC_FAILED;
454     }
455 
456     int32_t ret;
457     if (!reply.ReadInt32(ret)) {
458         return WMError::WM_ERROR_IPC_FAILED;
459     }
460 
461     WLOGFE("MinimizeAllAppWindows: %{public}u", ret);
462     return static_cast<WMError>(ret);
463 }
464 
ToggleShownStateForAllAppWindows()465 WMError WindowManagerProxy::ToggleShownStateForAllAppWindows()
466 {
467     MessageParcel data;
468     MessageParcel reply;
469     MessageOption option;
470     if (!data.WriteInterfaceToken(GetDescriptor())) {
471         WLOGFE("WriteInterfaceToken failed");
472         return WMError::WM_ERROR_IPC_FAILED;
473     }
474     sptr<IRemoteObject> remote = Remote();
475     if (remote == nullptr) {
476         WLOGFE("remote is null");
477         return WMError::WM_ERROR_IPC_FAILED;
478     }
479     if (remote->SendRequest(
480         static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS),
481         data, reply, option) != ERR_NONE) {
482         WLOGFE("SendRequest failed");
483         return WMError::WM_ERROR_IPC_FAILED;
484     }
485     int32_t ret;
486     if (!reply.ReadInt32(ret)) {
487         return WMError::WM_ERROR_IPC_FAILED;
488     }
489     return static_cast<WMError>(ret);
490 }
491 
SetWindowLayoutMode(WindowLayoutMode mode)492 WMError WindowManagerProxy::SetWindowLayoutMode(WindowLayoutMode mode)
493 {
494     MessageParcel data;
495     MessageParcel reply;
496     MessageOption option;
497     if (!data.WriteInterfaceToken(GetDescriptor())) {
498         WLOGFE("WriteInterfaceToken failed");
499         return WMError::WM_ERROR_IPC_FAILED;
500     }
501     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
502         WLOGFE("Write mode failed");
503         return WMError::WM_ERROR_IPC_FAILED;
504     }
505     sptr<IRemoteObject> remote = Remote();
506     if (remote == nullptr) {
507         WLOGFE("remote is null");
508         return WMError::WM_ERROR_IPC_FAILED;
509     }
510     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE),
511         data, reply, option) != ERR_NONE) {
512         return WMError::WM_ERROR_IPC_FAILED;
513     }
514 
515     int32_t ret = reply.ReadInt32();
516     return static_cast<WMError>(ret);
517 }
518 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)519 WMError WindowManagerProxy::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
520     bool isAsyncTask)
521 {
522     MessageParcel data;
523     MessageParcel reply;
524     MessageOption option;
525     if (!data.WriteInterfaceToken(GetDescriptor())) {
526         WLOGFE("WriteInterfaceToken failed");
527         return WMError::WM_ERROR_IPC_FAILED;
528     }
529 
530     if (!data.WriteUint32(static_cast<uint32_t>(action))) {
531         WLOGFE("Write PropertyChangeAction failed");
532         return WMError::WM_ERROR_IPC_FAILED;
533     }
534 
535     if (!windowProperty || !windowProperty->Write(data, action)) {
536         WLOGFE("Write windowProperty failed");
537         return WMError::WM_ERROR_IPC_FAILED;
538     }
539 
540     sptr<IRemoteObject> remote = Remote();
541     if (remote == nullptr) {
542         WLOGFE("remote is null");
543         return WMError::WM_ERROR_IPC_FAILED;
544     }
545     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY),
546         data, reply, option) != ERR_NONE) {
547         return WMError::WM_ERROR_IPC_FAILED;
548     }
549 
550     int32_t ret = reply.ReadInt32();
551     return static_cast<WMError>(ret);
552 }
553 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)554 WMError WindowManagerProxy::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
555 {
556     MessageParcel data;
557     if (!data.WriteInterfaceToken(GetDescriptor())) {
558         WLOGFE("WriteInterfaceToken failed");
559         return WMError::WM_ERROR_IPC_FAILED;
560     }
561     if (!data.WriteUint32(windowId)) {
562         WLOGFE("Write mainWinId failed");
563         return WMError::WM_ERROR_IPC_FAILED;
564     }
565     if (!data.WriteUint32(static_cast<uint32_t>(gravity))) {
566         WLOGFE("Write mainWinId failed");
567         return WMError::WM_ERROR_IPC_FAILED;
568     }
569     if (!data.WriteUint32(percent)) {
570         WLOGFE("Write mainWinId failed");
571         return WMError::WM_ERROR_IPC_FAILED;
572     }
573 
574     MessageParcel reply;
575     MessageOption option;
576     sptr<IRemoteObject> remote = Remote();
577     if (remote == nullptr) {
578         WLOGFE("remote is null");
579         return WMError::WM_ERROR_IPC_FAILED;
580     }
581     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY),
582         data, reply, option) != ERR_NONE) {
583         return WMError::WM_ERROR_IPC_FAILED;
584     }
585 
586     int32_t ret = reply.ReadInt32();
587     return static_cast<WMError>(ret);
588 }
589 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)590 __attribute__((no_sanitize("cfi"))) WMError WindowManagerProxy::GetTopWindowId(
591     uint32_t mainWinId, uint32_t& topWinId)
592 {
593     MessageParcel data;
594     MessageParcel reply;
595     MessageOption option;
596     if (!data.WriteInterfaceToken(GetDescriptor())) {
597         WLOGFE("WriteInterfaceToken failed");
598         return WMError::WM_ERROR_IPC_FAILED;
599     }
600 
601     if (!data.WriteUint32(mainWinId)) {
602         WLOGFE("Write mainWinId failed");
603         return WMError::WM_ERROR_IPC_FAILED;
604     }
605 
606     sptr<IRemoteObject> remote = Remote();
607     if (remote == nullptr) {
608         WLOGFE("remote is null");
609         return WMError::WM_ERROR_IPC_FAILED;
610     }
611     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
612         data, reply, option) != ERR_NONE) {
613         return WMError::WM_ERROR_IPC_FAILED;
614     }
615     topWinId = reply.ReadUint32();
616     int32_t ret = reply.ReadInt32();
617     return static_cast<WMError>(ret);
618 }
619 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)620 WMError WindowManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
621 {
622     MessageParcel data;
623     MessageParcel reply;
624     MessageOption option;
625     if (!data.WriteInterfaceToken(GetDescriptor())) {
626         WLOGFE("WriteInterfaceToken failed");
627         return WMError::WM_ERROR_IPC_FAILED;
628     }
629     sptr<IRemoteObject> remote = Remote();
630     if (remote == nullptr) {
631         WLOGFE("remote is null");
632         return WMError::WM_ERROR_IPC_FAILED;
633     }
634     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID),
635         data, reply, option) != ERR_NONE) {
636         return WMError::WM_ERROR_IPC_FAILED;
637     }
638     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
639         WLOGFE("read accessibility window infos failed");
640         return WMError::WM_ERROR_IPC_FAILED;
641     }
642     return static_cast<WMError>(reply.ReadInt32());
643 }
644 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)645 WMError WindowManagerProxy::GetUnreliableWindowInfo(int32_t windowId,
646     std::vector<sptr<UnreliableWindowInfo>>& infos)
647 {
648     MessageParcel data;
649     MessageParcel reply;
650     MessageOption option;
651     if (!data.WriteInterfaceToken(GetDescriptor())) {
652         WLOGFE("WriteInterfaceToken failed");
653         return WMError::WM_ERROR_IPC_FAILED;
654     }
655     if (!data.WriteInt32(windowId)) {
656         WLOGFE("Write windowId failed");
657         return WMError::WM_ERROR_IPC_FAILED;
658     }
659     sptr<IRemoteObject> remote = Remote();
660     if (remote == nullptr) {
661         WLOGFE("remote is null");
662         return WMError::WM_ERROR_IPC_FAILED;
663     }
664     if (remote->SendRequest(
665         static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO_ID),
666         data, reply, option) != ERR_NONE) {
667         return WMError::WM_ERROR_IPC_FAILED;
668     }
669     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<UnreliableWindowInfo>(reply, infos)) {
670         WLOGFE("read unreliable window infos failed");
671         return WMError::WM_ERROR_IPC_FAILED;
672     }
673     return static_cast<WMError>(reply.ReadInt32());
674 }
675 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)676 WMError WindowManagerProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
677 {
678     MessageParcel data;
679     MessageParcel reply;
680     MessageOption option;
681     if (!data.WriteInterfaceToken(GetDescriptor())) {
682         WLOGFE("WriteInterfaceToken failed");
683         return WMError::WM_ERROR_IPC_FAILED;
684     }
685     sptr<IRemoteObject> remote = Remote();
686     if (remote == nullptr) {
687         WLOGFE("remote is null");
688         return WMError::WM_ERROR_IPC_FAILED;
689     }
690     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID),
691         data, reply, option) != ERR_NONE) {
692         return WMError::WM_ERROR_IPC_FAILED;
693     }
694     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
695         WLOGFE("read visibility window infos failed");
696         return WMError::WM_ERROR_IPC_FAILED;
697     }
698     return static_cast<WMError>(reply.ReadInt32());
699 }
700 
GetSystemConfig(SystemConfig & systemConfig)701 WMError WindowManagerProxy::GetSystemConfig(SystemConfig& systemConfig)
702 {
703     MessageParcel data;
704     MessageParcel reply;
705     MessageOption option;
706     if (!data.WriteInterfaceToken(GetDescriptor())) {
707         WLOGFE("WriteInterfaceToken failed");
708         return WMError::WM_ERROR_IPC_FAILED;
709     }
710     sptr<IRemoteObject> remote = Remote();
711     if (remote == nullptr) {
712         WLOGFE("remote is null");
713         return WMError::WM_ERROR_IPC_FAILED;
714     }
715     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG),
716         data, reply, option) != ERR_NONE) {
717         return WMError::WM_ERROR_IPC_FAILED;
718     }
719     sptr<SystemConfig> config = reply.ReadParcelable<SystemConfig>();
720     if (config == nullptr) {
721         WLOGFE("Read SystemConfig failed");
722         return WMError::WM_ERROR_IPC_FAILED;
723     }
724     systemConfig = *config;
725     int32_t ret = reply.ReadInt32();
726     return static_cast<WMError>(ret);
727 }
728 
NotifyWindowTransition(sptr<WindowTransitionInfo> & from,sptr<WindowTransitionInfo> & to,bool isFromClient)729 WMError WindowManagerProxy::NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
730     bool isFromClient)
731 {
732     MessageParcel data;
733     MessageParcel reply;
734     MessageOption option;
735 
736     if (!data.WriteInterfaceToken(GetDescriptor())) {
737         WLOGFE("Failed to WriteInterfaceToken!");
738         return WMError::WM_ERROR_IPC_FAILED;
739     }
740 
741     if (!data.WriteParcelable(from)) {
742         WLOGFE("Failed to write from ability window info!");
743         return WMError::WM_ERROR_IPC_FAILED;
744     }
745 
746     if (!data.WriteParcelable(to)) {
747         WLOGFE("Failed to write to ability window info!");
748         return WMError::WM_ERROR_IPC_FAILED;
749     }
750 
751     if (!data.WriteBool(isFromClient)) {
752         WLOGFE("Failed to write to isFromClient!");
753         return WMError::WM_ERROR_IPC_FAILED;
754     }
755     sptr<IRemoteObject> remote = Remote();
756     if (remote == nullptr) {
757         WLOGFE("remote is null");
758         return WMError::WM_ERROR_IPC_FAILED;
759     }
760     auto error = remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION),
761         data, reply, option);
762     if (error != ERR_NONE) {
763         WLOGFE("Send request error: %{public}d", static_cast<uint32_t>(error));
764         return WMError::WM_ERROR_IPC_FAILED;
765     }
766     auto ret = static_cast<WMError>(reply.ReadInt32());
767     return ret;
768 }
769 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)770 WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
771 {
772     MessageParcel data;
773     MessageParcel reply;
774     MessageOption option;
775 
776     if (!data.WriteInterfaceToken(GetDescriptor())) {
777         WLOGFE("WriteInterfaceToken failed");
778         return WMError::WM_ERROR_IPC_FAILED;
779     }
780     if (!data.WriteUint64(displayId)) {
781         WLOGFE("Write displayId failed");
782         return WMError::WM_ERROR_IPC_FAILED;
783     }
784     sptr<IRemoteObject> remote = Remote();
785     if (remote == nullptr) {
786         WLOGFE("remote is null");
787         return WMError::WM_ERROR_IPC_FAILED;
788     }
789     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
790         data, reply, option) != ERR_NONE) {
791         return WMError::WM_ERROR_IPC_FAILED;
792     }
793 
794     auto ret = static_cast<WMError>(reply.ReadInt32());
795     if (ret == WMError::WM_OK) {
796         hotZones.fullscreen_.posX_ = reply.ReadInt32();
797         hotZones.fullscreen_.posY_ = reply.ReadInt32();
798         hotZones.fullscreen_.width_ = reply.ReadUint32();
799         hotZones.fullscreen_.height_ = reply.ReadUint32();
800 
801         hotZones.primary_.posX_ = reply.ReadInt32();
802         hotZones.primary_.posY_ = reply.ReadInt32();
803         hotZones.primary_.width_ = reply.ReadUint32();
804         hotZones.primary_.height_ = reply.ReadUint32();
805 
806         hotZones.secondary_.posX_ = reply.ReadInt32();
807         hotZones.secondary_.posY_ = reply.ReadInt32();
808         hotZones.secondary_.width_ = reply.ReadUint32();
809         hotZones.secondary_.height_ = reply.ReadUint32();
810     }
811     return ret;
812 }
813 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)814 void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
815     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
816 {
817     MessageParcel data;
818     MessageParcel reply;
819     MessageOption option;
820     if (!data.WriteInterfaceToken(GetDescriptor())) {
821         WLOGFE("WriteInterfaceToken failed");
822         return;
823     }
824 
825     if (!data.WriteUInt32Vector(windowIds)) {
826         WLOGFE("Write windowIds failed");
827         return;
828     }
829 
830     if (!data.WriteBool(isAnimated)) {
831         WLOGFE("Write isAnimated failed");
832         return;
833     }
834     sptr<IRemoteObject> remote = Remote();
835     if (remote == nullptr) {
836         WLOGFE("remote is null");
837         return;
838     }
839     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK),
840         data, reply, option) != ERR_NONE) {
841         WLOGFE("Send request error");
842         return;
843     }
844     if (reply.ReadBool()) {
845         sptr<IRemoteObject> finishCallbackObject = reply.ReadRemoteObject();
846         finishCallback = iface_cast<RSIWindowAnimationFinishedCallback>(finishCallbackObject);
847     } else {
848         finishCallback = nullptr;
849     }
850     return;
851 }
852 
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)853 WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
854 {
855     MessageParcel data;
856     MessageParcel reply;
857     MessageOption option;
858 
859     if (!data.WriteInterfaceToken(GetDescriptor())) {
860         WLOGFE("WriteInterfaceToken failed");
861         return WMError::WM_ERROR_IPC_FAILED;
862     }
863     if (!data.WriteUint32(windowId)) {
864         WLOGFE("Write windowId failed");
865         return WMError::WM_ERROR_IPC_FAILED;
866     }
867     if (!data.WriteBool(haveListener)) {
868         WLOGFE("Write avoid area listener failed");
869         return WMError::WM_ERROR_IPC_FAILED;
870     }
871     sptr<IRemoteObject> remote = Remote();
872     if (remote == nullptr) {
873         WLOGFE("remote is null");
874         return WMError::WM_ERROR_IPC_FAILED;
875     }
876     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
877         data, reply, option) != ERR_NONE) {
878         return WMError::WM_ERROR_IPC_FAILED;
879     }
880     return static_cast<WMError>(reply.ReadInt32());
881 }
882 
UpdateRsTree(uint32_t windowId,bool isAdd)883 WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd)
884 {
885     MessageParcel data;
886     MessageParcel reply;
887     MessageOption option(MessageOption::TF_ASYNC);
888 
889     if (!data.WriteInterfaceToken(GetDescriptor())) {
890         WLOGFE("WriteInterfaceToken failed");
891         return WMError::WM_ERROR_IPC_FAILED;
892     }
893     if (!data.WriteUint32(windowId)) {
894         WLOGFE("Write windowId failed");
895         return WMError::WM_ERROR_IPC_FAILED;
896     }
897     if (!data.WriteBool(isAdd)) {
898         WLOGFE("Write avoid area listener failed");
899         return WMError::WM_ERROR_IPC_FAILED;
900     }
901     sptr<IRemoteObject> remote = Remote();
902     if (remote == nullptr) {
903         WLOGFE("remote is null");
904         return WMError::WM_ERROR_IPC_FAILED;
905     }
906     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE),
907         data, reply, option) != ERR_NONE) {
908         return WMError::WM_ERROR_IPC_FAILED;
909     }
910     return static_cast<WMError>(reply.ReadInt32());
911 }
912 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)913 WMError WindowManagerProxy::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
914 {
915     MessageParcel data;
916     MessageParcel reply;
917     MessageOption option;
918     if (!data.WriteInterfaceToken(GetDescriptor())) {
919         WLOGFE("WriteInterfaceToken failed");
920         return WMError::WM_ERROR_IPC_FAILED;
921     }
922     if (!data.WriteUint32(windowId)) {
923         WLOGFE("Write windowId failed");
924         return WMError::WM_ERROR_IPC_FAILED;
925     }
926     if (targetToken != nullptr) {
927         if (!data.WriteRemoteObject(targetToken)) {
928             WLOGFE("Write targetToken failed");
929             return WMError::WM_ERROR_IPC_FAILED;
930         }
931     }
932     sptr<IRemoteObject> remote = Remote();
933     if (remote == nullptr) {
934         WLOGFE("remote is null");
935         return WMError::WM_ERROR_IPC_FAILED;
936     }
937     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
938         data, reply, option) != ERR_NONE) {
939         return WMError::WM_ERROR_IPC_FAILED;
940     }
941 
942     int32_t ret = reply.ReadInt32();
943     return static_cast<WMError>(ret);
944 }
945 
SetAnchorAndScale(int32_t x,int32_t y,float scale)946 void WindowManagerProxy::SetAnchorAndScale(int32_t x, int32_t y, float scale)
947 {
948     MessageParcel data;
949     MessageParcel reply;
950     MessageOption option;
951     if (!data.WriteInterfaceToken(GetDescriptor())) {
952         WLOGFE("WriteInterfaceToken failed");
953         return;
954     }
955     if (!data.WriteInt32(x)) {
956         WLOGFE("Write anchor x failed");
957         return;
958     }
959     if (!data.WriteInt32(y)) {
960         WLOGFE("Write anchor y failed");
961         return;
962     }
963     if (!data.WriteFloat(scale)) {
964         WLOGFE("Write scale failed");
965         return;
966     }
967     sptr<IRemoteObject> remote = Remote();
968     if (remote == nullptr) {
969         WLOGFE("remote is null");
970         return;
971     }
972     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE),
973         data, reply, option) != ERR_NONE) {
974         WLOGFE("SendRequest failed");
975     }
976 }
977 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)978 void WindowManagerProxy::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
979 {
980     MessageParcel data;
981     MessageParcel reply;
982     MessageOption option;
983     if (!data.WriteInterfaceToken(GetDescriptor())) {
984         WLOGFE("WriteInterfaceToken failed");
985         return;
986     }
987     if (!data.WriteInt32(deltaX)) {
988         WLOGFE("Write anchor delatX failed");
989         return;
990     }
991     if (!data.WriteInt32(deltaY)) {
992         WLOGFE("Write anchor deltaY failed");
993         return;
994     }
995     sptr<IRemoteObject> remote = Remote();
996     if (remote == nullptr) {
997         WLOGFE("remote is null");
998         return;
999     }
1000     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET),
1001         data, reply, option) != ERR_NONE) {
1002         WLOGFE("SendRequest failed");
1003     }
1004 }
1005 
OffWindowZoom()1006 void WindowManagerProxy::OffWindowZoom()
1007 {
1008     MessageParcel data;
1009     MessageParcel reply;
1010     MessageOption option;
1011     if (!data.WriteInterfaceToken(GetDescriptor())) {
1012         WLOGFE("WriteInterfaceToken failed");
1013         return;
1014     }
1015     sptr<IRemoteObject> remote = Remote();
1016     if (remote == nullptr) {
1017         WLOGFE("remote is null");
1018         return;
1019     }
1020     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM),
1021         data, reply, option) != ERR_NONE) {
1022         WLOGFE("SendRequest failed");
1023     }
1024 }
1025 
1026 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)1027 WMError WindowManagerProxy::RaiseToAppTop(uint32_t windowId)
1028 {
1029     MessageParcel data;
1030     MessageParcel reply;
1031     MessageOption option;
1032     if (!data.WriteInterfaceToken(GetDescriptor())) {
1033         WLOGFE("WriteInterfaceToken failed");
1034         return WMError::WM_ERROR_IPC_FAILED;
1035     }
1036 
1037     if (!data.WriteUint32(windowId)) {
1038         WLOGFE("Write anchor delatX failed");
1039         return WMError::WM_ERROR_IPC_FAILED;
1040     }
1041 
1042     sptr<IRemoteObject> remote = Remote();
1043     if (remote == nullptr) {
1044         WLOGFE("remote is null");
1045         return WMError::WM_ERROR_IPC_FAILED;
1046     }
1047     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER),
1048         data, reply, option) != ERR_NONE) {
1049         WLOGFE("SendRequest failed");
1050         return WMError::WM_ERROR_IPC_FAILED;
1051     }
1052     return WMError::WM_OK;
1053 }
1054 
GetSnapshot(int32_t windowId)1055 std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowId)
1056 {
1057     MessageParcel data;
1058     MessageParcel reply;
1059     MessageOption option;
1060 
1061     if (!data.WriteInterfaceToken(GetDescriptor())) {
1062         WLOGFE("WriteInterfaceToken failed");
1063         return nullptr;
1064     }
1065     if (!data.WriteUint32(windowId)) {
1066         WLOGFE("Write windowId failed");
1067         return nullptr;
1068     }
1069     sptr<IRemoteObject> remote = Remote();
1070     if (remote == nullptr) {
1071         WLOGFE("remote is null");
1072         return nullptr;
1073     }
1074     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SNAPSHOT),
1075         data, reply, option) != ERR_NONE) {
1076         WLOGFE("SendRequest failed");
1077         return nullptr;
1078     }
1079 
1080     std::shared_ptr<Media::PixelMap> map(reply.ReadParcelable<Media::PixelMap>());
1081     if (map == nullptr) {
1082         WLOGFE("Read pixelMap is null");
1083         return nullptr;
1084     }
1085     return map;
1086 }
1087 
GetSnapshotByWindowId(int32_t persistentId,std::shared_ptr<Media::PixelMap> & pixelMap)1088 WMError WindowManagerProxy::GetSnapshotByWindowId(int32_t persistentId, std::shared_ptr<Media::PixelMap>& pixelMap)
1089 {
1090     pixelMap = GetSnapshot(persistentId);
1091     if (pixelMap == nullptr) {
1092         WLOGFE("Get snapshot is nullptr");
1093         return WMError::WM_ERROR_NULLPTR;
1094     }
1095     return WMError::WM_OK;
1096 }
1097 
SetGestureNavigaionEnabled(bool enable)1098 WMError WindowManagerProxy::SetGestureNavigaionEnabled(bool enable)
1099 {
1100     MessageParcel data;
1101     MessageParcel reply;
1102     MessageOption option;
1103     if (!data.WriteInterfaceToken(GetDescriptor())) {
1104         WLOGFE("WriteInterfaceToken failed");
1105         return WMError::WM_ERROR_IPC_FAILED;
1106     }
1107 
1108     if (!data.WriteBool(enable)) {
1109         WLOGFE("Write anchor delatX failed");
1110         return WMError::WM_ERROR_IPC_FAILED;
1111     }
1112 
1113     sptr<IRemoteObject> remote = Remote();
1114     if (remote == nullptr) {
1115         WLOGFE("remote is null");
1116         return WMError::WM_ERROR_IPC_FAILED;
1117     }
1118     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED),
1119         data, reply, option) != ERR_NONE) {
1120         WLOGFE("SendRequest failed");
1121         return WMError::WM_ERROR_IPC_FAILED;
1122     }
1123     int32_t ret = reply.ReadInt32();
1124     return static_cast<WMError>(ret);
1125 }
1126 
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1127 void WindowManagerProxy::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1128 {
1129     MessageParcel data;
1130     MessageParcel reply;
1131     MessageOption option(MessageOption::TF_ASYNC);
1132     if (!data.WriteInterfaceToken(GetDescriptor())) {
1133         WLOGFE("WriteInterfaceToken failed");
1134         return;
1135     }
1136     if (!data.WriteUint32(windowId)) {
1137         WLOGFE("Write anchor delatX failed");
1138         return;
1139     }
1140     if (!event || !event->WriteToParcel(data)) {
1141         WLOGFE("Write event faild");
1142         return;
1143     }
1144     sptr<IRemoteObject> remote = Remote();
1145     if (remote == nullptr) {
1146         WLOGFE("remote is null");
1147         return;
1148     }
1149     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT),
1150         data, reply, option) != ERR_NONE) {
1151         WLOGFE("SendRequest failed");
1152         return;
1153     }
1154 }
1155 
NotifyDumpInfoResult(const std::vector<std::string> & info)1156 void WindowManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
1157 {
1158     MessageParcel data;
1159     MessageParcel reply;
1160     MessageOption option(MessageOption::TF_ASYNC);
1161     if (!data.WriteInterfaceToken(GetDescriptor())) {
1162         WLOGFE("WriteInterfaceToken pfailed");
1163         return;
1164     }
1165     if (!data.WriteStringVector(info)) {
1166         WLOGFE("Write info failed");
1167         return;
1168     }
1169     sptr<IRemoteObject> remote = Remote();
1170     if (remote == nullptr) {
1171         WLOGFE("remote is null");
1172         return;
1173     }
1174     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
1175         data, reply, option) != ERR_NONE) {
1176         WLOGFE("SendRequest failed");
1177         return;
1178     }
1179 }
1180 
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)1181 WMError WindowManagerProxy::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
1182     std::vector<sptr<RSWindowAnimationTarget>>& targets)
1183 {
1184     MessageParcel data;
1185     MessageParcel reply;
1186     MessageOption option;
1187     if (!data.WriteInterfaceToken(GetDescriptor())) {
1188         WLOGFE("write interfaceToken failed");
1189         return WMError::WM_ERROR_IPC_FAILED;
1190     }
1191     if (!data.WriteUInt32Vector(missionIds)) {
1192         WLOGFE("Write missionIds failed");
1193         return WMError::WM_ERROR_IPC_FAILED;
1194     }
1195     sptr<IRemoteObject> remote = Remote();
1196     if (remote == nullptr) {
1197         WLOGFE("remote is null");
1198         return WMError::WM_ERROR_IPC_FAILED;
1199     }
1200     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS),
1201         data, reply, option) != ERR_NONE) {
1202         return WMError::WM_ERROR_IPC_FAILED;
1203     }
1204     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<RSWindowAnimationTarget>(reply, targets)) {
1205         WLOGFE("read window animation targets failed");
1206         return WMError::WM_ERROR_IPC_FAILED;
1207     }
1208     return static_cast<WMError>(reply.ReadInt32());
1209 }
1210 
SetMaximizeMode(MaximizeMode maximizeMode)1211 void WindowManagerProxy::SetMaximizeMode(MaximizeMode maximizeMode)
1212 {
1213     MessageParcel data;
1214     MessageOption option;
1215     MessageParcel reply;
1216     if (!data.WriteInterfaceToken(GetDescriptor())) {
1217         WLOGFE("WriteInterfaceToken failed!");
1218         return;
1219     }
1220     if (!data.WriteInt32(static_cast<uint32_t>(maximizeMode))) {
1221         WLOGFE("Write maximizeMode failed");
1222         return;
1223     }
1224     sptr<IRemoteObject> remote = Remote();
1225     if (remote == nullptr) {
1226         WLOGFE("remote is null");
1227         return;
1228     }
1229     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_MAXIMIZE_MODE),
1230         data, reply, option) != ERR_NONE) {
1231         WLOGFE("SendRequest failed");
1232     }
1233 }
1234 
GetMaximizeMode()1235 MaximizeMode WindowManagerProxy::GetMaximizeMode()
1236 {
1237     MessageParcel data;
1238     MessageParcel reply;
1239     MessageOption option;
1240     if (!data.WriteInterfaceToken(GetDescriptor())) {
1241         WLOGFE("WriteInterfaceToken failed");
1242         return MaximizeMode::MODE_FULL_FILL;
1243     }
1244 
1245     sptr<IRemoteObject> remote = Remote();
1246     if (remote == nullptr) {
1247         WLOGFE("remote is null");
1248         return MaximizeMode::MODE_FULL_FILL;
1249     }
1250     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_MAXIMIZE_MODE),
1251         data, reply, option) != ERR_NONE) {
1252         WLOGFE("SendRequest failed");
1253         return MaximizeMode::MODE_FULL_FILL;
1254     }
1255     int32_t ret = reply.ReadInt32();
1256     return static_cast<MaximizeMode>(ret);
1257 }
1258 
GetFocusWindowInfo(FocusChangeInfo & focusInfo)1259 void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
1260 {
1261     MessageParcel data;
1262     MessageParcel reply;
1263     MessageOption option;
1264     if (!data.WriteInterfaceToken(GetDescriptor())) {
1265         WLOGFE("WriteInterfaceToken failed");
1266         return;
1267     }
1268 
1269     sptr<IRemoteObject> remote = Remote();
1270     if (remote == nullptr) {
1271         WLOGFE("remote is null");
1272         return;
1273     }
1274     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO),
1275         data, reply, option) != ERR_NONE) {
1276         WLOGFE("SendRequest failed");
1277         return;
1278     }
1279     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
1280     if (info != nullptr) {
1281         focusInfo = *info;
1282     }
1283 }
1284 } // namespace Rosen
1285 } // namespace OHOS
1286