• 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 <rs_iwindow_animation_controller.h>
19 
20 #include "marshalling_helper.h"
21 #include "window_manager_hilog.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 namespace {
26     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerProxy"};
27 }
28 
29 
CreateWindow(sptr<IWindow> & window,sptr<WindowProperty> & property,const std::shared_ptr<RSSurfaceNode> & surfaceNode,uint32_t & windowId,sptr<IRemoteObject> token)30 WMError WindowManagerProxy::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
31     const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId, sptr<IRemoteObject> token)
32 {
33     MessageParcel data;
34     MessageParcel reply;
35     MessageOption option;
36     if (!data.WriteInterfaceToken(GetDescriptor())) {
37         WLOGFE("WriteInterfaceToken failed");
38         return WMError::WM_ERROR_IPC_FAILED;
39     }
40 
41     if (!data.WriteRemoteObject(window->AsObject())) {
42         WLOGFE("Write IWindow failed");
43         return WMError::WM_ERROR_IPC_FAILED;
44     }
45 
46     if (!data.WriteParcelable(property.GetRefPtr())) {
47         WLOGFE("Write windowProperty failed");
48         return WMError::WM_ERROR_IPC_FAILED;
49     }
50 
51     if (surfaceNode == nullptr || !surfaceNode->Marshalling(data)) {
52         WLOGFE("Write windowProperty failed");
53         return WMError::WM_ERROR_IPC_FAILED;
54     }
55     if (token != nullptr) {
56         if (!data.WriteRemoteObject(token)) {
57             WLOGFE("Write abilityToken failed");
58             return WMError::WM_ERROR_IPC_FAILED;
59         }
60     }
61 
62     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_CREATE_WINDOW),
63         data, reply, option) != ERR_NONE) {
64         return WMError::WM_ERROR_IPC_FAILED;
65     }
66     windowId = reply.ReadUint32();
67     int32_t ret = reply.ReadInt32();
68     return static_cast<WMError>(ret);
69 }
70 
AddWindow(sptr<WindowProperty> & property)71 WMError WindowManagerProxy::AddWindow(sptr<WindowProperty>& property)
72 {
73     MessageParcel data;
74     MessageParcel reply;
75     MessageOption option;
76     if (!data.WriteInterfaceToken(GetDescriptor())) {
77         WLOGFE("WriteInterfaceToken failed");
78         return WMError::WM_ERROR_IPC_FAILED;
79     }
80 
81     if (!data.WriteParcelable(property.GetRefPtr())) {
82         WLOGFE("Write windowProperty failed");
83         return WMError::WM_ERROR_IPC_FAILED;
84     }
85 
86     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ADD_WINDOW),
87         data, reply, option) != ERR_NONE) {
88         return WMError::WM_ERROR_IPC_FAILED;
89     }
90 
91     int32_t ret = reply.ReadInt32();
92     return static_cast<WMError>(ret);
93 }
94 
RemoveWindow(uint32_t windowId)95 WMError WindowManagerProxy::RemoveWindow(uint32_t windowId)
96 {
97     MessageParcel data;
98     MessageParcel reply;
99     MessageOption option;
100     if (!data.WriteInterfaceToken(GetDescriptor())) {
101         WLOGFE("WriteInterfaceToken failed");
102         return WMError::WM_ERROR_IPC_FAILED;
103     }
104 
105     if (!data.WriteUint32(windowId)) {
106         WLOGFE("Write windowId failed");
107         return WMError::WM_ERROR_IPC_FAILED;
108     }
109 
110     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REMOVE_WINDOW),
111         data, reply, option) != ERR_NONE) {
112         return WMError::WM_ERROR_IPC_FAILED;
113     }
114 
115     int32_t ret = reply.ReadInt32();
116     return static_cast<WMError>(ret);
117 }
118 
DestroyWindow(uint32_t windowId,bool)119 WMError WindowManagerProxy::DestroyWindow(uint32_t windowId, bool /* onlySelf */)
120 {
121     MessageParcel data;
122     MessageParcel reply;
123     MessageOption option;
124     if (!data.WriteInterfaceToken(GetDescriptor())) {
125         WLOGFE("WriteInterfaceToken failed");
126         return WMError::WM_ERROR_IPC_FAILED;
127     }
128 
129     if (!data.WriteUint32(windowId)) {
130         WLOGFE("Write windowId failed");
131         return WMError::WM_ERROR_IPC_FAILED;
132     }
133 
134     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_DESTROY_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 
RequestFocus(uint32_t windowId)143 WMError WindowManagerProxy::RequestFocus(uint32_t windowId)
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     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REQUEST_FOCUS),
158         data, reply, option) != ERR_NONE) {
159         return WMError::WM_ERROR_IPC_FAILED;
160     }
161 
162     int32_t ret = reply.ReadInt32();
163     return static_cast<WMError>(ret);
164 }
165 
GetAvoidAreaByType(uint32_t windowId,AvoidAreaType type)166 AvoidArea WindowManagerProxy::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type)
167 {
168     MessageParcel data;
169     MessageParcel reply;
170     MessageOption option;
171 
172     AvoidArea avoidArea;
173     if (!data.WriteInterfaceToken(GetDescriptor())) {
174         WLOGFE("WriteInterfaceToken failed");
175         return avoidArea;
176     }
177 
178     if (!data.WriteUint32(windowId)) {
179         WLOGFE("Write windowId failed");
180         return avoidArea;
181     }
182 
183     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
184         WLOGFE("Write AvoidAreaType failed");
185         return avoidArea;
186     }
187 
188     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_AVOID_AREA),
189         data, reply, option) != ERR_NONE) {
190         return avoidArea;
191     }
192     sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
193     if (area == nullptr) {
194         return avoidArea;
195     }
196     return *area;
197 }
198 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)199 bool WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
200     const sptr<IWindowManagerAgent>& windowManagerAgent)
201 {
202     MessageParcel data;
203     MessageParcel reply;
204     MessageOption option;
205     if (!data.WriteInterfaceToken(GetDescriptor())) {
206         WLOGFE("WriteInterfaceToken failed");
207         return false;
208     }
209 
210     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
211         WLOGFE("Write type failed");
212         return false;
213     }
214 
215     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
216         WLOGFE("Write IWindowManagerAgent failed");
217         return false;
218     }
219 
220     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
221         data, reply, option) != ERR_NONE) {
222         WLOGFE("SendRequest failed");
223         return false;
224     }
225 
226     return reply.ReadBool();
227 }
228 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)229 bool WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
230     const sptr<IWindowManagerAgent>& windowManagerAgent)
231 {
232     MessageParcel data;
233     MessageParcel reply;
234     MessageOption option;
235     if (!data.WriteInterfaceToken(GetDescriptor())) {
236         WLOGFE("WriteInterfaceToken failed");
237         return false;
238     }
239 
240     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
241         WLOGFE("Write type failed");
242         return false;
243     }
244 
245     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
246         WLOGFE("Write IWindowManagerAgent failed");
247         return false;
248     }
249 
250     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
251         data, reply, option) != ERR_NONE) {
252         WLOGFE("SendRequest failed");
253         return false;
254     }
255 
256     return reply.ReadBool();
257 }
258 
SetWindowAnimationController(const sptr<RSIWindowAnimationController> & controller)259 WMError WindowManagerProxy::SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller)
260 {
261     MessageParcel data;
262     MessageParcel reply;
263     MessageOption option;
264 
265     if (controller == nullptr) {
266         WLOGFE("RSWindowAnimation Failed to set window animation controller, controller is null!");
267         return WMError::WM_ERROR_IPC_FAILED;
268     }
269 
270     if (!data.WriteInterfaceToken(GetDescriptor())) {
271         WLOGFE("RSWindowAnimation Failed to WriteInterfaceToken!");
272         return WMError::WM_ERROR_IPC_FAILED;
273     }
274 
275     if (!data.WriteRemoteObject(controller->AsObject())) {
276         WLOGFE("RSWindowAnimation Failed to write controller!");
277         return WMError::WM_ERROR_IPC_FAILED;
278     }
279 
280     auto error = Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_ANIMATION_SET_CONTROLLER),
281         data, reply, option);
282     if (error != ERR_NONE) {
283         WLOGFE("RSWindowAnimation Send request error: %{public}d", error);
284         return WMError::WM_ERROR_IPC_FAILED;
285     }
286 
287     int32_t ret = reply.ReadInt32();
288     return static_cast<WMError>(ret);
289 }
290 
NotifyServerReadyToMoveOrDrag(uint32_t windowId,sptr<WindowProperty> & windowProperty,sptr<MoveDragProperty> & moveDragProperty)291 void WindowManagerProxy::NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<WindowProperty>& windowProperty,
292     sptr<MoveDragProperty>& moveDragProperty)
293 {
294     MessageParcel data;
295     MessageParcel reply;
296     MessageOption option;
297     if (!data.WriteInterfaceToken(GetDescriptor())) {
298         WLOGFE("WriteInterfaceToken failed");
299         return;
300     }
301     if (!data.WriteUint32(windowId)) {
302         WLOGFE("Write windowId failed");
303         return;
304     }
305     if (!data.WriteParcelable(windowProperty.GetRefPtr())) {
306         WLOGFE("Failed to write windowProperty!");
307         return;
308     }
309     if (!data.WriteParcelable(moveDragProperty.GetRefPtr())) {
310         WLOGFE("Failed to write moveDragProperty!");
311         return;
312     }
313     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_READY_MOVE_OR_DRAG),
314         data, reply, option) != ERR_NONE) {
315         WLOGFE("SendRequest failed");
316     }
317 }
318 
ProcessPointDown(uint32_t windowId,bool isPointDown)319 void WindowManagerProxy::ProcessPointDown(uint32_t windowId, bool isPointDown)
320 {
321     MessageParcel data;
322     MessageParcel reply;
323     MessageOption option;
324     if (!data.WriteInterfaceToken(GetDescriptor())) {
325         WLOGFE("WriteInterfaceToken failed");
326         return;
327     }
328     if (!data.WriteUint32(windowId)) {
329         WLOGFE("Write windowId failed");
330         return;
331     }
332     if (!data.WriteBool(isPointDown)) {
333         WLOGFE("Write isPointDown failed");
334         return;
335     }
336     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_DOWN),
337         data, reply, option) != ERR_NONE) {
338         WLOGFE("SendRequest failed");
339     }
340 }
341 
ProcessPointUp(uint32_t windowId)342 void WindowManagerProxy::ProcessPointUp(uint32_t windowId)
343 {
344     MessageParcel data;
345     MessageParcel reply;
346     MessageOption option;
347     if (!data.WriteInterfaceToken(GetDescriptor())) {
348         WLOGFE("WriteInterfaceToken failed");
349         return;
350     }
351     if (!data.WriteUint32(windowId)) {
352         WLOGFE("Write windowId failed");
353         return;
354     }
355     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_PROCESS_POINT_UP),
356         data, reply, option) != ERR_NONE) {
357         WLOGFE("SendRequest failed");
358     }
359 }
360 
MinimizeAllAppWindows(DisplayId displayId)361 void WindowManagerProxy::MinimizeAllAppWindows(DisplayId displayId)
362 {
363     MessageParcel data;
364     MessageParcel reply;
365     MessageOption option;
366     if (!data.WriteInterfaceToken(GetDescriptor())) {
367         WLOGFE("WriteInterfaceToken failed");
368         return;
369     }
370     if (!data.WriteUint64(displayId)) {
371         WLOGFE("Write displayId failed");
372         return;
373     }
374     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_MINIMIZE_ALL_APP_WINDOWS),
375         data, reply, option) != ERR_NONE) {
376         WLOGFE("SendRequest failed");
377     }
378 }
379 
ToggleShownStateForAllAppWindows()380 WMError WindowManagerProxy::ToggleShownStateForAllAppWindows()
381 {
382     MessageParcel data;
383     MessageParcel reply;
384     MessageOption option;
385     if (!data.WriteInterfaceToken(GetDescriptor())) {
386         WLOGFE("WriteInterfaceToken failed");
387         return WMError::WM_ERROR_IPC_FAILED;
388     }
389     if (Remote()->SendRequest(
390         static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_TOGGLE_SHOWN_STATE_FOR_ALL_APP_WINDOWS),
391         data, reply, option) != ERR_NONE) {
392         WLOGFE("SendRequest failed");
393         return WMError::WM_ERROR_IPC_FAILED;
394     }
395     int32_t ret;
396     if (!reply.ReadInt32(ret)) {
397         return WMError::WM_ERROR_IPC_FAILED;
398     }
399     return static_cast<WMError>(ret);
400 }
401 
SetWindowLayoutMode(WindowLayoutMode mode)402 WMError WindowManagerProxy::SetWindowLayoutMode(WindowLayoutMode mode)
403 {
404     MessageParcel data;
405     MessageParcel reply;
406     MessageOption option;
407     if (!data.WriteInterfaceToken(GetDescriptor())) {
408         WLOGFE("WriteInterfaceToken failed");
409         return WMError::WM_ERROR_IPC_FAILED;
410     }
411     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
412         WLOGFE("Write mode failed");
413         return WMError::WM_ERROR_IPC_FAILED;
414     }
415     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_LAYOUT_MODE),
416         data, reply, option) != ERR_NONE) {
417         return WMError::WM_ERROR_IPC_FAILED;
418     }
419 
420     int32_t ret = reply.ReadInt32();
421     return static_cast<WMError>(ret);
422 }
423 
UpdateProperty(sptr<WindowProperty> & windowProperty,PropertyChangeAction action,bool isAsyncTask)424 WMError WindowManagerProxy::UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action,
425     bool isAsyncTask)
426 {
427     MessageParcel data;
428     MessageParcel reply;
429     MessageOption option;
430     if (!data.WriteInterfaceToken(GetDescriptor())) {
431         WLOGFE("WriteInterfaceToken failed");
432         return WMError::WM_ERROR_IPC_FAILED;
433     }
434 
435     if (!data.WriteUint32(static_cast<uint32_t>(action))) {
436         WLOGFE("Write PropertyChangeAction failed");
437         return WMError::WM_ERROR_IPC_FAILED;
438     }
439 
440     if (!windowProperty->Write(data, action)) {
441         WLOGFE("Write windowProperty failed");
442         return WMError::WM_ERROR_IPC_FAILED;
443     }
444 
445     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_PROPERTY),
446         data, reply, option) != ERR_NONE) {
447         return WMError::WM_ERROR_IPC_FAILED;
448     }
449 
450     int32_t ret = reply.ReadInt32();
451     return static_cast<WMError>(ret);
452 }
453 
GetTopWindowId(uint32_t mainWinId,uint32_t & topWinId)454 WMError WindowManagerProxy::GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId)
455 {
456     MessageParcel data;
457     MessageParcel reply;
458     MessageOption option;
459     if (!data.WriteInterfaceToken(GetDescriptor())) {
460         WLOGFE("WriteInterfaceToken failed");
461         return WMError::WM_ERROR_IPC_FAILED;
462     }
463 
464     if (!data.WriteUint32(mainWinId)) {
465         WLOGFE("Write mainWinId failed");
466         return WMError::WM_ERROR_IPC_FAILED;
467     }
468 
469     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
470         data, reply, option) != ERR_NONE) {
471         return WMError::WM_ERROR_IPC_FAILED;
472     }
473     topWinId = reply.ReadUint32();
474     int32_t ret = reply.ReadInt32();
475     return static_cast<WMError>(ret);
476 }
477 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)478 WMError WindowManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
479 {
480     MessageParcel data;
481     MessageParcel reply;
482     MessageOption option;
483     if (!data.WriteInterfaceToken(GetDescriptor())) {
484         WLOGFE("WriteInterfaceToken failed");
485         return WMError::WM_ERROR_IPC_FAILED;
486     }
487     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ACCESSIBILITY_WINDOW_INFO_ID),
488         data, reply, option) != ERR_NONE) {
489         return WMError::WM_ERROR_IPC_FAILED;
490     }
491     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
492         WLOGFE("read accessibility window infos failed");
493         return WMError::WM_ERROR_IPC_FAILED;
494     }
495     return static_cast<WMError>(reply.ReadInt32());
496 }
497 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)498 WMError WindowManagerProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
499 {
500     MessageParcel data;
501     MessageParcel reply;
502     MessageOption option;
503     if (!data.WriteInterfaceToken(GetDescriptor())) {
504         WLOGFE("WriteInterfaceToken failed");
505         return WMError::WM_ERROR_IPC_FAILED;
506     }
507     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID),
508         data, reply, option) != ERR_NONE) {
509         return WMError::WM_ERROR_IPC_FAILED;
510     }
511     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
512         WLOGFE("read visibility window infos failed");
513         return WMError::WM_ERROR_IPC_FAILED;
514     }
515     return static_cast<WMError>(reply.ReadInt32());
516 }
517 
GetSystemConfig(SystemConfig & systemConfig)518 WMError WindowManagerProxy::GetSystemConfig(SystemConfig& systemConfig)
519 {
520     MessageParcel data;
521     MessageParcel reply;
522     MessageOption option;
523     if (!data.WriteInterfaceToken(GetDescriptor())) {
524         WLOGFE("WriteInterfaceToken failed");
525         return WMError::WM_ERROR_IPC_FAILED;
526     }
527     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG),
528         data, reply, option) != ERR_NONE) {
529         return WMError::WM_ERROR_IPC_FAILED;
530     }
531     sptr<SystemConfig> config = reply.ReadParcelable<SystemConfig>();
532     systemConfig = *config;
533     int32_t ret = reply.ReadInt32();
534     return static_cast<WMError>(ret);
535 }
536 
NotifyWindowTransition(sptr<WindowTransitionInfo> & from,sptr<WindowTransitionInfo> & to,bool isFromClient)537 WMError WindowManagerProxy::NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
538     bool isFromClient)
539 {
540     MessageParcel data;
541     MessageParcel reply;
542     MessageOption option;
543 
544     if (!data.WriteInterfaceToken(GetDescriptor())) {
545         WLOGFE("Failed to WriteInterfaceToken!");
546         return WMError::WM_ERROR_IPC_FAILED;
547     }
548 
549     if (!data.WriteParcelable(from)) {
550         WLOGFE("Failed to write from ability window info!");
551         return WMError::WM_ERROR_IPC_FAILED;
552     }
553 
554     if (!data.WriteParcelable(to)) {
555         WLOGFE("Failed to write to ability window info!");
556         return WMError::WM_ERROR_IPC_FAILED;
557     }
558 
559     if (!data.WriteBool(isFromClient)) {
560         WLOGFE("Failed to write to isFromClient!");
561         return WMError::WM_ERROR_IPC_FAILED;
562     }
563     auto error = Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION),
564         data, reply, option);
565     if (error != ERR_NONE) {
566         WLOGFE("Send request error: %{public}d", static_cast<uint32_t>(error));
567         return WMError::WM_ERROR_IPC_FAILED;
568     }
569     auto ret = static_cast<WMError>(reply.ReadInt32());
570     return ret;
571 }
572 
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)573 WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
574 {
575     MessageParcel data;
576     MessageParcel reply;
577     MessageOption option;
578 
579     if (!data.WriteInterfaceToken(GetDescriptor())) {
580         WLOGFE("WriteInterfaceToken failed");
581         return WMError::WM_ERROR_IPC_FAILED;
582     }
583     if (!data.WriteUint64(displayId)) {
584         WLOGFE("Write displayId failed");
585         return WMError::WM_ERROR_IPC_FAILED;
586     }
587     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
588         data, reply, option) != ERR_NONE) {
589         return WMError::WM_ERROR_IPC_FAILED;
590     }
591 
592     auto ret = static_cast<WMError>(reply.ReadInt32());
593     if (ret == WMError::WM_OK) {
594         hotZones.fullscreen_.posX_ = reply.ReadInt32();
595         hotZones.fullscreen_.posY_ = reply.ReadInt32();
596         hotZones.fullscreen_.width_ = reply.ReadUint32();
597         hotZones.fullscreen_.height_ = reply.ReadUint32();
598 
599         hotZones.primary_.posX_ = reply.ReadInt32();
600         hotZones.primary_.posY_ = reply.ReadInt32();
601         hotZones.primary_.width_ = reply.ReadUint32();
602         hotZones.primary_.height_ = reply.ReadUint32();
603 
604         hotZones.secondary_.posX_ = reply.ReadInt32();
605         hotZones.secondary_.posY_ = reply.ReadInt32();
606         hotZones.secondary_.width_ = reply.ReadUint32();
607         hotZones.secondary_.height_ = reply.ReadUint32();
608     }
609     return ret;
610 }
611 
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)612 void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
613     sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
614 {
615     MessageParcel data;
616     MessageParcel reply;
617     MessageOption option;
618     if (!data.WriteInterfaceToken(GetDescriptor())) {
619         WLOGFE("WriteInterfaceToken failed");
620         return;
621     }
622 
623     if (!data.WriteUInt32Vector(windowIds)) {
624         WLOGFE("Write windowIds failed");
625         return;
626     }
627 
628     if (!data.WriteBool(isAnimated)) {
629         WLOGFE("Write isAnimated failed");
630         return;
631     }
632     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK),
633         data, reply, option) != ERR_NONE) {
634         WLOGFE("Send request error");
635         return;
636     }
637     ;
638     if (reply.ReadBool()) {
639         sptr<IRemoteObject> finishCallbackObject = reply.ReadRemoteObject();
640         finishCallback = iface_cast<RSIWindowAnimationFinishedCallback>(finishCallbackObject);
641     } else {
642         finishCallback = nullptr;
643     }
644     return;
645 }
646 
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)647 WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
648 {
649     MessageParcel data;
650     MessageParcel reply;
651     MessageOption option;
652 
653     if (!data.WriteInterfaceToken(GetDescriptor())) {
654         WLOGFE("WriteInterfaceToken failed");
655         return WMError::WM_ERROR_IPC_FAILED;
656     }
657     if (!data.WriteUint32(windowId)) {
658         WLOGFE("Write windowId failed");
659         return WMError::WM_ERROR_IPC_FAILED;
660     }
661     if (!data.WriteBool(haveListener)) {
662         WLOGFE("Write avoid area listener failed");
663         return WMError::WM_ERROR_IPC_FAILED;
664     }
665     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
666         data, reply, option) != ERR_NONE) {
667         return WMError::WM_ERROR_IPC_FAILED;
668     }
669     return static_cast<WMError>(reply.ReadInt32());
670 }
671 
UpdateRsTree(uint32_t windowId,bool isAdd)672 WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd)
673 {
674     MessageParcel data;
675     MessageParcel reply;
676     MessageOption option(MessageOption::TF_ASYNC);
677 
678     if (!data.WriteInterfaceToken(GetDescriptor())) {
679         WLOGFE("WriteInterfaceToken failed");
680         return WMError::WM_ERROR_IPC_FAILED;
681     }
682     if (!data.WriteUint32(windowId)) {
683         WLOGFE("Write windowId failed");
684         return WMError::WM_ERROR_IPC_FAILED;
685     }
686     if (!data.WriteBool(isAdd)) {
687         WLOGFE("Write avoid area listener failed");
688         return WMError::WM_ERROR_IPC_FAILED;
689     }
690     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE),
691         data, reply, option) != ERR_NONE) {
692         return WMError::WM_ERROR_IPC_FAILED;
693     }
694     return static_cast<WMError>(reply.ReadInt32());
695 }
696 
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)697 WMError WindowManagerProxy::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
698 {
699     MessageParcel data;
700     MessageParcel reply;
701     MessageOption option;
702     if (!data.WriteInterfaceToken(GetDescriptor())) {
703         WLOGFE("WriteInterfaceToken failed");
704         return WMError::WM_ERROR_IPC_FAILED;
705     }
706     if (!data.WriteUint32(windowId)) {
707         WLOGFE("Write windowId failed");
708         return WMError::WM_ERROR_IPC_FAILED;
709     }
710     if (targetToken != nullptr) {
711         if (!data.WriteRemoteObject(targetToken)) {
712             WLOGFE("Write targetToken failed");
713             return WMError::WM_ERROR_IPC_FAILED;
714         }
715     }
716     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
717         data, reply, option) != ERR_NONE) {
718         return WMError::WM_ERROR_IPC_FAILED;
719     }
720 
721     int32_t ret = reply.ReadInt32();
722     return static_cast<WMError>(ret);
723 }
724 
SetAnchorAndScale(int32_t x,int32_t y,float scale)725 void WindowManagerProxy::SetAnchorAndScale(int32_t x, int32_t y, float scale)
726 {
727     MessageParcel data;
728     MessageParcel reply;
729     MessageOption option;
730     if (!data.WriteInterfaceToken(GetDescriptor())) {
731         WLOGFE("WriteInterfaceToken failed");
732         return;
733     }
734     if (!data.WriteInt32(x)) {
735         WLOGFE("Write anchor x failed");
736         return;
737     }
738     if (!data.WriteInt32(y)) {
739         WLOGFE("Write anchor y failed");
740         return;
741     }
742     if (!data.WriteFloat(scale)) {
743         WLOGFE("Write scale failed");
744         return;
745     }
746     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE),
747         data, reply, option) != ERR_NONE) {
748         WLOGFE("SendRequest failed");
749     }
750 }
751 
SetAnchorOffset(int32_t deltaX,int32_t deltaY)752 void WindowManagerProxy::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
753 {
754     MessageParcel data;
755     MessageParcel reply;
756     MessageOption option;
757     if (!data.WriteInterfaceToken(GetDescriptor())) {
758         WLOGFE("WriteInterfaceToken failed");
759         return;
760     }
761     if (!data.WriteInt32(deltaX)) {
762         WLOGFE("Write anchor delatX failed");
763         return;
764     }
765     if (!data.WriteInt32(deltaY)) {
766         WLOGFE("Write anchor deltaY failed");
767         return;
768     }
769     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET),
770         data, reply, option) != ERR_NONE) {
771         WLOGFE("SendRequest failed");
772     }
773 }
774 
OffWindowZoom()775 void WindowManagerProxy::OffWindowZoom()
776 {
777     MessageParcel data;
778     MessageParcel reply;
779     MessageOption option;
780     if (!data.WriteInterfaceToken(GetDescriptor())) {
781         WLOGFE("WriteInterfaceToken failed");
782         return;
783     }
784     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM),
785         data, reply, option) != ERR_NONE) {
786         WLOGFE("SendRequest failed");
787     }
788 }
789 
GetSnapshot(int32_t windowId)790 std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowId)
791 {
792     MessageParcel data;
793     MessageParcel reply;
794     MessageOption option;
795 
796     Media::InitializationOptions opts;
797     opts.size.width = 200;  // 200:default width
798     opts.size.height = 300; // 300:default height
799     std::shared_ptr<Media::PixelMap> pixelMap(Media::PixelMap::Create(opts).release());
800     if (!data.WriteInterfaceToken(GetDescriptor())) {
801         WLOGFE("WriteInterfaceToken failed");
802         return pixelMap;
803     }
804     if (!data.WriteUint32(windowId)) {
805         WLOGFE("Write windowId failed");
806         return pixelMap;
807     }
808     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SNAPSHOT),
809         data, reply, option) != ERR_NONE) {
810         return pixelMap;
811     }
812 
813     std::shared_ptr<Media::PixelMap> map(reply.ReadParcelable<Media::PixelMap>());
814     if (map == nullptr) {
815         return pixelMap;
816     }
817     return map;
818 }
819 
NotifyDumpInfoResult(const std::vector<std::string> & info)820 void WindowManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
821 {
822     MessageParcel data;
823     MessageParcel reply;
824     MessageOption option(MessageOption::TF_ASYNC);
825     if (!data.WriteInterfaceToken(GetDescriptor())) {
826         WLOGFE("WriteInterfaceToken failed");
827         return;
828     }
829     if (!data.WriteStringVector(info)) {
830         WLOGFE("Write info failed");
831         return;
832     }
833     if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
834         data, reply, option) != ERR_NONE) {
835         WLOGFE("SendRequest failed");
836         return;
837     }
838 }
839 } // namespace Rosen
840 } // namespace OHOS