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