1 /*
2  * Copyright (c) 2023 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 "session/container/include/zidl/session_stage_proxy.h"
17 #include "session/container/include/zidl/session_stage_ipc_interface_code.h"
18 
19 #include <cstdint>
20 #include <ipc_types.h>
21 #include <message_option.h>
22 #include <message_parcel.h>
23 #include <securec.h>
24 
25 #include "window_manager_hilog.h"
26 #include "ws_common.h"
27 
28 namespace OHOS::Rosen {
29 namespace {
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageProxy"};
31 constexpr int32_t MAX_INFO_SIZE = 50;
32 constexpr size_t MAX_PARCEL_CAPACITY = 100 * 1024 * 1024; // 100M
33 
CopyBufferFromRawData(void * & buffer,size_t size,const void * data)34 bool CopyBufferFromRawData(void*& buffer, size_t size, const void* data)
35 {
36     if (data == nullptr) {
37         TLOGE(WmsLogTag::WMS_UIEXT, "data is nullptr");
38         return false;
39     }
40 
41     if (size == 0 || size >= MAX_PARCEL_CAPACITY) {
42         TLOGE(WmsLogTag::WMS_UIEXT, "size is invalid");
43         return false;
44     }
45 
46     buffer = malloc(size);
47     if (buffer == nullptr) {
48         TLOGE(WmsLogTag::WMS_UIEXT, "buffer malloc failed");
49         return false;
50     }
51 
52     if (memcpy_s(buffer, size, data, size) != EOK) {
53         free(buffer);
54         TLOGE(WmsLogTag::WMS_UIEXT, "memcpy_s failed");
55         return false;
56     }
57 
58     return true;
59 }
60 
ReadLittleStringVectorFromParcel(MessageParcel & reply,std::vector<std::string> & infos)61 bool ReadLittleStringVectorFromParcel(MessageParcel& reply, std::vector<std::string>& infos)
62 {
63     TLOGD(WmsLogTag::WMS_UIEXT, "entry");
64     if (!reply.ReadStringVector(&infos)) {
65         TLOGE(WmsLogTag::WMS_UIEXT, "Read string vector failed");
66         return false;
67     }
68     return true;
69 }
70 
ReadLargeStringVectorFromParcel(MessageParcel & reply,std::vector<std::string> & infos)71 bool ReadLargeStringVectorFromParcel(MessageParcel& reply, std::vector<std::string>& infos)
72 {
73     int32_t dataSizeInt = 0;
74     if (!reply.ReadInt32(dataSizeInt) || dataSizeInt == 0) {
75         TLOGE(WmsLogTag::WMS_UIEXT, "Read dataSize failed");
76         return false;
77     }
78 
79     size_t dataSize = static_cast<size_t>(dataSizeInt);
80     void* buffer = nullptr;
81     if (!CopyBufferFromRawData(buffer, dataSize, reply.ReadRawData(dataSize))) {
82         TLOGE(WmsLogTag::WMS_UIEXT, "Read rawData failed, dataSize: %{public}zu", dataSize);
83         return false;
84     }
85 
86     MessageParcel readParcel;
87     if (!readParcel.ParseFrom(reinterpret_cast<uintptr_t>(buffer), dataSize)) {
88         TLOGE(WmsLogTag::WMS_UIEXT, "Parse from buffer failed");
89         return false;
90     }
91 
92     int32_t infoSize = 0;
93     if (!readParcel.ReadInt32(infoSize)) {
94         TLOGE(WmsLogTag::WMS_UIEXT, "Read infoSize failed");
95         return false;
96     }
97 
98     TLOGD(WmsLogTag::WMS_UIEXT, "dataSize: %{public}zu, infoSize: %{public}d", dataSize, infoSize);
99     if (infoSize >= MAX_INFO_SIZE) {
100         TLOGE(WmsLogTag::WMS_UIEXT, "Too big infos, infoSize: %{public}d", infoSize);
101         return false;
102     }
103 
104     infos.clear();
105     infos.reserve(infoSize);
106     for (int32_t i = 0; i < infoSize; i++) {
107         infos.emplace_back(readParcel.ReadString());
108     }
109 
110     return true;
111 }
112 }
113 
SetActive(bool active)114 WSError SessionStageProxy::SetActive(bool active)
115 {
116     MessageParcel data;
117     MessageParcel reply;
118     MessageOption option(MessageOption::TF_ASYNC);
119     if (!data.WriteInterfaceToken(GetDescriptor())) {
120         WLOGFE("WriteInterfaceToken failed");
121         return WSError::WS_ERROR_IPC_FAILED;
122     }
123 
124     if (!data.WriteBool(active)) {
125         WLOGFE("Write active failed");
126         return WSError::WS_ERROR_IPC_FAILED;
127     }
128 
129     sptr<IRemoteObject> remote = Remote();
130     if (remote == nullptr) {
131         WLOGFE("remote is null");
132         return WSError::WS_ERROR_IPC_FAILED;
133     }
134 
135     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_ACTIVE),
136         data, reply, option) != ERR_NONE) {
137         WLOGFE("SendRequest failed");
138         return WSError::WS_ERROR_IPC_FAILED;
139     }
140     int32_t ret = reply.ReadInt32();
141     return static_cast<WSError>(ret);
142 }
143 
UpdateDisplayId(uint64_t displayId)144 WSError SessionStageProxy::UpdateDisplayId(uint64_t displayId)
145 {
146     MessageParcel data;
147     MessageParcel reply;
148     MessageOption option(MessageOption::TF_ASYNC);
149     if (!data.WriteInterfaceToken(GetDescriptor())) {
150         WLOGFE("WriteInterfaceToken failed");
151         return WSError::WS_ERROR_IPC_FAILED;
152     }
153 
154     if (!data.WriteUint64(displayId)) {
155         WLOGFE("Write displayId failed");
156         return WSError::WS_ERROR_IPC_FAILED;
157     }
158 
159     sptr<IRemoteObject> remote = Remote();
160     if (remote == nullptr) {
161         WLOGFE("remote is null");
162         return WSError::WS_ERROR_IPC_FAILED;
163     }
164 
165     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DISPLAYID_CHANGE),
166         data, reply, option) != ERR_NONE) {
167         WLOGFE("SendRequest failed");
168         return WSError::WS_ERROR_IPC_FAILED;
169     }
170     int32_t ret = reply.ReadInt32();
171     return static_cast<WSError>(ret);
172 }
173 
UpdateRect(const WSRect & rect,SizeChangeReason reason,const SceneAnimationConfig & config)174 WSError SessionStageProxy::UpdateRect(const WSRect& rect, SizeChangeReason reason,
175     const SceneAnimationConfig& config)
176 {
177     MessageParcel data;
178     MessageParcel reply;
179     MessageOption option(MessageOption::TF_ASYNC);
180     if (!data.WriteInterfaceToken(GetDescriptor())) {
181         WLOGFE("WriteInterfaceToken failed");
182         return WSError::WS_ERROR_IPC_FAILED;
183     }
184 
185     if (!(data.WriteInt32(rect.posX_) && data.WriteInt32(rect.posY_) &&
186         data.WriteUint32(rect.width_) && data.WriteUint32(rect.height_))) {
187         WLOGFE("Write WindowRect failed");
188         return WSError::WS_ERROR_IPC_FAILED;
189     }
190 
191     if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
192         WLOGFE("Write SessionSizeChangeReason failed");
193         return WSError::WS_ERROR_IPC_FAILED;
194     }
195 
196     const std::shared_ptr<RSTransaction>& rsTransaction = config.rsTransaction_;
197     bool hasRSTransaction = rsTransaction != nullptr;
198     if (!data.WriteBool(hasRSTransaction)) {
199         WLOGFE("Write has transaction failed");
200         return WSError::WS_ERROR_IPC_FAILED;
201     }
202     if (hasRSTransaction) {
203         auto pid = rsTransaction->GetParentPid();
204         rsTransaction->SetParentPid(getprocpid());
205         if (!data.WriteParcelable(rsTransaction.get())) {
206             WLOGFE("Write transaction sync Id failed");
207             return WSError::WS_ERROR_IPC_FAILED;
208         }
209         rsTransaction->SetParentPid(pid);
210     }
211 
212     if (!data.WriteInt32(config.animationDuration_)) {
213         TLOGE(WmsLogTag::DEFAULT, "Write animation duration failed");
214         return WSError::WS_ERROR_IPC_FAILED;
215     }
216 
217     sptr<IRemoteObject> remote = Remote();
218     if (remote == nullptr) {
219         WLOGFE("remote is null");
220         return WSError::WS_ERROR_IPC_FAILED;
221     }
222 
223     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SIZE_CHANGE),
224         data, reply, option) != ERR_NONE) {
225         WLOGFE("SendRequest failed");
226         return WSError::WS_ERROR_IPC_FAILED;
227     }
228     int32_t ret = reply.ReadInt32();
229     return static_cast<WSError>(ret);
230 }
231 
UpdateDensity()232 void SessionStageProxy::UpdateDensity()
233 {
234     MessageParcel data;
235     MessageParcel reply;
236     MessageOption option(MessageOption::TF_ASYNC);
237     if (!data.WriteInterfaceToken(GetDescriptor())) {
238         WLOGFE("WriteInterfaceToken failed");
239         return;
240     }
241 
242     sptr<IRemoteObject> remote = Remote();
243     if (remote == nullptr) {
244         WLOGFE("remote is null");
245         return;
246     }
247 
248     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_CHANGE),
249         data, reply, option) != ERR_NONE) {
250         WLOGFE("SendRequest failed");
251         return;
252     }
253 }
254 
UpdateOrientation()255 WSError SessionStageProxy::UpdateOrientation()
256 {
257     MessageParcel data;
258     MessageParcel reply;
259     MessageOption option(MessageOption::TF_ASYNC);
260     if (!data.WriteInterfaceToken(GetDescriptor())) {
261         TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed.");
262         return WSError::WS_ERROR_IPC_FAILED;
263     }
264 
265     sptr<IRemoteObject> remote = Remote();
266     if (remote == nullptr) {
267         TLOGE(WmsLogTag::DMS, "remote is null");
268         return WSError::WS_ERROR_IPC_FAILED;
269     }
270 
271     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_ORIENTATION_CHANGE),
272         data, reply, option) != ERR_NONE) {
273         TLOGE(WmsLogTag::DMS, "SendRequest failed.");
274         return WSError::WS_ERROR_IPC_FAILED;
275     }
276 
277     WSError ret = static_cast<WSError>(reply.ReadInt32());
278     if (ret != WSError::WS_OK) {
279         TLOGE(WmsLogTag::DMS, "update orientation by ipc failed with error: %{public}d.", ret);
280     }
281     return ret;
282 }
283 
HandleBackEvent()284 WSError SessionStageProxy::HandleBackEvent()
285 {
286     MessageParcel data;
287     MessageParcel reply;
288     MessageOption option(MessageOption::TF_ASYNC);
289     if (!data.WriteInterfaceToken(GetDescriptor())) {
290         WLOGFE("WriteInterfaceToken failed");
291         return WSError::WS_ERROR_IPC_FAILED;
292     }
293 
294     sptr<IRemoteObject> remote = Remote();
295     if (remote == nullptr) {
296         WLOGFE("remote is null");
297         return WSError::WS_ERROR_IPC_FAILED;
298     }
299 
300     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_HANDLE_BACK_EVENT),
301         data, reply, option) != ERR_NONE) {
302         WLOGFE("SendRequest failed");
303         return WSError::WS_ERROR_IPC_FAILED;
304     }
305     int32_t ret = reply.ReadInt32();
306     return static_cast<WSError>(ret);
307 }
308 
SwitchFreeMultiWindow(bool enable)309 WSError SessionStageProxy::SwitchFreeMultiWindow(bool enable)
310 {
311     MessageParcel data;
312     MessageParcel reply;
313     MessageOption option(MessageOption::TF_ASYNC);
314     if (!data.WriteInterfaceToken(GetDescriptor())) {
315         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
316         return WSError::WS_ERROR_IPC_FAILED;
317     }
318     if (!data.WriteBool(enable)) {
319         TLOGE(WmsLogTag::DEFAULT, "Write enable failed");
320         return WSError::WS_ERROR_IPC_FAILED;
321     }
322 
323     sptr<IRemoteObject> remote = Remote();
324     if (remote == nullptr) {
325         TLOGE(WmsLogTag::DEFAULT, "remote is null");
326         return WSError::WS_ERROR_IPC_FAILED;
327     }
328 
329     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SWITCH_FREEMULTIWINDOW),
330         data, reply, option) != ERR_NONE) {
331         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
332         return WSError::WS_ERROR_IPC_FAILED;
333     }
334     int32_t ret = reply.ReadInt32();
335     return static_cast<WSError>(ret);
336 }
337 
GetUIContentRemoteObj(sptr<IRemoteObject> & uiContentRemoteObj)338 WSError SessionStageProxy::GetUIContentRemoteObj(sptr<IRemoteObject>& uiContentRemoteObj)
339 {
340     MessageParcel data;
341     MessageParcel reply;
342     MessageOption option;
343     if (!data.WriteInterfaceToken(GetDescriptor())) {
344         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
345         return WSError::WS_ERROR_IPC_FAILED;
346     }
347 
348     sptr<IRemoteObject> remote = Remote();
349     if (remote == nullptr) {
350         TLOGE(WmsLogTag::DEFAULT, "remote is null");
351         return WSError::WS_ERROR_IPC_FAILED;
352     }
353 
354     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_GET_UI_CONTENT_REMOTE_OBJ),
355         data, reply, option) != ERR_NONE) {
356         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
357         return WSError::WS_ERROR_IPC_FAILED;
358     }
359     sptr<IRemoteObject> remoteObj = reply.ReadRemoteObject();
360     if (remoteObj == nullptr) {
361         TLOGE(WmsLogTag::DEFAULT, "ReadRemoteObject failed");
362         return WSError::WS_ERROR_IPC_FAILED;
363     }
364     uiContentRemoteObj = remoteObj;
365     return static_cast<WSError>(reply.ReadInt32());
366 }
367 
MarkProcessed(int32_t eventId)368 WSError SessionStageProxy::MarkProcessed(int32_t eventId)
369 {
370     return WSError::WS_DO_NOTHING;
371 }
372 
NotifyDestroy()373 WSError SessionStageProxy::NotifyDestroy()
374 {
375     MessageParcel data;
376     MessageParcel reply;
377     MessageOption option(MessageOption::TF_ASYNC);
378     if (!data.WriteInterfaceToken(GetDescriptor())) {
379         WLOGFE("WriteInterfaceToken failed");
380         return WSError::WS_ERROR_IPC_FAILED;
381     }
382 
383     sptr<IRemoteObject> remote = Remote();
384     if (remote == nullptr) {
385         WLOGFE("remote is null");
386         return WSError::WS_ERROR_IPC_FAILED;
387     }
388 
389     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DESTROY),
390         data, reply, option) != ERR_NONE) {
391         WLOGFE("SendRequest failed");
392         return WSError::WS_ERROR_IPC_FAILED;
393     }
394     int32_t ret = reply.ReadInt32();
395     return static_cast<WSError>(ret);
396 }
397 
NotifyCloseExistPipWindow()398 WSError SessionStageProxy::NotifyCloseExistPipWindow()
399 {
400     MessageParcel data;
401     MessageParcel reply;
402     MessageOption option(MessageOption::TF_ASYNC);
403     if (!data.WriteInterfaceToken(GetDescriptor())) {
404         WLOGFE("WriteInterfaceToken failed");
405         return WSError::WS_ERROR_IPC_FAILED;
406     }
407 
408     sptr<IRemoteObject> remote = Remote();
409     if (remote == nullptr) {
410         WLOGFE("remote is null");
411         return WSError::WS_ERROR_IPC_FAILED;
412     }
413 
414     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_CLOSE_EXIST_PIP_WINDOW),
415         data, reply, option) != ERR_NONE) {
416         WLOGFE("SendRequest failed");
417         return WSError::WS_ERROR_IPC_FAILED;
418     }
419     int32_t ret = reply.ReadInt32();
420     return static_cast<WSError>(ret);
421 }
422 
UpdateFocus(bool focus)423 WSError SessionStageProxy::UpdateFocus(bool focus)
424 {
425     MessageParcel data;
426     MessageParcel reply;
427     MessageOption option(MessageOption::TF_ASYNC);
428     if (!data.WriteInterfaceToken(GetDescriptor())) {
429         WLOGFE("WriteInterfaceToken failed");
430         return WSError::WS_ERROR_IPC_FAILED;
431     }
432 
433     if (!data.WriteBool(focus)) {
434         WLOGFE("Write focus failed");
435         return WSError::WS_ERROR_IPC_FAILED;
436     }
437 
438     sptr<IRemoteObject> remote = Remote();
439     if (remote == nullptr) {
440         WLOGFE("remote is null");
441         return WSError::WS_ERROR_IPC_FAILED;
442     }
443 
444     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_FOCUS_CHANGE),
445         data, reply, option) != ERR_NONE) {
446         WLOGFW("SendRequest failed");
447         return WSError::WS_ERROR_IPC_FAILED;
448     }
449     int32_t ret = reply.ReadInt32();
450     return static_cast<WSError>(ret);
451 }
452 
NotifyTransferComponentData(const AAFwk::WantParams & wantParams)453 WSError SessionStageProxy::NotifyTransferComponentData(const AAFwk::WantParams& wantParams)
454 {
455     MessageParcel data;
456     MessageParcel reply;
457     MessageOption option(MessageOption::TF_ASYNC);
458     if (!data.WriteInterfaceToken(GetDescriptor())) {
459         WLOGFE("WriteInterfaceToken failed");
460         return WSError::WS_ERROR_IPC_FAILED;
461     }
462 
463     if (!data.WriteParcelable(&wantParams)) {
464         WLOGFE("wantParams write failed.");
465         return WSError::WS_ERROR_IPC_FAILED;
466     }
467 
468     sptr<IRemoteObject> remote = Remote();
469     if (remote == nullptr) {
470         WLOGFE("remote is null");
471         return WSError::WS_ERROR_IPC_FAILED;
472     }
473 
474     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA),
475         data, reply, option) != ERR_NONE) {
476         WLOGFE("SendRequest failed");
477         return WSError::WS_ERROR_IPC_FAILED;
478     }
479     int32_t ret = reply.ReadInt32();
480     return static_cast<WSError>(ret);
481 }
482 
NotifyTransferComponentDataSync(const AAFwk::WantParams & wantParams,AAFwk::WantParams & reWantParams)483 WSErrorCode SessionStageProxy::NotifyTransferComponentDataSync(const AAFwk::WantParams& wantParams,
484                                                                AAFwk::WantParams& reWantParams)
485 {
486     MessageParcel data;
487     MessageParcel reply;
488     MessageOption option(MessageOption::TF_SYNC);
489     if (!data.WriteInterfaceToken(GetDescriptor())) {
490         WLOGFE("WriteInterfaceToken failed");
491         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
492     }
493 
494     if (!data.WriteParcelable(&wantParams)) {
495         WLOGFE("wantParams write failed.");
496         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
497     }
498 
499     sptr<IRemoteObject> remote = Remote();
500     if (remote == nullptr) {
501         WLOGFE("remote is null");
502         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
503     }
504 
505     int sendCode = remote->SendRequest(
506         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA_SYNC),
507         data, reply, option);
508     if (sendCode != ERR_NONE) {
509         WLOGFE("SendRequest failed");
510         return static_cast<WSErrorCode>(sendCode);
511     }
512 
513     std::shared_ptr<AAFwk::WantParams> readWantParams(reply.ReadParcelable<AAFwk::WantParams>());
514     if (readWantParams == nullptr) {
515         WLOGFE("readWantParams is nullptr");
516         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
517     }
518 
519     reWantParams = *readWantParams;
520     return WSErrorCode::WS_OK;
521 }
522 
NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info,const std::shared_ptr<RSTransaction> & rsTransaction)523 void SessionStageProxy::NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info,
524                                                      const std::shared_ptr<RSTransaction>& rsTransaction)
525 {
526     MessageParcel data;
527     MessageParcel reply;
528     MessageOption option(MessageOption::TF_ASYNC);
529     if (!data.WriteInterfaceToken(GetDescriptor())) {
530         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
531         return;
532     }
533 
534     if (!data.WriteParcelable(info.GetRefPtr())) {
535         TLOGE(WmsLogTag::WMS_KEYBOARD, "occupied info write failed.");
536         return;
537     }
538 
539     bool hasRSTransaction = rsTransaction != nullptr;
540     if (!data.WriteBool(hasRSTransaction)) {
541         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write has transaction failed");
542         return;
543     }
544     if (hasRSTransaction) {
545         if (!data.WriteParcelable(rsTransaction.get())) {
546             TLOGE(WmsLogTag::WMS_KEYBOARD, "Write transaction sync Id failed");
547             return;
548         }
549     }
550 
551     sptr<IRemoteObject> remote = Remote();
552     if (remote == nullptr) {
553         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
554         return;
555     }
556 
557     if (remote->SendRequest(
558         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_OCCUPIED_AREA_CHANGE_INFO),
559         data, reply, option) != ERR_NONE) {
560         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
561         return;
562     }
563     return;
564 }
565 
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)566 WSError SessionStageProxy::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
567 {
568     MessageParcel data;
569     MessageParcel reply;
570     MessageOption option(MessageOption::TF_ASYNC);
571     if (!data.WriteInterfaceToken(GetDescriptor())) {
572         WLOGFE("WriteInterfaceToken failed");
573         return WSError::WS_ERROR_IPC_FAILED;
574     }
575     if (!data.WriteStrongParcelable(avoidArea)) {
576         WLOGFE("Write AvoidArea failed");
577         return WSError::WS_ERROR_IPC_FAILED;
578     }
579     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
580         WLOGFE("Write AvoidAreaType failed");
581         return WSError::WS_ERROR_IPC_FAILED;
582     }
583     sptr<IRemoteObject> remote = Remote();
584     if (remote == nullptr) {
585         WLOGFE("remote is null");
586         return WSError::WS_ERROR_IPC_FAILED;
587     }
588     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_UPDATE_AVOID_AREA),
589         data, reply, option) != ERR_NONE) {
590         WLOGFE("SendRequest failed");
591         return WSError::WS_ERROR_IPC_FAILED;
592     }
593     return WSError::WS_OK;
594 }
595 
DumpSessionElementInfo(const std::vector<std::string> & params)596 void SessionStageProxy::DumpSessionElementInfo(const std::vector<std::string>& params)
597 {
598     MessageParcel data;
599     MessageParcel reply;
600     MessageOption option(MessageOption::TF_ASYNC);
601     if (!data.WriteInterfaceToken(GetDescriptor())) {
602         WLOGFE("WriteInterfaceToken failed");
603         return;
604     }
605     if (!data.WriteStringVector(params)) {
606         WLOGFE("Write params failed");
607         return;
608     }
609     sptr<IRemoteObject> remote = Remote();
610     if (remote == nullptr) {
611         WLOGFE("remote is null");
612         return;
613     }
614     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_DUMP_SESSSION_ELEMENT_INFO),
615         data, reply, option) != ERR_NONE) {
616         WLOGFE("SendRequest failed");
617         return;
618     }
619 }
620 
NotifyScreenshot()621 void SessionStageProxy::NotifyScreenshot()
622 {
623     MessageParcel data;
624     MessageParcel reply;
625     MessageOption option(MessageOption::TF_ASYNC);
626     if (!data.WriteInterfaceToken(GetDescriptor())) {
627         WLOGFE("WriteInterfaceToken failed");
628         return;
629     }
630     sptr<IRemoteObject> remote = Remote();
631     if (remote == nullptr) {
632         WLOGFE("remote is null");
633         return;
634     }
635     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SCREEN_SHOT),
636         data, reply, option) != ERR_NONE) {
637         WLOGFE("SendRequest failed");
638         return;
639     }
640 }
641 
NotifyTouchOutside()642 WSError SessionStageProxy::NotifyTouchOutside()
643 {
644     MessageParcel data;
645     MessageParcel reply;
646     MessageOption option(MessageOption::TF_ASYNC);
647     if (!data.WriteInterfaceToken(GetDescriptor())) {
648         WLOGFE("WriteInterfaceToken failed");
649         return WSError::WS_ERROR_IPC_FAILED;
650     }
651     sptr<IRemoteObject> remote = Remote();
652     if (remote == nullptr) {
653         WLOGFE("remote is null");
654         return WSError::WS_ERROR_IPC_FAILED;
655     }
656     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TOUCH_OUTSIDE),
657         data, reply, option) != ERR_NONE) {
658         WLOGFE("SendRequest failed");
659         return WSError::WS_ERROR_IPC_FAILED;
660     }
661     return WSError::WS_OK;
662 }
663 
NotifyWindowVisibility(bool isVisible)664 WSError SessionStageProxy::NotifyWindowVisibility(bool isVisible)
665 {
666     MessageParcel data;
667     MessageParcel reply;
668     MessageOption option(MessageOption::TF_ASYNC);
669     if (!data.WriteInterfaceToken(GetDescriptor())) {
670         WLOGFE("WriteInterfaceToken failed");
671         return WSError::WS_ERROR_IPC_FAILED;
672     }
673 
674     if (!data.WriteBool(isVisible)) {
675         WLOGFE("Write window visible failed");
676         return WSError::WS_ERROR_IPC_FAILED;
677     }
678     uint32_t messageCode = static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_WINDOW_VISIBILITY_CHANGE);
679 
680     sptr<IRemoteObject> remote = Remote();
681     if (remote == nullptr) {
682         WLOGFE("remote is null");
683         return WSError::WS_ERROR_IPC_FAILED;
684     }
685     if (remote->SendRequest(messageCode, data, reply, option) != ERR_NONE) {
686         WLOGFE("SendRequest failed");
687         return WSError::WS_ERROR_IPC_FAILED;
688     }
689     int32_t ret = reply.ReadInt32();
690     return static_cast<WSError>(ret);
691 }
692 
UpdateWindowMode(WindowMode mode)693 WSError SessionStageProxy::UpdateWindowMode(WindowMode mode)
694 {
695     MessageParcel data;
696     MessageParcel reply;
697     MessageOption option(MessageOption::TF_ASYNC);
698     if (!data.WriteInterfaceToken(GetDescriptor())) {
699         WLOGFE("WriteInterfaceToken failed");
700         return WSError::WS_ERROR_IPC_FAILED;
701     }
702 
703     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
704         WLOGFE("Write mode failed");
705         return WSError::WS_ERROR_IPC_FAILED;
706     }
707 
708     sptr<IRemoteObject> remote = Remote();
709     if (remote == nullptr) {
710         WLOGFE("remote is null");
711         return WSError::WS_ERROR_IPC_FAILED;
712     }
713     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_WINDOW_MODE_CHANGE),
714         data, reply, option) != ERR_NONE) {
715         WLOGFE("SendRequest failed");
716         return WSError::WS_ERROR_IPC_FAILED;
717     }
718     int32_t ret = reply.ReadInt32();
719     return static_cast<WSError>(ret);
720 }
721 
NotifyForegroundInteractiveStatus(bool interactive)722 void SessionStageProxy::NotifyForegroundInteractiveStatus(bool interactive)
723 {
724     MessageParcel data;
725     MessageParcel reply;
726     MessageOption option(MessageOption::TF_ASYNC);
727     if (!data.WriteInterfaceToken(GetDescriptor())) {
728         WLOGFE("WriteInterfaceToken failed");
729         return;
730     }
731 
732     if (!data.WriteBool(interactive)) {
733         WLOGFE("Write interactive failed");
734         return;
735     }
736 
737     sptr<IRemoteObject> remote = Remote();
738     if (remote == nullptr) {
739         WLOGFE("remote is null");
740         return;
741     }
742     if (remote->SendRequest(
743         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS),
744         data, reply, option) != ERR_NONE) {
745         WLOGFE("SendRequest failed");
746     }
747 }
748 
UpdateMaximizeMode(MaximizeMode mode)749 WSError SessionStageProxy::UpdateMaximizeMode(MaximizeMode mode)
750 {
751     MessageParcel data;
752     MessageParcel reply;
753     MessageOption option(MessageOption::TF_ASYNC);
754     if (!data.WriteInterfaceToken(GetDescriptor())) {
755         WLOGFE("UpdateMaximizeMode WriteInterfaceToken failed");
756         return WSError::WS_ERROR_IPC_FAILED;
757     }
758 
759     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
760         WLOGFE("UpdateMaximizeMode Write mode failed");
761         return WSError::WS_ERROR_IPC_FAILED;
762     }
763 
764     sptr<IRemoteObject> remote = Remote();
765     if (remote == nullptr) {
766         WLOGFE("remote is null");
767         return WSError::WS_ERROR_IPC_FAILED;
768     }
769     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_MAXIMIZE_MODE_CHANGE),
770         data, reply, option) != ERR_NONE) {
771         WLOGFE("UpdateMaximizeMode SendRequest failed");
772         return WSError::WS_ERROR_IPC_FAILED;
773     }
774     int32_t ret = reply.ReadInt32();
775     return static_cast<WSError>(ret);
776 }
777 
NotifySessionForeground(uint32_t reason,bool withAnimation)778 void  SessionStageProxy::NotifySessionForeground(uint32_t reason, bool withAnimation)
779 {
780     MessageParcel data;
781     MessageParcel reply;
782     MessageOption option(MessageOption::TF_ASYNC);
783     if (!data.WriteInterfaceToken(GetDescriptor())) {
784         WLOGFE("WriteInterfaceToken failed");
785         return;
786     }
787 
788     if (!data.WriteUint32(reason)) {
789         WLOGFE("Write reason failed");
790         return;
791     }
792     if (!data.WriteBool(withAnimation)) {
793         WLOGFE("Write withAnimation failed");
794         return;
795     }
796     sptr<IRemoteObject> remote = Remote();
797     if (remote == nullptr) {
798         WLOGFE("remote is null");
799         return;
800     }
801     if (remote->SendRequest(
802         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_FOREGROUND),
803         data, reply, option) != ERR_NONE) {
804         WLOGFE("Send NotifySessionForeground Request failed");
805     }
806 }
807 
NotifySessionFullScreen(bool fullScreen)808 void SessionStageProxy::NotifySessionFullScreen(bool fullScreen)
809 {
810     sptr<IRemoteObject> remote = Remote();
811     if (remote == nullptr) {
812         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
813         return;
814     }
815     MessageParcel data;
816     MessageParcel reply;
817     MessageOption option(MessageOption::TF_ASYNC);
818     if (!data.WriteInterfaceToken(GetDescriptor())) {
819         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
820         return;
821     }
822     if (!data.WriteBool(fullScreen)) {
823         TLOGE(WmsLogTag::WMS_LAYOUT, "Write fullScreen failed");
824         return;
825     }
826     if (remote->SendRequest(
827         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_FULLSCREEN),
828         data, reply, option) != ERR_NONE) {
829         TLOGE(WmsLogTag::WMS_LAYOUT, "Send Request failed");
830     }
831 }
832 
NotifySessionBackground(uint32_t reason,bool withAnimation,bool isFromInnerkits)833 void SessionStageProxy::NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits)
834 {
835     MessageParcel data;
836     MessageParcel reply;
837     MessageOption option(MessageOption::TF_ASYNC);
838     if (!data.WriteInterfaceToken(GetDescriptor())) {
839         WLOGFE("WriteInterfaceToken failed");
840         return;
841     }
842 
843     if (!data.WriteUint32(reason)) {
844         WLOGFE("Write reason failed");
845         return;
846     }
847     if (!data.WriteBool(withAnimation)) {
848         WLOGFE("Write withAnimation failed");
849         return;
850     }
851     if (!data.WriteBool(isFromInnerkits)) {
852         WLOGFE("Write isFromInnerkits failed");
853         return;
854     }
855     sptr<IRemoteObject> remote = Remote();
856     if (remote == nullptr) {
857         WLOGFE("remote is null");
858         return;
859     }
860     if (remote->SendRequest(
861         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_BACKGROUND),
862         data, reply, option) != ERR_NONE) {
863         WLOGFE("Send NotifySessionBackground Request failed");
864         return;
865     }
866 }
867 
UpdateTitleInTargetPos(bool isShow,int32_t height)868 WSError SessionStageProxy::UpdateTitleInTargetPos(bool isShow, int32_t height)
869 {
870     MessageParcel data;
871     MessageParcel reply;
872     MessageOption option(MessageOption::TF_ASYNC);
873     if (!data.WriteInterfaceToken(GetDescriptor())) {
874         WLOGFE("WriteInterfaceToken failed");
875         return WSError::WS_ERROR_IPC_FAILED;
876     }
877 
878     if (!data.WriteBool(isShow)) {
879         WLOGFE("Write isShow failed");
880         return WSError::WS_ERROR_IPC_FAILED;
881     }
882 
883     if (!data.WriteUint32(height)) {
884         WLOGFE("Write height failed");
885         return WSError::WS_ERROR_IPC_FAILED;
886     }
887 
888     sptr<IRemoteObject> remote = Remote();
889     if (remote == nullptr) {
890         WLOGFE("remote is null");
891         return WSError::WS_ERROR_IPC_FAILED;
892     }
893     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TITLE_POSITION_CHANGE),
894         data, reply, option) != ERR_NONE) {
895         WLOGFE("SendRequest failed");
896         return WSError::WS_ERROR_IPC_FAILED;
897     }
898     int32_t ret = reply.ReadInt32();
899     return static_cast<WSError>(ret);
900 }
901 
NotifyTransformChange(const Transform & transform)902 void SessionStageProxy::NotifyTransformChange(const Transform& transform)
903 {
904     MessageParcel data;
905     MessageParcel reply;
906     MessageOption option(MessageOption::TF_ASYNC);
907     if (!data.WriteInterfaceToken(GetDescriptor())) {
908         WLOGFE("WriteInterfaceToken failed");
909         return;
910     }
911 
912     if (!transform.Marshalling(data)) {
913         WLOGFE("Transform marshalling failed");
914         return;
915     }
916 
917     sptr<IRemoteObject> remote = Remote();
918     if (remote == nullptr) {
919         WLOGFE("remote is null");
920         return;
921     }
922     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFORM_CHANGE),
923                             data, reply, option) != ERR_NONE) {
924         WLOGFE("Send NotifyTransformChange Requset failed");
925     }
926 }
927 
NotifyDensityFollowHost(bool isFollowHost,float densityValue)928 WSError SessionStageProxy::NotifyDensityFollowHost(bool isFollowHost, float densityValue)
929 {
930     MessageParcel data;
931     MessageParcel reply;
932     MessageOption option(MessageOption::TF_ASYNC);
933     if (!data.WriteInterfaceToken(GetDescriptor())) {
934         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
935         return WSError::WS_ERROR_IPC_FAILED;
936     }
937 
938     if (!data.WriteBool(isFollowHost)) {
939         TLOGE(WmsLogTag::WMS_UIEXT, "Write isFollowHost failed");
940         return WSError::WS_ERROR_IPC_FAILED;
941     }
942 
943     if (!data.WriteFloat(densityValue)) {
944         TLOGE(WmsLogTag::WMS_UIEXT, "Write densityValue failed");
945         return WSError::WS_ERROR_IPC_FAILED;
946     }
947 
948     sptr<IRemoteObject> remote = Remote();
949     if (remote == nullptr) {
950         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
951         return WSError::WS_ERROR_IPC_FAILED;
952     }
953     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_FOLLOW_HOST),
954         data, reply, option) != ERR_NONE) {
955         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
956         return WSError::WS_ERROR_IPC_FAILED;
957     }
958 
959     return WSError::WS_OK;
960 }
961 
NotifyDialogStateChange(bool isForeground)962 WSError SessionStageProxy::NotifyDialogStateChange(bool isForeground)
963 {
964     MessageParcel data;
965     MessageParcel reply;
966     MessageOption option(MessageOption::TF_ASYNC);
967     if (!data.WriteInterfaceToken(GetDescriptor())) {
968         WLOGFE("WriteInterfaceToken failed");
969         return WSError::WS_ERROR_IPC_FAILED;
970     }
971 
972     if (!data.WriteBool(isForeground)) {
973         WLOGFE("Write isForeground failed");
974         return WSError::WS_ERROR_IPC_FAILED;
975     }
976 
977     sptr<IRemoteObject> remote = Remote();
978     if (remote == nullptr) {
979         WLOGFE("remote is null");
980         return WSError::WS_ERROR_IPC_FAILED;
981     }
982     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DIALOG_STATE_CHANGE),
983         data, reply, option) != ERR_NONE) {
984         WLOGFE("SendRequest failed");
985         return WSError::WS_ERROR_IPC_FAILED;
986     }
987     return WSError::WS_OK;
988 }
989 
SetPipActionEvent(const std::string & action,int32_t status)990 WSError SessionStageProxy::SetPipActionEvent(const std::string& action, int32_t status)
991 {
992     MessageParcel data;
993     MessageParcel reply;
994     MessageOption option(MessageOption::TF_ASYNC);
995     if (!data.WriteInterfaceToken(GetDescriptor())) {
996         WLOGFE("WriteInterfaceToken failed");
997         return WSError::WS_ERROR_IPC_FAILED;
998     }
999 
1000     if (!data.WriteString(action)) {
1001         WLOGFE("Write params failed");
1002         return WSError::WS_ERROR_IPC_FAILED;
1003     }
1004 
1005     if (!data.WriteInt32(status)) {
1006         WLOGFE("Write status failed");
1007         return WSError::WS_ERROR_IPC_FAILED;
1008     }
1009 
1010     sptr<IRemoteObject> remote = Remote();
1011     if (remote == nullptr) {
1012         WLOGFE("remote is null");
1013         return WSError::WS_ERROR_IPC_FAILED;
1014     }
1015     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_PIP_ACTION_EVENT),
1016         data, reply, option) != ERR_NONE) {
1017         WLOGFE("SendRequest failed");
1018         return WSError::WS_ERROR_IPC_FAILED;
1019     }
1020     return WSError::WS_OK;
1021 }
1022 
SetPiPControlEvent(WsPiPControlType controlType,WsPiPControlStatus status)1023 WSError SessionStageProxy::SetPiPControlEvent(WsPiPControlType controlType, WsPiPControlStatus status)
1024 {
1025     TLOGI(WmsLogTag::WMS_PIP, "controlType:%{public}u, enabled:%{public}d", controlType, status);
1026     MessageParcel data;
1027     MessageParcel reply;
1028     MessageOption option(MessageOption::TF_ASYNC);
1029     if (!data.WriteInterfaceToken(GetDescriptor())) {
1030         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1031         return WSError::WS_ERROR_IPC_FAILED;
1032     }
1033 
1034     if (!data.WriteUint32(static_cast<uint32_t>(controlType))) {
1035         TLOGE(WmsLogTag::WMS_PIP, "Write params failed");
1036         return WSError::WS_ERROR_IPC_FAILED;
1037     }
1038 
1039     if (!data.WriteInt32(static_cast<int32_t>(status))) {
1040         TLOGE(WmsLogTag::WMS_PIP, "Write status failed");
1041         return WSError::WS_ERROR_IPC_FAILED;
1042     }
1043 
1044     sptr<IRemoteObject> remote = Remote();
1045     if (remote == nullptr) {
1046         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1047         return WSError::WS_ERROR_IPC_FAILED;
1048     }
1049     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_PIP_CONTROL_EVENT),
1050         data, reply, option) != ERR_NONE) {
1051         TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed");
1052         return WSError::WS_ERROR_IPC_FAILED;
1053     }
1054     return WSError::WS_OK;
1055 }
1056 
NotifyDisplayMove(DisplayId from,DisplayId to)1057 void SessionStageProxy::NotifyDisplayMove(DisplayId from, DisplayId to)
1058 {
1059     MessageParcel data;
1060     MessageParcel reply;
1061     MessageOption option(MessageOption::TF_ASYNC);
1062     if (!data.WriteInterfaceToken(GetDescriptor())) {
1063         WLOGFE("WriteInterfaceToken failed");
1064         return;
1065     }
1066 
1067     if (!data.WriteUint64(from)) {
1068         WLOGFE("Write from id failed");
1069         return;
1070     }
1071 
1072     if (!data.WriteUint64(to)) {
1073         WLOGFE("Write to id failed");
1074         return;
1075     }
1076 
1077     sptr<IRemoteObject> remote = Remote();
1078     if (remote == nullptr) {
1079         WLOGFE("remote is null");
1080         return;
1081     }
1082     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DISPLAY_MOVE),
1083         data, reply, option) != ERR_NONE) {
1084         WLOGFE("SendRequest notify display move failed");
1085         return;
1086     }
1087 }
1088 
NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo & keyboardPanelInfo)1089 void SessionStageProxy::NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo)
1090 {
1091     MessageParcel data;
1092     MessageParcel reply;
1093     MessageOption option(MessageOption::TF_ASYNC);
1094     if (!data.WriteInterfaceToken(GetDescriptor())) {
1095         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
1096         return;
1097     }
1098 
1099     if (!data.WriteParcelable(&keyboardPanelInfo)) {
1100         TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardPanelInfo marshalling failed");
1101         return;
1102     }
1103 
1104     sptr<IRemoteObject> remote = Remote();
1105     if (remote == nullptr) {
1106         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
1107         return;
1108     }
1109     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_KEYBOARD_INFO_CHANGE),
1110         data, reply, option) != ERR_NONE) {
1111         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest notify keyboard panel info change failed");
1112         return;
1113     }
1114 }
1115 
NotifyCompatibleModeEnableInPad(bool enable)1116 WSError SessionStageProxy::NotifyCompatibleModeEnableInPad(bool enable)
1117 {
1118     sptr<IRemoteObject> remote = Remote();
1119     if (remote == nullptr) {
1120         TLOGE(WmsLogTag::WMS_SCB, "remote is null");
1121         return WSError::WS_ERROR_IPC_FAILED;
1122     }
1123     MessageParcel data;
1124     MessageParcel reply;
1125     MessageOption option(MessageOption::TF_ASYNC);
1126     if (!data.WriteInterfaceToken(GetDescriptor())) {
1127         TLOGE(WmsLogTag::WMS_SCB, "WriteInterfaceToken failed");
1128         return WSError::WS_ERROR_IPC_FAILED;
1129     }
1130     if (!data.WriteBool(enable)) {
1131         TLOGE(WmsLogTag::DEFAULT, "Write enable failed");
1132         return WSError::WS_ERROR_IPC_FAILED;
1133     }
1134 
1135     if (remote->SendRequest(
1136         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_COMPATIBLE_MODE_ENABLE),
1137         data, reply, option) != ERR_NONE) {
1138         TLOGE(WmsLogTag::WMS_SCB, "SendRequest failed");
1139         return WSError::WS_ERROR_IPC_FAILED;
1140     }
1141     return WSError::WS_OK;
1142 }
1143 
SetUniqueVirtualPixelRatio(bool useUniqueDensity,float virtualPixelRatio)1144 void SessionStageProxy::SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio)
1145 {
1146     sptr<IRemoteObject> remote = Remote();
1147     if (remote == nullptr) {
1148         TLOGE(WmsLogTag::DEFAULT, "remote is nullptr");
1149         return;
1150     }
1151 
1152     MessageParcel data;
1153     MessageParcel reply;
1154     MessageOption option(MessageOption::TF_ASYNC);
1155     if (!data.WriteInterfaceToken(GetDescriptor())) {
1156         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
1157         return;
1158     }
1159     if (!data.WriteBool(useUniqueDensity)) {
1160         TLOGE(WmsLogTag::DEFAULT, "Write useUniqueDensity failed");
1161         return;
1162     }
1163     if (!data.WriteFloat(virtualPixelRatio)) {
1164         TLOGE(WmsLogTag::DEFAULT, "Write virtualPixelRatio failed");
1165         return;
1166     }
1167 
1168     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_UNIQUE),
1169         data, reply, option) != ERR_NONE) {
1170         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
1171         return;
1172     }
1173 }
1174 
NotifyDumpInfo(const std::vector<std::string> & params,std::vector<std::string> & info)1175 WSError SessionStageProxy::NotifyDumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info)
1176 {
1177     sptr<IRemoteObject> remote = Remote();
1178     if (remote == nullptr) {
1179         TLOGE(WmsLogTag::WMS_UIEXT, "remote is nullptr");
1180         return WSError::WS_ERROR_NULLPTR;
1181     }
1182     MessageParcel data;
1183     MessageParcel reply;
1184     MessageOption option(MessageOption::TF_SYNC);
1185     if (!data.WriteInterfaceToken(GetDescriptor())) {
1186         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
1187         return WSError::WS_ERROR_IPC_FAILED;
1188     }
1189     if (!data.WriteStringVector(params)) {
1190         TLOGE(WmsLogTag::WMS_UIEXT, "Write params failed");
1191         return WSError::WS_ERROR_IPC_FAILED;
1192     }
1193     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DUMP_INFO),
1194         data, reply, option) != ERR_NONE) {
1195         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1196         return WSError::WS_ERROR_IPC_FAILED;
1197     }
1198 
1199     bool isLittleSize = false;
1200     if (!reply.ReadBool(isLittleSize)) {
1201         TLOGE(WmsLogTag::WMS_UIEXT, "ReadBool failed");
1202         return WSError::WS_ERROR_IPC_FAILED;
1203     }
1204 
1205     bool readResult = isLittleSize ? ReadLittleStringVectorFromParcel(reply, info) :
1206         ReadLargeStringVectorFromParcel(reply, info);
1207     if (!readResult) {
1208         TLOGE(WmsLogTag::WMS_UIEXT, "Read data failed");
1209         return WSError::WS_ERROR_IPC_FAILED;
1210     }
1211 
1212     int32_t ret = 0;
1213     if (!reply.ReadInt32(ret)) {
1214         TLOGE(WmsLogTag::WMS_UIEXT, "Read int32 failed");
1215         return WSError::WS_ERROR_IPC_FAILED;
1216     }
1217     return static_cast<WSError>(ret);
1218 }
1219 
SetEnableDragBySystem(bool dragEnable)1220 WSError SessionStageProxy::SetEnableDragBySystem(bool dragEnable)
1221 {
1222     MessageParcel data;
1223     MessageParcel reply;
1224     MessageOption option(MessageOption::TF_ASYNC);
1225     if (!data.WriteInterfaceToken(GetDescriptor())) {
1226         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
1227         return WSError::WS_ERROR_IPC_FAILED;
1228     }
1229     if (!data.WriteBool(dragEnable)) {
1230         TLOGE(WmsLogTag::WMS_LAYOUT, "Write params failed");
1231         return WSError::WS_ERROR_IPC_FAILED;
1232     }
1233     sptr<IRemoteObject> remote = Remote();
1234     if (remote == nullptr) {
1235         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
1236         return WSError::WS_ERROR_IPC_FAILED;
1237     }
1238     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_ENABLE_DRAG_BY_SYSTEM),
1239         data, reply, option) != ERR_NONE) {
1240         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1241         return WSError::WS_ERROR_IPC_FAILED;
1242     }
1243     return WSError::WS_OK;
1244 }
1245 } // namespace OHOS::Rosen
1246