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/host/include/zidl/session_proxy.h"
17  
18  #include "ability_start_setting.h"
19  #include <ipc_types.h>
20  #include <message_option.h>
21  #include <ui/rs_surface_node.h>
22  
23  #include "parcel/accessibility_event_info_parcel.h"
24  #include "process_options.h"
25  #include "start_window_option.h"
26  #include "want.h"
27  #include "key_event.h"
28  #include "pointer_event.h"
29  #include "process_options.h"
30  #include "session/host/include/zidl/session_ipc_interface_code.h"
31  #include "window_manager_hilog.h"
32  namespace OHOS::Rosen {
33  namespace {
34  constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionProxy" };
35  } // namespace
36  
Foreground(sptr<WindowSessionProperty> property,bool isFromClient,const std::string & identityToken)37  WSError SessionProxy::Foreground(
38      sptr<WindowSessionProperty> property, bool isFromClient, const std::string& identityToken)
39  {
40      MessageParcel data;
41      MessageParcel reply;
42      MessageOption option(MessageOption::TF_SYNC);
43      if (!data.WriteInterfaceToken(GetDescriptor())) {
44          WLOGFE("[WMSCom] WriteInterfaceToken failed");
45          return WSError::WS_ERROR_IPC_FAILED;
46      }
47  
48      if (property) {
49          if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
50              WLOGFE("[WMSCom] Write property failed");
51              return WSError::WS_ERROR_IPC_FAILED;
52          }
53      } else {
54          if (!data.WriteBool(false)) {
55              WLOGFE("[WMSCom] Write property failed");
56              return WSError::WS_ERROR_IPC_FAILED;
57          }
58      }
59      if (!data.WriteBool(isFromClient)) {
60          TLOGE(WmsLogTag::WMS_LIFE, "Write isFromClient failed");
61          return WSError::WS_ERROR_IPC_FAILED;
62      }
63      if (!data.WriteString(identityToken)) {
64          TLOGE(WmsLogTag::WMS_LIFE, "Write identityToken failed");
65          return WSError::WS_ERROR_IPC_FAILED;
66      }
67      sptr<IRemoteObject> remote = Remote();
68      if (remote == nullptr) {
69          WLOGFE("[WMSCom] remote is null");
70          return WSError::WS_ERROR_IPC_FAILED;
71      }
72      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FOREGROUND),
73          data, reply, option) != ERR_NONE) {
74          WLOGFE("[WMSCom] SendRequest failed");
75          return WSError::WS_ERROR_IPC_FAILED;
76      }
77      int32_t ret = reply.ReadInt32();
78      return static_cast<WSError>(ret);
79  }
80  
Background(bool isFromClient,const std::string & identityToken)81  WSError SessionProxy::Background(bool isFromClient, const std::string& identityToken)
82  {
83      MessageParcel data;
84      MessageParcel reply;
85      MessageOption option(MessageOption::TF_ASYNC);
86      if (!data.WriteInterfaceToken(GetDescriptor())) {
87          WLOGFE("[WMSCom] WriteInterfaceToken failed");
88          return WSError::WS_ERROR_IPC_FAILED;
89      }
90      if (!data.WriteBool(isFromClient)) {
91          TLOGE(WmsLogTag::WMS_LIFE, "Write isFromClient failed");
92          return WSError::WS_ERROR_IPC_FAILED;
93      }
94      if (!data.WriteString(identityToken)) {
95          TLOGE(WmsLogTag::WMS_LIFE, "Write identityToken failed");
96          return WSError::WS_ERROR_IPC_FAILED;
97      }
98      sptr<IRemoteObject> remote = Remote();
99      if (remote == nullptr) {
100          WLOGFE("[WMSCom] remote is null");
101          return WSError::WS_ERROR_IPC_FAILED;
102      }
103      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKGROUND),
104          data, reply, option) != ERR_NONE) {
105          WLOGFE("[WMSCom] SendRequest failed");
106          return WSError::WS_ERROR_IPC_FAILED;
107      }
108      int32_t ret = reply.ReadInt32();
109      return static_cast<WSError>(ret);
110  }
111  
Show(sptr<WindowSessionProperty> property)112  WSError SessionProxy::Show(sptr<WindowSessionProperty> property)
113  {
114      MessageParcel data;
115      MessageParcel reply;
116      MessageOption option(MessageOption::TF_SYNC);
117      if (!data.WriteInterfaceToken(GetDescriptor())) {
118          WLOGFE("WriteInterfaceToken failed");
119          return WSError::WS_ERROR_IPC_FAILED;
120      }
121  
122      if (property) {
123          if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
124              WLOGFE("Write property failed");
125              return WSError::WS_ERROR_IPC_FAILED;
126          }
127      } else {
128          if (!data.WriteBool(false)) {
129              WLOGFE("Write property failed");
130              return WSError::WS_ERROR_IPC_FAILED;
131          }
132      }
133  
134      sptr<IRemoteObject> remote = Remote();
135      if (remote == nullptr) {
136          WLOGFE("remote is null");
137          return WSError::WS_ERROR_IPC_FAILED;
138      }
139      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SHOW),
140          data, reply, option) != ERR_NONE) {
141          WLOGFE("SendRequest failed");
142          return WSError::WS_ERROR_IPC_FAILED;
143      }
144      int32_t ret = reply.ReadInt32();
145      return static_cast<WSError>(ret);
146  }
147  
Hide()148  WSError SessionProxy::Hide()
149  {
150      MessageParcel data;
151      MessageParcel reply;
152      MessageOption option(MessageOption::TF_SYNC);
153      if (!data.WriteInterfaceToken(GetDescriptor())) {
154          WLOGFE("WriteInterfaceToken failed");
155          return WSError::WS_ERROR_IPC_FAILED;
156      }
157  
158      sptr<IRemoteObject> remote = Remote();
159      if (remote == nullptr) {
160          WLOGFE("remote is null");
161          return WSError::WS_ERROR_IPC_FAILED;
162      }
163      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_HIDE),
164          data, reply, option) != ERR_NONE) {
165          WLOGFE("SendRequest failed");
166          return WSError::WS_ERROR_IPC_FAILED;
167      }
168      int32_t ret = reply.ReadInt32();
169      return static_cast<WSError>(ret);
170  }
171  
Disconnect(bool isFromClient,const std::string & identityToken)172  WSError SessionProxy::Disconnect(bool isFromClient, const std::string& identityToken)
173  {
174      MessageParcel data;
175      MessageParcel reply;
176      MessageOption option(MessageOption::TF_ASYNC);
177      if (!data.WriteInterfaceToken(GetDescriptor())) {
178          WLOGFE("WriteInterfaceToken failed");
179          return WSError::WS_ERROR_IPC_FAILED;
180      }
181  
182      if (!data.WriteBool(isFromClient)) {
183          WLOGFE("Write isFromClient failed");
184          return WSError::WS_ERROR_IPC_FAILED;
185      }
186      if (!data.WriteString(identityToken)) {
187          TLOGE(WmsLogTag::WMS_LIFE, "Write identityToken failed");
188          return WSError::WS_ERROR_IPC_FAILED;
189      }
190      sptr<IRemoteObject> remote = Remote();
191      if (remote == nullptr) {
192          WLOGFE("remote is null");
193          return WSError::WS_ERROR_IPC_FAILED;
194      }
195      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DISCONNECT),
196          data, reply, option) != ERR_NONE) {
197          WLOGFE("SendRequest failed");
198          return WSError::WS_ERROR_IPC_FAILED;
199      }
200      int32_t ret = reply.ReadInt32();
201      return static_cast<WSError>(ret);
202  }
203  
Connect(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,SystemSessionConfig & systemConfig,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token,const std::string & identityToken)204  WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
205      const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
206      sptr<WindowSessionProperty> property, sptr<IRemoteObject> token,
207      const std::string& identityToken)
208  {
209      MessageParcel data;
210      MessageParcel reply;
211      MessageOption option(MessageOption::TF_SYNC);
212      if (!data.WriteInterfaceToken(GetDescriptor())) {
213          WLOGFE("WriteInterfaceToken failed");
214          return WSError::WS_ERROR_IPC_FAILED;
215      }
216      if (!data.WriteRemoteObject(sessionStage->AsObject())) {
217          WLOGFE("Write ISessionStage failed");
218          return WSError::WS_ERROR_IPC_FAILED;
219      }
220      if (!data.WriteRemoteObject(eventChannel->AsObject())) {
221          WLOGFE("Write IWindowEventChannel failed");
222          return WSError::WS_ERROR_IPC_FAILED;
223      }
224      if (!surfaceNode || !surfaceNode->Marshalling(data)) {
225          WLOGFE("Write surfaceNode failed");
226          return WSError::WS_ERROR_IPC_FAILED;
227      }
228      if (property) {
229          if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
230              WLOGFE("Write property failed");
231              return WSError::WS_ERROR_IPC_FAILED;
232          }
233      } else {
234          if (!data.WriteBool(false)) {
235              WLOGFE("Write property failed");
236              return WSError::WS_ERROR_IPC_FAILED;
237          }
238      }
239      if (token != nullptr) {
240          if (!data.WriteRemoteObject(token)) {
241              WLOGFE("Write abilityToken failed");
242              return WSError::WS_ERROR_IPC_FAILED;
243          }
244      }
245      if (!data.WriteString(identityToken)) {
246          TLOGE(WmsLogTag::WMS_LIFE, "Write identityToken failed");
247          return WSError::WS_ERROR_IPC_FAILED;
248      }
249      sptr<IRemoteObject> remote = Remote();
250      if (remote == nullptr) {
251          WLOGFE("remote is null");
252          return WSError::WS_ERROR_IPC_FAILED;
253      }
254      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CONNECT),
255          data, reply, option) != ERR_NONE) {
256          WLOGFE("SendRequest failed");
257          return WSError::WS_ERROR_IPC_FAILED;
258      }
259      sptr<SystemSessionConfig> config = reply.ReadParcelable<SystemSessionConfig>();
260      if (config) {
261          systemConfig = *config;
262      }
263      if (property) {
264          property->SetPersistentId(reply.ReadInt32());
265          property->SetDisplayId(reply.ReadUint64());
266          bool needUpdate = reply.ReadBool();
267          property->SetIsNeedUpdateWindowMode(needUpdate);
268          if (needUpdate) {
269              property->SetWindowMode(static_cast<WindowMode>(reply.ReadUint32()));
270          }
271          Rect preRect = property->GetWindowRect();
272          Rect rect = { reply.ReadInt32(), reply.ReadInt32(), reply.ReadUint32(), reply.ReadUint32() };
273          TLOGI(WmsLogTag::WMS_LAYOUT, "updateRect when connect."
274              "preRect:[%{public}d,%{public}d,%{public}u,%{public}u]"
275              "rect:[%{public}d,%{public}d,%{public}u,%{public}u]",
276              preRect.posX_, preRect.posY_, preRect.width_, preRect.height_,
277              rect.posX_, rect.posY_, rect.width_, rect.height_);
278          if (preRect.IsUninitializedRect() && !rect.IsUninitializedRect()) {
279              property->SetWindowRect(rect);
280          }
281          property->SetCollaboratorType(reply.ReadInt32());
282          property->SetFullScreenStart(reply.ReadBool());
283          uint32_t size = reply.ReadUint32();
284          if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
285              std::vector<AppExecFwk::SupportWindowMode> supportWindowModes;
286              supportWindowModes.reserve(size);
287              for (uint32_t i = 0; i < size; i++) {
288                  supportWindowModes.push_back(
289                      static_cast<AppExecFwk::SupportWindowMode>(reply.ReadInt32()));
290              }
291              property->SetSupportWindowModes(supportWindowModes);
292          }
293          property->SetCompatibleModeInPc(reply.ReadBool());
294          property->SetCompatibleWindowSizeInPc(reply.ReadInt32(), reply.ReadInt32(),
295                                                reply.ReadInt32(), reply.ReadInt32());
296          property->SetIsAppSupportPhoneInPc(reply.ReadBool());
297          property->SetIsSupportDragInPcCompatibleMode(reply.ReadBool());
298          property->SetIsPcAppInPad(reply.ReadBool());
299          property->SetCompatibleModeEnableInPad(reply.ReadBool());
300          property->SetDragEnabled(reply.ReadBool());
301          property->SetRequestedOrientation(static_cast<Orientation>(reply.ReadUint32()));
302      }
303      int32_t ret = reply.ReadInt32();
304      return static_cast<WSError>(ret);
305  }
306  
DrawingCompleted()307  WSError SessionProxy::DrawingCompleted()
308  {
309      MessageParcel data;
310      MessageParcel reply;
311      MessageOption option;
312      if (!data.WriteInterfaceToken(GetDescriptor())) {
313          TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
314          return WSError::WS_ERROR_IPC_FAILED;
315      }
316  
317      sptr<IRemoteObject> remote = Remote();
318      if (remote == nullptr) {
319          TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
320          return WSError::WS_ERROR_IPC_FAILED;
321      }
322      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DRAWING_COMPLETED),
323          data, reply, option) != ERR_NONE) {
324          TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
325          return WSError::WS_ERROR_IPC_FAILED;
326      }
327      return static_cast<WSError>(reply.ReadInt32());
328  }
329  
RemoveStartingWindow()330  WSError SessionProxy::RemoveStartingWindow()
331  {
332      MessageParcel data;
333      MessageParcel reply;
334      MessageOption option;
335      if (!data.WriteInterfaceToken(GetDescriptor())) {
336          TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
337          return WSError::WS_ERROR_IPC_FAILED;
338      }
339      sptr<IRemoteObject> remote = Remote();
340      if (remote == nullptr) {
341          TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
342          return WSError::WS_ERROR_IPC_FAILED;
343      }
344      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_APP_REMOVE_STARTING_WINDOW),
345          data, reply, option) != ERR_NONE) {
346          TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
347          return WSError::WS_ERROR_IPC_FAILED;
348      }
349      return static_cast<WSError>(reply.ReadInt32());
350  }
351  
ChangeSessionVisibilityWithStatusBar(sptr<AAFwk::SessionInfo> abilitySessionInfo,bool visible)352  WSError SessionProxy::ChangeSessionVisibilityWithStatusBar(sptr<AAFwk::SessionInfo> abilitySessionInfo, bool visible)
353  {
354      if (abilitySessionInfo == nullptr) {
355          WLOGFE("abilitySessionInfo is null");
356          return WSError::WS_ERROR_INVALID_SESSION;
357      }
358  
359      MessageParcel data;
360      MessageParcel reply;
361      MessageOption option(MessageOption::TF_ASYNC);
362      if (!WriteAbilitySessionInfoBasic(data, abilitySessionInfo)) {
363          WLOGFE("WriteInterfaceToken or other param failed");
364          return WSError::WS_ERROR_IPC_FAILED;
365      }
366      if (abilitySessionInfo->callerToken) {
367          if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
368              WLOGFE("Write callerToken info failed");
369              return WSError::WS_ERROR_IPC_FAILED;
370          }
371      } else {
372          if (!data.WriteBool(false)) {
373              WLOGFE("Write has not callerToken info failed");
374              return WSError::WS_ERROR_IPC_FAILED;
375          }
376      }
377      if (abilitySessionInfo->startSetting) {
378          if (!data.WriteBool(true) || !data.WriteParcelable(abilitySessionInfo->startSetting.get())) {
379              WLOGFE("Write startSetting failed");
380              return WSError::WS_ERROR_IPC_FAILED;
381          }
382      } else {
383          if (!data.WriteBool(false)) {
384              WLOGFE("Write has not startSetting failed");
385              return WSError::WS_ERROR_IPC_FAILED;
386          }
387      }
388      data.WriteBool(visible);
389      sptr<IRemoteObject> remote = Remote();
390      if (remote == nullptr) {
391          WLOGFE("remote is null");
392          return WSError::WS_ERROR_IPC_FAILED;
393      }
394      if (remote->SendRequest(static_cast<uint32_t>(
395          SessionInterfaceCode::TRANS_ID_CHANGE_SESSION_VISIBILITY_WITH_STATUS_BAR),
396          data, reply, option) != ERR_NONE) {
397          WLOGFE("SendRequest failed");
398          return WSError::WS_ERROR_IPC_FAILED;
399      }
400      int32_t ret = reply.ReadInt32();
401      return static_cast<WSError>(ret);
402  }
403  
PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)404  WSError SessionProxy::PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)
405  {
406      if (abilitySessionInfo == nullptr) {
407          WLOGFE("abilitySessionInfo is null");
408          return WSError::WS_ERROR_INVALID_SESSION;
409      }
410  
411      MessageParcel data;
412      MessageParcel reply;
413      MessageOption option(MessageOption::TF_ASYNC);
414      if (!WriteAbilitySessionInfoBasic(data, abilitySessionInfo)) {
415          WLOGFE("WriteInterfaceToken or other param failed");
416          return WSError::WS_ERROR_IPC_FAILED;
417      }
418      if (!data.WriteBool(abilitySessionInfo->canStartAbilityFromBackground)) {
419          TLOGE(WmsLogTag::WMS_LIFE, "Write canStartAbilityFromBackground failed");
420          return WSError::WS_ERROR_IPC_FAILED;
421      }
422      if (!data.WriteBool(abilitySessionInfo->isAtomicService) ||
423          !data.WriteBool(abilitySessionInfo->isBackTransition) ||
424          !data.WriteBool(abilitySessionInfo->needClearInNotShowRecent)) {
425          TLOGE(WmsLogTag::WMS_LIFE, "Write isAtomicService or isBackTransition or needClearInNotShowRecent failed");
426          return WSError::WS_ERROR_IPC_FAILED;
427      }
428      if (abilitySessionInfo->callerToken) {
429          if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
430              WLOGFE("Write callerToken info failed");
431              return WSError::WS_ERROR_IPC_FAILED;
432          }
433      } else {
434          if (!data.WriteBool(false)) {
435              WLOGFE("Write has not callerToken info failed");
436              return WSError::WS_ERROR_IPC_FAILED;
437          }
438      }
439      if (abilitySessionInfo->startSetting) {
440          if (!data.WriteBool(true) || !data.WriteParcelable(abilitySessionInfo->startSetting.get())) {
441              WLOGFE("Write startSetting failed");
442              return WSError::WS_ERROR_IPC_FAILED;
443          }
444      } else {
445          if (!data.WriteBool(false)) {
446              WLOGFE("Write has not startSetting failed");
447              return WSError::WS_ERROR_IPC_FAILED;
448          }
449      }
450      if (!data.WriteBool(abilitySessionInfo->isFromIcon)) {
451          TLOGE(WmsLogTag::WMS_LIFE, "Write isFromIcon failed");
452          return WSError::WS_ERROR_IPC_FAILED;
453      }
454      if (abilitySessionInfo->startWindowOption) {
455          if (!data.WriteBool(true) || !data.WriteParcelable(abilitySessionInfo->startWindowOption.get())) {
456              TLOGE(WmsLogTag::WMS_LIFE, "Write startWindowOption failed");
457              return WSError::WS_ERROR_IPC_FAILED;
458          }
459      } else {
460          if (!data.WriteBool(false)) {
461              TLOGE(WmsLogTag::WMS_LIFE, "Write has not startWindowOption failed");
462              return WSError::WS_ERROR_IPC_FAILED;
463          }
464      }
465      auto size = abilitySessionInfo->supportWindowModes.size();
466      if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
467          if (!data.WriteUint32(static_cast<uint32_t>(size))) {
468              return WSError::WS_ERROR_IPC_FAILED;
469          }
470          for (decltype(size) i = 0; i < size; i++) {
471              if (!data.WriteInt32(static_cast<int32_t>(abilitySessionInfo->supportWindowModes[i]))) {
472                  return WSError::WS_ERROR_IPC_FAILED;
473              }
474          }
475      } else {
476          if (!data.WriteUint32(0)) {
477              return WSError::WS_ERROR_IPC_FAILED;
478          }
479      }
480      sptr<IRemoteObject> remote = Remote();
481      if (remote == nullptr) {
482          WLOGFE("remote is null");
483          return WSError::WS_ERROR_IPC_FAILED;
484      }
485      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ACTIVE_PENDING_SESSION),
486          data, reply, option) != ERR_NONE) {
487          WLOGFE("SendRequest failed");
488          return WSError::WS_ERROR_IPC_FAILED;
489      }
490      int32_t ret = reply.ReadInt32();
491      return static_cast<WSError>(ret);
492  }
493  
WriteAbilitySessionInfoBasic(MessageParcel & data,sptr<AAFwk::SessionInfo> abilitySessionInfo)494  bool SessionProxy::WriteAbilitySessionInfoBasic(MessageParcel& data, sptr<AAFwk::SessionInfo> abilitySessionInfo)
495  {
496      if (abilitySessionInfo == nullptr) {
497          WLOGFE("abilitySessionInfo is null");
498          return false;
499      }
500      if (!data.WriteInterfaceToken(GetDescriptor()) ||
501          !(data.WriteParcelable(&(abilitySessionInfo->want))) ||
502          !data.WriteInt32(abilitySessionInfo->requestCode) ||
503          !(data.WriteInt32(abilitySessionInfo->persistentId)) ||
504          !(data.WriteInt32(static_cast<uint32_t>(abilitySessionInfo->state))) ||
505          !(data.WriteInt64(abilitySessionInfo->uiAbilityId)) ||
506          !data.WriteInt32(abilitySessionInfo->callingTokenId) ||
507          !data.WriteBool(abilitySessionInfo->reuse) ||
508          !data.WriteParcelable(abilitySessionInfo->processOptions.get())) {
509          return false;
510      }
511      return true;
512  }
513  
TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)514  WSError SessionProxy::TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
515  {
516      if (abilitySessionInfo == nullptr) {
517          WLOGFE("abilitySessionInfo is null");
518          return WSError::WS_ERROR_INVALID_SESSION;
519      }
520      MessageParcel data;
521      MessageParcel reply;
522      MessageOption option(MessageOption::TF_ASYNC);
523      if (!data.WriteInterfaceToken(GetDescriptor())) {
524          WLOGFE("WriteInterfaceToken failed");
525          return WSError::WS_ERROR_IPC_FAILED;
526      }
527      if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
528          WLOGFE("Write want info failed");
529          return WSError::WS_ERROR_IPC_FAILED;
530      }
531      if (abilitySessionInfo->callerToken) {
532          if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
533              WLOGFE("Write ability info failed");
534              return WSError::WS_ERROR_IPC_FAILED;
535          }
536      } else {
537          if (!data.WriteBool(false)) {
538              WLOGFE("Write ability info failed");
539              return WSError::WS_ERROR_IPC_FAILED;
540          }
541      }
542      if (!data.WriteInt32(abilitySessionInfo->resultCode)) {
543          WLOGFE("Write resultCode info failed");
544          return WSError::WS_ERROR_IPC_FAILED;
545      }
546      sptr<IRemoteObject> remote = Remote();
547      if (remote == nullptr) {
548          WLOGFE("remote is null");
549          return WSError::WS_ERROR_IPC_FAILED;
550      }
551      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TERMINATE),
552          data, reply, option) != ERR_NONE) {
553          WLOGFE("SendRequest failed");
554          return WSError::WS_ERROR_IPC_FAILED;
555      }
556      int32_t ret = reply.ReadInt32();
557      return static_cast<WSError>(ret);
558  }
559  
NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needRemoveSession)560  WSError SessionProxy::NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo, bool needRemoveSession)
561  {
562      if (abilitySessionInfo == nullptr) {
563          TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfo is null");
564          return WSError::WS_ERROR_INVALID_SESSION;
565      }
566      MessageParcel data;
567      MessageParcel reply;
568      MessageOption option(MessageOption::TF_ASYNC);
569      if (!data.WriteInterfaceToken(GetDescriptor())) {
570          TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
571          return WSError::WS_ERROR_IPC_FAILED;
572      }
573      if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
574          TLOGE(WmsLogTag::WMS_LIFE, "Write want info failed");
575          return WSError::WS_ERROR_IPC_FAILED;
576      }
577      if (abilitySessionInfo->callerToken) {
578          if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
579              TLOGE(WmsLogTag::WMS_LIFE, "Write ability info failed");
580              return WSError::WS_ERROR_IPC_FAILED;
581          }
582      } else {
583          if (!data.WriteBool(false)) {
584              TLOGE(WmsLogTag::WMS_LIFE, "Write ability info failed");
585              return WSError::WS_ERROR_IPC_FAILED;
586          }
587      }
588      if (!data.WriteInt32(abilitySessionInfo->persistentId)) {
589          TLOGE(WmsLogTag::WMS_LIFE, "Write persistentId info failed");
590          return WSError::WS_ERROR_IPC_FAILED;
591      }
592      if (!data.WriteInt32(abilitySessionInfo->errorCode) ||
593          !data.WriteString(abilitySessionInfo->errorReason)) {
594          TLOGE(WmsLogTag::WMS_LIFE, "Write error info failed");
595          return WSError::WS_ERROR_IPC_FAILED;
596      }
597      if (!data.WriteString(abilitySessionInfo->identityToken)) {
598          TLOGE(WmsLogTag::WMS_LIFE, "Write identity token info failed");
599          return WSError::WS_ERROR_IPC_FAILED;
600      }
601      sptr<IRemoteObject> remote = Remote();
602      if (remote == nullptr) {
603          TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
604          return WSError::WS_ERROR_IPC_FAILED;
605      }
606      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_EXCEPTION),
607          data, reply, option) != ERR_NONE) {
608          TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
609          return WSError::WS_ERROR_IPC_FAILED;
610      }
611      int32_t ret = reply.ReadInt32();
612      return static_cast<WSError>(ret);
613  }
614  
OnSessionEvent(SessionEvent event)615  WSError SessionProxy::OnSessionEvent(SessionEvent event)
616  {
617      MessageParcel data;
618      MessageParcel reply;
619      MessageOption option(MessageOption::TF_ASYNC);
620      if (!data.WriteInterfaceToken(GetDescriptor())) {
621          WLOGFE("WriteInterfaceToken failed");
622          return WSError::WS_ERROR_IPC_FAILED;
623      }
624      if (!(data.WriteUint32(static_cast<uint32_t>(event)))) {
625          WLOGFE("Write event id failed");
626          return WSError::WS_ERROR_IPC_FAILED;
627      }
628      sptr<IRemoteObject> remote = Remote();
629      if (remote == nullptr) {
630          WLOGFE("remote is null");
631          return WSError::WS_ERROR_IPC_FAILED;
632      }
633      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SESSION_EVENT),
634          data, reply, option) != ERR_NONE) {
635          WLOGFE("SendRequest failed");
636          return WSError::WS_ERROR_IPC_FAILED;
637      }
638      int32_t ret = reply.ReadInt32();
639      return static_cast<WSError>(ret);
640  }
641  
SyncSessionEvent(SessionEvent event)642  WSError SessionProxy::SyncSessionEvent(SessionEvent event)
643  {
644      MessageParcel data;
645      MessageParcel reply;
646      MessageOption option(MessageOption::TF_SYNC);
647      if (!data.WriteInterfaceToken(GetDescriptor())) {
648          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
649          return WSError::WS_ERROR_IPC_FAILED;
650      }
651      if (!data.WriteInt32(static_cast<int32_t>(event))) {
652          TLOGE(WmsLogTag::WMS_LAYOUT, "Write event id failed");
653          return WSError::WS_ERROR_IPC_FAILED;
654      }
655      if (Remote()->SendRequest(static_cast<int32_t>(SessionInterfaceCode::TRANS_ID_SYNC_SESSION_EVENT),
656          data, reply, option) != ERR_NONE) {
657          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
658          return WSError::WS_ERROR_IPC_FAILED;
659      }
660      int32_t ret = reply.ReadInt32();
661      return static_cast<WSError>(ret);
662  }
663  
OnLayoutFullScreenChange(bool isLayoutFullScreen)664  WSError SessionProxy::OnLayoutFullScreenChange(bool isLayoutFullScreen)
665  {
666      MessageParcel data;
667      MessageParcel reply;
668      MessageOption option(MessageOption::TF_ASYNC);
669      if (!data.WriteInterfaceToken(GetDescriptor())) {
670          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
671          return WSError::WS_ERROR_IPC_FAILED;
672      }
673      if (!data.WriteBool(isLayoutFullScreen)) {
674          TLOGE(WmsLogTag::WMS_LAYOUT, "Write isLayoutFullScreen failed");
675          return WSError::WS_ERROR_IPC_FAILED;
676      }
677      sptr<IRemoteObject> remote = Remote();
678      if (remote == nullptr) {
679          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
680          return WSError::WS_ERROR_IPC_FAILED;
681      }
682      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE),
683          data, reply, option) != ERR_NONE) {
684          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
685          return WSError::WS_ERROR_IPC_FAILED;
686      }
687      int32_t ret = reply.ReadInt32();
688      return static_cast<WSError>(ret);
689  }
690  
OnDefaultDensityEnabled(bool isDefaultDensityEnabled)691  WSError SessionProxy::OnDefaultDensityEnabled(bool isDefaultDensityEnabled)
692  {
693      MessageParcel data;
694      MessageParcel reply;
695      MessageOption option(MessageOption::TF_ASYNC);
696      if (!data.WriteInterfaceToken(GetDescriptor())) {
697          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
698          return WSError::WS_ERROR_IPC_FAILED;
699      }
700      if (!data.WriteBool(isDefaultDensityEnabled)) {
701          TLOGE(WmsLogTag::WMS_LAYOUT, "Write isDefaultDensityEnabled failed");
702          return WSError::WS_ERROR_IPC_FAILED;
703      }
704      sptr<IRemoteObject> remote = Remote();
705      if (remote == nullptr) {
706          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
707          return WSError::WS_ERROR_IPC_FAILED;
708      }
709      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DEFAULT_DENSITY_ENABLED),
710          data, reply, option) != ERR_NONE) {
711          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
712          return WSError::WS_ERROR_IPC_FAILED;
713      }
714      int32_t ret = reply.ReadInt32();
715      return static_cast<WSError>(ret);
716  }
717  
OnTitleAndDockHoverShowChange(bool isTitleHoverShown,bool isDockHoverShown)718  WSError SessionProxy::OnTitleAndDockHoverShowChange(bool isTitleHoverShown, bool isDockHoverShown)
719  {
720      MessageParcel data;
721      MessageParcel reply;
722      MessageOption option(MessageOption::TF_ASYNC);
723      if (!data.WriteInterfaceToken(GetDescriptor())) {
724          TLOGE(WmsLogTag::WMS_IMMS, "WriteInterfaceToken failed");
725          return WSError::WS_ERROR_IPC_FAILED;
726      }
727      if (!data.WriteBool(isTitleHoverShown) || !data.WriteBool(isDockHoverShown)) {
728          TLOGE(WmsLogTag::WMS_IMMS, "Write isTitleHoverShown or isDockHoverShown failed");
729          return WSError::WS_ERROR_IPC_FAILED;
730      }
731      sptr<IRemoteObject> remote = Remote();
732      if (remote == nullptr) {
733          TLOGE(WmsLogTag::WMS_IMMS, "remote is null");
734          return WSError::WS_ERROR_IPC_FAILED;
735      }
736      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TITLE_AND_DOCK_HOVER_SHOW_CHANGE),
737          data, reply, option) != ERR_NONE) {
738          TLOGE(WmsLogTag::WMS_IMMS, "SendRequest failed");
739          return WSError::WS_ERROR_IPC_FAILED;
740      }
741      uint32_t ret = reply.ReadUint32();
742      return static_cast<WSError>(ret);
743  }
744  
OnRestoreMainWindow()745  WSError SessionProxy::OnRestoreMainWindow()
746  {
747      MessageParcel data;
748      MessageParcel reply;
749      MessageOption option(MessageOption::TF_ASYNC);
750      if (!data.WriteInterfaceToken(GetDescriptor())) {
751          TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
752          return WSError::WS_ERROR_IPC_FAILED;
753      }
754      sptr<IRemoteObject> remote = Remote();
755      if (remote == nullptr) {
756          TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
757          return WSError::WS_ERROR_IPC_FAILED;
758      }
759      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RESTORE_MAIN_WINDOW),
760          data, reply, option) != ERR_NONE) {
761          TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
762          return WSError::WS_ERROR_IPC_FAILED;
763      }
764      return WSError::WS_OK;
765  }
766  
UpdateSessionRect(const WSRect & rect,const SizeChangeReason reason,bool isGlobal,bool isFromMoveToGlobal)767  WSError SessionProxy::UpdateSessionRect(const WSRect& rect, const SizeChangeReason reason,
768      bool isGlobal, bool isFromMoveToGlobal)
769  {
770      TLOGI(WmsLogTag::WMS_LAYOUT, "Rect [%{public}d, %{public}d, %{public}u, %{public}u]",
771          rect.posX_, rect.posY_, rect.width_, rect.height_);
772      MessageParcel data;
773      MessageParcel reply;
774      MessageOption option(MessageOption::TF_ASYNC);
775      if (!data.WriteInterfaceToken(GetDescriptor())) {
776          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
777          return WSError::WS_ERROR_IPC_FAILED;
778      }
779      if (!((data.WriteInt32(static_cast<int32_t>(rect.posX_))) &&
780          (data.WriteInt32(static_cast<int32_t>(rect.posY_))) &&
781          (data.WriteUint32(static_cast<uint32_t>(rect.width_))) &&
782          (data.WriteUint32(static_cast<uint32_t>(rect.height_))))) {
783          TLOGE(WmsLogTag::WMS_LAYOUT, "Write rect failed");
784          return WSError::WS_ERROR_IPC_FAILED;
785      }
786  
787      if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
788          TLOGE(WmsLogTag::WMS_LAYOUT, "Write SessionSizeChangeReason failed");
789          return WSError::WS_ERROR_IPC_FAILED;
790      }
791  
792      if (!data.WriteBool(isGlobal)) {
793          TLOGE(WmsLogTag::WMS_LAYOUT, "Write bool failed");
794          return WSError::WS_ERROR_IPC_FAILED;
795      }
796  
797      if (!data.WriteBool(isFromMoveToGlobal)) {
798          TLOGE(WmsLogTag::WMS_LAYOUT, "Write bool failed");
799          return WSError::WS_ERROR_IPC_FAILED;
800      }
801  
802      sptr<IRemoteObject> remote = Remote();
803      if (remote == nullptr) {
804          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
805          return WSError::WS_ERROR_IPC_FAILED;
806      }
807      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT),
808          data, reply, option) != ERR_NONE) {
809          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
810          return WSError::WS_ERROR_IPC_FAILED;
811      }
812      int32_t ret = reply.ReadInt32();
813      return static_cast<WSError>(ret);
814  }
815  
816  /** @note @window.layout */
GetGlobalScaledRect(Rect & globalScaledRect)817  WMError SessionProxy::GetGlobalScaledRect(Rect& globalScaledRect)
818  {
819      MessageParcel data;
820      MessageParcel reply;
821      MessageOption option;
822      if (!data.WriteInterfaceToken(GetDescriptor())) {
823          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
824          return WMError::WM_ERROR_IPC_FAILED;
825      }
826      sptr<IRemoteObject> remote = Remote();
827      if (remote == nullptr) {
828          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
829          return WMError::WM_ERROR_IPC_FAILED;
830      }
831      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_GLOBAL_SCALED_RECT),
832          data, reply, option) != ERR_NONE) {
833          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
834          return WMError::WM_ERROR_IPC_FAILED;
835      }
836      int32_t posX = 0;
837      int32_t posY = 0;
838      uint32_t width = 0;
839      uint32_t height = 0;
840      int32_t ret = 0;
841      if (!reply.ReadInt32(posX) || !reply.ReadInt32(posY) ||
842          !reply.ReadUint32(width) || !reply.ReadUint32(height) || !reply.ReadInt32(ret)) {
843          TLOGE(WmsLogTag::WMS_LAYOUT, "read failed");
844          return WMError::WM_ERROR_IPC_FAILED;
845      }
846      globalScaledRect = { posX, posY, width, height };
847      return static_cast<WMError>(ret);
848  }
849  
850  /** @note @window.layout */
UpdateClientRect(const WSRect & rect)851  WSError SessionProxy::UpdateClientRect(const WSRect& rect)
852  {
853      TLOGD(WmsLogTag::WMS_LAYOUT, "rect:[%{public}d, %{public}d, %{public}u, %{public}u]",
854          rect.posX_, rect.posY_, rect.width_, rect.height_);
855      MessageParcel data;
856      MessageParcel reply;
857      MessageOption option;
858      if (!data.WriteInterfaceToken(GetDescriptor())) {
859          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
860          return WSError::WS_ERROR_IPC_FAILED;
861      }
862      if (!data.WriteInt32(rect.posX_) ||
863          !data.WriteInt32(rect.posY_) ||
864          !data.WriteInt32(rect.width_) ||
865          !data.WriteInt32(rect.height_)) {
866          TLOGE(WmsLogTag::WMS_LAYOUT, "Write rect failed");
867          return WSError::WS_ERROR_IPC_FAILED;
868      }
869  
870      sptr<IRemoteObject> remote = Remote();
871      if (remote == nullptr) {
872          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
873          return WSError::WS_ERROR_IPC_FAILED;
874      }
875      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CLIENT_RECT),
876          data, reply, option) != ERR_NONE) {
877          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
878          return WSError::WS_ERROR_IPC_FAILED;
879      }
880      int32_t ret = reply.ReadInt32();
881      return static_cast<WSError>(ret);
882  }
883  
884  /** @note @window.hierarchy */
RaiseToAppTop()885  WSError SessionProxy::RaiseToAppTop()
886  {
887      MessageParcel data;
888      MessageParcel reply;
889      MessageOption option;
890      if (!data.WriteInterfaceToken(GetDescriptor())) {
891          WLOGFE("WriteInterfaceToken failed");
892          return WSError::WS_ERROR_IPC_FAILED;
893      }
894      sptr<IRemoteObject> remote = Remote();
895      if (remote == nullptr) {
896          WLOGFE("remote is null");
897          return WSError::WS_ERROR_IPC_FAILED;
898      }
899      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP),
900          data, reply, option) != ERR_NONE) {
901          WLOGFE("SendRequest failed");
902          return WSError::WS_ERROR_IPC_FAILED;
903      }
904      int32_t ret = reply.ReadInt32();
905      return static_cast<WSError>(ret);
906  }
907  
NotifyFrameLayoutFinishFromApp(bool notifyListener,const WSRect & rect)908  WSError SessionProxy::NotifyFrameLayoutFinishFromApp(bool notifyListener, const WSRect& rect)
909  {
910      MessageParcel data;
911      MessageParcel reply;
912      MessageOption option(MessageOption::TF_ASYNC);
913      if (!data.WriteInterfaceToken(GetDescriptor())) {
914          TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
915          return WSError::WS_ERROR_IPC_FAILED;
916      }
917  
918      if (!data.WriteBool(notifyListener)) {
919          TLOGE(WmsLogTag::WMS_LAYOUT, "Write notifyListener failed");
920          return WSError::WS_ERROR_IPC_FAILED;
921      }
922  
923      if (!data.WriteInt32(rect.posX_) || !data.WriteInt32(rect.posY_) ||
924          !data.WriteInt32(rect.width_) || !data.WriteInt32(rect.height_)) {
925          TLOGE(WmsLogTag::WMS_LAYOUT, "Write rect failed");
926          return WSError::WS_ERROR_IPC_FAILED;
927      }
928  
929      sptr<IRemoteObject> remote = Remote();
930      if (remote == nullptr) {
931          TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is null");
932          return WSError::WS_ERROR_IPC_FAILED;
933      }
934  
935      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FRAME_LAYOUT_FINISH),
936          data, reply, option) != ERR_NONE) {
937          TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "SendRequest failed");
938          return WSError::WS_ERROR_IPC_FAILED;
939      }
940      return WSError::WS_OK;
941  }
942  
943  /** @note @window.hierarchy */
RaiseAboveTarget(int32_t subWindowId)944  WSError SessionProxy::RaiseAboveTarget(int32_t subWindowId)
945  {
946      MessageParcel data;
947      MessageParcel reply;
948      MessageOption option;
949      if (!data.WriteInterfaceToken(GetDescriptor())) {
950          WLOGFE("WriteInterfaceToken failed");
951          return WSError::WS_ERROR_IPC_FAILED;
952      }
953      if (!data.WriteInt32(subWindowId)) {
954          WLOGFE("Write subWindowId failed");
955      }
956      sptr<IRemoteObject> remote = Remote();
957      if (remote == nullptr) {
958          WLOGFE("remote is null");
959          return WSError::WS_ERROR_IPC_FAILED;
960      }
961      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_ABOVE_TARGET),
962          data, reply, option) != ERR_NONE) {
963          WLOGFE("SendRequest failed");
964          return WSError::WS_ERROR_IPC_FAILED;
965      }
966      int32_t ret = reply.ReadInt32();
967      return static_cast<WSError>(ret);
968  }
969  
RaiseAppMainWindowToTop()970  WSError SessionProxy::RaiseAppMainWindowToTop()
971  {
972      MessageParcel data;
973      MessageParcel reply;
974      MessageOption option(MessageOption::TF_ASYNC);
975      if (!data.WriteInterfaceToken(GetDescriptor())) {
976          WLOGFE("WriteInterfaceToken failed");
977          return WSError::WS_ERROR_IPC_FAILED;
978      }
979      sptr<IRemoteObject> remote = Remote();
980      if (remote == nullptr) {
981          WLOGFE("remote is null");
982          return WSError::WS_ERROR_IPC_FAILED;
983      }
984      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_APP_MAIN_WINDOW),
985          data, reply, option) != ERR_NONE) {
986          WLOGFE("SendRequest failed");
987          return WSError::WS_ERROR_IPC_FAILED;
988      }
989      int32_t ret = reply.ReadInt32();
990      return static_cast<WSError>(ret);
991  }
992  
OnNeedAvoid(bool status)993  WSError SessionProxy::OnNeedAvoid(bool status)
994  {
995      MessageParcel data;
996      MessageParcel reply;
997      MessageOption option(MessageOption::TF_ASYNC);
998      if (!data.WriteInterfaceToken(GetDescriptor())) {
999          WLOGFE("WriteInterfaceToken failed");
1000          return WSError::WS_ERROR_IPC_FAILED;
1001      }
1002      if (!(data.WriteUint32(static_cast<uint32_t>(status)))) {
1003          WLOGFE("Write status failed");
1004          return WSError::WS_ERROR_IPC_FAILED;
1005      }
1006      sptr<IRemoteObject> remote = Remote();
1007      if (remote == nullptr) {
1008          WLOGFE("remote is null");
1009          return WSError::WS_ERROR_IPC_FAILED;
1010      }
1011      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NEED_AVOID),
1012          data, reply, option) != ERR_NONE) {
1013          WLOGFE("SendRequest failed");
1014          return WSError::WS_ERROR_IPC_FAILED;
1015      }
1016      int32_t ret = reply.ReadInt32();
1017      return static_cast<WSError>(ret);
1018  }
1019  
GetAvoidAreaByType(AvoidAreaType type)1020  AvoidArea SessionProxy::GetAvoidAreaByType(AvoidAreaType type)
1021  {
1022      MessageParcel data;
1023      MessageParcel reply;
1024      MessageOption option(MessageOption::TF_SYNC);
1025      AvoidArea avoidArea;
1026      if (!data.WriteInterfaceToken(GetDescriptor())) {
1027          WLOGFE("WriteInterfaceToken failed");
1028          return avoidArea;
1029      }
1030      if (!(data.WriteUint32(static_cast<uint32_t>(type)))) {
1031          WLOGFE("Write type failed");
1032          return avoidArea;
1033      }
1034      sptr<IRemoteObject> remote = Remote();
1035      if (remote == nullptr) {
1036          WLOGFE("remote is null");
1037          return avoidArea;
1038      }
1039      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_AVOID_AREA),
1040          data, reply, option) != ERR_NONE) {
1041          WLOGFE("SendRequest failed");
1042          return avoidArea;
1043      }
1044      sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
1045      if (area == nullptr) {
1046          return avoidArea;
1047      }
1048      return *area;
1049  }
1050  
GetAllAvoidAreas(std::map<AvoidAreaType,AvoidArea> & avoidAreas)1051  WSError SessionProxy::GetAllAvoidAreas(std::map<AvoidAreaType, AvoidArea>& avoidAreas)
1052  {
1053      MessageParcel data;
1054      MessageParcel reply;
1055      MessageOption option(MessageOption::TF_SYNC);
1056      if (!data.WriteInterfaceToken(GetDescriptor())) {
1057          WLOGFE("WriteInterfaceToken failed");
1058          return WSError::WS_ERROR_IPC_FAILED;
1059      }
1060      sptr<IRemoteObject> remote = Remote();
1061      if (remote == nullptr) {
1062          WLOGFE("remote is null");
1063          return WSError::WS_ERROR_IPC_FAILED;
1064      }
1065      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_ALL_AVOID_AREAS),
1066          data, reply, option) != ERR_NONE) {
1067          WLOGFE("SendRequest failed");
1068          return WSError::WS_ERROR_IPC_FAILED;
1069      }
1070      uint32_t size = reply.ReadUint32();
1071      constexpr uint32_t AVOID_AREA_TYPE_MAX_SIZE = 100;
1072      if (size > AVOID_AREA_TYPE_MAX_SIZE) {
1073          TLOGE(WmsLogTag::WMS_IMMS, "size is invalid");
1074          return WSError::WS_ERROR_IPC_FAILED;
1075      }
1076      for (uint32_t i = 0; i < size; i++) {
1077          uint32_t type = reply.ReadUint32();
1078          if (type < static_cast<uint32_t>(AvoidAreaType::TYPE_SYSTEM) ||
1079              type > static_cast<uint32_t>(AvoidAreaType::TYPE_NAVIGATION_INDICATOR)) {
1080              WLOGFE("Read type failed");
1081              return WSError::WS_ERROR_IPC_FAILED;
1082          }
1083          sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
1084          if (area == nullptr) {
1085              return WSError::WS_ERROR_IPC_FAILED;
1086          }
1087          avoidAreas[static_cast<AvoidAreaType>(type)] = *area;
1088      }
1089      uint32_t ret = reply.ReadUint32();
1090      return static_cast<WSError>(ret);
1091  }
1092  
RequestSessionBack(bool needMoveToBackground)1093  WSError SessionProxy::RequestSessionBack(bool needMoveToBackground)
1094  {
1095      MessageParcel data;
1096      MessageParcel reply;
1097      MessageOption option(MessageOption::TF_ASYNC);
1098      if (!data.WriteInterfaceToken(GetDescriptor())) {
1099          WLOGFE("WriteInterfaceToken failed");
1100          return WSError::WS_ERROR_IPC_FAILED;
1101      }
1102      if (!data.WriteBool(needMoveToBackground)) {
1103          WLOGFE("Write needMoveToBackground failed");
1104          return WSError::WS_ERROR_IPC_FAILED;
1105      }
1106      sptr<IRemoteObject> remote = Remote();
1107      if (remote == nullptr) {
1108          WLOGFE("remote is null");
1109          return WSError::WS_ERROR_IPC_FAILED;
1110      }
1111      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKPRESSED),
1112          data, reply, option) != ERR_NONE) {
1113          WLOGFE("SendRequest failed");
1114          return WSError::WS_ERROR_IPC_FAILED;
1115      }
1116      int32_t ret = reply.ReadInt32();
1117      return static_cast<WSError>(ret);
1118  }
1119  
MarkProcessed(int32_t eventId)1120  WSError SessionProxy::MarkProcessed(int32_t eventId)
1121  {
1122      MessageParcel data;
1123      MessageParcel reply;
1124      MessageOption option(MessageOption::TF_ASYNC);
1125      if (!data.WriteInterfaceToken(GetDescriptor())) {
1126          WLOGFE("WriteInterfaceToken failed");
1127          return WSError::WS_ERROR_IPC_FAILED;
1128      }
1129      if (!data.WriteInt32(eventId)) {
1130          WLOGFE("WriteInterfaceToken failed");
1131          return WSError::WS_ERROR_IPC_FAILED;
1132      }
1133      sptr<IRemoteObject> remote = Remote();
1134      if (remote == nullptr) {
1135          WLOGFE("remote is null");
1136          return WSError::WS_ERROR_IPC_FAILED;
1137      }
1138      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MARK_PROCESSED),
1139          data, reply, option) != ERR_NONE) {
1140          WLOGFE("SendRequest failed");
1141          return WSError::WS_ERROR_IPC_FAILED;
1142      }
1143      int32_t ret = reply.ReadInt32();
1144      return static_cast<WSError>(ret);
1145  }
1146  
SetGlobalMaximizeMode(MaximizeMode mode)1147  WSError OHOS::Rosen::SessionProxy::SetGlobalMaximizeMode(MaximizeMode mode)
1148  {
1149      MessageParcel data;
1150      MessageParcel reply;
1151      MessageOption option;
1152      if (!data.WriteInterfaceToken(GetDescriptor())) {
1153          WLOGFE("WriteInterfaceToken failed");
1154          return WSError::WS_ERROR_IPC_FAILED;
1155      }
1156      if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
1157          WLOGFE("Write uint32_t failed");
1158      }
1159      sptr<IRemoteObject> remote = Remote();
1160      if (remote == nullptr) {
1161          WLOGFE("remote is null");
1162          return WSError::WS_ERROR_IPC_FAILED;
1163      }
1164      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_MAXIMIZE_MODE),
1165          data, reply, option) != ERR_NONE) {
1166          WLOGFE("SendRequest failed");
1167          return WSError::WS_ERROR_IPC_FAILED;
1168      }
1169      int32_t ret = reply.ReadInt32();
1170      return static_cast<WSError>(ret);
1171  }
1172  
GetGlobalMaximizeMode(MaximizeMode & mode)1173  WSError SessionProxy::GetGlobalMaximizeMode(MaximizeMode& mode)
1174  {
1175      MessageParcel data;
1176      MessageParcel reply;
1177      MessageOption option;
1178      if (!data.WriteInterfaceToken(GetDescriptor())) {
1179          WLOGFE("WriteInterfaceToken failed");
1180          return WSError::WS_ERROR_IPC_FAILED;
1181      }
1182      sptr<IRemoteObject> remote = Remote();
1183      if (remote == nullptr) {
1184          WLOGFE("remote is null");
1185          return WSError::WS_ERROR_IPC_FAILED;
1186      }
1187      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_MAXIMIZE_MODE),
1188          data, reply, option) != ERR_NONE) {
1189          WLOGFE("SendRequest failed");
1190          return WSError::WS_ERROR_IPC_FAILED;
1191      }
1192      mode = static_cast<MaximizeMode>(reply.ReadUint32());
1193      int32_t ret = reply.ReadInt32();
1194      return static_cast<WSError>(ret);
1195  }
1196  
SetAspectRatio(float ratio)1197  WSError SessionProxy::SetAspectRatio(float ratio)
1198  {
1199      MessageParcel data;
1200      MessageParcel reply;
1201      MessageOption option;
1202      if (!data.WriteInterfaceToken(GetDescriptor())) {
1203          WLOGFE("WriteInterfaceToken failed");
1204          return WSError::WS_ERROR_IPC_FAILED;
1205      }
1206      if (!data.WriteFloat(ratio)) {
1207          WLOGFE("Write ratio failed");
1208          return WSError::WS_ERROR_IPC_FAILED;
1209      }
1210      sptr<IRemoteObject> remote = Remote();
1211      if (remote == nullptr) {
1212          WLOGFE("remote is null");
1213          return WSError::WS_ERROR_IPC_FAILED;
1214      }
1215      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_ASPECT_RATIO),
1216                              data, reply, option) != ERR_NONE) {
1217          WLOGFE("SendRequest failed");
1218          return WSError::WS_ERROR_IPC_FAILED;
1219      }
1220      int32_t ret = reply.ReadInt32();
1221      return static_cast<WSError>(ret);
1222  }
1223  
UpdateWindowSceneAfterCustomAnimation(bool isAdd)1224  WSError SessionProxy::UpdateWindowSceneAfterCustomAnimation(bool isAdd)
1225  {
1226      MessageParcel data;
1227      MessageParcel reply;
1228      MessageOption option(MessageOption::TF_ASYNC);
1229      if (!data.WriteInterfaceToken(GetDescriptor())) {
1230          WLOGFE("WriteInterfaceToken failed");
1231          return WSError::WS_ERROR_IPC_FAILED;
1232      }
1233      if (!data.WriteBool(isAdd)) {
1234          WLOGFE("Write isAdd failed");
1235          return WSError::WS_ERROR_IPC_FAILED;
1236      }
1237      sptr<IRemoteObject> remote = Remote();
1238      if (remote == nullptr) {
1239          WLOGFE("remote is null");
1240          return WSError::WS_ERROR_IPC_FAILED;
1241      }
1242      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
1243                              data, reply, option) != ERR_NONE) {
1244          WLOGFE("SendRequest failed");
1245          return WSError::WS_ERROR_IPC_FAILED;
1246      }
1247      int32_t ret = reply.ReadInt32();
1248      return static_cast<WSError>(ret);
1249  }
1250  
SetLandscapeMultiWindow(bool isLandscapeMultiWindow)1251  WSError SessionProxy::SetLandscapeMultiWindow(bool isLandscapeMultiWindow)
1252  {
1253      MessageParcel data;
1254      MessageParcel reply;
1255      MessageOption option(MessageOption::TF_ASYNC);
1256      if (!data.WriteInterfaceToken(GetDescriptor())) {
1257          TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
1258          return WSError::WS_ERROR_IPC_FAILED;
1259      }
1260      if (!data.WriteBool(isLandscapeMultiWindow)) {
1261          TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write isLandscapeMultiWindow failed");
1262          return WSError::WS_ERROR_IPC_FAILED;
1263      }
1264      sptr<IRemoteObject> remote = Remote();
1265      if (remote == nullptr) {
1266          WLOGFE("remote is null");
1267          return WSError::WS_ERROR_IPC_FAILED;
1268      }
1269      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_LANDSCAPE_MULTI_WINDOW),
1270                              data, reply, option) != ERR_NONE) {
1271          WLOGFE("SendRequest failed");
1272          return WSError::WS_ERROR_IPC_FAILED;
1273      }
1274      int32_t ret = reply.ReadInt32();
1275      return static_cast<WSError>(ret);
1276  }
1277  
TransferAbilityResult(uint32_t resultCode,const AAFwk::Want & want)1278  WSError SessionProxy::TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want)
1279  {
1280      MessageParcel data;
1281      MessageParcel reply;
1282      MessageOption option(MessageOption::TF_ASYNC);
1283      if (!data.WriteInterfaceToken(GetDescriptor())) {
1284          WLOGFE("WriteInterfaceToken failed");
1285          return WSError::WS_ERROR_IPC_FAILED;
1286      }
1287      if (!data.WriteUint32(resultCode)) {
1288          WLOGFE("resultCode write failed.");
1289          return WSError::WS_ERROR_IPC_FAILED;
1290      }
1291      if (!data.WriteParcelable(&want)) {
1292          WLOGFE("want write failed.");
1293          return WSError::WS_ERROR_IPC_FAILED;
1294      }
1295      sptr<IRemoteObject> remote = Remote();
1296      if (remote == nullptr) {
1297          WLOGFE("remote is null");
1298          return WSError::WS_ERROR_IPC_FAILED;
1299      }
1300      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT),
1301          data, reply, option) != ERR_NONE) {
1302          WLOGFE("SendRequest failed");
1303          return WSError::WS_ERROR_IPC_FAILED;
1304      }
1305      int32_t ret = reply.ReadInt32();
1306      return static_cast<WSError>(ret);
1307  }
1308  
TransferExtensionData(const AAFwk::WantParams & wantParams)1309  WSError SessionProxy::TransferExtensionData(const AAFwk::WantParams& wantParams)
1310  {
1311      MessageParcel data;
1312      MessageParcel reply;
1313      MessageOption option(MessageOption::TF_ASYNC);
1314      if (!data.WriteInterfaceToken(GetDescriptor())) {
1315          WLOGFE("WriteInterfaceToken failed");
1316          return WSError::WS_ERROR_IPC_FAILED;
1317      }
1318      if (!data.WriteParcelable(&wantParams)) {
1319          WLOGFE("wantParams write failed.");
1320          return WSError::WS_ERROR_IPC_FAILED;
1321      }
1322      sptr<IRemoteObject> remote = Remote();
1323      if (remote == nullptr) {
1324          WLOGFE("remote is null");
1325          return WSError::WS_ERROR_IPC_FAILED;
1326      }
1327      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_EXTENSION_DATA),
1328          data, reply, option) != ERR_NONE) {
1329          WLOGFE("SendRequest failed");
1330          return WSError::WS_ERROR_IPC_FAILED;
1331      }
1332      int32_t ret = reply.ReadInt32();
1333      return static_cast<WSError>(ret);
1334  }
1335  
NotifySyncOn()1336  void SessionProxy::NotifySyncOn()
1337  {
1338      MessageParcel data;
1339      MessageParcel reply;
1340      MessageOption option(MessageOption::TF_ASYNC);
1341      if (!data.WriteInterfaceToken(GetDescriptor())) {
1342          WLOGFE("WriteInterfaceToken failed");
1343          return;
1344      }
1345      sptr<IRemoteObject> remote = Remote();
1346      if (remote == nullptr) {
1347          WLOGFE("remote is null");
1348          return;
1349      }
1350      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_SYNC_ON),
1351          data, reply, option) != ERR_NONE) {
1352          WLOGFE("SendRequest failed");
1353          return;
1354      }
1355  }
1356  
NotifyAsyncOn()1357  void SessionProxy::NotifyAsyncOn()
1358  {
1359      MessageParcel data;
1360      MessageParcel reply;
1361      MessageOption option(MessageOption::TF_ASYNC);
1362      if (!data.WriteInterfaceToken(GetDescriptor())) {
1363          WLOGFE("WriteInterfaceToken failed");
1364          return;
1365      }
1366      sptr<IRemoteObject> remote = Remote();
1367      if (remote == nullptr) {
1368          WLOGFE("remote is null");
1369          return;
1370      }
1371      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_ASYNC_ON),
1372          data, reply, option) != ERR_NONE) {
1373          WLOGFE("SendRequest failed");
1374          return;
1375      }
1376  }
1377  
NotifyExtensionDied()1378  void SessionProxy::NotifyExtensionDied()
1379  {
1380      TLOGI(WmsLogTag::WMS_UIEXT, "NotifyExtensionDied called.");
1381      MessageParcel data;
1382      MessageParcel reply;
1383      MessageOption option(MessageOption::TF_ASYNC);
1384      if (!data.WriteInterfaceToken(GetDescriptor())) {
1385          TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
1386          return;
1387      }
1388      sptr<IRemoteObject> remote = Remote();
1389      if (remote == nullptr) {
1390          TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1391          return;
1392      }
1393      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DIED),
1394          data, reply, option) != ERR_NONE) {
1395          TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1396          return;
1397      }
1398  }
1399  
NotifyExtensionTimeout(int32_t errorCode)1400  void SessionProxy::NotifyExtensionTimeout(int32_t errorCode)
1401  {
1402      TLOGI(WmsLogTag::WMS_UIEXT, "NotifyExtensionTimeout(errorCode:%{public}d) called.", errorCode);
1403      MessageParcel data;
1404      MessageParcel reply;
1405      MessageOption option(MessageOption::TF_ASYNC);
1406      if (!data.WriteInterfaceToken(GetDescriptor())) {
1407          TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
1408          return;
1409      }
1410      if (!data.WriteInt32(static_cast<int32_t>(errorCode))) {
1411          TLOGE(WmsLogTag::WMS_UIEXT, "errorCode write failed.");
1412          return;
1413      }
1414      sptr<IRemoteObject> remote = Remote();
1415      if (remote == nullptr) {
1416          TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1417          return;
1418      }
1419      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_TIMEOUT),
1420          data, reply, option) != ERR_NONE) {
1421          TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1422      }
1423  }
1424  
TriggerBindModalUIExtension()1425  void SessionProxy::TriggerBindModalUIExtension()
1426  {
1427      MessageParcel data;
1428      MessageParcel reply;
1429      MessageOption option(MessageOption::TF_SYNC);
1430      if (!data.WriteInterfaceToken(GetDescriptor())) {
1431          WLOGFE("WriteInterfaceToken failed");
1432          return;
1433      }
1434      sptr<IRemoteObject> remote = Remote();
1435      if (remote == nullptr) {
1436          WLOGFE("remote is null");
1437          return;
1438      }
1439      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRIGGER_BIND_MODAL_UI_EXTENSION),
1440          data, reply, option) != ERR_NONE) {
1441          WLOGFE("SendRequest failed");
1442          return;
1443      }
1444  }
1445  
UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)1446  WSError SessionProxy::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)
1447  {
1448      MessageParcel data;
1449      MessageParcel reply;
1450      MessageOption option;
1451      if (!data.WriteInterfaceToken(GetDescriptor())) {
1452          WLOGFE("WriteInterfaceToken failed");
1453          return WSError::WS_ERROR_IPC_FAILED;
1454      }
1455      if (!data.WriteBool(needDefaultAnimationFlag)) {
1456          WLOGFE("wantParams write failed.");
1457          return WSError::WS_ERROR_IPC_FAILED;
1458      }
1459      sptr<IRemoteObject> remote = Remote();
1460      if (remote == nullptr) {
1461          WLOGFE("remote is null");
1462          return WSError::WS_ERROR_IPC_FAILED;
1463      }
1464      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG),
1465          data, reply, option) != ERR_NONE) {
1466          WLOGFE("SendRequest failed");
1467          return WSError::WS_ERROR_IPC_FAILED;
1468      }
1469      int32_t ret = reply.ReadInt32();
1470      return static_cast<WSError>(ret);
1471  }
1472  
TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)1473  WSError SessionProxy::TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
1474      int64_t uiExtensionIdLevel)
1475  {
1476      MessageParcel data;
1477      MessageParcel reply;
1478      MessageOption option(MessageOption::TF_ASYNC);
1479      if (!data.WriteInterfaceToken(GetDescriptor())) {
1480          WLOGFE("WriteInterfaceToken failed");
1481          return WSError::WS_ERROR_IPC_FAILED;
1482      }
1483      Accessibility::AccessibilityEventInfoParcel infoParcel(info);
1484      if (!data.WriteParcelable(&infoParcel)) {
1485          WLOGFE("infoParcel write failed.");
1486          return WSError::WS_ERROR_IPC_FAILED;
1487      }
1488      if (!data.WriteInt64(uiExtensionIdLevel)) {
1489          WLOGFE("idVec write failed.");
1490          return WSError::WS_ERROR_IPC_FAILED;
1491      }
1492      sptr<IRemoteObject> remote = Remote();
1493      if (remote == nullptr) {
1494          WLOGFE("remote is null");
1495          return WSError::WS_ERROR_IPC_FAILED;
1496      }
1497      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_REPORT_ACCESSIBILITY_EVENT),
1498          data, reply, option) != ERR_NONE) {
1499          WLOGFE("SendRequest failed");
1500          return WSError::WS_ERROR_IPC_FAILED;
1501      }
1502      return WSError::WS_OK;
1503  }
1504  
NotifyPiPWindowPrepareClose()1505  void SessionProxy::NotifyPiPWindowPrepareClose()
1506  {
1507      MessageParcel data;
1508      MessageParcel reply;
1509      MessageOption option(MessageOption::TF_ASYNC);
1510      if (!data.WriteInterfaceToken(GetDescriptor())) {
1511          WLOGFE("writeInterfaceToken failed");
1512          return;
1513      }
1514      sptr<IRemoteObject> remote = Remote();
1515      if (remote == nullptr) {
1516          WLOGFE("remote is null");
1517          return;
1518      }
1519      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE),
1520          data, reply, option) != ERR_NONE) {
1521          WLOGFE("SendRequest failed");
1522          return;
1523      }
1524  }
1525  
UpdatePiPRect(const Rect & rect,SizeChangeReason reason)1526  WSError SessionProxy::UpdatePiPRect(const Rect& rect, SizeChangeReason reason)
1527  {
1528      MessageParcel data;
1529      MessageParcel reply;
1530      MessageOption option;
1531      if (!data.WriteInterfaceToken(GetDescriptor())) {
1532          WLOGFE("writeInterfaceToken failed");
1533          return WSError::WS_ERROR_IPC_FAILED;
1534      }
1535      if (!data.WriteInt32(rect.posX_)) {
1536          WLOGFE("write posX_ failed.");
1537          return WSError::WS_ERROR_IPC_FAILED;
1538      }
1539      if (!data.WriteInt32(rect.posY_)) {
1540          WLOGFE("write posY_ failed.");
1541          return WSError::WS_ERROR_IPC_FAILED;
1542      }
1543      if (!data.WriteUint32(rect.width_)) {
1544          WLOGFE("write width_ failed.");
1545          return WSError::WS_ERROR_IPC_FAILED;
1546      }
1547      if (!data.WriteUint32(rect.height_)) {
1548          WLOGFE("write height_ failed.");
1549          return WSError::WS_ERROR_IPC_FAILED;
1550      }
1551      if (!data.WriteInt32(static_cast<int32_t>(reason))) {
1552          WLOGFE("reason write failed.");
1553          return WSError::WS_ERROR_IPC_FAILED;
1554      }
1555      sptr<IRemoteObject> remote = Remote();
1556      if (remote == nullptr) {
1557          WLOGFE("remote is null");
1558          return WSError::WS_ERROR_IPC_FAILED;
1559      }
1560      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT),
1561          data, reply, option) != ERR_NONE) {
1562          WLOGFE("SendRequest failed");
1563          return WSError::WS_ERROR_IPC_FAILED;
1564      }
1565      int32_t ret = reply.ReadInt32();
1566      return static_cast<WSError>(ret);
1567  }
1568  
UpdatePiPControlStatus(WsPiPControlType controlType,WsPiPControlStatus status)1569  WSError SessionProxy::UpdatePiPControlStatus(WsPiPControlType controlType, WsPiPControlStatus status)
1570  {
1571      TLOGI(WmsLogTag::WMS_PIP, "controlType:%{public}u, status:%{public}d", controlType, status);
1572      MessageParcel data;
1573      MessageParcel reply;
1574      MessageOption option;
1575      if (!data.WriteInterfaceToken(GetDescriptor())) {
1576          TLOGE(WmsLogTag::WMS_PIP, "writeInterfaceToken failed");
1577          return WSError::WS_ERROR_IPC_FAILED;
1578      }
1579      if (!data.WriteUint32(static_cast<uint32_t>(controlType))) {
1580          TLOGE(WmsLogTag::WMS_PIP, "Write controlType failed");
1581          return WSError::WS_ERROR_IPC_FAILED;
1582      }
1583      if (!data.WriteInt32(static_cast<int32_t>(status))) {
1584          TLOGE(WmsLogTag::WMS_PIP, "write status failed.");
1585          return WSError::WS_ERROR_IPC_FAILED;
1586      }
1587      sptr<IRemoteObject> remote = Remote();
1588      if (remote == nullptr) {
1589          TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1590          return WSError::WS_ERROR_IPC_FAILED;
1591      }
1592      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_CONTROL_STATUS),
1593          data, reply, option) != ERR_NONE) {
1594          TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed");
1595          return WSError::WS_ERROR_IPC_FAILED;
1596      }
1597      int32_t ret = reply.ReadInt32();
1598      return static_cast<WSError>(ret);
1599  }
1600  
SetAutoStartPiP(bool isAutoStart,uint32_t priority)1601  WSError SessionProxy::SetAutoStartPiP(bool isAutoStart, uint32_t priority)
1602  {
1603      TLOGD(WmsLogTag::WMS_PIP, "isAutoStart:%{public}u priority:%{public}u", isAutoStart, priority);
1604      MessageParcel data;
1605      MessageParcel reply;
1606      MessageOption option;
1607      if (!data.WriteInterfaceToken(GetDescriptor())) {
1608          TLOGE(WmsLogTag::WMS_PIP, "writeInterfaceToken failed");
1609          return WSError::WS_ERROR_IPC_FAILED;
1610      }
1611      if (!data.WriteBool(isAutoStart)) {
1612          TLOGE(WmsLogTag::WMS_PIP, "write isAutoStart failed");
1613          return WSError::WS_ERROR_IPC_FAILED;
1614      }
1615      if (!data.WriteUint32(priority)) {
1616          TLOGE(WmsLogTag::WMS_PIP, "write priority failed");
1617          return WSError::WS_ERROR_IPC_FAILED;
1618      }
1619      sptr<IRemoteObject> remote = Remote();
1620      if (remote == nullptr) {
1621          TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1622          return WSError::WS_ERROR_IPC_FAILED;
1623      }
1624      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_AUTOSTART_PIP),
1625          data, reply, option) != ERR_NONE) {
1626          TLOGE(WmsLogTag::WMS_PIP, "SendRequest failed");
1627          return WSError::WS_ERROR_IPC_FAILED;
1628      }
1629      int32_t ret = reply.ReadInt32();
1630      return static_cast<WSError>(ret);
1631  }
1632  
ProcessPointDownSession(int32_t posX,int32_t posY)1633  WSError SessionProxy::ProcessPointDownSession(int32_t posX, int32_t posY)
1634  {
1635      MessageParcel data;
1636      MessageParcel reply;
1637      MessageOption option;
1638      if (!data.WriteInterfaceToken(GetDescriptor())) {
1639          WLOGFE("writeInterfaceToken failed");
1640          return WSError::WS_ERROR_IPC_FAILED;
1641      }
1642      if (!data.WriteInt32(posX)) {
1643          WLOGFE("width poX failed.");
1644          return WSError::WS_ERROR_IPC_FAILED;
1645      }
1646      if (!data.WriteInt32(posY)) {
1647          WLOGFE("width posY failed.");
1648          return WSError::WS_ERROR_IPC_FAILED;
1649      }
1650      sptr<IRemoteObject> remote = Remote();
1651      if (remote == nullptr) {
1652          WLOGFE("remote is null");
1653          return WSError::WS_ERROR_IPC_FAILED;
1654      }
1655      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_PROCESS_POINT_DOWN_SESSION),
1656          data, reply, option) != ERR_NONE) {
1657          WLOGFE("SendRequest failed");
1658          return WSError::WS_ERROR_IPC_FAILED;
1659      }
1660      return static_cast<WSError>(reply.ReadInt32());
1661  }
1662  
SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)1663  WSError SessionProxy::SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
1664  {
1665      MessageParcel data;
1666      MessageParcel reply;
1667      MessageOption option;
1668      if (!data.WriteInterfaceToken(GetDescriptor())) {
1669          WLOGFE("writeInterfaceToken failed");
1670          return WSError::WS_ERROR_IPC_FAILED;
1671      }
1672      if (!pointerEvent->WriteToParcel(data)) {
1673          WLOGFE("width pointerEvent failed.");
1674          return WSError::WS_ERROR_IPC_FAILED;
1675      }
1676      sptr<IRemoteObject> remote = Remote();
1677      if (remote == nullptr) {
1678          WLOGFE("remote is null");
1679          return WSError::WS_ERROR_IPC_FAILED;
1680      }
1681      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG),
1682          data, reply, option) != ERR_NONE) {
1683          WLOGFE("SendRequest failed");
1684          return WSError::WS_ERROR_IPC_FAILED;
1685      }
1686      return static_cast<WSError>(reply.ReadInt32());
1687  }
1688  
IsStartMoving()1689  bool SessionProxy::IsStartMoving()
1690  {
1691      MessageParcel data;
1692      MessageParcel reply;
1693      MessageOption option;
1694      if (!data.WriteInterfaceToken(GetDescriptor())) {
1695          TLOGE(WmsLogTag::WMS_LAYOUT, "writeInterfaceToken failed");
1696          return false;
1697      }
1698      sptr<IRemoteObject> remote = Remote();
1699      if (remote == nullptr) {
1700          TLOGE(WmsLogTag::WMS_LAYOUT, "remote is null");
1701          return false;
1702      }
1703      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_IS_START_MOVING),
1704          data, reply, option) != ERR_NONE) {
1705          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1706          return false;
1707      }
1708      bool isMoving = false;
1709      if (!reply.ReadBool(isMoving)) {
1710          TLOGE(WmsLogTag::WMS_LAYOUT, "Read isMoving failed");
1711          return false;
1712      }
1713      return isMoving;
1714  }
1715  
SetSystemWindowEnableDrag(bool enableDrag)1716  WMError SessionProxy::SetSystemWindowEnableDrag(bool enableDrag)
1717  {
1718      TLOGD(WmsLogTag::WMS_LAYOUT, "enableDrag: %{public}d", enableDrag);
1719      MessageParcel data;
1720      MessageParcel reply;
1721      MessageOption option(MessageOption::TF_SYNC);
1722      if (!data.WriteInterfaceToken(GetDescriptor())) {
1723          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
1724          return WMError::WM_ERROR_IPC_FAILED;
1725      }
1726      if (!data.WriteBool(enableDrag)) {
1727          TLOGE(WmsLogTag::WMS_LAYOUT, "write enableDrag failed");
1728          return WMError::WM_ERROR_IPC_FAILED;
1729      }
1730      sptr<IRemoteObject> remote = Remote();
1731      if (remote == nullptr) {
1732          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1733          return WMError::WM_ERROR_IPC_FAILED;
1734      }
1735      if (remote->SendRequest(
1736          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SYSTEM_DRAG_ENABLE),
1737          data, reply, option) != ERR_NONE) {
1738          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1739          return WMError::WM_ERROR_IPC_FAILED;
1740      }
1741      int32_t ret = reply.ReadInt32();
1742      return static_cast<WMError>(ret);
1743  }
1744  
UpdateRectChangeListenerRegistered(bool isRegister)1745  WSError SessionProxy::UpdateRectChangeListenerRegistered(bool isRegister)
1746  {
1747      MessageParcel data;
1748      MessageParcel reply;
1749      MessageOption option(MessageOption::TF_SYNC);
1750      if (!data.WriteInterfaceToken(GetDescriptor())) {
1751          TLOGE(WmsLogTag::WMS_LAYOUT, "WriteInterfaceToken failed");
1752          return WSError::WS_ERROR_IPC_FAILED;
1753      }
1754      if (!data.WriteBool(isRegister)) {
1755          TLOGE(WmsLogTag::WMS_LAYOUT, "write isRegister failed");
1756          return WSError::WS_ERROR_IPC_FAILED;
1757      }
1758      sptr<IRemoteObject> remote = Remote();
1759      if (remote == nullptr) {
1760          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1761          return WSError::WS_ERROR_IPC_FAILED;
1762      }
1763      if (remote->SendRequest(
1764          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED),
1765          data, reply, option) != ERR_NONE) {
1766          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1767          return WSError::WS_ERROR_IPC_FAILED;
1768      }
1769      int32_t ret = reply.ReadInt32();
1770      return static_cast<WSError>(ret);
1771  }
1772  
SetCallingSessionId(const uint32_t callingSessionId)1773  void SessionProxy::SetCallingSessionId(const uint32_t callingSessionId)
1774  {
1775      MessageParcel data;
1776      MessageParcel reply;
1777      MessageOption option;
1778      if (!data.WriteInterfaceToken(GetDescriptor())) {
1779          TLOGE(WmsLogTag::WMS_KEYBOARD, "writeInterfaceToken failed");
1780          return;
1781      }
1782      if (!data.WriteUint32(callingSessionId)) {
1783          TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingSessionId failed.");
1784          return;
1785      }
1786      sptr<IRemoteObject> remote = Remote();
1787      if (remote == nullptr) {
1788          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1789          return;
1790      }
1791      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID),
1792          data, reply, option) != ERR_NONE) {
1793          TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
1794          return;
1795      }
1796  }
1797  
SetCustomDecorHeight(int32_t height)1798  void SessionProxy::SetCustomDecorHeight(int32_t height)
1799  {
1800      MessageParcel data;
1801      MessageParcel reply;
1802      MessageOption option(MessageOption::TF_ASYNC);
1803      if (!data.WriteInterfaceToken(GetDescriptor())) {
1804          TLOGE(WmsLogTag::WMS_LAYOUT, "writeInterfaceToken failed");
1805          return;
1806      }
1807      if (!data.WriteInt32(height)) {
1808          TLOGE(WmsLogTag::WMS_LAYOUT, "Write height failed.");
1809          return;
1810      }
1811      sptr<IRemoteObject> remote = Remote();
1812      if (remote == nullptr) {
1813          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1814          return;
1815      }
1816      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT),
1817          data, reply, option) != ERR_NONE) {
1818          TLOGE(WmsLogTag::WMS_LAYOUT, "SendRequest failed");
1819          return;
1820      }
1821  }
1822  
AdjustKeyboardLayout(const KeyboardLayoutParams & params)1823  WSError SessionProxy::AdjustKeyboardLayout(const KeyboardLayoutParams& params)
1824  {
1825      MessageParcel data;
1826      MessageParcel reply;
1827      MessageOption option(MessageOption::TF_ASYNC);
1828      if (!data.WriteInterfaceToken(GetDescriptor())) {
1829          TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
1830          return WSError::WS_ERROR_IPC_FAILED;
1831      }
1832      if (!data.WriteParcelable(&params)) {
1833          TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboard layout params write failed");
1834          return WSError::WS_ERROR_IPC_FAILED;
1835      }
1836      sptr<IRemoteObject> remote = Remote();
1837      if (remote == nullptr) {
1838          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1839          return WSError::WS_ERROR_IPC_FAILED;
1840      }
1841      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ADJUST_KEYBOARD_LAYOUT),
1842          data, reply, option) != ERR_NONE) {
1843          TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
1844          return WSError::WS_ERROR_IPC_FAILED;
1845      }
1846      return static_cast<WSError>(reply.ReadInt32());
1847  }
1848  
UpdateSessionPropertyByAction(const sptr<WindowSessionProperty> & property,WSPropertyChangeAction action)1849  WMError SessionProxy::UpdateSessionPropertyByAction(const sptr<WindowSessionProperty>& property,
1850      WSPropertyChangeAction action)
1851  {
1852      MessageParcel data;
1853      MessageParcel reply;
1854      MessageOption option(MessageOption::TF_SYNC);
1855      if (action == WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON) {
1856          option.SetFlags(MessageOption::TF_ASYNC);
1857      }
1858      if (!data.WriteInterfaceToken(GetDescriptor())) {
1859          TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
1860          return WMError::WM_ERROR_IPC_FAILED;
1861      }
1862      if (!data.WriteUint32(static_cast<uint32_t>(action))) {
1863          TLOGE(WmsLogTag::DEFAULT, "Write PropertyChangeAction failed");
1864          return WMError::WM_ERROR_IPC_FAILED;
1865      }
1866      if (property) {
1867          if (!data.WriteBool(true) || !property->Write(data, action)) {
1868              TLOGE(WmsLogTag::DEFAULT, "Write property failed");
1869              return WMError::WM_ERROR_IPC_FAILED;
1870          }
1871      } else {
1872          if (!data.WriteBool(false)) {
1873              TLOGE(WmsLogTag::DEFAULT, "Write property failed");
1874              return WMError::WM_ERROR_IPC_FAILED;
1875          }
1876      }
1877  
1878      sptr<IRemoteObject> remote = Remote();
1879      if (remote == nullptr) {
1880          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1881          return WMError::WM_ERROR_IPC_FAILED;
1882      }
1883      if (remote->SendRequest(static_cast<uint32_t>(
1884          SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_PROPERTY),
1885          data, reply, option) != ERR_NONE) {
1886          TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
1887          return WMError::WM_ERROR_IPC_FAILED;
1888      }
1889      int32_t ret = reply.ReadInt32();
1890      return static_cast<WMError>(ret);
1891  }
1892  
GetAppForceLandscapeConfig(AppForceLandscapeConfig & config)1893  WMError SessionProxy::GetAppForceLandscapeConfig(AppForceLandscapeConfig& config)
1894  {
1895      MessageParcel data;
1896      MessageParcel reply;
1897      MessageOption option(MessageOption::TF_SYNC);
1898      if (!data.WriteInterfaceToken(GetDescriptor())) {
1899          TLOGE(WmsLogTag::DEFAULT, "WriteInterfaceToken failed");
1900          return WMError::WM_ERROR_IPC_FAILED;
1901      }
1902      sptr<IRemoteObject> remote = Remote();
1903      if (remote == nullptr) {
1904          TLOGE(WmsLogTag::DEFAULT, "remote is null");
1905          return WMError::WM_ERROR_IPC_FAILED;
1906      }
1907      if (remote->SendRequest(static_cast<uint32_t>(
1908          SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG),
1909          data, reply, option) != ERR_NONE) {
1910          TLOGE(WmsLogTag::DEFAULT, "SendRequest failed");
1911          return WMError::WM_ERROR_IPC_FAILED;
1912      }
1913      sptr<AppForceLandscapeConfig> replyConfig = reply.ReadParcelable<AppForceLandscapeConfig>();
1914      if (replyConfig) {
1915          config = *replyConfig;
1916      }
1917      int32_t ret = reply.ReadInt32();
1918      return static_cast<WMError>(ret);
1919  }
1920  
SetDialogSessionBackGestureEnabled(bool isEnabled)1921  WSError SessionProxy::SetDialogSessionBackGestureEnabled(bool isEnabled)
1922  {
1923      MessageParcel data;
1924      MessageParcel reply;
1925      MessageOption option(MessageOption::TF_SYNC);
1926      if (!data.WriteInterfaceToken(GetDescriptor())) {
1927          TLOGE(WmsLogTag::WMS_DIALOG, "WriteInterfaceToken failed");
1928          return WSError::WS_ERROR_IPC_FAILED;
1929      }
1930      if (!data.WriteBool(isEnabled)) {
1931          TLOGE(WmsLogTag::WMS_DIALOG, "Write isEnabled failed");
1932          return WSError::WS_ERROR_IPC_FAILED;
1933      }
1934      sptr<IRemoteObject> remote = Remote();
1935      if (remote == nullptr) {
1936          TLOGE(WmsLogTag::WMS_DIALOG, "remote is null");
1937          return WSError::WS_ERROR_IPC_FAILED;
1938      }
1939      if (remote->SendRequest(
1940          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_DIALOG_SESSION_BACKGESTURE_ENABLE),
1941          data, reply, option) != ERR_NONE) {
1942          TLOGE(WmsLogTag::WMS_DIALOG, "SendRequest failed");
1943          return WSError::WS_ERROR_IPC_FAILED;
1944      }
1945      int32_t ret = reply.ReadInt32();
1946      return static_cast<WSError>(ret);
1947  }
1948  
NotifyExtensionEventAsync(uint32_t notifyEvent)1949  void SessionProxy::NotifyExtensionEventAsync(uint32_t notifyEvent)
1950  {
1951      MessageParcel data;
1952      MessageParcel reply;
1953      MessageOption option(MessageOption::TF_ASYNC);
1954      if (!data.WriteInterfaceToken(GetDescriptor())) {
1955          TLOGE(WmsLogTag::WMS_UIEXT, "WriteInterfaceToken failed");
1956          return;
1957      }
1958      if (!data.WriteUint32(notifyEvent)) {
1959          TLOGE(WmsLogTag::WMS_UIEXT, "Write notifyEvent failed");
1960          return;
1961      }
1962      sptr<IRemoteObject> remote = Remote();
1963      if (remote == nullptr) {
1964          TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1965          return;
1966      }
1967      if (remote->SendRequest(
1968          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_EVENT_ASYNC),
1969          data, reply, option) != ERR_NONE) {
1970          TLOGE(WmsLogTag::WMS_UIEXT, "SendRequest failed");
1971          return;
1972      }
1973  }
1974  
RequestFocus(bool isFocused)1975  WSError SessionProxy::RequestFocus(bool isFocused)
1976  {
1977      MessageParcel data;
1978      MessageParcel reply;
1979      MessageOption option(MessageOption::TF_SYNC);
1980      if (!data.WriteInterfaceToken(GetDescriptor())) {
1981          TLOGE(WmsLogTag::WMS_FOCUS, "WriteInterfaceToken failed");
1982          return WSError::WS_ERROR_IPC_FAILED;
1983      }
1984      if (!data.WriteBool(isFocused)) {
1985          TLOGE(WmsLogTag::WMS_FOCUS, "Write isFocused failed");
1986          return WSError::WS_ERROR_IPC_FAILED;
1987      }
1988      sptr<IRemoteObject> remote = Remote();
1989      if (remote == nullptr) {
1990          TLOGE(WmsLogTag::WMS_FOCUS, "remote is null");
1991          return WSError::WS_ERROR_IPC_FAILED;
1992      }
1993      if (remote->SendRequest(
1994          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_REQUEST_FOCUS),
1995          data, reply, option) != ERR_NONE) {
1996          TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed");
1997          return WSError::WS_ERROR_IPC_FAILED;
1998      }
1999      int32_t ret = reply.ReadInt32();
2000      return static_cast<WSError>(ret);
2001  }
2002  
NotifyExtensionDetachToDisplay()2003  void SessionProxy::NotifyExtensionDetachToDisplay()
2004  {
2005      TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: UIExtcalled");
2006      MessageParcel data;
2007      MessageParcel reply;
2008      MessageOption option(MessageOption::TF_SYNC);
2009      if (!data.WriteInterfaceToken(GetDescriptor())) {
2010          TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: WriteInterfaceToken failed");
2011          return;
2012      }
2013  
2014      sptr<IRemoteObject> remote = Remote();
2015      if (!remote) {
2016          TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: remote is null");
2017          return;
2018      }
2019  
2020      auto ret = remote->SendRequest(
2021          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DETACH_TO_DISPLAY), data, reply, option);
2022      if (ret != ERR_NONE) {
2023          TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: SendRequest failed, ret code: %{public}u", ret);
2024      }
2025  }
2026  
SetGestureBackEnabled(bool isEnabled)2027  WMError SessionProxy::SetGestureBackEnabled(bool isEnabled)
2028  {
2029      MessageParcel data;
2030      MessageParcel reply;
2031      MessageOption option(MessageOption::TF_SYNC);
2032      if (!data.WriteInterfaceToken(GetDescriptor())) {
2033          TLOGE(WmsLogTag::WMS_IMMS, "WriteInterfaceToken failed");
2034          return WMError::WM_ERROR_IPC_FAILED;
2035      }
2036      if (!data.WriteBool(isEnabled)) {
2037          TLOGE(WmsLogTag::WMS_IMMS, "Write isEnabled failed");
2038          return WMError::WM_ERROR_IPC_FAILED;
2039      }
2040      sptr<IRemoteObject> remote = Remote();
2041      if (remote == nullptr) {
2042          TLOGE(WmsLogTag::WMS_IMMS, "remote is null");
2043          return WMError::WM_ERROR_IPC_FAILED;
2044      }
2045      if (remote->SendRequest(
2046          static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_GESTURE_BACK_ENABLE),
2047          data, reply, option) != ERR_NONE) {
2048          TLOGE(WmsLogTag::WMS_IMMS, "SendRequest failed");
2049          return WMError::WM_ERROR_IPC_FAILED;
2050      }
2051      int32_t ret = reply.ReadInt32();
2052      return static_cast<WMError>(ret);
2053  }
2054  
NotifySubModalTypeChange(SubWindowModalType subWindowModalType)2055  WSError SessionProxy::NotifySubModalTypeChange(SubWindowModalType subWindowModalType)
2056  {
2057      MessageParcel data;
2058      MessageParcel reply;
2059      MessageOption option(MessageOption::TF_ASYNC);
2060      if (!data.WriteInterfaceToken(GetDescriptor())) {
2061          TLOGE(WmsLogTag::WMS_HIERARCHY, "WriteInterfaceToken failed");
2062          return WSError::WS_ERROR_IPC_FAILED;
2063      }
2064      if (!data.WriteUint32(static_cast<uint32_t>(subWindowModalType))) {
2065          TLOGE(WmsLogTag::WMS_HIERARCHY, "Write subWindowModalType failed");
2066          return WSError::WS_ERROR_IPC_FAILED;
2067      }
2068      sptr<IRemoteObject> remote = Remote();
2069      if (remote == nullptr) {
2070          TLOGE(WmsLogTag::WMS_HIERARCHY, "remote is null");
2071          return WSError::WS_ERROR_IPC_FAILED;
2072      }
2073      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SUB_MODAL_TYPE_CHANGE),
2074          data, reply, option) != ERR_NONE) {
2075          TLOGE(WmsLogTag::WMS_HIERARCHY, "SendRequest failed");
2076          return WSError::WS_ERROR_IPC_FAILED;
2077      }
2078      return WSError::WS_OK;
2079  }
2080  
NotifyMainModalTypeChange(bool isModal)2081  WSError SessionProxy::NotifyMainModalTypeChange(bool isModal)
2082  {
2083      MessageParcel data;
2084      MessageParcel reply;
2085      MessageOption option(MessageOption::TF_ASYNC);
2086      if (!data.WriteInterfaceToken(GetDescriptor())) {
2087          TLOGE(WmsLogTag::WMS_HIERARCHY, "WriteInterfaceToken failed");
2088          return WSError::WS_ERROR_IPC_FAILED;
2089      }
2090      if (!data.WriteBool(isModal)) {
2091          TLOGE(WmsLogTag::WMS_HIERARCHY, "Write isModal failed");
2092          return WSError::WS_ERROR_IPC_FAILED;
2093      }
2094      sptr<IRemoteObject> remote = Remote();
2095      if (remote == nullptr) {
2096          TLOGE(WmsLogTag::WMS_HIERARCHY, "remote is null");
2097          return WSError::WS_ERROR_IPC_FAILED;
2098      }
2099      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MAIN_MODAL_TYPE_CHANGE),
2100          data, reply, option) != ERR_NONE) {
2101          TLOGE(WmsLogTag::WMS_HIERARCHY, "SendRequest failed");
2102          return WSError::WS_ERROR_IPC_FAILED;
2103      }
2104      return WSError::WS_OK;
2105  }
2106  
OnSetWindowRectAutoSave(bool enabled)2107  WSError SessionProxy::OnSetWindowRectAutoSave(bool enabled)
2108  {
2109      MessageParcel data;
2110      MessageParcel reply;
2111      MessageOption option(MessageOption::TF_ASYNC);
2112      if (!data.WriteInterfaceToken(GetDescriptor())) {
2113          TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
2114          return WSError::WS_ERROR_IPC_FAILED;
2115      }
2116      if (!data.WriteBool(enabled)) {
2117          TLOGE(WmsLogTag::WMS_MAIN, "Write enable failed");
2118          return WSError::WS_ERROR_IPC_FAILED;
2119      }
2120      sptr<IRemoteObject> remote = Remote();
2121      if (remote == nullptr) {
2122          TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
2123          return WSError::WS_ERROR_IPC_FAILED;
2124      }
2125      if (remote->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_WINDOW_RECT_AUTO_SAVE),
2126          data, reply, option) != ERR_NONE) {
2127          TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
2128          return WSError::WS_ERROR_IPC_FAILED;
2129      }
2130      return WSError::WS_OK;
2131  }
2132  } // namespace OHOS::Rosen
2133