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 
DumpInfo(const std::vector<std::string> & params)456 WMError WindowProxy::DumpInfo(const std::vector<std::string>& params)
457 {
458     MessageParcel data;
459     MessageParcel reply;
460     MessageOption option(MessageOption::TF_ASYNC);
461     if (!data.WriteInterfaceToken(GetDescriptor())) {
462         WLOGFE("WriteInterfaceToken failed");
463         return WMError::WM_ERROR_IPC_FAILED;
464     }
465     if (!data.WriteStringVector(params)) {
466         WLOGFE("Write params failed");
467         return WMError::WM_ERROR_IPC_FAILED;
468     }
469     sptr<IRemoteObject> remote = Remote();
470     if (remote == nullptr) {
471         WLOGFE("remote is null");
472         return WMError::WM_ERROR_IPC_FAILED;
473     }
474     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_DUMP_INFO),
475         data, reply, option) != ERR_NONE) {
476         WLOGFE("SendRequest failed");
477         return WMError::WM_ERROR_IPC_FAILED;
478     }
479     return WMError::WM_OK;
480 }
481 
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)482 WMError WindowProxy::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
483 {
484     MessageParcel data;
485     MessageParcel reply;
486     MessageOption option;
487     if (!data.WriteInterfaceToken(GetDescriptor())) {
488         WLOGFE("WriteInterfaceToken failed");
489         return WMError::WM_ERROR_IPC_FAILED;
490     }
491     if (!trans.Marshalling(data)) {
492         WLOGFE("Write params failed");
493         return WMError::WM_ERROR_IPC_FAILED;
494     }
495     if (!data.WriteBool(isDisplayZoomOn)) {
496         WLOGFE("Write params failed");
497         return WMError::WM_ERROR_IPC_FAILED;
498     }
499     sptr<IRemoteObject> remote = Remote();
500     if (remote == nullptr) {
501         WLOGFE("remote is null");
502         return WMError::WM_ERROR_IPC_FAILED;
503     }
504     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_UPDATE_ZOOM_TRANSFORM),
505         data, reply, option) != ERR_NONE) {
506         WLOGFE("SendRequest failed");
507         return WMError::WM_ERROR_IPC_FAILED;
508     }
509     return WMError::WM_OK;
510 }
511 
NotifyDestroy(void)512 WMError WindowProxy::NotifyDestroy(void)
513 {
514     MessageParcel data;
515     MessageParcel replay;
516     MessageOption option(MessageOption::TF_ASYNC);
517     if (!data.WriteInterfaceToken(GetDescriptor())) {
518         WLOGFE("WriteInterfaceToken failed");
519         return WMError::WM_ERROR_IPC_FAILED;
520     }
521 
522     sptr<IRemoteObject> remote = Remote();
523     if (remote == nullptr) {
524         WLOGFE("remote is null");
525         return WMError::WM_ERROR_IPC_FAILED;
526     }
527     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_DESTROY),
528         data, replay, option) != ERR_NONE) {
529         WLOGFE("SendRequest failed");
530         return WMError::WM_ERROR_IPC_FAILED;
531     }
532     return WMError::WM_OK;
533 }
534 
NotifyForeground(void)535 WMError WindowProxy::NotifyForeground(void)
536 {
537     MessageParcel data;
538     MessageParcel replay;
539     MessageOption option(MessageOption::TF_ASYNC);
540     if (!data.WriteInterfaceToken(GetDescriptor())) {
541         WLOGFE("WriteInterfaceToken failed");
542         return WMError::WM_ERROR_IPC_FAILED;
543     }
544 
545     sptr<IRemoteObject> remote = Remote();
546     if (remote == nullptr) {
547         WLOGFE("remote is null");
548         return WMError::WM_ERROR_IPC_FAILED;
549     }
550     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_FOREGROUND),
551         data, replay, option) != ERR_NONE) {
552         WLOGFE("SendRequest failed");
553         return WMError::WM_ERROR_IPC_FAILED;
554     }
555     return WMError::WM_OK;
556 }
557 
NotifyBackground(void)558 WMError WindowProxy::NotifyBackground(void)
559 {
560     MessageParcel data;
561     MessageParcel replay;
562     MessageOption option(MessageOption::TF_ASYNC);
563     if (!data.WriteInterfaceToken(GetDescriptor())) {
564         WLOGFE("WriteInterfaceToken failed");
565         return WMError::WM_ERROR_IPC_FAILED;
566     }
567 
568     sptr<IRemoteObject> remote = Remote();
569     if (remote == nullptr) {
570         WLOGFE("remote is null");
571         return WMError::WM_ERROR_IPC_FAILED;
572     }
573     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_BACKGROUND),
574         data, replay, option) != ERR_NONE) {
575         WLOGFE("SendRequest failed");
576         return WMError::WM_ERROR_IPC_FAILED;
577     }
578     return WMError::WM_OK;
579 }
580 
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)581 WMError WindowProxy::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
582 {
583     if (!pointerEvent) {
584         WLOGFE("pointerEvent is nullptr");
585         return WMError::WM_ERROR_NULLPTR;
586     }
587     MessageParcel data;
588     MessageParcel reply;
589     MessageOption option(MessageOption::TF_ASYNC);
590     if (!data.WriteInterfaceToken(GetDescriptor())) {
591         WLOGFE("WriteInterfaceToken failed");
592         return WMError::WM_ERROR_IPC_FAILED;
593     }
594     if (!pointerEvent->WriteToParcel(data)) {
595         WLOGFE("Failed to write point event");
596         return WMError::WM_ERROR_IPC_FAILED;
597     }
598     sptr<IRemoteObject> remote = Remote();
599     if (remote == nullptr) {
600         WLOGFE("remote is null");
601         return WMError::WM_ERROR_IPC_FAILED;
602     }
603     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_NOTIFY_CLIENT_POINT_UP),
604         data, reply, option) != ERR_NONE) {
605         WLOGFE("SendRequest failed");
606         return WMError::WM_ERROR_IPC_FAILED;
607     }
608     return WMError::WM_OK;
609 }
610 
RestoreSplitWindowMode(uint32_t mode)611 WMError WindowProxy::RestoreSplitWindowMode(uint32_t mode)
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 (!data.WriteUint32(mode)) {
621         WLOGFE("mode failed");
622         return WMError::WM_ERROR_IPC_FAILED;
623     }
624     uint32_t requestCode = static_cast<uint32_t>(WindowMessage::TRANS_ID_RESTORE_SPLIT_WINDOW_MODE);
625     sptr<IRemoteObject> remote = Remote();
626     if (remote == nullptr) {
627         WLOGFE("remote is null");
628         return WMError::WM_ERROR_IPC_FAILED;
629     }
630     if (remote->SendRequest(requestCode, data, reply, option) != ERR_NONE) {
631         WLOGFE("SendRequest failed");
632         return WMError::WM_ERROR_IPC_FAILED;
633     }
634     return WMError::WM_OK;
635 }
636 
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)637 void WindowProxy::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)
638 {
639     MessageParcel data;
640     MessageParcel reply;
641     MessageOption option(MessageOption::TF_ASYNC);
642     if (!data.WriteInterfaceToken(GetDescriptor())) {
643         WLOGFE("WriteInterfaceToken failed");
644         return;
645     }
646     if (!event->WriteToParcel(data)) {
647         WLOGFE("Write point event failed");
648         return;
649     }
650     sptr<IRemoteObject> remote = Remote();
651     if (remote == nullptr) {
652         WLOGFE("remote is null");
653         return;
654     }
655     if (remote->SendRequest(static_cast<uint32_t>(WindowMessage::TRANS_ID_CONSUME_KEY_EVENT),
656         data, reply, option) != ERR_NONE) {
657         WLOGFE("SendRequest failed");
658         return;
659     }
660 }
661 
NotifyForegroundInteractiveStatus(bool interactive)662 void WindowProxy::NotifyForegroundInteractiveStatus(bool interactive)
663 {
664     MessageParcel data;
665     MessageParcel reply;
666     MessageOption option(MessageOption::TF_ASYNC);
667     if (!data.WriteInterfaceToken(GetDescriptor())) {
668         WLOGFE("WriteInterfaceToken failed");
669         return;
670     }
671     if (!data.WriteBool(interactive)) {
672         WLOGFE("Write Focus failed");
673         return;
674     }
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_NOTIFY_FOREGROUND_INTERACTIVE_STATUS),
682         data, reply, option) != ERR_NONE) {
683         WLOGFE("SendRequest failed");
684     }
685 }
686 
687 } // namespace Rosen
688 } // namespace OHOS
689 
690