• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,const std::map<AvoidAreaType,AvoidArea> & avoidAreas)174 WSError SessionStageProxy::UpdateRect(const WSRect& rect, SizeChangeReason reason,
175     const SceneAnimationConfig& config, const std::map<AvoidAreaType, AvoidArea>& avoidAreas)
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     if (!data.WriteUint32(avoidAreas.size())) {
218         TLOGE(WmsLogTag::WMS_IMMS, "Write avoid area size failed");
219         return WSError::WS_ERROR_IPC_FAILED;
220     }
221     for (const auto& [type, avoidArea] : avoidAreas) {
222         if (!data.WriteUint32(static_cast<uint32_t>(type))) {
223             TLOGE(WmsLogTag::WMS_IMMS, "Write avoid area type failed");
224             return WSError::WS_ERROR_IPC_FAILED;
225         }
226         if (!data.WriteParcelable(&avoidArea)) {
227             TLOGE(WmsLogTag::WMS_IMMS, "Write avoid area failed");
228             return WSError::WS_ERROR_IPC_FAILED;
229         }
230     }
231 
232     sptr<IRemoteObject> remote = Remote();
233     if (remote == nullptr) {
234         WLOGFE("remote is null");
235         return WSError::WS_ERROR_IPC_FAILED;
236     }
237 
238     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SIZE_CHANGE),
239         data, reply, option) != ERR_NONE) {
240         WLOGFE("SendRequest failed");
241         return WSError::WS_ERROR_IPC_FAILED;
242     }
243     int32_t ret = reply.ReadInt32();
244     return static_cast<WSError>(ret);
245 }
246 
UpdateDensity()247 void SessionStageProxy::UpdateDensity()
248 {
249     MessageParcel data;
250     MessageParcel reply;
251     MessageOption option(MessageOption::TF_ASYNC);
252     if (!data.WriteInterfaceToken(GetDescriptor())) {
253         WLOGFE("WriteInterfaceToken failed");
254         return;
255     }
256 
257     sptr<IRemoteObject> remote = Remote();
258     if (remote == nullptr) {
259         WLOGFE("remote is null");
260         return;
261     }
262 
263     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_CHANGE),
264         data, reply, option) != ERR_NONE) {
265         WLOGFE("SendRequest failed");
266         return;
267     }
268 }
269 
UpdateOrientation()270 WSError SessionStageProxy::UpdateOrientation()
271 {
272     MessageParcel data;
273     MessageParcel reply;
274     MessageOption option(MessageOption::TF_ASYNC);
275     if (!data.WriteInterfaceToken(GetDescriptor())) {
276         TLOGE(WmsLogTag::DMS, "WriteInterfaceToken failed.");
277         return WSError::WS_ERROR_IPC_FAILED;
278     }
279 
280     sptr<IRemoteObject> remote = Remote();
281     if (remote == nullptr) {
282         TLOGE(WmsLogTag::DMS, "remote is null");
283         return WSError::WS_ERROR_IPC_FAILED;
284     }
285 
286     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_ORIENTATION_CHANGE),
287         data, reply, option) != ERR_NONE) {
288         TLOGE(WmsLogTag::DMS, "SendRequest failed.");
289         return WSError::WS_ERROR_IPC_FAILED;
290     }
291 
292     WSError ret = static_cast<WSError>(reply.ReadInt32());
293     if (ret != WSError::WS_OK) {
294         TLOGE(WmsLogTag::DMS, "update orientation by ipc failed with error: %{public}d.", ret);
295     }
296     return ret;
297 }
298 
HandleBackEvent()299 WSError SessionStageProxy::HandleBackEvent()
300 {
301     MessageParcel data;
302     MessageParcel reply;
303     MessageOption option(MessageOption::TF_ASYNC);
304     if (!data.WriteInterfaceToken(GetDescriptor())) {
305         WLOGFE("WriteInterfaceToken failed");
306         return WSError::WS_ERROR_IPC_FAILED;
307     }
308 
309     sptr<IRemoteObject> remote = Remote();
310     if (remote == nullptr) {
311         WLOGFE("remote is null");
312         return WSError::WS_ERROR_IPC_FAILED;
313     }
314 
315     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_HANDLE_BACK_EVENT),
316         data, reply, option) != ERR_NONE) {
317         WLOGFE("SendRequest failed");
318         return WSError::WS_ERROR_IPC_FAILED;
319     }
320     int32_t ret = reply.ReadInt32();
321     return static_cast<WSError>(ret);
322 }
323 
SwitchFreeMultiWindow(bool enable)324 WSError SessionStageProxy::SwitchFreeMultiWindow(bool enable)
325 {
326     MessageParcel data;
327     MessageParcel reply;
328     MessageOption option(MessageOption::TF_ASYNC);
329     if (!data.WriteInterfaceToken(GetDescriptor())) {
330         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
331         return WSError::WS_ERROR_IPC_FAILED;
332     }
333     if (!data.WriteBool(enable)) {
334         TLOGE(WmsLogTag::DEFAULT, "Write enable failed");
335         return WSError::WS_ERROR_IPC_FAILED;
336     }
337 
338     sptr<IRemoteObject> remote = Remote();
339     if (remote == nullptr) {
340         TLOGE(WmsLogTag::DEFAULT, "remote is null");
341         return WSError::WS_ERROR_IPC_FAILED;
342     }
343 
344     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SWITCH_FREEMULTIWINDOW),
345         data, reply, option) != ERR_NONE) {
346         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
347         return WSError::WS_ERROR_IPC_FAILED;
348     }
349     int32_t ret = reply.ReadInt32();
350     return static_cast<WSError>(ret);
351 }
352 
GetUIContentRemoteObj(sptr<IRemoteObject> & uiContentRemoteObj)353 WSError SessionStageProxy::GetUIContentRemoteObj(sptr<IRemoteObject>& uiContentRemoteObj)
354 {
355     MessageParcel data;
356     MessageParcel reply;
357     MessageOption option;
358     if (!data.WriteInterfaceToken(GetDescriptor())) {
359         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
360         return WSError::WS_ERROR_IPC_FAILED;
361     }
362 
363     sptr<IRemoteObject> remote = Remote();
364     if (remote == nullptr) {
365         TLOGE(WmsLogTag::DEFAULT, "remote is null");
366         return WSError::WS_ERROR_IPC_FAILED;
367     }
368 
369     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_GET_UI_CONTENT_REMOTE_OBJ),
370         data, reply, option) != ERR_NONE) {
371         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
372         return WSError::WS_ERROR_IPC_FAILED;
373     }
374     sptr<IRemoteObject> remoteObj = reply.ReadRemoteObject();
375     if (remoteObj == nullptr) {
376         TLOGE(WmsLogTag::DEFAULT, "ReadRemoteObject failed");
377         return WSError::WS_ERROR_IPC_FAILED;
378     }
379     uiContentRemoteObj = remoteObj;
380     return static_cast<WSError>(reply.ReadInt32());
381 }
382 
MarkProcessed(int32_t eventId)383 WSError SessionStageProxy::MarkProcessed(int32_t eventId)
384 {
385     return WSError::WS_DO_NOTHING;
386 }
387 
NotifyDestroy()388 WSError SessionStageProxy::NotifyDestroy()
389 {
390     MessageParcel data;
391     MessageParcel reply;
392     MessageOption option(MessageOption::TF_ASYNC);
393     if (!data.WriteInterfaceToken(GetDescriptor())) {
394         WLOGFE("WriteInterfaceToken failed");
395         return WSError::WS_ERROR_IPC_FAILED;
396     }
397 
398     sptr<IRemoteObject> remote = Remote();
399     if (remote == nullptr) {
400         WLOGFE("remote is null");
401         return WSError::WS_ERROR_IPC_FAILED;
402     }
403 
404     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DESTROY),
405         data, reply, option) != ERR_NONE) {
406         WLOGFE("SendRequest failed");
407         return WSError::WS_ERROR_IPC_FAILED;
408     }
409     int32_t ret = reply.ReadInt32();
410     return static_cast<WSError>(ret);
411 }
412 
NotifyCloseExistPipWindow()413 WSError SessionStageProxy::NotifyCloseExistPipWindow()
414 {
415     MessageParcel data;
416     MessageParcel reply;
417     MessageOption option(MessageOption::TF_ASYNC);
418     if (!data.WriteInterfaceToken(GetDescriptor())) {
419         WLOGFE("WriteInterfaceToken failed");
420         return WSError::WS_ERROR_IPC_FAILED;
421     }
422 
423     sptr<IRemoteObject> remote = Remote();
424     if (remote == nullptr) {
425         WLOGFE("remote is null");
426         return WSError::WS_ERROR_IPC_FAILED;
427     }
428 
429     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_CLOSE_EXIST_PIP_WINDOW),
430         data, reply, option) != ERR_NONE) {
431         WLOGFE("SendRequest failed");
432         return WSError::WS_ERROR_IPC_FAILED;
433     }
434     int32_t ret = reply.ReadInt32();
435     return static_cast<WSError>(ret);
436 }
437 
UpdateFocus(bool focus)438 WSError SessionStageProxy::UpdateFocus(bool focus)
439 {
440     MessageParcel data;
441     MessageParcel reply;
442     MessageOption option(MessageOption::TF_ASYNC);
443     if (!data.WriteInterfaceToken(GetDescriptor())) {
444         WLOGFE("WriteInterfaceToken failed");
445         return WSError::WS_ERROR_IPC_FAILED;
446     }
447 
448     if (!data.WriteBool(focus)) {
449         WLOGFE("Write focus failed");
450         return WSError::WS_ERROR_IPC_FAILED;
451     }
452 
453     sptr<IRemoteObject> remote = Remote();
454     if (remote == nullptr) {
455         WLOGFE("remote is null");
456         return WSError::WS_ERROR_IPC_FAILED;
457     }
458 
459     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_FOCUS_CHANGE),
460         data, reply, option) != ERR_NONE) {
461         WLOGFW("SendRequest failed");
462         return WSError::WS_ERROR_IPC_FAILED;
463     }
464     int32_t ret = reply.ReadInt32();
465     return static_cast<WSError>(ret);
466 }
467 
NotifyTransferComponentData(const AAFwk::WantParams & wantParams)468 WSError SessionStageProxy::NotifyTransferComponentData(const AAFwk::WantParams& wantParams)
469 {
470     MessageParcel data;
471     MessageParcel reply;
472     MessageOption option(MessageOption::TF_ASYNC);
473     if (!data.WriteInterfaceToken(GetDescriptor())) {
474         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
475         return WSError::WS_ERROR_IPC_FAILED;
476     }
477 
478     if (!data.WriteParcelable(&wantParams)) {
479         TLOGE(WmsLogTag::WMS_UIEXT, "wantParams write failed.");
480         return WSError::WS_ERROR_IPC_FAILED;
481     }
482 
483     sptr<IRemoteObject> remote = Remote();
484     if (remote == nullptr) {
485         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
486         return WSError::WS_ERROR_IPC_FAILED;
487     }
488 
489     int sendCode = remote->SendRequest(
490         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA),
491         data, reply, option);
492     if (sendCode != ERR_NONE) {
493         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed, code: %{public}d", sendCode);
494         return WSError::WS_ERROR_IPC_FAILED;
495     }
496     int32_t ret = reply.ReadInt32();
497     return static_cast<WSError>(ret);
498 }
499 
NotifyTransferComponentDataSync(const AAFwk::WantParams & wantParams,AAFwk::WantParams & reWantParams)500 WSErrorCode SessionStageProxy::NotifyTransferComponentDataSync(const AAFwk::WantParams& wantParams,
501                                                                AAFwk::WantParams& reWantParams)
502 {
503     MessageParcel data;
504     MessageParcel reply;
505     MessageOption option(MessageOption::TF_SYNC);
506     if (!data.WriteInterfaceToken(GetDescriptor())) {
507         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
508         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
509     }
510 
511     if (!data.WriteParcelable(&wantParams)) {
512         TLOGE(WmsLogTag::WMS_UIEXT, "wantParams write failed.");
513         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
514     }
515 
516     sptr<IRemoteObject> remote = Remote();
517     if (remote == nullptr) {
518         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
519         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
520     }
521 
522     int sendCode = remote->SendRequest(
523         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA_SYNC),
524         data, reply, option);
525     if (sendCode != ERR_NONE) {
526         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed, code: %{public}d", sendCode);
527         return static_cast<WSErrorCode>(sendCode);
528     }
529 
530     std::shared_ptr<AAFwk::WantParams> readWantParams(reply.ReadParcelable<AAFwk::WantParams>());
531     if (readWantParams == nullptr) {
532         TLOGE(WmsLogTag::WMS_UIEXT, "readWantParams is nullptr");
533         return WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED;
534     }
535 
536     reWantParams = *readWantParams;
537     return WSErrorCode::WS_OK;
538 }
539 
NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info,const std::shared_ptr<RSTransaction> & rsTransaction)540 void SessionStageProxy::NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info,
541                                                      const std::shared_ptr<RSTransaction>& rsTransaction)
542 {
543     MessageParcel data;
544     MessageParcel reply;
545     MessageOption option(MessageOption::TF_ASYNC);
546     if (!data.WriteInterfaceToken(GetDescriptor())) {
547         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
548         return;
549     }
550 
551     if (!data.WriteParcelable(info.GetRefPtr())) {
552         TLOGE(WmsLogTag::WMS_KEYBOARD, "occupied info write failed.");
553         return;
554     }
555 
556     bool hasRSTransaction = rsTransaction != nullptr;
557     if (!data.WriteBool(hasRSTransaction)) {
558         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write has transaction failed");
559         return;
560     }
561     if (hasRSTransaction) {
562         if (!data.WriteParcelable(rsTransaction.get())) {
563             TLOGE(WmsLogTag::WMS_KEYBOARD, "Write transaction sync Id failed");
564             return;
565         }
566     }
567 
568     sptr<IRemoteObject> remote = Remote();
569     if (remote == nullptr) {
570         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
571         return;
572     }
573 
574     if (remote->SendRequest(
575         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_OCCUPIED_AREA_CHANGE_INFO),
576         data, reply, option) != ERR_NONE) {
577         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
578         return;
579     }
580     return;
581 }
582 
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)583 WSError SessionStageProxy::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
584 {
585     MessageParcel data;
586     MessageParcel reply;
587     MessageOption option(MessageOption::TF_ASYNC);
588     if (!data.WriteInterfaceToken(GetDescriptor())) {
589         TLOGE(WmsLogTag::WMS_IMMS, "WriteInterfaceToken failed");
590         return WSError::WS_ERROR_IPC_FAILED;
591     }
592     if (!data.WriteStrongParcelable(avoidArea)) {
593         TLOGE(WmsLogTag::WMS_IMMS, "Write AvoidArea failed");
594         return WSError::WS_ERROR_IPC_FAILED;
595     }
596     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
597         TLOGE(WmsLogTag::WMS_IMMS, "Write AvoidAreaType failed");
598         return WSError::WS_ERROR_IPC_FAILED;
599     }
600     sptr<IRemoteObject> remote = Remote();
601     if (remote == nullptr) {
602         TLOGE(WmsLogTag::WMS_IMMS, "remote is null");
603         return WSError::WS_ERROR_IPC_FAILED;
604     }
605     int sendCode = remote->SendRequest(
606         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_UPDATE_AVOID_AREA), data, reply, option);
607     if (sendCode != ERR_NONE) {
608         TLOGE(WmsLogTag::WMS_IMMS, "SendRequest failed, code: %{public}d", sendCode);
609         return WSError::WS_ERROR_IPC_FAILED;
610     }
611     return WSError::WS_OK;
612 }
613 
DumpSessionElementInfo(const std::vector<std::string> & params)614 void SessionStageProxy::DumpSessionElementInfo(const std::vector<std::string>& params)
615 {
616     MessageParcel data;
617     MessageParcel reply;
618     MessageOption option(MessageOption::TF_ASYNC);
619     if (!data.WriteInterfaceToken(GetDescriptor())) {
620         WLOGFE("WriteInterfaceToken failed");
621         return;
622     }
623     if (!data.WriteStringVector(params)) {
624         WLOGFE("Write params failed");
625         return;
626     }
627     sptr<IRemoteObject> remote = Remote();
628     if (remote == nullptr) {
629         WLOGFE("remote is null");
630         return;
631     }
632     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_DUMP_SESSSION_ELEMENT_INFO),
633         data, reply, option) != ERR_NONE) {
634         WLOGFE("SendRequest failed");
635         return;
636     }
637 }
638 
NotifyScreenshot()639 void SessionStageProxy::NotifyScreenshot()
640 {
641     MessageParcel data;
642     MessageParcel reply;
643     MessageOption option(MessageOption::TF_ASYNC);
644     if (!data.WriteInterfaceToken(GetDescriptor())) {
645         WLOGFE("WriteInterfaceToken failed");
646         return;
647     }
648     sptr<IRemoteObject> remote = Remote();
649     if (remote == nullptr) {
650         WLOGFE("remote is null");
651         return;
652     }
653     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SCREEN_SHOT),
654         data, reply, option) != ERR_NONE) {
655         WLOGFE("SendRequest failed");
656         return;
657     }
658 }
659 
NotifyTouchOutside()660 WSError SessionStageProxy::NotifyTouchOutside()
661 {
662     MessageParcel data;
663     MessageParcel reply;
664     MessageOption option(MessageOption::TF_ASYNC);
665     if (!data.WriteInterfaceToken(GetDescriptor())) {
666         WLOGFE("WriteInterfaceToken failed");
667         return WSError::WS_ERROR_IPC_FAILED;
668     }
669     sptr<IRemoteObject> remote = Remote();
670     if (remote == nullptr) {
671         WLOGFE("remote is null");
672         return WSError::WS_ERROR_IPC_FAILED;
673     }
674     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TOUCH_OUTSIDE),
675         data, reply, option) != ERR_NONE) {
676         WLOGFE("SendRequest failed");
677         return WSError::WS_ERROR_IPC_FAILED;
678     }
679     return WSError::WS_OK;
680 }
681 
NotifyWindowVisibility(bool isVisible)682 WSError SessionStageProxy::NotifyWindowVisibility(bool isVisible)
683 {
684     MessageParcel data;
685     MessageParcel reply;
686     MessageOption option(MessageOption::TF_ASYNC);
687     if (!data.WriteInterfaceToken(GetDescriptor())) {
688         WLOGFE("WriteInterfaceToken failed");
689         return WSError::WS_ERROR_IPC_FAILED;
690     }
691 
692     if (!data.WriteBool(isVisible)) {
693         WLOGFE("Write window visible failed");
694         return WSError::WS_ERROR_IPC_FAILED;
695     }
696     uint32_t messageCode = static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_WINDOW_VISIBILITY_CHANGE);
697 
698     sptr<IRemoteObject> remote = Remote();
699     if (remote == nullptr) {
700         WLOGFE("remote is null");
701         return WSError::WS_ERROR_IPC_FAILED;
702     }
703     if (remote->SendRequest(messageCode, data, reply, option) != ERR_NONE) {
704         WLOGFE("SendRequest failed");
705         return WSError::WS_ERROR_IPC_FAILED;
706     }
707     int32_t ret = reply.ReadInt32();
708     return static_cast<WSError>(ret);
709 }
710 
UpdateWindowMode(WindowMode mode)711 WSError SessionStageProxy::UpdateWindowMode(WindowMode mode)
712 {
713     MessageParcel data;
714     MessageParcel reply;
715     MessageOption option(MessageOption::TF_ASYNC);
716     if (!data.WriteInterfaceToken(GetDescriptor())) {
717         WLOGFE("WriteInterfaceToken failed");
718         return WSError::WS_ERROR_IPC_FAILED;
719     }
720 
721     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
722         WLOGFE("Write mode failed");
723         return WSError::WS_ERROR_IPC_FAILED;
724     }
725 
726     sptr<IRemoteObject> remote = Remote();
727     if (remote == nullptr) {
728         WLOGFE("remote is null");
729         return WSError::WS_ERROR_IPC_FAILED;
730     }
731     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_WINDOW_MODE_CHANGE),
732         data, reply, option) != ERR_NONE) {
733         WLOGFE("SendRequest failed");
734         return WSError::WS_ERROR_IPC_FAILED;
735     }
736     int32_t ret = reply.ReadInt32();
737     return static_cast<WSError>(ret);
738 }
739 
NotifyForegroundInteractiveStatus(bool interactive)740 void SessionStageProxy::NotifyForegroundInteractiveStatus(bool interactive)
741 {
742     MessageParcel data;
743     MessageParcel reply;
744     MessageOption option(MessageOption::TF_ASYNC);
745     if (!data.WriteInterfaceToken(GetDescriptor())) {
746         WLOGFE("WriteInterfaceToken failed");
747         return;
748     }
749 
750     if (!data.WriteBool(interactive)) {
751         WLOGFE("Write interactive failed");
752         return;
753     }
754 
755     sptr<IRemoteObject> remote = Remote();
756     if (remote == nullptr) {
757         WLOGFE("remote is null");
758         return;
759     }
760     if (remote->SendRequest(
761         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS),
762         data, reply, option) != ERR_NONE) {
763         WLOGFE("SendRequest failed");
764     }
765 }
766 
UpdateMaximizeMode(MaximizeMode mode)767 WSError SessionStageProxy::UpdateMaximizeMode(MaximizeMode mode)
768 {
769     MessageParcel data;
770     MessageParcel reply;
771     MessageOption option(MessageOption::TF_ASYNC);
772     if (!data.WriteInterfaceToken(GetDescriptor())) {
773         WLOGFE("UpdateMaximizeMode WriteInterfaceToken failed");
774         return WSError::WS_ERROR_IPC_FAILED;
775     }
776 
777     if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
778         WLOGFE("UpdateMaximizeMode Write mode failed");
779         return WSError::WS_ERROR_IPC_FAILED;
780     }
781 
782     sptr<IRemoteObject> remote = Remote();
783     if (remote == nullptr) {
784         WLOGFE("remote is null");
785         return WSError::WS_ERROR_IPC_FAILED;
786     }
787     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_MAXIMIZE_MODE_CHANGE),
788         data, reply, option) != ERR_NONE) {
789         WLOGFE("UpdateMaximizeMode SendRequest failed");
790         return WSError::WS_ERROR_IPC_FAILED;
791     }
792     int32_t ret = reply.ReadInt32();
793     return static_cast<WSError>(ret);
794 }
795 
NotifySessionForeground(uint32_t reason,bool withAnimation)796 void  SessionStageProxy::NotifySessionForeground(uint32_t reason, bool withAnimation)
797 {
798     MessageParcel data;
799     MessageParcel reply;
800     MessageOption option(MessageOption::TF_ASYNC);
801     if (!data.WriteInterfaceToken(GetDescriptor())) {
802         WLOGFE("WriteInterfaceToken failed");
803         return;
804     }
805 
806     if (!data.WriteUint32(reason)) {
807         WLOGFE("Write reason failed");
808         return;
809     }
810     if (!data.WriteBool(withAnimation)) {
811         WLOGFE("Write withAnimation failed");
812         return;
813     }
814     sptr<IRemoteObject> remote = Remote();
815     if (remote == nullptr) {
816         WLOGFE("remote is null");
817         return;
818     }
819     if (remote->SendRequest(
820         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_FOREGROUND),
821         data, reply, option) != ERR_NONE) {
822         WLOGFE("Send NotifySessionForeground Request failed");
823     }
824 }
825 
NotifySessionFullScreen(bool fullScreen)826 void SessionStageProxy::NotifySessionFullScreen(bool fullScreen)
827 {
828     sptr<IRemoteObject> remote = Remote();
829     if (remote == nullptr) {
830         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
831         return;
832     }
833     MessageParcel data;
834     MessageParcel reply;
835     MessageOption option(MessageOption::TF_ASYNC);
836     if (!data.WriteInterfaceToken(GetDescriptor())) {
837         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
838         return;
839     }
840     if (!data.WriteBool(fullScreen)) {
841         TLOGE(WmsLogTag::WMS_LAYOUT, "Write fullScreen failed");
842         return;
843     }
844     if (remote->SendRequest(
845         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_FULLSCREEN),
846         data, reply, option) != ERR_NONE) {
847         TLOGE(WmsLogTag::WMS_LAYOUT, "Send Request failed");
848     }
849 }
850 
NotifySessionBackground(uint32_t reason,bool withAnimation,bool isFromInnerkits)851 void SessionStageProxy::NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits)
852 {
853     MessageParcel data;
854     MessageParcel reply;
855     MessageOption option(MessageOption::TF_ASYNC);
856     if (!data.WriteInterfaceToken(GetDescriptor())) {
857         WLOGFE("WriteInterfaceToken failed");
858         return;
859     }
860 
861     if (!data.WriteUint32(reason)) {
862         WLOGFE("Write reason failed");
863         return;
864     }
865     if (!data.WriteBool(withAnimation)) {
866         WLOGFE("Write withAnimation failed");
867         return;
868     }
869     if (!data.WriteBool(isFromInnerkits)) {
870         WLOGFE("Write isFromInnerkits failed");
871         return;
872     }
873     sptr<IRemoteObject> remote = Remote();
874     if (remote == nullptr) {
875         WLOGFE("remote is null");
876         return;
877     }
878     if (remote->SendRequest(
879         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SESSION_BACKGROUND),
880         data, reply, option) != ERR_NONE) {
881         WLOGFE("Send NotifySessionBackground Request failed");
882         return;
883     }
884 }
885 
UpdateTitleInTargetPos(bool isShow,int32_t height)886 WSError SessionStageProxy::UpdateTitleInTargetPos(bool isShow, int32_t height)
887 {
888     MessageParcel data;
889     MessageParcel reply;
890     MessageOption option(MessageOption::TF_ASYNC);
891     if (!data.WriteInterfaceToken(GetDescriptor())) {
892         WLOGFE("WriteInterfaceToken failed");
893         return WSError::WS_ERROR_IPC_FAILED;
894     }
895 
896     if (!data.WriteBool(isShow)) {
897         WLOGFE("Write isShow failed");
898         return WSError::WS_ERROR_IPC_FAILED;
899     }
900 
901     if (!data.WriteUint32(height)) {
902         WLOGFE("Write height failed");
903         return WSError::WS_ERROR_IPC_FAILED;
904     }
905 
906     sptr<IRemoteObject> remote = Remote();
907     if (remote == nullptr) {
908         WLOGFE("remote is null");
909         return WSError::WS_ERROR_IPC_FAILED;
910     }
911     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TITLE_POSITION_CHANGE),
912         data, reply, option) != ERR_NONE) {
913         WLOGFE("SendRequest failed");
914         return WSError::WS_ERROR_IPC_FAILED;
915     }
916     int32_t ret = reply.ReadInt32();
917     return static_cast<WSError>(ret);
918 }
919 
NotifyTransformChange(const Transform & transform)920 void SessionStageProxy::NotifyTransformChange(const Transform& transform)
921 {
922     MessageParcel data;
923     MessageParcel reply;
924     MessageOption option(MessageOption::TF_ASYNC);
925     if (!data.WriteInterfaceToken(GetDescriptor())) {
926         WLOGFE("WriteInterfaceToken failed");
927         return;
928     }
929 
930     if (!transform.Marshalling(data)) {
931         WLOGFE("Transform marshalling failed");
932         return;
933     }
934 
935     sptr<IRemoteObject> remote = Remote();
936     if (remote == nullptr) {
937         WLOGFE("remote is null");
938         return;
939     }
940     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_TRANSFORM_CHANGE),
941                             data, reply, option) != ERR_NONE) {
942         WLOGFE("Send NotifyTransformChange Requset failed");
943     }
944 }
945 
NotifySingleHandTransformChange(const SingleHandTransform & singleHandTransform)946 void SessionStageProxy::NotifySingleHandTransformChange(const SingleHandTransform& singleHandTransform)
947 {
948     MessageParcel data;
949     MessageParcel reply;
950     MessageOption option(MessageOption::TF_ASYNC);
951     if (!data.WriteInterfaceToken(GetDescriptor())) {
952         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
953         return;
954     }
955 
956     if (!singleHandTransform.Marshalling(data)) {
957         TLOGE(WmsLogTag::WMS_LAYOUT, "singleHandTransform marshalling failed");
958         return;
959     }
960 
961     sptr<IRemoteObject> remote = Remote();
962     if (remote == nullptr) {
963         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
964         return;
965     }
966     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SINGLE_HAND_TRANSFORM),
967                             data, reply, option) != ERR_NONE) {
968         TLOGE(WmsLogTag::WMS_LAYOUT, "Send Requset failed");
969     }
970 }
971 
NotifyDensityFollowHost(bool isFollowHost,float densityValue)972 WSError SessionStageProxy::NotifyDensityFollowHost(bool isFollowHost, float densityValue)
973 {
974     MessageParcel data;
975     MessageParcel reply;
976     MessageOption option(MessageOption::TF_ASYNC);
977     if (!data.WriteInterfaceToken(GetDescriptor())) {
978         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
979         return WSError::WS_ERROR_IPC_FAILED;
980     }
981 
982     if (!data.WriteBool(isFollowHost)) {
983         TLOGE(WmsLogTag::WMS_UIEXT, "Write isFollowHost failed");
984         return WSError::WS_ERROR_IPC_FAILED;
985     }
986 
987     if (!data.WriteFloat(densityValue)) {
988         TLOGE(WmsLogTag::WMS_UIEXT, "Write densityValue failed");
989         return WSError::WS_ERROR_IPC_FAILED;
990     }
991 
992     sptr<IRemoteObject> remote = Remote();
993     if (remote == nullptr) {
994         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
995         return WSError::WS_ERROR_IPC_FAILED;
996     }
997     int sendCode = remote->SendRequest(
998         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_FOLLOW_HOST), data, reply, option);
999     if (sendCode != ERR_NONE) {
1000         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed, code: %{public}d", sendCode);
1001         return WSError::WS_ERROR_IPC_FAILED;
1002     }
1003 
1004     return WSError::WS_OK;
1005 }
1006 
NotifyDialogStateChange(bool isForeground)1007 WSError SessionStageProxy::NotifyDialogStateChange(bool isForeground)
1008 {
1009     MessageParcel data;
1010     MessageParcel reply;
1011     MessageOption option(MessageOption::TF_ASYNC);
1012     if (!data.WriteInterfaceToken(GetDescriptor())) {
1013         WLOGFE("WriteInterfaceToken failed");
1014         return WSError::WS_ERROR_IPC_FAILED;
1015     }
1016 
1017     if (!data.WriteBool(isForeground)) {
1018         WLOGFE("Write isForeground failed");
1019         return WSError::WS_ERROR_IPC_FAILED;
1020     }
1021 
1022     sptr<IRemoteObject> remote = Remote();
1023     if (remote == nullptr) {
1024         WLOGFE("remote is null");
1025         return WSError::WS_ERROR_IPC_FAILED;
1026     }
1027     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DIALOG_STATE_CHANGE),
1028         data, reply, option) != ERR_NONE) {
1029         WLOGFE("SendRequest failed");
1030         return WSError::WS_ERROR_IPC_FAILED;
1031     }
1032     return WSError::WS_OK;
1033 }
1034 
SetPipActionEvent(const std::string & action,int32_t status)1035 WSError SessionStageProxy::SetPipActionEvent(const std::string& action, int32_t status)
1036 {
1037     MessageParcel data;
1038     MessageParcel reply;
1039     MessageOption option(MessageOption::TF_ASYNC);
1040     if (!data.WriteInterfaceToken(GetDescriptor())) {
1041         WLOGFE("WriteInterfaceToken failed");
1042         return WSError::WS_ERROR_IPC_FAILED;
1043     }
1044 
1045     if (!data.WriteString(action)) {
1046         WLOGFE("Write params failed");
1047         return WSError::WS_ERROR_IPC_FAILED;
1048     }
1049 
1050     if (!data.WriteInt32(status)) {
1051         WLOGFE("Write status failed");
1052         return WSError::WS_ERROR_IPC_FAILED;
1053     }
1054 
1055     sptr<IRemoteObject> remote = Remote();
1056     if (remote == nullptr) {
1057         WLOGFE("remote is null");
1058         return WSError::WS_ERROR_IPC_FAILED;
1059     }
1060     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_PIP_ACTION_EVENT),
1061         data, reply, option) != ERR_NONE) {
1062         WLOGFE("SendRequest failed");
1063         return WSError::WS_ERROR_IPC_FAILED;
1064     }
1065     return WSError::WS_OK;
1066 }
1067 
NotifyPipWindowSizeChange(uint32_t width,uint32_t height,double scale)1068 WSError SessionStageProxy::NotifyPipWindowSizeChange(uint32_t width, uint32_t height, double scale)
1069 {
1070     MessageParcel data;
1071     MessageParcel reply;
1072     MessageOption option(MessageOption::TF_ASYNC);
1073     if (!data.WriteInterfaceToken(GetDescriptor())) {
1074         WLOGFE("WriteInterfaceToken failed");
1075         return WSError::WS_ERROR_IPC_FAILED;
1076     }
1077 
1078     if (!data.WriteUint32(width)) {
1079         WLOGFE("Write width failed");
1080         return WSError::WS_ERROR_IPC_FAILED;
1081     }
1082 
1083     if (!data.WriteUint32(height)) {
1084         WLOGFE("Write height failed");
1085         return WSError::WS_ERROR_IPC_FAILED;
1086     }
1087 
1088     if (!data.WriteFloat(scale)) {
1089         WLOGFE("Write scale failed");
1090         return WSError::WS_ERROR_IPC_FAILED;
1091     }
1092 
1093     sptr<IRemoteObject> remote = Remote();
1094     if (remote == nullptr) {
1095         WLOGFE("remote is null");
1096         return WSError::WS_ERROR_IPC_FAILED;
1097     }
1098 
1099     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_PIPSIZE_CHANGE),
1100         data, reply, option) != ERR_NONE) {
1101         WLOGFE("SendRequest failed");
1102         return WSError::WS_ERROR_IPC_FAILED;
1103     }
1104     return WSError::WS_OK;
1105 }
1106 
SetPiPControlEvent(WsPiPControlType controlType,WsPiPControlStatus status)1107 WSError SessionStageProxy::SetPiPControlEvent(WsPiPControlType controlType, WsPiPControlStatus status)
1108 {
1109     TLOGI(WmsLogTag::WMS_PIP, "controlType:%{public}u, enabled:%{public}d", controlType, status);
1110     MessageParcel data;
1111     MessageParcel reply;
1112     MessageOption option(MessageOption::TF_ASYNC);
1113     if (!data.WriteInterfaceToken(GetDescriptor())) {
1114         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1115         return WSError::WS_ERROR_IPC_FAILED;
1116     }
1117 
1118     if (!data.WriteUint32(static_cast<uint32_t>(controlType))) {
1119         TLOGE(WmsLogTag::WMS_PIP, "Write params failed");
1120         return WSError::WS_ERROR_IPC_FAILED;
1121     }
1122 
1123     if (!data.WriteInt32(static_cast<int32_t>(status))) {
1124         TLOGE(WmsLogTag::WMS_PIP, "Write status failed");
1125         return WSError::WS_ERROR_IPC_FAILED;
1126     }
1127 
1128     sptr<IRemoteObject> remote = Remote();
1129     if (remote == nullptr) {
1130         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1131         return WSError::WS_ERROR_IPC_FAILED;
1132     }
1133     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_PIP_CONTROL_EVENT),
1134         data, reply, option) != ERR_NONE) {
1135         TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed");
1136         return WSError::WS_ERROR_IPC_FAILED;
1137     }
1138     return WSError::WS_OK;
1139 }
1140 
NotifyDisplayMove(DisplayId from,DisplayId to)1141 void SessionStageProxy::NotifyDisplayMove(DisplayId from, DisplayId to)
1142 {
1143     MessageParcel data;
1144     MessageParcel reply;
1145     MessageOption option(MessageOption::TF_ASYNC);
1146     if (!data.WriteInterfaceToken(GetDescriptor())) {
1147         WLOGFE("WriteInterfaceToken failed");
1148         return;
1149     }
1150 
1151     if (!data.WriteUint64(from)) {
1152         WLOGFE("Write from id failed");
1153         return;
1154     }
1155 
1156     if (!data.WriteUint64(to)) {
1157         WLOGFE("Write to id failed");
1158         return;
1159     }
1160 
1161     sptr<IRemoteObject> remote = Remote();
1162     if (remote == nullptr) {
1163         WLOGFE("remote is null");
1164         return;
1165     }
1166     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DISPLAY_MOVE),
1167         data, reply, option) != ERR_NONE) {
1168         WLOGFE("SendRequest notify display move failed");
1169         return;
1170     }
1171 }
1172 
NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo & keyboardPanelInfo)1173 void SessionStageProxy::NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo)
1174 {
1175     MessageParcel data;
1176     MessageParcel reply;
1177     MessageOption option(MessageOption::TF_ASYNC);
1178     if (!data.WriteInterfaceToken(GetDescriptor())) {
1179         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
1180         return;
1181     }
1182 
1183     if (!data.WriteParcelable(&keyboardPanelInfo)) {
1184         TLOGE(WmsLogTag::WMS_KEYBOARD, "KeyboardPanelInfo marshalling failed");
1185         return;
1186     }
1187 
1188     sptr<IRemoteObject> remote = Remote();
1189     if (remote == nullptr) {
1190         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
1191         return;
1192     }
1193     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_KEYBOARD_INFO_CHANGE),
1194         data, reply, option) != ERR_NONE) {
1195         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest notify keyboard panel info change failed");
1196         return;
1197     }
1198 }
1199 
NotifyCompatibleModeEnableInPad(bool enable)1200 WSError SessionStageProxy::NotifyCompatibleModeEnableInPad(bool enable)
1201 {
1202     sptr<IRemoteObject> remote = Remote();
1203     if (remote == nullptr) {
1204         TLOGE(WmsLogTag::WMS_SCB, "remote is null");
1205         return WSError::WS_ERROR_IPC_FAILED;
1206     }
1207     MessageParcel data;
1208     MessageParcel reply;
1209     MessageOption option(MessageOption::TF_ASYNC);
1210     if (!data.WriteInterfaceToken(GetDescriptor())) {
1211         TLOGE(WmsLogTag::WMS_SCB, "WriteInterfaceToken failed");
1212         return WSError::WS_ERROR_IPC_FAILED;
1213     }
1214     if (!data.WriteBool(enable)) {
1215         TLOGE(WmsLogTag::DEFAULT, "Write enable failed");
1216         return WSError::WS_ERROR_IPC_FAILED;
1217     }
1218 
1219     if (remote->SendRequest(
1220         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_COMPATIBLE_MODE_ENABLE),
1221         data, reply, option) != ERR_NONE) {
1222         TLOGE(WmsLogTag::WMS_SCB, "SendRequest failed");
1223         return WSError::WS_ERROR_IPC_FAILED;
1224     }
1225     return WSError::WS_OK;
1226 }
1227 
SetUniqueVirtualPixelRatio(bool useUniqueDensity,float virtualPixelRatio)1228 void SessionStageProxy::SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio)
1229 {
1230     sptr<IRemoteObject> remote = Remote();
1231     if (remote == nullptr) {
1232         TLOGE(WmsLogTag::DEFAULT, "remote is nullptr");
1233         return;
1234     }
1235 
1236     MessageParcel data;
1237     MessageParcel reply;
1238     MessageOption option(MessageOption::TF_ASYNC);
1239     if (!data.WriteInterfaceToken(GetDescriptor())) {
1240         TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
1241         return;
1242     }
1243     if (!data.WriteBool(useUniqueDensity)) {
1244         TLOGE(WmsLogTag::DEFAULT, "Write useUniqueDensity failed");
1245         return;
1246     }
1247     if (!data.WriteFloat(virtualPixelRatio)) {
1248         TLOGE(WmsLogTag::DEFAULT, "Write virtualPixelRatio failed");
1249         return;
1250     }
1251 
1252     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DENSITY_UNIQUE),
1253         data, reply, option) != ERR_NONE) {
1254         TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
1255         return;
1256     }
1257 }
1258 
NotifyDumpInfo(const std::vector<std::string> & params,std::vector<std::string> & info)1259 WSError SessionStageProxy::NotifyDumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info)
1260 {
1261     sptr<IRemoteObject> remote = Remote();
1262     if (remote == nullptr) {
1263         TLOGE(WmsLogTag::WMS_UIEXT, "remote is nullptr");
1264         return WSError::WS_ERROR_NULLPTR;
1265     }
1266     MessageParcel data;
1267     MessageParcel reply;
1268     MessageOption option(MessageOption::TF_SYNC);
1269     if (!data.WriteInterfaceToken(GetDescriptor())) {
1270         TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
1271         return WSError::WS_ERROR_IPC_FAILED;
1272     }
1273     if (!data.WriteStringVector(params)) {
1274         TLOGE(WmsLogTag::WMS_UIEXT, "Write params failed");
1275         return WSError::WS_ERROR_IPC_FAILED;
1276     }
1277     int sendCode = remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_DUMP_INFO),
1278         data, reply, option);
1279     if (sendCode != ERR_NONE) {
1280         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed, code: %{public}d", sendCode);
1281         return WSError::WS_ERROR_IPC_FAILED;
1282     }
1283 
1284     bool isLittleSize = false;
1285     if (!reply.ReadBool(isLittleSize)) {
1286         TLOGE(WmsLogTag::WMS_UIEXT, "ReadBool failed");
1287         return WSError::WS_ERROR_IPC_FAILED;
1288     }
1289 
1290     bool readResult = isLittleSize ? ReadLittleStringVectorFromParcel(reply, info) :
1291         ReadLargeStringVectorFromParcel(reply, info);
1292     if (!readResult) {
1293         TLOGE(WmsLogTag::WMS_UIEXT, "Read data failed");
1294         return WSError::WS_ERROR_IPC_FAILED;
1295     }
1296 
1297     int32_t ret = 0;
1298     if (!reply.ReadInt32(ret)) {
1299         TLOGE(WmsLogTag::WMS_UIEXT, "Read int32 failed");
1300         return WSError::WS_ERROR_IPC_FAILED;
1301     }
1302     return static_cast<WSError>(ret);
1303 }
1304 
SendExtensionData(MessageParcel & data,MessageParcel & reply,MessageOption & option)1305 WSError SessionStageProxy::SendExtensionData(MessageParcel& data, MessageParcel& reply, MessageOption& option)
1306 {
1307     sptr<IRemoteObject> remote = Remote();
1308     if (remote == nullptr) {
1309         TLOGE(WmsLogTag::WMS_UIEXT, "remote is nullptr");
1310         return WSError::WS_ERROR_NULLPTR;
1311     }
1312 
1313     auto ret = remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SEND_EXTENSION_DATA), data,
1314                                    reply, option);
1315     if (ret != ERR_NONE) {
1316         TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed, ret: %{public}d", ret);
1317         return WSError::WS_ERROR_IPC_FAILED;
1318     }
1319     return WSError::WS_OK;
1320 }
1321 
SetDragActivated(bool dragActivated)1322 WSError SessionStageProxy::SetDragActivated(bool dragActivated)
1323 {
1324     MessageParcel data;
1325     MessageParcel reply;
1326     MessageOption option(MessageOption::TF_ASYNC);
1327     if (!data.WriteInterfaceToken(GetDescriptor())) {
1328         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
1329         return WSError::WS_ERROR_IPC_FAILED;
1330     }
1331     if (!data.WriteBool(dragActivated)) {
1332         TLOGE(WmsLogTag::WMS_LAYOUT, "Write params failed");
1333         return WSError::WS_ERROR_IPC_FAILED;
1334     }
1335     sptr<IRemoteObject> remote = Remote();
1336     if (remote == nullptr) {
1337         TLOGE(WmsLogTag::WMS_LAYOUT, "Remote is null");
1338         return WSError::WS_ERROR_IPC_FAILED;
1339     }
1340     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_DRAG_ACTIVATED),
1341                             data, reply, option) != ERR_NONE) {
1342         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1343         return WSError::WS_ERROR_IPC_FAILED;
1344     }
1345     return WSError::WS_OK;
1346 }
1347 
SetEnableDragBySystem(bool dragEnable)1348 WSError SessionStageProxy::SetEnableDragBySystem(bool dragEnable)
1349 {
1350     MessageParcel data;
1351     MessageParcel reply;
1352     MessageOption option(MessageOption::TF_ASYNC);
1353     if (!data.WriteInterfaceToken(GetDescriptor())) {
1354         TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
1355         return WSError::WS_ERROR_IPC_FAILED;
1356     }
1357     if (!data.WriteBool(dragEnable)) {
1358         TLOGE(WmsLogTag::WMS_LAYOUT, "Write params failed");
1359         return WSError::WS_ERROR_IPC_FAILED;
1360     }
1361     sptr<IRemoteObject> remote = Remote();
1362     if (remote == nullptr) {
1363         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
1364         return WSError::WS_ERROR_IPC_FAILED;
1365     }
1366     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_SET_ENABLE_DRAG_BY_SYSTEM),
1367         data, reply, option) != ERR_NONE) {
1368         TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1369         return WSError::WS_ERROR_IPC_FAILED;
1370     }
1371     return WSError::WS_OK;
1372 }
1373 
NotifyHighlightChange(bool isHighlight)1374 WSError SessionStageProxy::NotifyHighlightChange(bool isHighlight)
1375 {
1376     MessageParcel data;
1377     MessageParcel reply;
1378     MessageOption option(MessageOption::TF_ASYNC);
1379     if (!data.WriteInterfaceToken(GetDescriptor())) {
1380         TLOGE(WmsLogTag::WMS_FOCUS, "Write interfaceToken failed");
1381         return WSError::WS_ERROR_IPC_FAILED;
1382     }
1383 
1384     if (!data.WriteBool(isHighlight)) {
1385         TLOGE(WmsLogTag::WMS_FOCUS, "Write isHighlight failed");
1386         return WSError::WS_ERROR_IPC_FAILED;
1387     }
1388 
1389     sptr<IRemoteObject> remote = Remote();
1390     if (remote == nullptr) {
1391         TLOGE(WmsLogTag::WMS_FOCUS, "remote is null");
1392         return WSError::WS_ERROR_IPC_FAILED;
1393     }
1394 
1395     if (remote->SendRequest(static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_HIGHLIGHT_CHANGE),
1396                             data, reply, option) != ERR_NONE) {
1397         TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed");
1398         return WSError::WS_ERROR_IPC_FAILED;
1399     }
1400     return WSError::WS_OK;
1401 }
1402 
NotifyWindowAttachStateChange(bool isAttach)1403 WSError SessionStageProxy::NotifyWindowAttachStateChange(bool isAttach)
1404 {
1405     MessageParcel data;
1406     MessageParcel reply;
1407     MessageOption option(MessageOption::TF_ASYNC);
1408     if (!data.WriteInterfaceToken(GetDescriptor())) {
1409         TLOGE(WmsLogTag::WMS_SUB, "WriteInterfaceToken failed");
1410         return WSError::WS_ERROR_IPC_FAILED;
1411     }
1412     if (!data.WriteBool(isAttach)) {
1413         TLOGE(WmsLogTag::WMS_SUB, "Write params failed");
1414         return WSError::WS_ERROR_IPC_FAILED;
1415     }
1416     sptr<IRemoteObject> remote = Remote();
1417     if (remote == nullptr) {
1418         TLOGE(WmsLogTag::WMS_SUB, "remote is null");
1419         return WSError::WS_ERROR_IPC_FAILED;
1420     }
1421     if (remote->SendRequest(
1422         static_cast<uint32_t>(SessionStageInterfaceCode::TRANS_ID_NOTIFY_WINDOW_ATTACH_STATE_CHANGE),
1423         data, reply, option) != ERR_NONE) {
1424         TLOGE(WmsLogTag::WMS_SUB, "SendRequest failed");
1425         return WSError::WS_ERROR_IPC_FAILED;
1426     }
1427     return WSError::WS_OK;
1428 }
1429 } // namespace OHOS::Rosen
1430