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_proxy.h"
17 #include <ipc_types.h>
18 #include <key_event.h>
19 #include "pointer_event.h"
20 #include "message_option.h"
21 #include "window_manager_hilog.h"
22 #include "wm_common.h"
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowProxy"};
28 }
29
UpdateWindowRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)30 WMError WindowProxy::UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason,
31 const std::shared_ptr<RSTransaction>& rsTransaction)
32 {
33 MessageParcel data;
34 MessageParcel reply;
35 MessageOption option(MessageOption::TF_ASYNC);
36 if (!data.WriteInterfaceToken(GetDescriptor())) {
37 WLOGFE("WriteInterfaceToken failed");
38 return WMError::WM_ERROR_IPC_FAILED;
39 }
40 if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
41 data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) {
42 WLOGFE("Write WindowRect failed");
43 return WMError::WM_ERROR_IPC_FAILED;
44 }
45 if (!data.WriteBool(decoStatus)) {
46 WLOGFE("Write deco status failed");
47 return WMError::WM_ERROR_IPC_FAILED;
48 }
49 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
50 WLOGFE("Write WindowSizeChangeReason failed");
51 return WMError::WM_ERROR_IPC_FAILED;
52 }
53
54 bool hasRSTransaction = rsTransaction != nullptr;
55 if (!data.WriteBool(hasRSTransaction)) {
56 WLOGFE("Write transaction sync Id failed");
57 return WMError::WM_ERROR_IPC_FAILED;
58 }
59 if (hasRSTransaction) {
60 if (!data.WriteParcelable(rsTransaction.get())) {
61 WLOGFE("Write transaction sync Id failed");
62 return WMError::WM_ERROR_IPC_FAILED;
63 }
64 }
65
66 sptr<IRemoteObject> remote = Remote();
67 if (remote == nullptr) {
68 WLOGFE("remote is null");
69 return WMError::WM_ERROR_IPC_FAILED;
70 }
71 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_RECT),
72 data, reply, option) != ERR_NONE) {
73 WLOGFE("SendRequest failed");
74 return WMError::WM_ERROR_IPC_FAILED;
75 }
76 return WMError::WM_OK;
77 }
78
UpdateWindowMode(WindowMode mode)79 WMError WindowProxy::UpdateWindowMode(WindowMode mode)
80 {
81 MessageParcel data;
82 MessageParcel reply;
83 MessageOption option(MessageOption::TF_ASYNC);
84 if (!data.WriteInterfaceToken(GetDescriptor())) {
85 WLOGFE("WriteInterfaceToken failed");
86 return WMError::WM_ERROR_IPC_FAILED;
87 }
88 if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
89 WLOGFE("Write WindowMode failed");
90 return WMError::WM_ERROR_IPC_FAILED;
91 }
92
93 sptr<IRemoteObject> remote = Remote();
94 if (remote == nullptr) {
95 WLOGFE("remote is null");
96 return WMError::WM_ERROR_IPC_FAILED;
97 }
98 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_MODE),
99 data, reply, option) != ERR_NONE) {
100 WLOGFE("SendRequest failed");
101 return WMError::WM_ERROR_IPC_FAILED;
102 }
103 return WMError::WM_OK;
104 }
105
UpdateWindowModeSupportType(uint32_t windowModeSupportType)106 WMError WindowProxy::UpdateWindowModeSupportType(uint32_t windowModeSupportType)
107 {
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option(MessageOption::TF_ASYNC);
111 if (!data.WriteInterfaceToken(GetDescriptor())) {
112 WLOGFE("WriteInterfaceToken failed");
113 return WMError::WM_ERROR_IPC_FAILED;
114 }
115 if (!data.WriteUint32(windowModeSupportType)) {
116 WLOGFE("Write WindowMode failed");
117 return WMError::WM_ERROR_IPC_FAILED;
118 }
119
120 sptr<IRemoteObject> remote = Remote();
121 if (remote == nullptr) {
122 WLOGFE("remote is null");
123 return WMError::WM_ERROR_IPC_FAILED;
124 }
125 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_MODE_SUPPORT_INFO),
126 data, reply, option) != ERR_NONE) {
127 WLOGFE("SendRequest failed");
128 return WMError::WM_ERROR_IPC_FAILED;
129 }
130 return WMError::WM_OK;
131 }
132
UpdateFocusStatus(bool focused)133 WMError WindowProxy::UpdateFocusStatus(bool focused)
134 {
135 MessageParcel data;
136 MessageParcel reply;
137 MessageOption option(MessageOption::TF_ASYNC);
138 if (!data.WriteInterfaceToken(GetDescriptor())) {
139 WLOGFE("WriteInterfaceToken failed");
140 return WMError::WM_ERROR_IPC_FAILED;
141 }
142 if (!data.WriteBool(focused)) {
143 WLOGFE("Write Focus failed");
144 return WMError::WM_ERROR_IPC_FAILED;
145 }
146
147 sptr<IRemoteObject> remote = Remote();
148 if (remote == nullptr) {
149 WLOGFE("remote is null");
150 return WMError::WM_ERROR_IPC_FAILED;
151 }
152 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_FOCUS_STATUS),
153 data, reply, option) != ERR_NONE) {
154 WLOGFE("SendRequest failed");
155 return WMError::WM_ERROR_IPC_FAILED;
156 }
157 return WMError::WM_OK;
158 }
159
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)160 WMError WindowProxy::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
161 {
162 MessageParcel data;
163 MessageParcel reply;
164 MessageOption option(MessageOption::TF_ASYNC);
165 if (!data.WriteInterfaceToken(GetDescriptor())) {
166 WLOGFE("WriteInterfaceToken failed");
167 return WMError::WM_ERROR_IPC_FAILED;
168 }
169 if (!data.WriteStrongParcelable(avoidArea)) {
170 WLOGFE("Write WindowRect failed");
171 return WMError::WM_ERROR_IPC_FAILED;
172 }
173 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
174 WLOGFE("Write AvoidAreaType failed");
175 return WMError::WM_ERROR_IPC_FAILED;
176 }
177 sptr<IRemoteObject> remote = Remote();
178 if (remote == nullptr) {
179 WLOGFE("remote is null");
180 return WMError::WM_ERROR_IPC_FAILED;
181 }
182 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_AVOID_AREA),
183 data, reply, option) != ERR_NONE) {
184 WLOGFE("SendRequest failed");
185 return WMError::WM_ERROR_IPC_FAILED;
186 }
187 return WMError::WM_OK;
188 }
189
UpdateWindowState(WindowState state)190 WMError WindowProxy::UpdateWindowState(WindowState state)
191 {
192 MessageParcel data;
193 MessageParcel reply;
194 MessageOption option(MessageOption::TF_ASYNC);
195 if (!data.WriteInterfaceToken(GetDescriptor())) {
196 WLOGFE("WriteInterfaceToken failed");
197 return WMError::WM_ERROR_IPC_FAILED;
198 }
199
200 if (!data.WriteUint32(static_cast<uint32_t>(state))) {
201 WLOGFE("Write isStopped");
202 return WMError::WM_ERROR_IPC_FAILED;
203 }
204 sptr<IRemoteObject> remote = Remote();
205 if (remote == nullptr) {
206 WLOGFE("remote is null");
207 return WMError::WM_ERROR_IPC_FAILED;
208 }
209 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_WINDOW_STATE),
210 data, reply, option) != ERR_NONE) {
211 WLOGFE("SendRequest failed");
212 return WMError::WM_ERROR_IPC_FAILED;
213 }
214 return WMError::WM_OK;
215 }
216
UpdateWindowDragInfo(const PointInfo & point,DragEvent event)217 WMError WindowProxy::UpdateWindowDragInfo(const PointInfo& point, DragEvent event)
218 {
219 MessageParcel data;
220 MessageParcel reply;
221 MessageOption option(MessageOption::TF_ASYNC);
222 if (!data.WriteInterfaceToken(GetDescriptor())) {
223 WLOGFE("WriteInterfaceToken failed");
224 return WMError::WM_ERROR_IPC_FAILED;
225 }
226 if (!(data.WriteInt32(point.x) and data.WriteInt32(point.y))) {
227 WLOGFE("Write pos failed");
228 return WMError::WM_ERROR_IPC_FAILED;
229 }
230 if (!data.WriteInt32(static_cast<uint32_t>(event))) {
231 WLOGFE("Write event failed");
232 return WMError::WM_ERROR_IPC_FAILED;
233 }
234
235 sptr<IRemoteObject> remote = Remote();
236 if (remote == nullptr) {
237 WLOGFE("remote is null");
238 return WMError::WM_ERROR_IPC_FAILED;
239 }
240 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_DRAG_EVENT),
241 data, reply, option) != ERR_NONE) {
242 WLOGFE("SendRequest TRANS_ID_UPDATE_DRAG_EVENT failed");
243 return WMError::WM_ERROR_IPC_FAILED;
244 }
245 return WMError::WM_OK;
246 }
247
UpdateDisplayId(DisplayId from,DisplayId to)248 WMError WindowProxy::UpdateDisplayId(DisplayId from, DisplayId to)
249 {
250 MessageParcel data;
251 MessageParcel reply;
252 MessageOption option(MessageOption::TF_ASYNC);
253 if (!data.WriteInterfaceToken(GetDescriptor())) {
254 WLOGFE("WriteInterfaceToken failed");
255 return WMError::WM_ERROR_IPC_FAILED;
256 }
257 if (!(data.WriteUint64(from) and data.WriteUint64(to))) {
258 WLOGFE("Write displayid failed");
259 return WMError::WM_ERROR_IPC_FAILED;
260 }
261 sptr<IRemoteObject> remote = Remote();
262 if (remote == nullptr) {
263 WLOGFE("remote is null");
264 return WMError::WM_ERROR_IPC_FAILED;
265 }
266 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_DISPLAY_ID),
267 data, reply, option) != ERR_NONE) {
268 WLOGFE("SendRequest TRANS_ID_UPDATE_DISPLAY_ID failed");
269 return WMError::WM_ERROR_IPC_FAILED;
270 }
271 return WMError::WM_OK;
272 }
273
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)274 WMError WindowProxy::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info,
275 const std::shared_ptr<RSTransaction>& rsTransaction)
276 {
277 MessageParcel data;
278 MessageParcel reply;
279 MessageOption option(MessageOption::TF_ASYNC);
280 if (!data.WriteInterfaceToken(GetDescriptor())) {
281 WLOGFE("WriteInterfaceToken failed");
282 return WMError::WM_ERROR_IPC_FAILED;
283 }
284 if (!data.WriteParcelable(info)) {
285 WLOGFE("Write OccupiedAreaChangeInfo failed");
286 return WMError::WM_ERROR_IPC_FAILED;
287 }
288
289 bool hasRSTransaction = rsTransaction != nullptr;
290 if (!data.WriteBool(hasRSTransaction)) {
291 WLOGFE("Write transaction sync Id failed");
292 return WMError::WM_ERROR_IPC_FAILED;
293 }
294 if (hasRSTransaction) {
295 if (!data.WriteParcelable(rsTransaction.get())) {
296 WLOGFE("Write transaction sync Id failed");
297 return WMError::WM_ERROR_IPC_FAILED;
298 }
299 }
300
301 sptr<IRemoteObject> remote = Remote();
302 if (remote == nullptr) {
303 WLOGFE("remote is null");
304 return WMError::WM_ERROR_IPC_FAILED;
305 }
306 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA),
307 data, reply, option) != ERR_NONE) {
308 WLOGFE("SendRequest failed");
309 return WMError::WM_ERROR_IPC_FAILED;
310 }
311 return WMError::WM_OK;
312 }
313
UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo> & info,const Rect & rect,const std::shared_ptr<RSTransaction> & rsTransaction)314 WMError WindowProxy::UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo>& info, const Rect& rect,
315 const std::shared_ptr<RSTransaction>& rsTransaction)
316 {
317 MessageParcel data;
318 MessageParcel reply;
319 MessageOption option(MessageOption::TF_ASYNC);
320 if (!data.WriteInterfaceToken(GetDescriptor())) {
321 WLOGFE("WriteInterfaceToken failed");
322 return WMError::WM_ERROR_IPC_FAILED;
323 }
324 if (!data.WriteParcelable(info)) {
325 WLOGFE("Write OccupiedAreaChangeInfo failed");
326 return WMError::WM_ERROR_IPC_FAILED;
327 }
328
329 if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
330 data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) {
331 WLOGFE("Write WindowRect failed");
332 return WMError::WM_ERROR_IPC_FAILED;
333 }
334
335 bool hasRSTransaction = rsTransaction != nullptr;
336 if (!data.WriteBool(hasRSTransaction)) {
337 WLOGFE("Write transaction sync Id failed");
338 return WMError::WM_ERROR_IPC_FAILED;
339 }
340 if (hasRSTransaction) {
341 if (!data.WriteParcelable(rsTransaction.get())) {
342 WLOGFE("Write transaction sync Id failed");
343 return WMError::WM_ERROR_IPC_FAILED;
344 }
345 }
346
347 sptr<IRemoteObject> remote = Remote();
348 if (remote == nullptr) {
349 WLOGFE("remote is null");
350 return WMError::WM_ERROR_IPC_FAILED;
351 }
352 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_OCCUPIED_AREA_AND_RECT),
353 data, reply, option) != ERR_NONE) {
354 WLOGFE("SendRequest failed");
355 return WMError::WM_ERROR_IPC_FAILED;
356 }
357 return WMError::WM_OK;
358 }
359
UpdateActiveStatus(bool isActive)360 WMError WindowProxy::UpdateActiveStatus(bool isActive)
361 {
362 MessageParcel data;
363 MessageParcel reply;
364 MessageOption option(MessageOption::TF_ASYNC);
365 if (!data.WriteInterfaceToken(GetDescriptor())) {
366 WLOGFE("WriteInterfaceToken failed");
367 return WMError::WM_ERROR_IPC_FAILED;
368 }
369 if (!data.WriteBool(isActive)) {
370 WLOGFE("Write Focus failed");
371 return WMError::WM_ERROR_IPC_FAILED;
372 }
373
374 sptr<IRemoteObject> remote = Remote();
375 if (remote == nullptr) {
376 WLOGFE("remote is null");
377 return WMError::WM_ERROR_IPC_FAILED;
378 }
379 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_ACTIVE_STATUS),
380 data, reply, option) != ERR_NONE) {
381 WLOGFE("SendRequest failed");
382 return WMError::WM_ERROR_IPC_FAILED;
383 }
384 return WMError::WM_OK;
385 }
386
GetWindowProperty()387 sptr<WindowProperty> WindowProxy::GetWindowProperty()
388 {
389 MessageParcel data;
390 MessageParcel reply;
391 MessageOption option;
392 if (!data.WriteInterfaceToken(GetDescriptor())) {
393 WLOGFE("WriteInterfaceToken failed");
394 return nullptr;
395 }
396 uint32_t requestCode = static_cast<uint32_t>(WindowMessage::TRANS_ID_GET_WINDOW_PROPERTY);
397 sptr<IRemoteObject> remote = Remote();
398 if (remote == nullptr) {
399 WLOGFE("remote is null");
400 return nullptr;
401 }
402 if (remote->SendRequest(requestCode, data, reply, option) != ERR_NONE) {
403 WLOGFE("SendRequest failed");
404 return nullptr;
405 }
406 sptr<WindowProperty> property = reply.ReadParcelable<WindowProperty>();
407 return property;
408 }
409
NotifyTouchOutside()410 WMError WindowProxy::NotifyTouchOutside()
411 {
412 MessageParcel data;
413 MessageParcel reply;
414 MessageOption option(MessageOption::TF_ASYNC);
415 if (!data.WriteInterfaceToken(GetDescriptor())) {
416 WLOGFE("WriteInterfaceToken failed");
417 return WMError::WM_ERROR_IPC_FAILED;
418 }
419
420 sptr<IRemoteObject> remote = Remote();
421 if (remote == nullptr) {
422 WLOGFE("remote is null");
423 return WMError::WM_ERROR_IPC_FAILED;
424 }
425 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_OUTSIDE_PRESSED),
426 data, reply, option) != ERR_NONE) {
427 WLOGFE("SendRequest failed");
428 return WMError::WM_ERROR_IPC_FAILED;
429 }
430 return WMError::WM_OK;
431 }
432
NotifyScreenshot()433 WMError WindowProxy::NotifyScreenshot()
434 {
435 MessageParcel data;
436 MessageParcel reply;
437 MessageOption option(MessageOption::TF_ASYNC);
438 if (!data.WriteInterfaceToken(GetDescriptor())) {
439 WLOGFE("WriteInterfaceToken failed");
440 return WMError::WM_ERROR_IPC_FAILED;
441 }
442
443 sptr<IRemoteObject> remote = Remote();
444 if (remote == nullptr) {
445 WLOGFE("remote is null");
446 return WMError::WM_ERROR_IPC_FAILED;
447 }
448 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_SCREEN_SHOT),
449 data, reply, option) != ERR_NONE) {
450 WLOGFE("SendRequest failed");
451 return WMError::WM_ERROR_IPC_FAILED;
452 }
453 return WMError::WM_OK;
454 }
455
NotifyScreenshotAppEvent(ScreenshotEventType type)456 WMError WindowProxy::NotifyScreenshotAppEvent(ScreenshotEventType type)
457 {
458 MessageParcel data;
459 MessageParcel reply;
460 MessageOption option(MessageOption::TF_ASYNC);
461 if (!data.WriteInterfaceToken(GetDescriptor())) {
462 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "WriteInterfaceToken failed");
463 return WMError::WM_ERROR_IPC_FAILED;
464 }
465 if (!data.WriteInt32(static_cast<int32_t>(type))) {
466 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write screenshot event type failed");
467 return WMError::WM_ERROR_IPC_FAILED;
468 }
469 sptr<IRemoteObject> remote = Remote();
470 if (remote == nullptr) {
471 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null");
472 return WMError::WM_ERROR_IPC_FAILED;
473 }
474 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_SCREEN_SHOT_APP_EVENT),
475 data, reply, option) != ERR_NONE) {
476 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "SendRequest failed");
477 return WMError::WM_ERROR_IPC_FAILED;
478 }
479 return WMError::WM_OK;
480 }
481
DumpInfo(const std::vector<std::string> & params)482 WMError WindowProxy::DumpInfo(const std::vector<std::string>& params)
483 {
484 MessageParcel data;
485 MessageParcel reply;
486 MessageOption option(MessageOption::TF_ASYNC);
487 if (!data.WriteInterfaceToken(GetDescriptor())) {
488 WLOGFE("WriteInterfaceToken failed");
489 return WMError::WM_ERROR_IPC_FAILED;
490 }
491 if (!data.WriteStringVector(params)) {
492 WLOGFE("Write params failed");
493 return WMError::WM_ERROR_IPC_FAILED;
494 }
495 sptr<IRemoteObject> remote = Remote();
496 if (remote == nullptr) {
497 WLOGFE("remote is null");
498 return WMError::WM_ERROR_IPC_FAILED;
499 }
500 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_DUMP_INFO),
501 data, reply, option) != ERR_NONE) {
502 WLOGFE("SendRequest failed");
503 return WMError::WM_ERROR_IPC_FAILED;
504 }
505 return WMError::WM_OK;
506 }
507
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)508 WMError WindowProxy::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
509 {
510 MessageParcel data;
511 MessageParcel reply;
512 MessageOption option;
513 if (!data.WriteInterfaceToken(GetDescriptor())) {
514 WLOGFE("WriteInterfaceToken failed");
515 return WMError::WM_ERROR_IPC_FAILED;
516 }
517 if (!trans.Marshalling(data)) {
518 WLOGFE("Write params failed");
519 return WMError::WM_ERROR_IPC_FAILED;
520 }
521 if (!data.WriteBool(isDisplayZoomOn)) {
522 WLOGFE("Write params failed");
523 return WMError::WM_ERROR_IPC_FAILED;
524 }
525 sptr<IRemoteObject> remote = Remote();
526 if (remote == nullptr) {
527 WLOGFE("remote is null");
528 return WMError::WM_ERROR_IPC_FAILED;
529 }
530 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_ZOOM_TRANSFORM),
531 data, reply, option) != ERR_NONE) {
532 WLOGFE("SendRequest failed");
533 return WMError::WM_ERROR_IPC_FAILED;
534 }
535 return WMError::WM_OK;
536 }
537
NotifyDestroy(void)538 WMError WindowProxy::NotifyDestroy(void)
539 {
540 MessageParcel data;
541 MessageParcel replay;
542 MessageOption option(MessageOption::TF_ASYNC);
543 if (!data.WriteInterfaceToken(GetDescriptor())) {
544 WLOGFE("WriteInterfaceToken failed");
545 return WMError::WM_ERROR_IPC_FAILED;
546 }
547
548 sptr<IRemoteObject> remote = Remote();
549 if (remote == nullptr) {
550 WLOGFE("remote is null");
551 return WMError::WM_ERROR_IPC_FAILED;
552 }
553 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_DESTROY),
554 data, replay, option) != ERR_NONE) {
555 WLOGFE("SendRequest failed");
556 return WMError::WM_ERROR_IPC_FAILED;
557 }
558 return WMError::WM_OK;
559 }
560
NotifyForeground(void)561 WMError WindowProxy::NotifyForeground(void)
562 {
563 MessageParcel data;
564 MessageParcel replay;
565 MessageOption option(MessageOption::TF_ASYNC);
566 if (!data.WriteInterfaceToken(GetDescriptor())) {
567 WLOGFE("WriteInterfaceToken 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>(WindowMessage::TRANS_ID_NOTIFY_FOREGROUND),
577 data, replay, option) != ERR_NONE) {
578 WLOGFE("SendRequest failed");
579 return WMError::WM_ERROR_IPC_FAILED;
580 }
581 return WMError::WM_OK;
582 }
583
NotifyBackground(void)584 WMError WindowProxy::NotifyBackground(void)
585 {
586 MessageParcel data;
587 MessageParcel replay;
588 MessageOption option(MessageOption::TF_ASYNC);
589 if (!data.WriteInterfaceToken(GetDescriptor())) {
590 WLOGFE("WriteInterfaceToken failed");
591 return WMError::WM_ERROR_IPC_FAILED;
592 }
593
594 sptr<IRemoteObject> remote = Remote();
595 if (remote == nullptr) {
596 WLOGFE("remote is null");
597 return WMError::WM_ERROR_IPC_FAILED;
598 }
599 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_BACKGROUND),
600 data, replay, option) != ERR_NONE) {
601 WLOGFE("SendRequest failed");
602 return WMError::WM_ERROR_IPC_FAILED;
603 }
604 return WMError::WM_OK;
605 }
606
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)607 WMError WindowProxy::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
608 {
609 if (!pointerEvent) {
610 WLOGFE("pointerEvent is nullptr");
611 return WMError::WM_ERROR_NULLPTR;
612 }
613 MessageParcel data;
614 MessageParcel reply;
615 MessageOption option(MessageOption::TF_ASYNC);
616 if (!data.WriteInterfaceToken(GetDescriptor())) {
617 WLOGFE("WriteInterfaceToken failed");
618 return WMError::WM_ERROR_IPC_FAILED;
619 }
620 if (!pointerEvent->WriteToParcel(data)) {
621 WLOGFE("Failed to write point event");
622 return WMError::WM_ERROR_IPC_FAILED;
623 }
624 sptr<IRemoteObject> remote = Remote();
625 if (remote == nullptr) {
626 WLOGFE("remote is null");
627 return WMError::WM_ERROR_IPC_FAILED;
628 }
629 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_CLIENT_POINT_UP),
630 data, reply, option) != ERR_NONE) {
631 WLOGFE("SendRequest failed");
632 return WMError::WM_ERROR_IPC_FAILED;
633 }
634 return WMError::WM_OK;
635 }
636
RestoreSplitWindowMode(uint32_t mode)637 WMError WindowProxy::RestoreSplitWindowMode(uint32_t mode)
638 {
639 MessageParcel data;
640 MessageParcel reply;
641 MessageOption option(MessageOption::TF_ASYNC);
642 if (!data.WriteInterfaceToken(GetDescriptor())) {
643 WLOGFE("WriteInterfaceToken failed");
644 return WMError::WM_ERROR_IPC_FAILED;
645 }
646 if (!data.WriteUint32(mode)) {
647 WLOGFE("mode failed");
648 return WMError::WM_ERROR_IPC_FAILED;
649 }
650 uint32_t requestCode = static_cast<uint32_t>(WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE);
651 sptr<IRemoteObject> remote = Remote();
652 if (remote == nullptr) {
653 WLOGFE("remote is null");
654 return WMError::WM_ERROR_IPC_FAILED;
655 }
656 if (remote->SendRequest(requestCode, data, reply, option) != ERR_NONE) {
657 WLOGFE("SendRequest failed");
658 return WMError::WM_ERROR_IPC_FAILED;
659 }
660 return WMError::WM_OK;
661 }
662
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)663 void WindowProxy::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)
664 {
665 MessageParcel data;
666 MessageParcel reply;
667 MessageOption option(MessageOption::TF_ASYNC);
668 if (!data.WriteInterfaceToken(GetDescriptor())) {
669 WLOGFE("WriteInterfaceToken failed");
670 return;
671 }
672 if (!event->WriteToParcel(data)) {
673 WLOGFE("Write point event failed");
674 return;
675 }
676 sptr<IRemoteObject> remote = Remote();
677 if (remote == nullptr) {
678 WLOGFE("remote is null");
679 return;
680 }
681 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_CONSUME_KEY_EVENT),
682 data, reply, option) != ERR_NONE) {
683 WLOGFE("SendRequest failed");
684 return;
685 }
686 }
687
NotifyForegroundInteractiveStatus(bool interactive)688 void WindowProxy::NotifyForegroundInteractiveStatus(bool interactive)
689 {
690 MessageParcel data;
691 MessageParcel reply;
692 MessageOption option(MessageOption::TF_ASYNC);
693 if (!data.WriteInterfaceToken(GetDescriptor())) {
694 WLOGFE("WriteInterfaceToken failed");
695 return;
696 }
697 if (!data.WriteBool(interactive)) {
698 WLOGFE("Write Focus failed");
699 return;
700 }
701
702 sptr<IRemoteObject> remote = Remote();
703 if (remote == nullptr) {
704 WLOGFE("remote is null");
705 return;
706 }
707 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS),
708 data, reply, option) != ERR_NONE) {
709 WLOGFE("SendRequest failed");
710 }
711 }
712
NotifyMMIServiceOnline(uint32_t winId)713 void WindowProxy::NotifyMMIServiceOnline(uint32_t winId)
714 {
715 MessageParcel data;
716 MessageParcel reply;
717 MessageOption option(MessageOption::TF_ASYNC);
718 if (!data.WriteInterfaceToken(GetDescriptor())) {
719 WLOGFE("WriteInterfaceToken failed");
720 return;
721 }
722 if (!data.WriteUint32(winId)) {
723 WLOGFE("Write windowId failed");
724 return;
725 }
726 sptr<IRemoteObject> remote = Remote();
727 if (remote == nullptr) {
728 WLOGFE("remote is null");
729 return;
730 }
731 if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_MMI_SERVICE_ONLINE),
732 data, reply, option) != ERR_NONE) {
733 WLOGFE("SendRequest failed");
734 return;
735 }
736 }
737
738 } // namespace Rosen
739 } // namespace OHOS
740
741