• 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 
NotifyScreenshotEvent(ScreenshotEventType type)523 WMError WindowManagerProxy::NotifyScreenshotEvent(ScreenshotEventType type)
524 {
525     MessageParcel data;
526     MessageParcel reply;
527     MessageOption option;
528     if (!data.WriteInterfaceToken(GetDescriptor())) {
529         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "WriteInterfaceToken failed");
530         return WMError::WM_ERROR_IPC_FAILED;
531     }
532     if (!data.WriteInt32(static_cast<int32_t>(type))) {
533         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write screen shot event type failed");
534         return WMError::WM_ERROR_IPC_FAILED;
535     }
536     sptr<IRemoteObject> remote = Remote();
537     if (remote == nullptr) {
538         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null");
539         return WMError::WM_ERROR_IPC_FAILED;
540     }
541     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_SCREEN_SHOT_EVENT),
542         data, reply, option) != ERR_NONE) {
543         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "SendRequest failed");
544         return WMError::WM_ERROR_IPC_FAILED;
545     }
546     int32_t ret = reply.ReadInt32();
547     return static_cast<WMError>(ret);
548 }
549 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)550 WMError WindowManagerProxy::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
551     bool isAsyncTask)
552 {
553     MessageParcel data;
554     MessageParcel reply;
555     MessageOption option;
556     if (!data.WriteInterfaceToken(GetDescriptor())) {
557         WLOGFE("WriteInterfaceToken failed");
558         return WMError::WM_ERROR_IPC_FAILED;
559     }
560 
561     if (!data.WriteUint32(static_cast<uint32_t>(action))) {
562         WLOGFE("Write PropertyChangeAction failed");
563         return WMError::WM_ERROR_IPC_FAILED;
564     }
565 
566     if (!windowProperty || !windowProperty->Write(data, action)) {
567         WLOGFE("Write windowProperty failed");
568         return WMError::WM_ERROR_IPC_FAILED;
569     }
570 
571     sptr<IRemoteObject> remote = Remote();
572     if (remote == nullptr) {
573         WLOGFE("remote is null");
574         return WMError::WM_ERROR_IPC_FAILED;
575     }
576     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY),
577         data, reply, option) != ERR_NONE) {
578         return WMError::WM_ERROR_IPC_FAILED;
579     }
580 
581     int32_t ret = reply.ReadInt32();
582     return static_cast<WMError>(ret);
583 }
584 
SetWindowGravity(uint32_t windowId,WindowGravity gravity,uint32_t percent)585 WMError WindowManagerProxy::SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent)
586 {
587     MessageParcel data;
588     if (!data.WriteInterfaceToken(GetDescriptor())) {
589         WLOGFE("WriteInterfaceToken failed");
590         return WMError::WM_ERROR_IPC_FAILED;
591     }
592     if (!data.WriteUint32(windowId)) {
593         WLOGFE("Write mainWinId failed");
594         return WMError::WM_ERROR_IPC_FAILED;
595     }
596     if (!data.WriteUint32(static_cast<uint32_t>(gravity))) {
597         WLOGFE("Write mainWinId failed");
598         return WMError::WM_ERROR_IPC_FAILED;
599     }
600     if (!data.WriteUint32(percent)) {
601         WLOGFE("Write mainWinId failed");
602         return WMError::WM_ERROR_IPC_FAILED;
603     }
604 
605     MessageParcel reply;
606     MessageOption option;
607     sptr<IRemoteObject> remote = Remote();
608     if (remote == nullptr) {
609         WLOGFE("remote is null");
610         return WMError::WM_ERROR_IPC_FAILED;
611     }
612     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_WINDOW_GRAVITY),
613         data, reply, option) != ERR_NONE) {
614         return WMError::WM_ERROR_IPC_FAILED;
615     }
616 
617     int32_t ret = reply.ReadInt32();
618     return static_cast<WMError>(ret);
619 }
620 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)621 __attribute__((no_sanitize("cfi"))) WMError WindowManagerProxy::GetTopWindowId(
622     uint32_t mainWinId, uint32_t& topWinId)
623 {
624     MessageParcel data;
625     MessageParcel reply;
626     MessageOption option;
627     if (!data.WriteInterfaceToken(GetDescriptor())) {
628         WLOGFE("WriteInterfaceToken failed");
629         return WMError::WM_ERROR_IPC_FAILED;
630     }
631 
632     if (!data.WriteUint32(mainWinId)) {
633         WLOGFE("Write mainWinId failed");
634         return WMError::WM_ERROR_IPC_FAILED;
635     }
636 
637     sptr<IRemoteObject> remote = Remote();
638     if (remote == nullptr) {
639         WLOGFE("remote is null");
640         return WMError::WM_ERROR_IPC_FAILED;
641     }
642     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
643         data, reply, option) != ERR_NONE) {
644         return WMError::WM_ERROR_IPC_FAILED;
645     }
646     topWinId = reply.ReadUint32();
647     int32_t ret = reply.ReadInt32();
648     return static_cast<WMError>(ret);
649 }
650 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)651 WMError WindowManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
652 {
653     MessageParcel data;
654     MessageParcel reply;
655     MessageOption option;
656     if (!data.WriteInterfaceToken(GetDescriptor())) {
657         WLOGFE("WriteInterfaceToken failed");
658         return WMError::WM_ERROR_IPC_FAILED;
659     }
660     sptr<IRemoteObject> remote = Remote();
661     if (remote == nullptr) {
662         WLOGFE("remote is null");
663         return WMError::WM_ERROR_IPC_FAILED;
664     }
665     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID),
666         data, reply, option) != ERR_NONE) {
667         return WMError::WM_ERROR_IPC_FAILED;
668     }
669     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
670         WLOGFE("read accessibility window infos failed");
671         return WMError::WM_ERROR_IPC_FAILED;
672     }
673     return static_cast<WMError>(reply.ReadInt32());
674 }
675 
GetUnreliableWindowInfo(int32_t windowId,std::vector<sptr<UnreliableWindowInfo>> & infos)676 WMError WindowManagerProxy::GetUnreliableWindowInfo(int32_t windowId,
677     std::vector<sptr<UnreliableWindowInfo>>& infos)
678 {
679     MessageParcel data;
680     MessageParcel reply;
681     MessageOption option;
682     if (!data.WriteInterfaceToken(GetDescriptor())) {
683         WLOGFE("WriteInterfaceToken failed");
684         return WMError::WM_ERROR_IPC_FAILED;
685     }
686     if (!data.WriteInt32(windowId)) {
687         WLOGFE("Write windowId failed");
688         return WMError::WM_ERROR_IPC_FAILED;
689     }
690     sptr<IRemoteObject> remote = Remote();
691     if (remote == nullptr) {
692         WLOGFE("remote is null");
693         return WMError::WM_ERROR_IPC_FAILED;
694     }
695     if (remote->SendRequest(
696         static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO_ID),
697         data, reply, option) != ERR_NONE) {
698         return WMError::WM_ERROR_IPC_FAILED;
699     }
700     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<UnreliableWindowInfo>(reply, infos)) {
701         WLOGFE("read unreliable window infos failed");
702         return WMError::WM_ERROR_IPC_FAILED;
703     }
704     return static_cast<WMError>(reply.ReadInt32());
705 }
706 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)707 WMError WindowManagerProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
708 {
709     MessageParcel data;
710     MessageParcel reply;
711     MessageOption option;
712     if (!data.WriteInterfaceToken(GetDescriptor())) {
713         WLOGFE("WriteInterfaceToken failed");
714         return WMError::WM_ERROR_IPC_FAILED;
715     }
716     sptr<IRemoteObject> remote = Remote();
717     if (remote == nullptr) {
718         WLOGFE("remote is null");
719         return WMError::WM_ERROR_IPC_FAILED;
720     }
721     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID),
722         data, reply, option) != ERR_NONE) {
723         return WMError::WM_ERROR_IPC_FAILED;
724     }
725     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
726         WLOGFE("read visibility window infos failed");
727         return WMError::WM_ERROR_IPC_FAILED;
728     }
729     return static_cast<WMError>(reply.ReadInt32());
730 }
731 
GetSystemConfig(SystemConfig & systemConfig)732 WMError WindowManagerProxy::GetSystemConfig(SystemConfig& systemConfig)
733 {
734     MessageParcel data;
735     MessageParcel reply;
736     MessageOption option;
737     if (!data.WriteInterfaceToken(GetDescriptor())) {
738         WLOGFE("WriteInterfaceToken failed");
739         return WMError::WM_ERROR_IPC_FAILED;
740     }
741     sptr<IRemoteObject> remote = Remote();
742     if (remote == nullptr) {
743         WLOGFE("remote is null");
744         return WMError::WM_ERROR_IPC_FAILED;
745     }
746     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG),
747         data, reply, option) != ERR_NONE) {
748         return WMError::WM_ERROR_IPC_FAILED;
749     }
750     sptr<SystemConfig> config = reply.ReadParcelable<SystemConfig>();
751     if (config == nullptr) {
752         WLOGFE("Read SystemConfig failed");
753         return WMError::WM_ERROR_IPC_FAILED;
754     }
755     systemConfig = *config;
756     int32_t ret = reply.ReadInt32();
757     return static_cast<WMError>(ret);
758 }
759 
NotifyWindowTransition(sptr<WindowTransitionInfo> & from,sptr<WindowTransitionInfo> & to,bool isFromClient)760 WMError WindowManagerProxy::NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
761     bool isFromClient)
762 {
763     MessageParcel data;
764     MessageParcel reply;
765     MessageOption option;
766 
767     if (!data.WriteInterfaceToken(GetDescriptor())) {
768         WLOGFE("Failed to WriteInterfaceToken!");
769         return WMError::WM_ERROR_IPC_FAILED;
770     }
771 
772     if (!data.WriteParcelable(from)) {
773         WLOGFE("Failed to write from ability window info!");
774         return WMError::WM_ERROR_IPC_FAILED;
775     }
776 
777     if (!data.WriteParcelable(to)) {
778         WLOGFE("Failed to write to ability window info!");
779         return WMError::WM_ERROR_IPC_FAILED;
780     }
781 
782     if (!data.WriteBool(isFromClient)) {
783         WLOGFE("Failed to write to isFromClient!");
784         return WMError::WM_ERROR_IPC_FAILED;
785     }
786     sptr<IRemoteObject> remote = Remote();
787     if (remote == nullptr) {
788         WLOGFE("remote is null");
789         return WMError::WM_ERROR_IPC_FAILED;
790     }
791     auto error = remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION),
792         data, reply, option);
793     if (error != ERR_NONE) {
794         WLOGFE("Send request error: %{public}d", static_cast<uint32_t>(error));
795         return WMError::WM_ERROR_IPC_FAILED;
796     }
797     auto ret = static_cast<WMError>(reply.ReadInt32());
798     return ret;
799 }
800 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)801 WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
802 {
803     MessageParcel data;
804     MessageParcel reply;
805     MessageOption option;
806 
807     if (!data.WriteInterfaceToken(GetDescriptor())) {
808         WLOGFE("WriteInterfaceToken failed");
809         return WMError::WM_ERROR_IPC_FAILED;
810     }
811     if (!data.WriteUint64(displayId)) {
812         WLOGFE("Write displayId failed");
813         return WMError::WM_ERROR_IPC_FAILED;
814     }
815     sptr<IRemoteObject> remote = Remote();
816     if (remote == nullptr) {
817         WLOGFE("remote is null");
818         return WMError::WM_ERROR_IPC_FAILED;
819     }
820     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
821         data, reply, option) != ERR_NONE) {
822         return WMError::WM_ERROR_IPC_FAILED;
823     }
824 
825     auto ret = static_cast<WMError>(reply.ReadInt32());
826     if (ret == WMError::WM_OK) {
827         hotZones.fullscreen_.posX_ = reply.ReadInt32();
828         hotZones.fullscreen_.posY_ = reply.ReadInt32();
829         hotZones.fullscreen_.width_ = reply.ReadUint32();
830         hotZones.fullscreen_.height_ = reply.ReadUint32();
831 
832         hotZones.primary_.posX_ = reply.ReadInt32();
833         hotZones.primary_.posY_ = reply.ReadInt32();
834         hotZones.primary_.width_ = reply.ReadUint32();
835         hotZones.primary_.height_ = reply.ReadUint32();
836 
837         hotZones.secondary_.posX_ = reply.ReadInt32();
838         hotZones.secondary_.posY_ = reply.ReadInt32();
839         hotZones.secondary_.width_ = reply.ReadUint32();
840         hotZones.secondary_.height_ = reply.ReadUint32();
841     }
842     return ret;
843 }
844 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)845 void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
846     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
847 {
848     MessageParcel data;
849     MessageParcel reply;
850     MessageOption option;
851     if (!data.WriteInterfaceToken(GetDescriptor())) {
852         WLOGFE("WriteInterfaceToken failed");
853         return;
854     }
855 
856     if (!data.WriteUInt32Vector(windowIds)) {
857         WLOGFE("Write windowIds failed");
858         return;
859     }
860 
861     if (!data.WriteBool(isAnimated)) {
862         WLOGFE("Write isAnimated failed");
863         return;
864     }
865     sptr<IRemoteObject> remote = Remote();
866     if (remote == nullptr) {
867         WLOGFE("remote is null");
868         return;
869     }
870     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK),
871         data, reply, option) != ERR_NONE) {
872         WLOGFE("Send request error");
873         return;
874     }
875     if (reply.ReadBool()) {
876         sptr<IRemoteObject> finishCallbackObject = reply.ReadRemoteObject();
877         finishCallback = iface_cast<RSIWindowAnimationFinishedCallback>(finishCallbackObject);
878     } else {
879         finishCallback = nullptr;
880     }
881     return;
882 }
883 
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)884 WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
885 {
886     MessageParcel data;
887     MessageParcel reply;
888     MessageOption option;
889 
890     if (!data.WriteInterfaceToken(GetDescriptor())) {
891         WLOGFE("WriteInterfaceToken failed");
892         return WMError::WM_ERROR_IPC_FAILED;
893     }
894     if (!data.WriteUint32(windowId)) {
895         WLOGFE("Write windowId failed");
896         return WMError::WM_ERROR_IPC_FAILED;
897     }
898     if (!data.WriteBool(haveListener)) {
899         WLOGFE("Write avoid area listener failed");
900         return WMError::WM_ERROR_IPC_FAILED;
901     }
902     sptr<IRemoteObject> remote = Remote();
903     if (remote == nullptr) {
904         WLOGFE("remote is null");
905         return WMError::WM_ERROR_IPC_FAILED;
906     }
907     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
908         data, reply, option) != ERR_NONE) {
909         return WMError::WM_ERROR_IPC_FAILED;
910     }
911     return static_cast<WMError>(reply.ReadInt32());
912 }
913 
UpdateRsTree(uint32_t windowId,bool isAdd)914 WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd)
915 {
916     MessageParcel data;
917     MessageParcel reply;
918     MessageOption option(MessageOption::TF_ASYNC);
919 
920     if (!data.WriteInterfaceToken(GetDescriptor())) {
921         WLOGFE("WriteInterfaceToken failed");
922         return WMError::WM_ERROR_IPC_FAILED;
923     }
924     if (!data.WriteUint32(windowId)) {
925         WLOGFE("Write windowId failed");
926         return WMError::WM_ERROR_IPC_FAILED;
927     }
928     if (!data.WriteBool(isAdd)) {
929         WLOGFE("Write avoid area listener failed");
930         return WMError::WM_ERROR_IPC_FAILED;
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_UPDATE_RS_TREE),
938         data, reply, option) != ERR_NONE) {
939         return WMError::WM_ERROR_IPC_FAILED;
940     }
941     return static_cast<WMError>(reply.ReadInt32());
942 }
943 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)944 WMError WindowManagerProxy::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
945 {
946     MessageParcel data;
947     MessageParcel reply;
948     MessageOption option;
949     if (!data.WriteInterfaceToken(GetDescriptor())) {
950         WLOGFE("WriteInterfaceToken failed");
951         return WMError::WM_ERROR_IPC_FAILED;
952     }
953     if (!data.WriteUint32(windowId)) {
954         WLOGFE("Write windowId failed");
955         return WMError::WM_ERROR_IPC_FAILED;
956     }
957     if (targetToken != nullptr) {
958         if (!data.WriteRemoteObject(targetToken)) {
959             WLOGFE("Write targetToken failed");
960             return WMError::WM_ERROR_IPC_FAILED;
961         }
962     }
963     sptr<IRemoteObject> remote = Remote();
964     if (remote == nullptr) {
965         WLOGFE("remote is null");
966         return WMError::WM_ERROR_IPC_FAILED;
967     }
968     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
969         data, reply, option) != ERR_NONE) {
970         return WMError::WM_ERROR_IPC_FAILED;
971     }
972 
973     int32_t ret = reply.ReadInt32();
974     return static_cast<WMError>(ret);
975 }
976 
SetAnchorAndScale(int32_t x,int32_t y,float scale)977 void WindowManagerProxy::SetAnchorAndScale(int32_t x, int32_t y, float scale)
978 {
979     MessageParcel data;
980     MessageParcel reply;
981     MessageOption option;
982     if (!data.WriteInterfaceToken(GetDescriptor())) {
983         WLOGFE("WriteInterfaceToken failed");
984         return;
985     }
986     if (!data.WriteInt32(x)) {
987         WLOGFE("Write anchor x failed");
988         return;
989     }
990     if (!data.WriteInt32(y)) {
991         WLOGFE("Write anchor y failed");
992         return;
993     }
994     if (!data.WriteFloat(scale)) {
995         WLOGFE("Write scale failed");
996         return;
997     }
998     sptr<IRemoteObject> remote = Remote();
999     if (remote == nullptr) {
1000         WLOGFE("remote is null");
1001         return;
1002     }
1003     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE),
1004         data, reply, option) != ERR_NONE) {
1005         WLOGFE("SendRequest failed");
1006     }
1007 }
1008 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)1009 void WindowManagerProxy::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
1010 {
1011     MessageParcel data;
1012     MessageParcel reply;
1013     MessageOption option;
1014     if (!data.WriteInterfaceToken(GetDescriptor())) {
1015         WLOGFE("WriteInterfaceToken failed");
1016         return;
1017     }
1018     if (!data.WriteInt32(deltaX)) {
1019         WLOGFE("Write anchor delatX failed");
1020         return;
1021     }
1022     if (!data.WriteInt32(deltaY)) {
1023         WLOGFE("Write anchor deltaY failed");
1024         return;
1025     }
1026     sptr<IRemoteObject> remote = Remote();
1027     if (remote == nullptr) {
1028         WLOGFE("remote is null");
1029         return;
1030     }
1031     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET),
1032         data, reply, option) != ERR_NONE) {
1033         WLOGFE("SendRequest failed");
1034     }
1035 }
1036 
OffWindowZoom()1037 void WindowManagerProxy::OffWindowZoom()
1038 {
1039     MessageParcel data;
1040     MessageParcel reply;
1041     MessageOption option;
1042     if (!data.WriteInterfaceToken(GetDescriptor())) {
1043         WLOGFE("WriteInterfaceToken failed");
1044         return;
1045     }
1046     sptr<IRemoteObject> remote = Remote();
1047     if (remote == nullptr) {
1048         WLOGFE("remote is null");
1049         return;
1050     }
1051     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM),
1052         data, reply, option) != ERR_NONE) {
1053         WLOGFE("SendRequest failed");
1054     }
1055 }
1056 
1057 /** @note @window.hierarchy */
RaiseToAppTop(uint32_t windowId)1058 WMError WindowManagerProxy::RaiseToAppTop(uint32_t windowId)
1059 {
1060     MessageParcel data;
1061     MessageParcel reply;
1062     MessageOption option;
1063     if (!data.WriteInterfaceToken(GetDescriptor())) {
1064         WLOGFE("WriteInterfaceToken failed");
1065         return WMError::WM_ERROR_IPC_FAILED;
1066     }
1067 
1068     if (!data.WriteUint32(windowId)) {
1069         WLOGFE("Write anchor delatX failed");
1070         return WMError::WM_ERROR_IPC_FAILED;
1071     }
1072 
1073     sptr<IRemoteObject> remote = Remote();
1074     if (remote == nullptr) {
1075         WLOGFE("remote is null");
1076         return WMError::WM_ERROR_IPC_FAILED;
1077     }
1078     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER),
1079         data, reply, option) != ERR_NONE) {
1080         WLOGFE("SendRequest failed");
1081         return WMError::WM_ERROR_IPC_FAILED;
1082     }
1083     return WMError::WM_OK;
1084 }
1085 
GetSnapshot(int32_t windowId)1086 std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowId)
1087 {
1088     MessageParcel data;
1089     MessageParcel reply;
1090     MessageOption option;
1091 
1092     if (!data.WriteInterfaceToken(GetDescriptor())) {
1093         WLOGFE("WriteInterfaceToken failed");
1094         return nullptr;
1095     }
1096     if (!data.WriteUint32(windowId)) {
1097         WLOGFE("Write windowId failed");
1098         return nullptr;
1099     }
1100     sptr<IRemoteObject> remote = Remote();
1101     if (remote == nullptr) {
1102         WLOGFE("remote is null");
1103         return nullptr;
1104     }
1105     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SNAPSHOT),
1106         data, reply, option) != ERR_NONE) {
1107         WLOGFE("SendRequest failed");
1108         return nullptr;
1109     }
1110 
1111     std::shared_ptr<Media::PixelMap> map(reply.ReadParcelable<Media::PixelMap>());
1112     if (map == nullptr) {
1113         WLOGFE("Read pixelMap is null");
1114         return nullptr;
1115     }
1116     return map;
1117 }
1118 
GetSnapshotByWindowId(int32_t persistentId,std::shared_ptr<Media::PixelMap> & pixelMap)1119 WMError WindowManagerProxy::GetSnapshotByWindowId(int32_t persistentId, std::shared_ptr<Media::PixelMap>& pixelMap)
1120 {
1121     pixelMap = GetSnapshot(persistentId);
1122     if (pixelMap == nullptr) {
1123         WLOGFE("Get snapshot is nullptr");
1124         return WMError::WM_ERROR_NULLPTR;
1125     }
1126     return WMError::WM_OK;
1127 }
1128 
SetGestureNavigationEnabled(bool enable)1129 WMError WindowManagerProxy::SetGestureNavigationEnabled(bool enable)
1130 {
1131     MessageParcel data;
1132     MessageParcel reply;
1133     MessageOption option;
1134     if (!data.WriteInterfaceToken(GetDescriptor())) {
1135         WLOGFE("WriteInterfaceToken failed");
1136         return WMError::WM_ERROR_IPC_FAILED;
1137     }
1138 
1139     if (!data.WriteBool(enable)) {
1140         WLOGFE("Write anchor delatX failed");
1141         return WMError::WM_ERROR_IPC_FAILED;
1142     }
1143 
1144     sptr<IRemoteObject> remote = Remote();
1145     if (remote == nullptr) {
1146         WLOGFE("remote is null");
1147         return WMError::WM_ERROR_IPC_FAILED;
1148     }
1149     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GESTURE_NAVIGATION_ENABLED),
1150         data, reply, option) != ERR_NONE) {
1151         WLOGFE("SendRequest failed");
1152         return WMError::WM_ERROR_IPC_FAILED;
1153     }
1154     int32_t ret = reply.ReadInt32();
1155     return static_cast<WMError>(ret);
1156 }
1157 
DispatchKeyEvent(uint32_t windowId,std::shared_ptr<MMI::KeyEvent> event)1158 void WindowManagerProxy::DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event)
1159 {
1160     MessageParcel data;
1161     MessageParcel reply;
1162     MessageOption option(MessageOption::TF_ASYNC);
1163     if (!data.WriteInterfaceToken(GetDescriptor())) {
1164         WLOGFE("WriteInterfaceToken failed");
1165         return;
1166     }
1167     if (!data.WriteUint32(windowId)) {
1168         WLOGFE("Write anchor delatX failed");
1169         return;
1170     }
1171     if (!event || !event->WriteToParcel(data)) {
1172         WLOGFE("Write event faild");
1173         return;
1174     }
1175     sptr<IRemoteObject> remote = Remote();
1176     if (remote == nullptr) {
1177         WLOGFE("remote is null");
1178         return;
1179     }
1180     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DISPATCH_KEY_EVENT),
1181         data, reply, option) != ERR_NONE) {
1182         WLOGFE("SendRequest failed");
1183         return;
1184     }
1185 }
1186 
NotifyDumpInfoResult(const std::vector<std::string> & info)1187 void WindowManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
1188 {
1189     MessageParcel data;
1190     MessageParcel reply;
1191     MessageOption option(MessageOption::TF_ASYNC);
1192     if (!data.WriteInterfaceToken(GetDescriptor())) {
1193         WLOGFE("WriteInterfaceToken pfailed");
1194         return;
1195     }
1196     if (!data.WriteStringVector(info)) {
1197         WLOGFE("Write info failed");
1198         return;
1199     }
1200     sptr<IRemoteObject> remote = Remote();
1201     if (remote == nullptr) {
1202         WLOGFE("remote is null");
1203         return;
1204     }
1205     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
1206         data, reply, option) != ERR_NONE) {
1207         WLOGFE("SendRequest failed");
1208         return;
1209     }
1210 }
1211 
GetWindowAnimationTargets(std::vector<uint32_t> missionIds,std::vector<sptr<RSWindowAnimationTarget>> & targets)1212 WMError WindowManagerProxy::GetWindowAnimationTargets(std::vector<uint32_t> missionIds,
1213     std::vector<sptr<RSWindowAnimationTarget>>& targets)
1214 {
1215     MessageParcel data;
1216     MessageParcel reply;
1217     MessageOption option;
1218     if (!data.WriteInterfaceToken(GetDescriptor())) {
1219         WLOGFE("write interfaceToken failed");
1220         return WMError::WM_ERROR_IPC_FAILED;
1221     }
1222     if (!data.WriteUInt32Vector(missionIds)) {
1223         WLOGFE("Write missionIds failed");
1224         return WMError::WM_ERROR_IPC_FAILED;
1225     }
1226     sptr<IRemoteObject> remote = Remote();
1227     if (remote == nullptr) {
1228         WLOGFE("remote is null");
1229         return WMError::WM_ERROR_IPC_FAILED;
1230     }
1231     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_WINDOW_ANIMATION_TARGETS),
1232         data, reply, option) != ERR_NONE) {
1233         return WMError::WM_ERROR_IPC_FAILED;
1234     }
1235     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<RSWindowAnimationTarget>(reply, targets)) {
1236         WLOGFE("read window animation targets failed");
1237         return WMError::WM_ERROR_IPC_FAILED;
1238     }
1239     return static_cast<WMError>(reply.ReadInt32());
1240 }
1241 
SetMaximizeMode(MaximizeMode maximizeMode)1242 void WindowManagerProxy::SetMaximizeMode(MaximizeMode maximizeMode)
1243 {
1244     MessageParcel data;
1245     MessageOption option;
1246     MessageParcel reply;
1247     if (!data.WriteInterfaceToken(GetDescriptor())) {
1248         WLOGFE("WriteInterfaceToken failed!");
1249         return;
1250     }
1251     if (!data.WriteInt32(static_cast<uint32_t>(maximizeMode))) {
1252         WLOGFE("Write maximizeMode failed");
1253         return;
1254     }
1255     sptr<IRemoteObject> remote = Remote();
1256     if (remote == nullptr) {
1257         WLOGFE("remote is null");
1258         return;
1259     }
1260     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_MAXIMIZE_MODE),
1261         data, reply, option) != ERR_NONE) {
1262         WLOGFE("SendRequest failed");
1263     }
1264 }
1265 
GetMaximizeMode()1266 MaximizeMode WindowManagerProxy::GetMaximizeMode()
1267 {
1268     MessageParcel data;
1269     MessageParcel reply;
1270     MessageOption option;
1271     if (!data.WriteInterfaceToken(GetDescriptor())) {
1272         WLOGFE("WriteInterfaceToken failed");
1273         return MaximizeMode::MODE_FULL_FILL;
1274     }
1275 
1276     sptr<IRemoteObject> remote = Remote();
1277     if (remote == nullptr) {
1278         WLOGFE("remote is null");
1279         return MaximizeMode::MODE_FULL_FILL;
1280     }
1281     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_MAXIMIZE_MODE),
1282         data, reply, option) != ERR_NONE) {
1283         WLOGFE("SendRequest failed");
1284         return MaximizeMode::MODE_FULL_FILL;
1285     }
1286     int32_t ret = reply.ReadInt32();
1287     return static_cast<MaximizeMode>(ret);
1288 }
1289 
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)1290 void WindowManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
1291 {
1292     MessageParcel data;
1293     MessageParcel reply;
1294     MessageOption option;
1295     if (!data.WriteInterfaceToken(GetDescriptor())) {
1296         WLOGFE("WriteInterfaceToken failed");
1297         return;
1298     }
1299     if (!data.WriteUint64(displayId)) {
1300         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
1301         return;
1302     }
1303     sptr<IRemoteObject> remote = Remote();
1304     if (remote == nullptr) {
1305         WLOGFE("remote is null");
1306         return;
1307     }
1308     if (remote->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FOCUS_WINDOW_INFO),
1309         data, reply, option) != ERR_NONE) {
1310         WLOGFE("SendRequest failed");
1311         return;
1312     }
1313     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
1314     if (info != nullptr) {
1315         focusInfo = *info;
1316     }
1317 }
1318 } // namespace Rosen
1319 } // namespace OHOS
1320