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 "accessibility_event_info_parcel.h"
24 #include "want.h"
25 #include "key_event.h"
26 #include "pointer_event.h"
27 #include "session/host/include/zidl/session_ipc_interface_code.h"
28 #include "window_manager_hilog.h"
29 namespace OHOS::Rosen {
30 namespace {
31 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionProxy" };
32 } // namespace
33
Foreground(sptr<WindowSessionProperty> property)34 WSError SessionProxy::Foreground(sptr<WindowSessionProperty> property)
35 {
36 MessageParcel data;
37 MessageParcel reply;
38 MessageOption option(MessageOption::TF_SYNC);
39 if (!data.WriteInterfaceToken(GetDescriptor())) {
40 WLOGFE("[WMSCom] WriteInterfaceToken failed");
41 return WSError::WS_ERROR_IPC_FAILED;
42 }
43
44 if (property) {
45 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
46 WLOGFE("[WMSCom] Write property failed");
47 return WSError::WS_ERROR_IPC_FAILED;
48 }
49 } else {
50 if (!data.WriteBool(false)) {
51 WLOGFE("[WMSCom] Write property failed");
52 return WSError::WS_ERROR_IPC_FAILED;
53 }
54 }
55
56 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FOREGROUND),
57 data, reply, option) != ERR_NONE) {
58 WLOGFE("[WMSCom] SendRequest failed");
59 return WSError::WS_ERROR_IPC_FAILED;
60 }
61 int32_t ret = reply.ReadInt32();
62 return static_cast<WSError>(ret);
63 }
64
Background()65 WSError SessionProxy::Background()
66 {
67 MessageParcel data;
68 MessageParcel reply;
69 MessageOption option(MessageOption::TF_ASYNC);
70 if (!data.WriteInterfaceToken(GetDescriptor())) {
71 WLOGFE("[WMSCom] WriteInterfaceToken failed");
72 return WSError::WS_ERROR_IPC_FAILED;
73 }
74
75 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKGROUND),
76 data, reply, option) != ERR_NONE) {
77 WLOGFE("[WMSCom] SendRequest failed");
78 return WSError::WS_ERROR_IPC_FAILED;
79 }
80 int32_t ret = reply.ReadInt32();
81 return static_cast<WSError>(ret);
82 }
83
Show(sptr<WindowSessionProperty> property)84 WSError SessionProxy::Show(sptr<WindowSessionProperty> property)
85 {
86 MessageParcel data;
87 MessageParcel reply;
88 MessageOption option(MessageOption::TF_SYNC);
89 if (!data.WriteInterfaceToken(GetDescriptor())) {
90 WLOGFE("WriteInterfaceToken failed");
91 return WSError::WS_ERROR_IPC_FAILED;
92 }
93
94 if (property) {
95 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
96 WLOGFE("Write property failed");
97 return WSError::WS_ERROR_IPC_FAILED;
98 }
99 } else {
100 if (!data.WriteBool(false)) {
101 WLOGFE("Write property failed");
102 return WSError::WS_ERROR_IPC_FAILED;
103 }
104 }
105
106 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SHOW),
107 data, reply, option) != ERR_NONE) {
108 WLOGFE("SendRequest failed");
109 return WSError::WS_ERROR_IPC_FAILED;
110 }
111 int32_t ret = reply.ReadInt32();
112 return static_cast<WSError>(ret);
113 }
114
Hide()115 WSError SessionProxy::Hide()
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option(MessageOption::TF_SYNC);
120 if (!data.WriteInterfaceToken(GetDescriptor())) {
121 WLOGFE("WriteInterfaceToken failed");
122 return WSError::WS_ERROR_IPC_FAILED;
123 }
124
125 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_HIDE),
126 data, reply, option) != ERR_NONE) {
127 WLOGFE("SendRequest failed");
128 return WSError::WS_ERROR_IPC_FAILED;
129 }
130 int32_t ret = reply.ReadInt32();
131 return static_cast<WSError>(ret);
132 }
133
Disconnect(bool isFromClient)134 WSError SessionProxy::Disconnect(bool isFromClient)
135 {
136 MessageParcel data;
137 MessageParcel reply;
138 MessageOption option(MessageOption::TF_ASYNC);
139 if (!data.WriteInterfaceToken(GetDescriptor())) {
140 WLOGFE("WriteInterfaceToken failed");
141 return WSError::WS_ERROR_IPC_FAILED;
142 }
143
144 if (!data.WriteBool(isFromClient)) {
145 WLOGFE("Write isFromClient failed");
146 return WSError::WS_ERROR_IPC_FAILED;
147 }
148
149 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DISCONNECT),
150 data, reply, option) != ERR_NONE) {
151 WLOGFE("SendRequest failed");
152 return WSError::WS_ERROR_IPC_FAILED;
153 }
154 int32_t ret = reply.ReadInt32();
155 return static_cast<WSError>(ret);
156 }
157
Connect(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,SystemSessionConfig & systemConfig,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token,int32_t pid,int32_t uid)158 WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
159 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
160 sptr<WindowSessionProperty> property, sptr<IRemoteObject> token, int32_t pid, int32_t uid)
161 {
162 MessageParcel data;
163 MessageParcel reply;
164 MessageOption option(MessageOption::TF_SYNC);
165 if (!data.WriteInterfaceToken(GetDescriptor())) {
166 WLOGFE("WriteInterfaceToken failed");
167 return WSError::WS_ERROR_IPC_FAILED;
168 }
169 if (!data.WriteRemoteObject(sessionStage->AsObject())) {
170 WLOGFE("Write ISessionStage failed");
171 return WSError::WS_ERROR_IPC_FAILED;
172 }
173 if (!data.WriteRemoteObject(eventChannel->AsObject())) {
174 WLOGFE("Write IWindowEventChannel failed");
175 return WSError::WS_ERROR_IPC_FAILED;
176 }
177 if (!surfaceNode || !surfaceNode->Marshalling(data)) {
178 WLOGFE("Write surfaceNode failed");
179 return WSError::WS_ERROR_IPC_FAILED;
180 }
181 if (property) {
182 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
183 WLOGFE("Write property failed");
184 return WSError::WS_ERROR_IPC_FAILED;
185 }
186 } else {
187 if (!data.WriteBool(false)) {
188 WLOGFE("Write property failed");
189 return WSError::WS_ERROR_IPC_FAILED;
190 }
191 }
192 if (token != nullptr) {
193 if (!data.WriteRemoteObject(token)) {
194 WLOGFE("Write abilityToken failed");
195 return WSError::WS_ERROR_IPC_FAILED;
196 }
197 }
198 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CONNECT),
199 data, reply, option) != ERR_NONE) {
200 WLOGFE("SendRequest failed");
201 return WSError::WS_ERROR_IPC_FAILED;
202 }
203 sptr<SystemSessionConfig> config = reply.ReadParcelable<SystemSessionConfig>();
204 if (config) {
205 systemConfig = *config;
206 }
207 if (property) {
208 property->SetPersistentId(reply.ReadInt32());
209 bool needUpdate = reply.ReadBool();
210 property->SetIsNeedUpdateWindowMode(needUpdate);
211 if (needUpdate) {
212 property->SetWindowMode(static_cast<WindowMode>(reply.ReadUint32()));
213 }
214 }
215 int32_t ret = reply.ReadInt32();
216 return static_cast<WSError>(ret);
217 }
218
PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)219 WSError SessionProxy::PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)
220 {
221 if (abilitySessionInfo == nullptr) {
222 WLOGFE("abilitySessionInfo is null");
223 return WSError::WS_ERROR_INVALID_SESSION;
224 }
225
226 MessageParcel data;
227 MessageParcel reply;
228 MessageOption option(MessageOption::TF_ASYNC);
229 if (!WriteAbilitySessionInfoBasic(data, abilitySessionInfo)) {
230 WLOGFE("WriteInterfaceToken or other param failed");
231 return WSError::WS_ERROR_IPC_FAILED;
232 }
233 if (abilitySessionInfo->callerToken) {
234 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
235 WLOGFE("Write callerToken info failed");
236 return WSError::WS_ERROR_IPC_FAILED;
237 }
238 } else {
239 if (!data.WriteBool(false)) {
240 WLOGFE("Write has not callerToken info failed");
241 return WSError::WS_ERROR_IPC_FAILED;
242 }
243 }
244 if (abilitySessionInfo->startSetting) {
245 if (!data.WriteBool(true) || !data.WriteParcelable(abilitySessionInfo->startSetting.get())) {
246 WLOGFE("Write startSetting failed");
247 return WSError::WS_ERROR_IPC_FAILED;
248 }
249 } else {
250 if (!data.WriteBool(false)) {
251 WLOGFE("Write has not startSetting failed");
252 return WSError::WS_ERROR_IPC_FAILED;
253 }
254 }
255 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ACTIVE_PENDING_SESSION),
256 data, reply, option) != ERR_NONE) {
257 WLOGFE("SendRequest failed");
258 return WSError::WS_ERROR_IPC_FAILED;
259 }
260 int32_t ret = reply.ReadInt32();
261 return static_cast<WSError>(ret);
262 }
263
WriteAbilitySessionInfoBasic(MessageParcel & data,sptr<AAFwk::SessionInfo> abilitySessionInfo)264 bool SessionProxy::WriteAbilitySessionInfoBasic(MessageParcel& data, sptr<AAFwk::SessionInfo> abilitySessionInfo)
265 {
266 if (abilitySessionInfo == nullptr) {
267 WLOGFE("abilitySessionInfo is null");
268 return false;
269 }
270 if (!data.WriteInterfaceToken(GetDescriptor()) ||
271 !(data.WriteParcelable(&(abilitySessionInfo->want))) ||
272 !data.WriteInt32(abilitySessionInfo->requestCode) ||
273 !(data.WriteInt32(abilitySessionInfo->persistentId)) ||
274 !(data.WriteInt32(static_cast<uint32_t>(abilitySessionInfo->state))) ||
275 !(data.WriteInt64(abilitySessionInfo->uiAbilityId)) ||
276 !data.WriteInt32(abilitySessionInfo->callingTokenId) ||
277 !data.WriteBool(abilitySessionInfo->reuse)) {
278 return false;
279 }
280 return true;
281 }
282
TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)283 WSError SessionProxy::TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
284 {
285 if (abilitySessionInfo == nullptr) {
286 WLOGFE("abilitySessionInfo is null");
287 return WSError::WS_ERROR_INVALID_SESSION;
288 }
289 MessageParcel data;
290 MessageParcel reply;
291 MessageOption option(MessageOption::TF_ASYNC);
292 if (!data.WriteInterfaceToken(GetDescriptor())) {
293 WLOGFE("WriteInterfaceToken failed");
294 return WSError::WS_ERROR_IPC_FAILED;
295 }
296 if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
297 WLOGFE("Write want info failed");
298 return WSError::WS_ERROR_IPC_FAILED;
299 }
300 if (abilitySessionInfo->callerToken) {
301 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
302 WLOGFE("Write ability info failed");
303 return WSError::WS_ERROR_IPC_FAILED;
304 }
305 } else {
306 if (!data.WriteBool(false)) {
307 WLOGFE("Write ability info failed");
308 return WSError::WS_ERROR_IPC_FAILED;
309 }
310 }
311 if (!data.WriteInt32(abilitySessionInfo->resultCode)) {
312 WLOGFE("Write resultCode info failed");
313 return WSError::WS_ERROR_IPC_FAILED;
314 }
315 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TERMINATE),
316 data, reply, option) != ERR_NONE) {
317 WLOGFE("SendRequest failed");
318 return WSError::WS_ERROR_IPC_FAILED;
319 }
320 int32_t ret = reply.ReadInt32();
321 return static_cast<WSError>(ret);
322 }
323
NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needRemoveSession)324 WSError SessionProxy::NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo, bool needRemoveSession)
325 {
326 if (abilitySessionInfo == nullptr) {
327 WLOGFE("abilitySessionInfo is null");
328 return WSError::WS_ERROR_INVALID_SESSION;
329 }
330 MessageParcel data;
331 MessageParcel reply;
332 MessageOption option(MessageOption::TF_ASYNC);
333 if (!data.WriteInterfaceToken(GetDescriptor())) {
334 WLOGFE("WriteInterfaceToken failed");
335 return WSError::WS_ERROR_IPC_FAILED;
336 }
337 if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
338 WLOGFE("Write want info failed");
339 return WSError::WS_ERROR_IPC_FAILED;
340 }
341 if (abilitySessionInfo->callerToken) {
342 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
343 WLOGFE("Write ability info failed");
344 return WSError::WS_ERROR_IPC_FAILED;
345 }
346 } else {
347 if (!data.WriteBool(false)) {
348 WLOGFE("Write ability info failed");
349 return WSError::WS_ERROR_IPC_FAILED;
350 }
351 }
352 if (!data.WriteInt32(abilitySessionInfo->persistentId)) {
353 WLOGFE("Write persistentId info failed");
354 return WSError::WS_ERROR_IPC_FAILED;
355 }
356 if (!data.WriteInt32(abilitySessionInfo->errorCode)) {
357 WLOGFE("Write erroCode info failed");
358 return WSError::WS_ERROR_IPC_FAILED;
359 }
360 if (!data.WriteString(abilitySessionInfo->errorReason)) {
361 WLOGFE("Write erroCode info failed");
362 return WSError::WS_ERROR_IPC_FAILED;
363 }
364 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_EXCEPTION),
365 data, reply, option) != ERR_NONE) {
366 WLOGFE("SendRequest failed");
367 return WSError::WS_ERROR_IPC_FAILED;
368 }
369 int32_t ret = reply.ReadInt32();
370 return static_cast<WSError>(ret);
371 }
372
UpdateActiveStatus(bool isActive)373 WSError SessionProxy::UpdateActiveStatus(bool isActive)
374 {
375 MessageParcel data;
376 MessageParcel reply;
377 MessageOption option(MessageOption::TF_ASYNC);
378 if (!data.WriteInterfaceToken(GetDescriptor())) {
379 WLOGFE("WriteInterfaceToken failed");
380 return WSError::WS_ERROR_IPC_FAILED;
381 }
382 if (!(data.WriteBool(isActive))) {
383 WLOGFE("Write active status failed");
384 return WSError::WS_ERROR_IPC_FAILED;
385 }
386 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_ACTIVE_STATUS),
387 data, reply, option) != ERR_NONE) {
388 WLOGFE("SendRequest failed");
389 return WSError::WS_ERROR_IPC_FAILED;
390 }
391 int32_t ret = reply.ReadInt32();
392 return static_cast<WSError>(ret);
393 }
394
OnSessionEvent(SessionEvent event)395 WSError SessionProxy::OnSessionEvent(SessionEvent event)
396 {
397 MessageParcel data;
398 MessageParcel reply;
399 MessageOption option(MessageOption::TF_ASYNC);
400 if (!data.WriteInterfaceToken(GetDescriptor())) {
401 WLOGFE("WriteInterfaceToken failed");
402 return WSError::WS_ERROR_IPC_FAILED;
403 }
404 if (!(data.WriteUint32(static_cast<uint32_t>(event)))) {
405 WLOGFE("Write event id failed");
406 return WSError::WS_ERROR_IPC_FAILED;
407 }
408 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SESSION_EVENT),
409 data, reply, option) != ERR_NONE) {
410 WLOGFE("SendRequest failed");
411 return WSError::WS_ERROR_IPC_FAILED;
412 }
413 int32_t ret = reply.ReadInt32();
414 return static_cast<WSError>(ret);
415 }
416
UpdateSessionRect(const WSRect & rect,const SizeChangeReason & reason)417 WSError SessionProxy::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason)
418 {
419 WLOGFI("UpdateSessionRect [%{public}d, %{public}d, %{public}u, %{public}u]", rect.posX_, rect.posY_,
420 rect.width_, rect.height_);
421 MessageParcel data;
422 MessageParcel reply;
423 MessageOption option(MessageOption::TF_ASYNC);
424 if (!data.WriteInterfaceToken(GetDescriptor())) {
425 WLOGFE("WriteInterfaceToken failed");
426 return WSError::WS_ERROR_IPC_FAILED;
427 }
428 if (!((data.WriteInt32(static_cast<int32_t>(rect.posX_))) &&
429 (data.WriteInt32(static_cast<int32_t>(rect.posY_))) &&
430 (data.WriteUint32(static_cast<uint32_t>(rect.width_))) &&
431 (data.WriteUint32(static_cast<uint32_t>(rect.height_))))) {
432 WLOGFE("Write rect failed");
433 return WSError::WS_ERROR_IPC_FAILED;
434 }
435
436 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
437 WLOGFE("Write SessionSizeChangeReason failed");
438 return WSError::WS_ERROR_IPC_FAILED;
439 }
440
441 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT),
442 data, reply, option) != ERR_NONE) {
443 WLOGFE("SendRequest failed");
444 return WSError::WS_ERROR_IPC_FAILED;
445 }
446 int32_t ret = reply.ReadInt32();
447 return static_cast<WSError>(ret);
448 }
449
RaiseToAppTop()450 WSError SessionProxy::RaiseToAppTop()
451 {
452 MessageParcel data;
453 MessageParcel reply;
454 MessageOption option;
455 if (!data.WriteInterfaceToken(GetDescriptor())) {
456 WLOGFE("WriteInterfaceToken failed");
457 return WSError::WS_ERROR_IPC_FAILED;
458 }
459 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP),
460 data, reply, option) != ERR_NONE) {
461 WLOGFE("SendRequest failed");
462 return WSError::WS_ERROR_IPC_FAILED;
463 }
464 int32_t ret = reply.ReadInt32();
465 return static_cast<WSError>(ret);
466 }
467
RaiseAboveTarget(int32_t subWindowId)468 WSError SessionProxy::RaiseAboveTarget(int32_t subWindowId)
469 {
470 MessageParcel data;
471 MessageParcel reply;
472 MessageOption option;
473 if (!data.WriteInterfaceToken(GetDescriptor())) {
474 WLOGFE("WriteInterfaceToken failed");
475 return WSError::WS_ERROR_IPC_FAILED;
476 }
477 if (!data.WriteInt32(subWindowId)) {
478 WLOGFE("Write subWindowId failed");
479 }
480 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_ABOVE_TARGET),
481 data, reply, option) != ERR_NONE) {
482 WLOGFE("SendRequest failed");
483 return WSError::WS_ERROR_IPC_FAILED;
484 }
485 int32_t ret = reply.ReadInt32();
486 return static_cast<WSError>(ret);
487 }
488
RaiseAppMainWindowToTop()489 WSError SessionProxy::RaiseAppMainWindowToTop()
490 {
491 MessageParcel data;
492 MessageParcel reply;
493 MessageOption option(MessageOption::TF_ASYNC);
494 if (!data.WriteInterfaceToken(GetDescriptor())) {
495 WLOGFE("WriteInterfaceToken failed");
496 return WSError::WS_ERROR_IPC_FAILED;
497 }
498 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_APP_MAIN_WINDOW),
499 data, reply, option) != ERR_NONE) {
500 WLOGFE("SendRequest failed");
501 return WSError::WS_ERROR_IPC_FAILED;
502 }
503 int32_t ret = reply.ReadInt32();
504 return static_cast<WSError>(ret);
505 }
506
OnNeedAvoid(bool status)507 WSError SessionProxy::OnNeedAvoid(bool status)
508 {
509 MessageParcel data;
510 MessageParcel reply;
511 MessageOption option(MessageOption::TF_ASYNC);
512 if (!data.WriteInterfaceToken(GetDescriptor())) {
513 WLOGFE("WriteInterfaceToken failed");
514 return WSError::WS_ERROR_IPC_FAILED;
515 }
516 if (!(data.WriteUint32(static_cast<uint32_t>(status)))) {
517 WLOGFE("Write status failed");
518 return WSError::WS_ERROR_IPC_FAILED;
519 }
520 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NEED_AVOID),
521 data, reply, option) != ERR_NONE) {
522 WLOGFE("SendRequest failed");
523 return WSError::WS_ERROR_IPC_FAILED;
524 }
525 int32_t ret = reply.ReadInt32();
526 return static_cast<WSError>(ret);
527 }
528
GetAvoidAreaByType(AvoidAreaType type)529 AvoidArea SessionProxy::GetAvoidAreaByType(AvoidAreaType type)
530 {
531 MessageParcel data;
532 MessageParcel reply;
533 MessageOption option(MessageOption::TF_SYNC);
534 AvoidArea avoidArea;
535 if (!data.WriteInterfaceToken(GetDescriptor())) {
536 WLOGFE("WriteInterfaceToken failed");
537 return avoidArea;
538 }
539 if (!(data.WriteUint32(static_cast<uint32_t>(type)))) {
540 WLOGFE("Write type failed");
541 return avoidArea;
542 }
543 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_AVOID_AREA),
544 data, reply, option) != ERR_NONE) {
545 WLOGFE("SendRequest failed");
546 return avoidArea;
547 }
548 sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
549 if (area == nullptr) {
550 return avoidArea;
551 }
552 return *area;
553 }
554
RequestSessionBack(bool needMoveToBackground)555 WSError SessionProxy::RequestSessionBack(bool needMoveToBackground)
556 {
557 MessageParcel data;
558 MessageParcel reply;
559 MessageOption option(MessageOption::TF_ASYNC);
560 if (!data.WriteInterfaceToken(GetDescriptor())) {
561 WLOGFE("WriteInterfaceToken failed");
562 return WSError::WS_ERROR_IPC_FAILED;
563 }
564 if (!data.WriteBool(needMoveToBackground)) {
565 WLOGFE("Write needMoveToBackground failed");
566 return WSError::WS_ERROR_IPC_FAILED;
567 }
568 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKPRESSED),
569 data, reply, option) != ERR_NONE) {
570 WLOGFE("SendRequest failed");
571 return WSError::WS_ERROR_IPC_FAILED;
572 }
573 int32_t ret = reply.ReadInt32();
574 return static_cast<WSError>(ret);
575 }
576
MarkProcessed(int32_t eventId)577 WSError SessionProxy::MarkProcessed(int32_t eventId)
578 {
579 MessageParcel data;
580 MessageParcel reply;
581 MessageOption option(MessageOption::TF_ASYNC);
582 if (!data.WriteInterfaceToken(GetDescriptor())) {
583 WLOGFE("WriteInterfaceToken failed");
584 return WSError::WS_ERROR_IPC_FAILED;
585 }
586 if (!data.WriteInt32(eventId)) {
587 WLOGFE("WriteInterfaceToken failed");
588 return WSError::WS_ERROR_IPC_FAILED;
589 }
590 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MARK_PROCESSED),
591 data, reply, option) != ERR_NONE) {
592 WLOGFE("SendRequest failed");
593 return WSError::WS_ERROR_IPC_FAILED;
594 }
595 int32_t ret = reply.ReadInt32();
596 return static_cast<WSError>(ret);
597 }
598
SetGlobalMaximizeMode(MaximizeMode mode)599 WSError OHOS::Rosen::SessionProxy::SetGlobalMaximizeMode(MaximizeMode mode)
600 {
601 MessageParcel data;
602 MessageParcel reply;
603 MessageOption option;
604 if (!data.WriteInterfaceToken(GetDescriptor())) {
605 WLOGFE("WriteInterfaceToken failed");
606 return WSError::WS_ERROR_IPC_FAILED;
607 }
608 if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
609 WLOGFE("Write uint32_t failed");
610 }
611 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_MAXIMIZE_MODE),
612 data, reply, option) != ERR_NONE) {
613 WLOGFE("SendRequest failed");
614 return WSError::WS_ERROR_IPC_FAILED;
615 }
616 int32_t ret = reply.ReadInt32();
617 return static_cast<WSError>(ret);
618 }
619
GetGlobalMaximizeMode(MaximizeMode & mode)620 WSError SessionProxy::GetGlobalMaximizeMode(MaximizeMode& mode)
621 {
622 MessageParcel data;
623 MessageParcel reply;
624 MessageOption option;
625 if (!data.WriteInterfaceToken(GetDescriptor())) {
626 WLOGFE("WriteInterfaceToken failed");
627 return WSError::WS_ERROR_IPC_FAILED;
628 }
629 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_MAXIMIZE_MODE),
630 data, reply, option) != ERR_NONE) {
631 WLOGFE("SendRequest failed");
632 return WSError::WS_ERROR_IPC_FAILED;
633 }
634 mode = static_cast<MaximizeMode>(reply.ReadUint32());
635 int32_t ret = reply.ReadInt32();
636 return static_cast<WSError>(ret);
637 }
638
SetSessionProperty(const sptr<WindowSessionProperty> & property)639 WSError SessionProxy::SetSessionProperty(const sptr<WindowSessionProperty>& property)
640 {
641 MessageParcel data;
642 MessageParcel reply;
643 MessageOption option;
644 if (!data.WriteInterfaceToken(GetDescriptor())) {
645 WLOGFE("WriteInterfaceToken failed");
646 return WSError::WS_ERROR_IPC_FAILED;
647 }
648 if (!data.WriteParcelable(property.GetRefPtr())) {
649 WLOGFE("Write property failed");
650 return WSError::WS_ERROR_IPC_FAILED;
651 }
652 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SESSION_PROPERTY),
653 data, reply, option) != ERR_NONE) {
654 WLOGFE("SendRequest failed");
655 return WSError::WS_ERROR_IPC_FAILED;
656 }
657 int32_t ret = reply.ReadInt32();
658 return static_cast<WSError>(ret);
659 }
660
SetAspectRatio(float ratio)661 WSError SessionProxy::SetAspectRatio(float ratio)
662 {
663 MessageParcel data;
664 MessageParcel reply;
665 MessageOption option;
666 if (!data.WriteInterfaceToken(GetDescriptor())) {
667 WLOGFE("WriteInterfaceToken failed");
668 return WSError::WS_ERROR_IPC_FAILED;
669 }
670 if (!data.WriteFloat(ratio)) {
671 WLOGFE("Write ratio failed");
672 return WSError::WS_ERROR_IPC_FAILED;
673 }
674 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_ASPECT_RATIO),
675 data, reply, option) != ERR_NONE) {
676 WLOGFE("SendRequest failed");
677 return WSError::WS_ERROR_IPC_FAILED;
678 }
679 int32_t ret = reply.ReadInt32();
680 return static_cast<WSError>(ret);
681 }
682
UpdateWindowSceneAfterCustomAnimation(bool isAdd)683 WSError SessionProxy::UpdateWindowSceneAfterCustomAnimation(bool isAdd)
684 {
685 MessageParcel data;
686 MessageParcel reply;
687 MessageOption option(MessageOption::TF_ASYNC);
688 if (!data.WriteInterfaceToken(GetDescriptor())) {
689 WLOGFE("WriteInterfaceToken failed");
690 return WSError::WS_ERROR_IPC_FAILED;
691 }
692 if (!data.WriteBool(isAdd)) {
693 WLOGFE("Write isAdd failed");
694 return WSError::WS_ERROR_IPC_FAILED;
695 }
696 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
697 data, reply, option) != ERR_NONE) {
698 WLOGFE("SendRequest failed");
699 return WSError::WS_ERROR_IPC_FAILED;
700 }
701 int32_t ret = reply.ReadInt32();
702 return static_cast<WSError>(ret);
703 }
704
TransferAbilityResult(uint32_t resultCode,const AAFwk::Want & want)705 WSError SessionProxy::TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want)
706 {
707 MessageParcel data;
708 MessageParcel reply;
709 MessageOption option(MessageOption::TF_ASYNC);
710 if (!data.WriteInterfaceToken(GetDescriptor())) {
711 WLOGFE("WriteInterfaceToken failed");
712 return WSError::WS_ERROR_IPC_FAILED;
713 }
714 if (!data.WriteUint32(resultCode)) {
715 WLOGFE("resultCode write failed.");
716 return WSError::WS_ERROR_IPC_FAILED;
717 }
718 if (!data.WriteParcelable(&want)) {
719 WLOGFE("want write failed.");
720 return WSError::WS_ERROR_IPC_FAILED;
721 }
722 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT),
723 data, reply, option) != ERR_NONE) {
724 WLOGFE("SendRequest failed");
725 return WSError::WS_ERROR_IPC_FAILED;
726 }
727 int32_t ret = reply.ReadInt32();
728 return static_cast<WSError>(ret);
729 }
730
TransferExtensionData(const AAFwk::WantParams & wantParams)731 WSError SessionProxy::TransferExtensionData(const AAFwk::WantParams& wantParams)
732 {
733 MessageParcel data;
734 MessageParcel reply;
735 MessageOption option(MessageOption::TF_ASYNC);
736 if (!data.WriteInterfaceToken(GetDescriptor())) {
737 WLOGFE("WriteInterfaceToken failed");
738 return WSError::WS_ERROR_IPC_FAILED;
739 }
740 if (!data.WriteParcelable(&wantParams)) {
741 WLOGFE("wantParams write failed.");
742 return WSError::WS_ERROR_IPC_FAILED;
743 }
744 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_EXTENSION_DATA),
745 data, reply, option) != ERR_NONE) {
746 WLOGFE("SendRequest failed");
747 return WSError::WS_ERROR_IPC_FAILED;
748 }
749 int32_t ret = reply.ReadInt32();
750 return static_cast<WSError>(ret);
751 }
752
NotifyRemoteReady()753 void SessionProxy::NotifyRemoteReady()
754 {
755 MessageParcel data;
756 MessageParcel reply;
757 MessageOption option(MessageOption::TF_ASYNC);
758 if (!data.WriteInterfaceToken(GetDescriptor())) {
759 WLOGFE("WriteInterfaceToken failed");
760 return;
761 }
762 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_REMOTE_READY),
763 data, reply, option) != ERR_NONE) {
764 WLOGFE("SendRequest failed");
765 return;
766 }
767 }
768
NotifySyncOn()769 void SessionProxy::NotifySyncOn()
770 {
771 MessageParcel data;
772 MessageParcel reply;
773 MessageOption option(MessageOption::TF_ASYNC);
774 if (!data.WriteInterfaceToken(GetDescriptor())) {
775 WLOGFE("WriteInterfaceToken failed");
776 return;
777 }
778 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_SYNC_ON),
779 data, reply, option) != ERR_NONE) {
780 WLOGFE("SendRequest failed");
781 return;
782 }
783 }
784
NotifyAsyncOn()785 void SessionProxy::NotifyAsyncOn()
786 {
787 MessageParcel data;
788 MessageParcel reply;
789 MessageOption option(MessageOption::TF_ASYNC);
790 if (!data.WriteInterfaceToken(GetDescriptor())) {
791 WLOGFE("WriteInterfaceToken failed");
792 return;
793 }
794 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_ASYNC_ON),
795 data, reply, option) != ERR_NONE) {
796 WLOGFE("SendRequest failed");
797 return;
798 }
799 }
800
NotifyExtensionDied()801 void SessionProxy::NotifyExtensionDied()
802 {
803 MessageParcel data;
804 MessageParcel reply;
805 MessageOption option(MessageOption::TF_ASYNC);
806 if (!data.WriteInterfaceToken(GetDescriptor())) {
807 WLOGFE("WriteInterfaceToken failed");
808 return;
809 }
810 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DIED),
811 data, reply, option) != ERR_NONE) {
812 WLOGFE("SendRequest failed");
813 return;
814 }
815 }
816
TriggerBindModalUIExtension()817 void SessionProxy::TriggerBindModalUIExtension()
818 {
819 MessageParcel data;
820 MessageParcel reply;
821 MessageOption option(MessageOption::TF_SYNC);
822 if (!data.WriteInterfaceToken(GetDescriptor())) {
823 WLOGFE("WriteInterfaceToken failed");
824 return;
825 }
826 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRIGGER_BIND_MODAL_UI_EXTENSION),
827 data, reply, option) != ERR_NONE) {
828 WLOGFE("SendRequest failed");
829 return;
830 }
831 }
832
UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)833 WSError SessionProxy::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)
834 {
835 MessageParcel data;
836 MessageParcel reply;
837 MessageOption option;
838 if (!data.WriteInterfaceToken(GetDescriptor())) {
839 WLOGFE("WriteInterfaceToken failed");
840 return WSError::WS_ERROR_IPC_FAILED;
841 }
842 if (!data.WriteBool(needDefaultAnimationFlag)) {
843 WLOGFE("wantParams write failed.");
844 return WSError::WS_ERROR_IPC_FAILED;
845 }
846 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG),
847 data, reply, option) != ERR_NONE) {
848 WLOGFE("SendRequest failed");
849 return WSError::WS_ERROR_IPC_FAILED;
850 }
851 int32_t ret = reply.ReadInt32();
852 return static_cast<WSError>(ret);
853 }
854
TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)855 WSError SessionProxy::TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
856 int64_t uiExtensionIdLevel)
857 {
858 MessageParcel data;
859 MessageParcel reply;
860 MessageOption option(MessageOption::TF_ASYNC);
861 if (!data.WriteInterfaceToken(GetDescriptor())) {
862 WLOGFE("WriteInterfaceToken failed");
863 return WSError::WS_ERROR_IPC_FAILED;
864 }
865 Accessibility::AccessibilityEventInfoParcel infoParcel(info);
866 if (!data.WriteParcelable(&infoParcel)) {
867 WLOGFE("infoParcel write failed.");
868 return WSError::WS_ERROR_IPC_FAILED;
869 }
870 if (!data.WriteInt64(uiExtensionIdLevel)) {
871 WLOGFE("idVec write failed.");
872 return WSError::WS_ERROR_IPC_FAILED;
873 }
874 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_REPORT_ACCESSIBILITY_EVENT),
875 data, reply, option) != ERR_NONE) {
876 WLOGFE("SendRequest failed");
877 return WSError::WS_ERROR_IPC_FAILED;
878 }
879 return WSError::WS_OK;
880 }
881
NotifyPiPWindowPrepareClose()882 void SessionProxy::NotifyPiPWindowPrepareClose()
883 {
884 MessageParcel data;
885 MessageParcel reply;
886 MessageOption option(MessageOption::TF_ASYNC);
887 if (!data.WriteInterfaceToken(GetDescriptor())) {
888 WLOGFE("writeInterfaceToken failed");
889 return;
890 }
891 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE),
892 data, reply, option) != ERR_NONE) {
893 WLOGFE("SendRequest failed");
894 return;
895 }
896 }
897
UpdatePiPRect(const uint32_t width,const uint32_t height,PiPRectUpdateReason reason)898 WSError SessionProxy::UpdatePiPRect(const uint32_t width, const uint32_t height, PiPRectUpdateReason reason)
899 {
900 MessageParcel data;
901 MessageParcel reply;
902 MessageOption option;
903 if (!data.WriteInterfaceToken(GetDescriptor())) {
904 WLOGFE("writeInterfaceToken failed");
905 return WSError::WS_ERROR_IPC_FAILED;
906 }
907 if (!data.WriteUint32(width)) {
908 WLOGFE("width write failed.");
909 return WSError::WS_ERROR_IPC_FAILED;
910 }
911 if (!data.WriteUint32(height)) {
912 WLOGFE("height write failed.");
913 return WSError::WS_ERROR_IPC_FAILED;
914 }
915 if (!data.WriteInt32(static_cast<int32_t>(reason))) {
916 WLOGFE("reason write failed.");
917 return WSError::WS_ERROR_IPC_FAILED;
918 }
919 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT),
920 data, reply, option) != ERR_NONE) {
921 WLOGFE("SendRequest failed");
922 return WSError::WS_ERROR_IPC_FAILED;
923 }
924 int32_t ret = reply.ReadInt32();
925 return static_cast<WSError>(ret);
926 }
927
RecoveryPullPiPMainWindow(int32_t persistentId,const Rect & rect)928 WSError SessionProxy::RecoveryPullPiPMainWindow(int32_t persistentId, const Rect& rect)
929 {
930 MessageParcel data;
931 MessageParcel reply;
932 MessageOption option(MessageOption::TF_ASYNC);
933 if (!data.WriteInterfaceToken(GetDescriptor())) {
934 WLOGFE("writeInterfaceToken failed");
935 return WSError::WS_ERROR_IPC_FAILED;
936 }
937 if (!data.WriteInt32(persistentId)) {
938 WLOGFE("WriteInterfaceToken failed");
939 return WSError::WS_ERROR_IPC_FAILED;
940 }
941 if (!data.WriteInt32(rect.posX_)) {
942 WLOGFE("Write posX_ failed");
943 return WSError::WS_ERROR_IPC_FAILED;
944 }
945 if (!data.WriteInt32(rect.posY_)) {
946 WLOGFE("Write posY_ failed");
947 return WSError::WS_ERROR_IPC_FAILED;
948 }
949 if (!data.WriteUint32(rect.width_)) {
950 WLOGFE("Write width_ failed");
951 return WSError::WS_ERROR_IPC_FAILED;
952 }
953 if (!data.WriteUint32(rect.height_)) {
954 WLOGFE("Write height_ failed");
955 return WSError::WS_ERROR_IPC_FAILED;
956 }
957 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RECOVERY_PULL_PIP_MAIN_WINDOW),
958 data, reply, option) != ERR_NONE) {
959 WLOGFE("SendRequest failed");
960 return WSError::WS_ERROR_IPC_FAILED;
961 }
962 return WSError::WS_OK;
963 }
964
ProcessPointDownSession(int32_t posX,int32_t posY)965 WSError SessionProxy::ProcessPointDownSession(int32_t posX, int32_t posY)
966 {
967 MessageParcel data;
968 MessageParcel reply;
969 MessageOption option;
970 if (!data.WriteInterfaceToken(GetDescriptor())) {
971 WLOGFE("writeInterfaceToken failed");
972 return WSError::WS_ERROR_IPC_FAILED;
973 }
974 if (!data.WriteInt32(posX)) {
975 WLOGFE("width poX failed.");
976 return WSError::WS_ERROR_IPC_FAILED;
977 }
978 if (!data.WriteInt32(posY)) {
979 WLOGFE("width posY failed.");
980 return WSError::WS_ERROR_IPC_FAILED;
981 }
982 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_PROCESS_POINT_DOWN_SESSION),
983 data, reply, option) != ERR_NONE) {
984 WLOGFE("SendRequest failed");
985 return WSError::WS_ERROR_IPC_FAILED;
986 }
987 return static_cast<WSError>(reply.ReadInt32());
988 }
989
SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)990 WSError SessionProxy::SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
991 {
992 MessageParcel data;
993 MessageParcel reply;
994 MessageOption option;
995 if (!data.WriteInterfaceToken(GetDescriptor())) {
996 WLOGFE("writeInterfaceToken failed");
997 return WSError::WS_ERROR_IPC_FAILED;
998 }
999 if (!pointerEvent->WriteToParcel(data)) {
1000 WLOGFE("width pointerEvent failed.");
1001 return WSError::WS_ERROR_IPC_FAILED;
1002 }
1003 if (Remote()->SendRequest(static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG),
1004 data, reply, option) != ERR_NONE) {
1005 WLOGFE("SendRequest failed");
1006 return WSError::WS_ERROR_IPC_FAILED;
1007 }
1008 return static_cast<WSError>(reply.ReadInt32());
1009 }
1010 } // namespace OHOS::Rosen
1011