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 systemConfig = *(reply.ReadParcelable<SystemConfig>());
532 int32_t ret = reply.ReadInt32();
533 return static_cast<WMError>(ret);
534 }
535
NotifyWindowTransition(sptr<WindowTransitionInfo> & from,sptr<WindowTransitionInfo> & to,bool isFromClient)536 WMError WindowManagerProxy::NotifyWindowTransition(sptr<WindowTransitionInfo>& from, sptr<WindowTransitionInfo>& to,
537 bool isFromClient)
538 {
539 MessageParcel data;
540 MessageParcel reply;
541 MessageOption option;
542
543 if (!data.WriteInterfaceToken(GetDescriptor())) {
544 WLOGFE("Failed to WriteInterfaceToken!");
545 return WMError::WM_ERROR_IPC_FAILED;
546 }
547
548 if (!data.WriteParcelable(from)) {
549 WLOGFE("Failed to write from ability window info!");
550 return WMError::WM_ERROR_IPC_FAILED;
551 }
552
553 if (!data.WriteParcelable(to)) {
554 WLOGFE("Failed to write to ability window info!");
555 return WMError::WM_ERROR_IPC_FAILED;
556 }
557
558 if (!data.WriteBool(isFromClient)) {
559 WLOGFE("Failed to write to isFromClient!");
560 return WMError::WM_ERROR_IPC_FAILED;
561 }
562 auto error = Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_WINDOW_TRANSITION),
563 data, reply, option);
564 if (error != ERR_NONE) {
565 WLOGFE("Send request error: %{public}d", static_cast<uint32_t>(error));
566 return WMError::WM_ERROR_IPC_FAILED;
567 }
568 auto ret = static_cast<WMError>(reply.ReadInt32());
569 return ret;
570 }
571
GetModeChangeHotZones(DisplayId displayId,ModeChangeHotZones & hotZones)572 WMError WindowManagerProxy::GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones)
573 {
574 MessageParcel data;
575 MessageParcel reply;
576 MessageOption option;
577
578 if (!data.WriteInterfaceToken(GetDescriptor())) {
579 WLOGFE("WriteInterfaceToken failed");
580 return WMError::WM_ERROR_IPC_FAILED;
581 }
582 if (!data.WriteUint64(displayId)) {
583 WLOGFE("Write displayId failed");
584 return WMError::WM_ERROR_IPC_FAILED;
585 }
586 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_FULLSCREEN_AND_SPLIT_HOT_ZONE),
587 data, reply, option) != ERR_NONE) {
588 return WMError::WM_ERROR_IPC_FAILED;
589 }
590
591 auto ret = static_cast<WMError>(reply.ReadInt32());
592 if (ret == WMError::WM_OK) {
593 hotZones.fullscreen_.posX_ = reply.ReadInt32();
594 hotZones.fullscreen_.posY_ = reply.ReadInt32();
595 hotZones.fullscreen_.width_ = reply.ReadUint32();
596 hotZones.fullscreen_.height_ = reply.ReadUint32();
597
598 hotZones.primary_.posX_ = reply.ReadInt32();
599 hotZones.primary_.posY_ = reply.ReadInt32();
600 hotZones.primary_.width_ = reply.ReadUint32();
601 hotZones.primary_.height_ = reply.ReadUint32();
602
603 hotZones.secondary_.posX_ = reply.ReadInt32();
604 hotZones.secondary_.posY_ = reply.ReadInt32();
605 hotZones.secondary_.width_ = reply.ReadUint32();
606 hotZones.secondary_.height_ = reply.ReadUint32();
607 }
608 return ret;
609 }
610
MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds,bool isAnimated,sptr<RSIWindowAnimationFinishedCallback> & finishCallback)611 void WindowManagerProxy::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, bool isAnimated,
612 sptr<RSIWindowAnimationFinishedCallback>& finishCallback)
613 {
614 MessageParcel data;
615 MessageParcel reply;
616 MessageOption option;
617 if (!data.WriteInterfaceToken(GetDescriptor())) {
618 WLOGFE("WriteInterfaceToken failed");
619 return;
620 }
621
622 if (!data.WriteUInt32Vector(windowIds)) {
623 WLOGFE("Write windowIds failed");
624 return;
625 }
626
627 if (!data.WriteBool(isAnimated)) {
628 WLOGFE("Write isAnimated failed");
629 return;
630 }
631 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_ANIMATION_CALLBACK),
632 data, reply, option) != ERR_NONE) {
633 WLOGFE("Send request error");
634 return;
635 }
636 ;
637 if (reply.ReadBool()) {
638 sptr<IRemoteObject> finishCallbackObject = reply.ReadRemoteObject();
639 finishCallback = iface_cast<RSIWindowAnimationFinishedCallback>(finishCallbackObject);
640 } else {
641 finishCallback = nullptr;
642 }
643 return;
644 }
645
UpdateAvoidAreaListener(uint32_t windowId,bool haveListener)646 WMError WindowManagerProxy::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
647 {
648 MessageParcel data;
649 MessageParcel reply;
650 MessageOption option;
651
652 if (!data.WriteInterfaceToken(GetDescriptor())) {
653 WLOGFE("WriteInterfaceToken failed");
654 return WMError::WM_ERROR_IPC_FAILED;
655 }
656 if (!data.WriteUint32(windowId)) {
657 WLOGFE("Write windowId failed");
658 return WMError::WM_ERROR_IPC_FAILED;
659 }
660 if (!data.WriteBool(haveListener)) {
661 WLOGFE("Write avoid area listener failed");
662 return WMError::WM_ERROR_IPC_FAILED;
663 }
664 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
665 data, reply, option) != ERR_NONE) {
666 return WMError::WM_ERROR_IPC_FAILED;
667 }
668 return static_cast<WMError>(reply.ReadInt32());
669 }
670
UpdateRsTree(uint32_t windowId,bool isAdd)671 WMError WindowManagerProxy::UpdateRsTree(uint32_t windowId, bool isAdd)
672 {
673 MessageParcel data;
674 MessageParcel reply;
675 MessageOption option(MessageOption::TF_ASYNC);
676
677 if (!data.WriteInterfaceToken(GetDescriptor())) {
678 WLOGFE("WriteInterfaceToken failed");
679 return WMError::WM_ERROR_IPC_FAILED;
680 }
681 if (!data.WriteUint32(windowId)) {
682 WLOGFE("Write windowId failed");
683 return WMError::WM_ERROR_IPC_FAILED;
684 }
685 if (!data.WriteBool(isAdd)) {
686 WLOGFE("Write avoid area listener failed");
687 return WMError::WM_ERROR_IPC_FAILED;
688 }
689 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_UPDATE_RS_TREE),
690 data, reply, option) != ERR_NONE) {
691 return WMError::WM_ERROR_IPC_FAILED;
692 }
693 return static_cast<WMError>(reply.ReadInt32());
694 }
695
BindDialogTarget(uint32_t & windowId,sptr<IRemoteObject> targetToken)696 WMError WindowManagerProxy::BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken)
697 {
698 MessageParcel data;
699 MessageParcel reply;
700 MessageOption option;
701 if (!data.WriteInterfaceToken(GetDescriptor())) {
702 WLOGFE("WriteInterfaceToken failed");
703 return WMError::WM_ERROR_IPC_FAILED;
704 }
705 if (!data.WriteUint32(windowId)) {
706 WLOGFE("Write windowId failed");
707 return WMError::WM_ERROR_IPC_FAILED;
708 }
709 if (targetToken != nullptr) {
710 if (!data.WriteRemoteObject(targetToken)) {
711 WLOGFE("Write targetToken failed");
712 return WMError::WM_ERROR_IPC_FAILED;
713 }
714 }
715 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
716 data, reply, option) != ERR_NONE) {
717 return WMError::WM_ERROR_IPC_FAILED;
718 }
719
720 int32_t ret = reply.ReadInt32();
721 return static_cast<WMError>(ret);
722 }
723
SetAnchorAndScale(int32_t x,int32_t y,float scale)724 void WindowManagerProxy::SetAnchorAndScale(int32_t x, int32_t y, float scale)
725 {
726 MessageParcel data;
727 MessageParcel reply;
728 MessageOption option;
729 if (!data.WriteInterfaceToken(GetDescriptor())) {
730 WLOGFE("WriteInterfaceToken failed");
731 return;
732 }
733 if (!data.WriteInt32(x)) {
734 WLOGFE("Write anchor x failed");
735 return;
736 }
737 if (!data.WriteInt32(y)) {
738 WLOGFE("Write anchor y failed");
739 return;
740 }
741 if (!data.WriteFloat(scale)) {
742 WLOGFE("Write scale failed");
743 return;
744 }
745 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_AND_SCALE),
746 data, reply, option) != ERR_NONE) {
747 WLOGFE("SendRequest failed");
748 }
749 }
750
SetAnchorOffset(int32_t deltaX,int32_t deltaY)751 void WindowManagerProxy::SetAnchorOffset(int32_t deltaX, int32_t deltaY)
752 {
753 MessageParcel data;
754 MessageParcel reply;
755 MessageOption option;
756 if (!data.WriteInterfaceToken(GetDescriptor())) {
757 WLOGFE("WriteInterfaceToken failed");
758 return;
759 }
760 if (!data.WriteInt32(deltaX)) {
761 WLOGFE("Write anchor delatX failed");
762 return;
763 }
764 if (!data.WriteInt32(deltaY)) {
765 WLOGFE("Write anchor deltaY failed");
766 return;
767 }
768 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_SET_ANCHOR_OFFSET),
769 data, reply, option) != ERR_NONE) {
770 WLOGFE("SendRequest failed");
771 }
772 }
773
OffWindowZoom()774 void WindowManagerProxy::OffWindowZoom()
775 {
776 MessageParcel data;
777 MessageParcel reply;
778 MessageOption option;
779 if (!data.WriteInterfaceToken(GetDescriptor())) {
780 WLOGFE("WriteInterfaceToken failed");
781 return;
782 }
783 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_OFF_WINDOW_ZOOM),
784 data, reply, option) != ERR_NONE) {
785 WLOGFE("SendRequest failed");
786 }
787 }
788
GetSnapshot(int32_t windowId)789 std::shared_ptr<Media::PixelMap> WindowManagerProxy::GetSnapshot(int32_t windowId)
790 {
791 MessageParcel data;
792 MessageParcel reply;
793 MessageOption option;
794
795 Media::InitializationOptions opts;
796 opts.size.width = 200; // 200:default width
797 opts.size.height = 300; // 300:default height
798 std::shared_ptr<Media::PixelMap> pixelMap(Media::PixelMap::Create(opts).release());
799 if (!data.WriteInterfaceToken(GetDescriptor())) {
800 WLOGFE("WriteInterfaceToken failed");
801 return pixelMap;
802 }
803 if (!data.WriteUint32(windowId)) {
804 WLOGFE("Write windowId failed");
805 return pixelMap;
806 }
807 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_GET_SNAPSHOT),
808 data, reply, option) != ERR_NONE) {
809 return pixelMap;
810 }
811
812 std::shared_ptr<Media::PixelMap> map(reply.ReadParcelable<Media::PixelMap>());
813 if (map == nullptr) {
814 return pixelMap;
815 }
816 return map;
817 }
818
NotifyDumpInfoResult(const std::vector<std::string> & info)819 void WindowManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
820 {
821 MessageParcel data;
822 MessageParcel reply;
823 MessageOption option(MessageOption::TF_ASYNC);
824 if (!data.WriteInterfaceToken(GetDescriptor())) {
825 WLOGFE("WriteInterfaceToken failed");
826 return;
827 }
828 if (!data.WriteStringVector(info)) {
829 WLOGFE("Write info failed");
830 return;
831 }
832 if (Remote()->SendRequest(static_cast<uint32_t>(WindowManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
833 data, reply, option) != ERR_NONE) {
834 WLOGFE("SendRequest failed");
835 return;
836 }
837 }
838 } // namespace Rosen
839 } // namespace OHOS