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 <ipc_types.h>
19 #include <message_option.h>
20 #include <ui/rs_surface_node.h>
21
22 #include "ability_start_setting.h"
23 #include "want.h"
24 #include "want_params.h"
25 #include "window_manager_hilog.h"
26
27 namespace OHOS::Rosen {
28 namespace {
29 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionProxy"};
30 }
31
Foreground(sptr<WindowSessionProperty> property)32 WSError SessionProxy::Foreground(sptr<WindowSessionProperty> property)
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option(MessageOption::TF_ASYNC);
37 if (!data.WriteInterfaceToken(GetDescriptor())) {
38 WLOGFE("WriteInterfaceToken failed");
39 return WSError::WS_ERROR_IPC_FAILED;
40 }
41
42 if (property) {
43 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
44 WLOGFE("Write property failed");
45 return WSError::WS_ERROR_IPC_FAILED;
46 }
47 } else {
48 if (!data.WriteBool(false)) {
49 WLOGFE("Write property failed");
50 return WSError::WS_ERROR_IPC_FAILED;
51 }
52 }
53
54 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_FOREGROUND),
55 data, reply, option) != ERR_NONE) {
56 WLOGFE("SendRequest failed");
57 return WSError::WS_ERROR_IPC_FAILED;
58 }
59 int32_t ret = reply.ReadInt32();
60 return static_cast<WSError>(ret);
61 }
62
Background()63 WSError SessionProxy::Background()
64 {
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option(MessageOption::TF_ASYNC);
68 if (!data.WriteInterfaceToken(GetDescriptor())) {
69 WLOGFE("WriteInterfaceToken failed");
70 return WSError::WS_ERROR_IPC_FAILED;
71 }
72
73 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_BACKGROUND),
74 data, reply, option) != ERR_NONE) {
75 WLOGFE("SendRequest failed");
76 return WSError::WS_ERROR_IPC_FAILED;
77 }
78 int32_t ret = reply.ReadInt32();
79 return static_cast<WSError>(ret);
80 }
81
Disconnect()82 WSError SessionProxy::Disconnect()
83 {
84 MessageParcel data;
85 MessageParcel reply;
86 MessageOption option(MessageOption::TF_ASYNC);
87 if (!data.WriteInterfaceToken(GetDescriptor())) {
88 WLOGFE("WriteInterfaceToken failed");
89 return WSError::WS_ERROR_IPC_FAILED;
90 }
91
92 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_DISCONNECT),
93 data, reply, option) != ERR_NONE) {
94 WLOGFE("SendRequest failed");
95 return WSError::WS_ERROR_IPC_FAILED;
96 }
97 int32_t ret = reply.ReadInt32();
98 return static_cast<WSError>(ret);
99 }
100
Connect(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,SystemSessionConfig & systemConfig,sptr<WindowSessionProperty> property,sptr<IRemoteObject> token)101 WSError SessionProxy::Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
102 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, sptr<WindowSessionProperty> property, sptr<IRemoteObject> token)
103 {
104 MessageParcel data;
105 MessageParcel reply;
106 MessageOption option(MessageOption::TF_SYNC);
107 if (!data.WriteInterfaceToken(GetDescriptor())) {
108 WLOGFE("WriteInterfaceToken failed");
109 return WSError::WS_ERROR_IPC_FAILED;
110 }
111 if (!data.WriteRemoteObject(sessionStage->AsObject())) {
112 WLOGFE("Write ISessionStage failed");
113 return WSError::WS_ERROR_IPC_FAILED;
114 }
115 if (!data.WriteRemoteObject(eventChannel->AsObject())) {
116 WLOGFE("Write IWindowEventChannel failed");
117 return WSError::WS_ERROR_IPC_FAILED;
118 }
119 if (!surfaceNode->Marshalling(data)) {
120 WLOGFE("Write surfaceNode failed");
121 return WSError::WS_ERROR_IPC_FAILED;
122 }
123 if (property) {
124 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
125 WLOGFE("Write property failed");
126 return WSError::WS_ERROR_IPC_FAILED;
127 }
128 } else {
129 if (!data.WriteBool(false)) {
130 WLOGFE("Write property failed");
131 return WSError::WS_ERROR_IPC_FAILED;
132 }
133 }
134 if (token != nullptr) {
135 if (!data.WriteRemoteObject(token)) {
136 WLOGFE("Write abilityToken failed");
137 return WSError::WS_ERROR_IPC_FAILED;
138 }
139 }
140 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_CONNECT),
141 data, reply, option) != ERR_NONE) {
142 WLOGFE("SendRequest failed");
143 return WSError::WS_ERROR_IPC_FAILED;
144 }
145 sptr<SystemSessionConfig> config = reply.ReadParcelable<SystemSessionConfig>();
146 systemConfig = *config;
147 if (property) {
148 property->SetPersistentId(reply.ReadInt32());
149 }
150 int32_t ret = reply.ReadInt32();
151 return static_cast<WSError>(ret);
152 }
153
PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)154 WSError SessionProxy::PendingSessionActivation(sptr<AAFwk::SessionInfo> abilitySessionInfo)
155 {
156 if (abilitySessionInfo == nullptr) {
157 WLOGFE("abilitySessionInfo is null");
158 return WSError::WS_ERROR_INVALID_SESSION;
159 }
160
161 MessageParcel data;
162 MessageParcel reply;
163 MessageOption option(MessageOption::TF_ASYNC);
164 if (!WriteAbilitySessionInfoBasic(data, abilitySessionInfo)) {
165 WLOGFE("WriteInterfaceToken or other param failed");
166 return WSError::WS_ERROR_IPC_FAILED;
167 }
168 if (abilitySessionInfo->callerToken) {
169 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
170 WLOGFE("Write callerToken info failed");
171 return WSError::WS_ERROR_IPC_FAILED;
172 }
173 } else {
174 if (!data.WriteBool(false)) {
175 WLOGFE("Write has not callerToken info failed");
176 return WSError::WS_ERROR_IPC_FAILED;
177 }
178 }
179 if (abilitySessionInfo->startSetting) {
180 if (!data.WriteBool(true) || !data.WriteParcelable(abilitySessionInfo->startSetting.get())) {
181 WLOGFE("Write startSetting failed");
182 return WSError::WS_ERROR_IPC_FAILED;
183 }
184 } else {
185 if (!data.WriteBool(false)) {
186 WLOGFE("Write has not startSetting failed");
187 return WSError::WS_ERROR_IPC_FAILED;
188 }
189 }
190 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_ACTIVE_PENDING_SESSION),
191 data, reply, option) != ERR_NONE) {
192 WLOGFE("SendRequest failed");
193 return WSError::WS_ERROR_IPC_FAILED;
194 }
195 int32_t ret = reply.ReadInt32();
196 return static_cast<WSError>(ret);
197 }
198
WriteAbilitySessionInfoBasic(MessageParcel & data,sptr<AAFwk::SessionInfo> abilitySessionInfo)199 bool SessionProxy::WriteAbilitySessionInfoBasic(MessageParcel& data, sptr<AAFwk::SessionInfo> abilitySessionInfo)
200 {
201 if (abilitySessionInfo == nullptr) {
202 WLOGFE("abilitySessionInfo is null");
203 return false;
204 }
205 if (!data.WriteInterfaceToken(GetDescriptor()) ||
206 !(data.WriteParcelable(&(abilitySessionInfo->want))) ||
207 !data.WriteInt32(abilitySessionInfo->requestCode) ||
208 !(data.WriteInt32(abilitySessionInfo->persistentId)) ||
209 !(data.WriteInt32(static_cast<uint32_t>(abilitySessionInfo->state))) ||
210 !(data.WriteInt64(abilitySessionInfo->uiAbilityId)) ||
211 !data.WriteInt32(abilitySessionInfo->callingTokenId) ||
212 !data.WriteBool(abilitySessionInfo->reuse)) {
213 return false;
214 }
215 return true;
216 }
217
TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)218 WSError SessionProxy::TerminateSession(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
219 {
220 if (abilitySessionInfo == nullptr) {
221 WLOGFE("abilitySessionInfo is null");
222 return WSError::WS_ERROR_INVALID_SESSION;
223 }
224 MessageParcel data;
225 MessageParcel reply;
226 MessageOption option(MessageOption::TF_ASYNC);
227 if (!data.WriteInterfaceToken(GetDescriptor())) {
228 WLOGFE("WriteInterfaceToken failed");
229 return WSError::WS_ERROR_IPC_FAILED;
230 }
231 if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
232 WLOGFE("Write want info failed");
233 return WSError::WS_ERROR_IPC_FAILED;
234 }
235 if (abilitySessionInfo->callerToken) {
236 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
237 WLOGFE("Write ability info failed");
238 return WSError::WS_ERROR_IPC_FAILED;
239 }
240 } else {
241 if (!data.WriteBool(false)) {
242 WLOGFE("Write ability info failed");
243 return WSError::WS_ERROR_IPC_FAILED;
244 }
245 }
246 if (!data.WriteInt32(abilitySessionInfo->resultCode)) {
247 WLOGFE("Write resultCode info failed");
248 return WSError::WS_ERROR_IPC_FAILED;
249 }
250 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_TERMINATE),
251 data, reply, option) != ERR_NONE) {
252 WLOGFE("SendRequest failed");
253 return WSError::WS_ERROR_IPC_FAILED;
254 }
255 int32_t ret = reply.ReadInt32();
256 return static_cast<WSError>(ret);
257 }
258
NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo)259 WSError SessionProxy::NotifySessionException(const sptr<AAFwk::SessionInfo> abilitySessionInfo)
260 {
261 if (abilitySessionInfo == nullptr) {
262 WLOGFE("abilitySessionInfo is null");
263 return WSError::WS_ERROR_INVALID_SESSION;
264 }
265 MessageParcel data;
266 MessageParcel reply;
267 MessageOption option(MessageOption::TF_ASYNC);
268 if (!data.WriteInterfaceToken(GetDescriptor())) {
269 WLOGFE("WriteInterfaceToken failed");
270 return WSError::WS_ERROR_IPC_FAILED;
271 }
272 if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
273 WLOGFE("Write want info failed");
274 return WSError::WS_ERROR_IPC_FAILED;
275 }
276 if (abilitySessionInfo->callerToken) {
277 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
278 WLOGFE("Write ability info failed");
279 return WSError::WS_ERROR_IPC_FAILED;
280 }
281 } else {
282 if (!data.WriteBool(false)) {
283 WLOGFE("Write ability info failed");
284 return WSError::WS_ERROR_IPC_FAILED;
285 }
286 }
287 if (!data.WriteInt32(abilitySessionInfo->errorCode)) {
288 WLOGFE("Write erroCode info failed");
289 return WSError::WS_ERROR_IPC_FAILED;
290 }
291 if (!data.WriteString(abilitySessionInfo->errorReason)) {
292 WLOGFE("Write erroCode info failed");
293 return WSError::WS_ERROR_IPC_FAILED;
294 }
295 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_EXCEPTION),
296 data, reply, option) != ERR_NONE) {
297 WLOGFE("SendRequest failed");
298 return WSError::WS_ERROR_IPC_FAILED;
299 }
300 int32_t ret = reply.ReadInt32();
301 return static_cast<WSError>(ret);
302 }
303
UpdateActiveStatus(bool isActive)304 WSError SessionProxy::UpdateActiveStatus(bool isActive)
305 {
306 MessageParcel data;
307 MessageParcel reply;
308 MessageOption option(MessageOption::TF_ASYNC);
309 if (!data.WriteInterfaceToken(GetDescriptor())) {
310 WLOGFE("WriteInterfaceToken failed");
311 return WSError::WS_ERROR_IPC_FAILED;
312 }
313 if (!(data.WriteBool(isActive))) {
314 WLOGFE("Write active status failed");
315 return WSError::WS_ERROR_IPC_FAILED;
316 }
317 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_UPDATE_ACTIVE_STATUS),
318 data, reply, option) != ERR_NONE) {
319 WLOGFE("SendRequest failed");
320 return WSError::WS_ERROR_IPC_FAILED;
321 }
322 int32_t ret = reply.ReadInt32();
323 return static_cast<WSError>(ret);
324 }
325
OnSessionEvent(SessionEvent event)326 WSError SessionProxy::OnSessionEvent(SessionEvent event)
327 {
328 MessageParcel data;
329 MessageParcel reply;
330 MessageOption option(MessageOption::TF_ASYNC);
331 if (!data.WriteInterfaceToken(GetDescriptor())) {
332 WLOGFE("WriteInterfaceToken failed");
333 return WSError::WS_ERROR_IPC_FAILED;
334 }
335 if (!(data.WriteUint32(static_cast<uint32_t>(event)))) {
336 WLOGFE("Write event id failed");
337 return WSError::WS_ERROR_IPC_FAILED;
338 }
339 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_SESSION_EVENT),
340 data, reply, option) != ERR_NONE) {
341 WLOGFE("SendRequest failed");
342 return WSError::WS_ERROR_IPC_FAILED;
343 }
344 int32_t ret = reply.ReadInt32();
345 return static_cast<WSError>(ret);
346 }
347
UpdateSessionRect(const WSRect & rect,const SizeChangeReason & reason)348 WSError SessionProxy::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason)
349 {
350 WLOGFI("UpdateSessionRect [%{public}d, %{public}d, %{public}u, %{public}u]", rect.posX_, rect.posY_,
351 rect.width_, rect.height_);
352 MessageParcel data;
353 MessageParcel reply;
354 MessageOption option(MessageOption::TF_ASYNC);
355 if (!data.WriteInterfaceToken(GetDescriptor())) {
356 WLOGFE("WriteInterfaceToken failed");
357 return WSError::WS_ERROR_IPC_FAILED;
358 }
359 if (!((data.WriteInt32(static_cast<int32_t>(rect.posX_))) &&
360 (data.WriteInt32(static_cast<int32_t>(rect.posY_))) &&
361 (data.WriteUint32(static_cast<uint32_t>(rect.width_))) &&
362 (data.WriteUint32(static_cast<uint32_t>(rect.height_))))) {
363 WLOGFE("Write rect failed");
364 return WSError::WS_ERROR_IPC_FAILED;
365 }
366
367 if (!data.WriteUint32(static_cast<uint32_t>(reason))) {
368 WLOGFE("Write SessionSizeChangeReason failed");
369 return WSError::WS_ERROR_IPC_FAILED;
370 }
371
372 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_UPDATE_SESSION_RECT),
373 data, reply, option) != ERR_NONE) {
374 WLOGFE("SendRequest failed");
375 return WSError::WS_ERROR_IPC_FAILED;
376 }
377 int32_t ret = reply.ReadInt32();
378 return static_cast<WSError>(ret);
379 }
380
CreateAndConnectSpecificSession(const sptr<ISessionStage> & sessionStage,const sptr<IWindowEventChannel> & eventChannel,const std::shared_ptr<RSSurfaceNode> & surfaceNode,sptr<WindowSessionProperty> property,int32_t & persistentId,sptr<ISession> & session,sptr<IRemoteObject> token)381 WSError SessionProxy::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
382 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
383 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, sptr<IRemoteObject> token)
384 {
385 MessageParcel data;
386 MessageParcel reply;
387 MessageOption option(MessageOption::TF_SYNC);
388 if (!data.WriteInterfaceToken(GetDescriptor())) {
389 WLOGFE("WriteInterfaceToken failed");
390 return WSError::WS_ERROR_IPC_FAILED;
391 }
392 if (!data.WriteRemoteObject(sessionStage->AsObject())) {
393 WLOGFE("Write ISessionStage failed");
394 return WSError::WS_ERROR_IPC_FAILED;
395 }
396 if (!data.WriteRemoteObject(eventChannel->AsObject())) {
397 WLOGFE("Write IWindowEventChannel failed");
398 return WSError::WS_ERROR_IPC_FAILED;
399 }
400 if (!surfaceNode->Marshalling(data)) {
401 WLOGFE("Write surfaceNode failed");
402 return WSError::WS_ERROR_IPC_FAILED;
403 }
404
405 if (property) {
406 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
407 return WSError::WS_ERROR_IPC_FAILED;
408 }
409 } else {
410 if (!data.WriteBool(false)) {
411 return WSError::WS_ERROR_IPC_FAILED;
412 }
413 }
414 if (token != nullptr) {
415 if (!data.WriteRemoteObject(token)) {
416 return WSError::WS_ERROR_IPC_FAILED;
417 }
418 }
419 if (Remote()->SendRequest(static_cast<uint32_t>(
420 SessionMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION),
421 data, reply, option) != ERR_NONE) {
422 WLOGFE("SendRequest failed");
423 return WSError::WS_ERROR_IPC_FAILED;
424 }
425 persistentId = reply.ReadInt32();
426 sptr<IRemoteObject> sessionObject = reply.ReadRemoteObject();
427 if (sessionObject == nullptr) {
428 WLOGFE("ReadRemoteObject failed");
429 return WSError::WS_ERROR_IPC_FAILED;
430 }
431 session = iface_cast<ISession>(sessionObject);
432 int32_t ret = reply.ReadInt32();
433 return static_cast<WSError>(ret);
434 }
435
DestroyAndDisconnectSpecificSession(const int32_t & persistentId)436 WSError SessionProxy::DestroyAndDisconnectSpecificSession(const int32_t& persistentId)
437 {
438 MessageParcel data;
439 MessageParcel reply;
440 MessageOption option(MessageOption::TF_SYNC);
441 if (!data.WriteInterfaceToken(GetDescriptor())) {
442 WLOGFE("WriteInterfaceToken failed");
443 return WSError::WS_ERROR_IPC_FAILED;
444 }
445 if (!data.WriteInt32(persistentId)) {
446 WLOGFE("Write persistentId failed");
447 }
448 if (Remote()->SendRequest(static_cast<uint32_t>(
449 SessionMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION),
450 data, reply, option) != ERR_NONE) {
451 WLOGFE("SendRequest failed");
452 return WSError::WS_ERROR_IPC_FAILED;
453 }
454 int32_t ret = reply.ReadInt32();
455 return static_cast<WSError>(ret);
456 }
457
RaiseToAppTop()458 WSError SessionProxy::RaiseToAppTop()
459 {
460 MessageParcel data;
461 MessageParcel reply;
462 MessageOption option;
463 if (!data.WriteInterfaceToken(GetDescriptor())) {
464 WLOGFE("WriteInterfaceToken failed");
465 return WSError::WS_ERROR_IPC_FAILED;
466 }
467 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_RAISE_TO_APP_TOP),
468 data, reply, option) != ERR_NONE) {
469 WLOGFE("SendRequest failed");
470 return WSError::WS_ERROR_IPC_FAILED;
471 }
472 int32_t ret = reply.ReadInt32();
473 return static_cast<WSError>(ret);
474 }
475
RaiseAboveTarget(int32_t subWindowId)476 WSError SessionProxy::RaiseAboveTarget(int32_t subWindowId)
477 {
478 MessageParcel data;
479 MessageParcel reply;
480 MessageOption option;
481 if (!data.WriteInterfaceToken(GetDescriptor())) {
482 WLOGFE("WriteInterfaceToken failed");
483 return WSError::WS_ERROR_IPC_FAILED;
484 }
485 if (!data.WriteInt32(subWindowId)) {
486 WLOGFE("Write subWindowId failed");
487 }
488 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_RAISE_ABOVE_TARGET),
489 data, reply, option) != ERR_NONE) {
490 WLOGFE("SendRequest failed");
491 return WSError::WS_ERROR_IPC_FAILED;
492 }
493 int32_t ret = reply.ReadInt32();
494 return static_cast<WSError>(ret);
495 }
496
OnNeedAvoid(bool status)497 WSError SessionProxy::OnNeedAvoid(bool status)
498 {
499 MessageParcel data;
500 MessageParcel reply;
501 MessageOption option(MessageOption::TF_ASYNC);
502 if (!data.WriteInterfaceToken(GetDescriptor())) {
503 WLOGFE("WriteInterfaceToken failed");
504 return WSError::WS_ERROR_IPC_FAILED;
505 }
506 if (!(data.WriteUint32(static_cast<uint32_t>(status)))) {
507 WLOGFE("Write status failed");
508 return WSError::WS_ERROR_IPC_FAILED;
509 }
510 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_NEED_AVOID),
511 data, reply, option) != ERR_NONE) {
512 WLOGFE("SendRequest failed");
513 return WSError::WS_ERROR_IPC_FAILED;
514 }
515 int32_t ret = reply.ReadInt32();
516 return static_cast<WSError>(ret);
517 }
518
GetAvoidAreaByType(AvoidAreaType type)519 AvoidArea SessionProxy::GetAvoidAreaByType(AvoidAreaType type)
520 {
521 MessageParcel data;
522 MessageParcel reply;
523 MessageOption option(MessageOption::TF_SYNC);
524 AvoidArea avoidArea;
525 if (!data.WriteInterfaceToken(GetDescriptor())) {
526 WLOGFE("WriteInterfaceToken failed");
527 return avoidArea;
528 }
529 if (!(data.WriteUint32(static_cast<uint32_t>(type)))) {
530 WLOGFE("Write type failed");
531 return avoidArea;
532 }
533 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_GET_AVOID_AREA),
534 data, reply, option) != ERR_NONE) {
535 WLOGFE("SendRequest failed");
536 return avoidArea;
537 }
538 sptr<AvoidArea> area = reply.ReadParcelable<AvoidArea>();
539 if (area == nullptr) {
540 return avoidArea;
541 }
542 return *area;
543 }
544
RequestSessionBack()545 WSError SessionProxy::RequestSessionBack()
546 {
547 MessageParcel data;
548 MessageParcel reply;
549 MessageOption option(MessageOption::TF_ASYNC);
550 if (!data.WriteInterfaceToken(GetDescriptor())) {
551 WLOGFE("WriteInterfaceToken failed");
552 return WSError::WS_ERROR_IPC_FAILED;
553 }
554 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_BACKPRESSED),
555 data, reply, option) != ERR_NONE) {
556 WLOGFE("SendRequest failed");
557 return WSError::WS_ERROR_IPC_FAILED;
558 }
559 int32_t ret = reply.ReadInt32();
560 return static_cast<WSError>(ret);
561 }
562
MarkProcessed(int32_t eventId)563 WSError SessionProxy::MarkProcessed(int32_t eventId)
564 {
565 MessageParcel data;
566 MessageParcel reply;
567 MessageOption option(MessageOption::TF_ASYNC);
568 if (!data.WriteInterfaceToken(GetDescriptor())) {
569 WLOGFE("WriteInterfaceToken failed");
570 return WSError::WS_ERROR_IPC_FAILED;
571 }
572 if (!data.WriteInt32(eventId)) {
573 WLOGFE("WriteInterfaceToken failed");
574 return WSError::WS_ERROR_IPC_FAILED;
575 }
576 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_MARK_PROCESSED),
577 data, reply, option) != ERR_NONE) {
578 WLOGFE("SendRequest failed");
579 return WSError::WS_ERROR_IPC_FAILED;
580 }
581 int32_t ret = reply.ReadInt32();
582 return static_cast<WSError>(ret);
583 }
584
SetGlobalMaximizeMode(MaximizeMode mode)585 WSError OHOS::Rosen::SessionProxy::SetGlobalMaximizeMode(MaximizeMode mode)
586 {
587 MessageParcel data;
588 MessageParcel reply;
589 MessageOption option;
590 if (!data.WriteInterfaceToken(GetDescriptor())) {
591 WLOGFE("WriteInterfaceToken failed");
592 return WSError::WS_ERROR_IPC_FAILED;
593 }
594 if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
595 WLOGFE("Write uint32_t failed");
596 }
597 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_SET_MAXIMIZE_MODE),
598 data, reply, option) != ERR_NONE) {
599 WLOGFE("SendRequest failed");
600 return WSError::WS_ERROR_IPC_FAILED;
601 }
602 int32_t ret = reply.ReadInt32();
603 return static_cast<WSError>(ret);
604 }
605
GetGlobalMaximizeMode(MaximizeMode & mode)606 WSError SessionProxy::GetGlobalMaximizeMode(MaximizeMode& mode)
607 {
608 MessageParcel data;
609 MessageParcel reply;
610 MessageOption option;
611 if (!data.WriteInterfaceToken(GetDescriptor())) {
612 WLOGFE("WriteInterfaceToken failed");
613 return WSError::WS_ERROR_IPC_FAILED;
614 }
615 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_GET_MAXIMIZE_MODE),
616 data, reply, option) != ERR_NONE) {
617 WLOGFE("SendRequest failed");
618 return WSError::WS_ERROR_IPC_FAILED;
619 }
620 mode = static_cast<MaximizeMode>(reply.ReadUint32());
621 int32_t ret = reply.ReadInt32();
622 return static_cast<WSError>(ret);
623 }
624
UpdateWindowSessionProperty(sptr<WindowSessionProperty> property)625 WSError SessionProxy::UpdateWindowSessionProperty(sptr<WindowSessionProperty> property)
626 {
627 MessageParcel data;
628 MessageParcel reply;
629 MessageOption option;
630 if (!data.WriteInterfaceToken(GetDescriptor())) {
631 WLOGFE("WriteInterfaceToken failed");
632 return WSError::WS_ERROR_IPC_FAILED;
633 }
634 if (!data.WriteParcelable(property.GetRefPtr())) {
635 WLOGFE("Write property failed");
636 return WSError::WS_ERROR_IPC_FAILED;
637 }
638 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_UPDATE_WINDOW_SESSION_PROPERTY),
639 data, reply, option) != ERR_NONE) {
640 WLOGFE("SendRequest failed");
641 return WSError::WS_ERROR_IPC_FAILED;
642 }
643 int32_t ret = reply.ReadInt32();
644 return static_cast<WSError>(ret);
645 }
646
SetAspectRatio(float ratio)647 WSError SessionProxy::SetAspectRatio(float ratio)
648 {
649 MessageParcel data;
650 MessageParcel reply;
651 MessageOption option;
652 if (!data.WriteInterfaceToken(GetDescriptor())) {
653 WLOGFE("WriteInterfaceToken failed");
654 return WSError::WS_ERROR_IPC_FAILED;
655 }
656 if (!data.WriteFloat(ratio)) {
657 WLOGFE("Write ratio failed");
658 return WSError::WS_ERROR_IPC_FAILED;
659 }
660 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_SET_ASPECT_RATIO),
661 data, reply, option) != ERR_NONE) {
662 WLOGFE("SendRequest failed");
663 return WSError::WS_ERROR_IPC_FAILED;
664 }
665 int32_t ret = reply.ReadInt32();
666 return static_cast<WSError>(ret);
667 }
668
UpdateWindowSceneAfterCustomAnimation(bool isAdd)669 WSError SessionProxy::UpdateWindowSceneAfterCustomAnimation(bool isAdd)
670 {
671 MessageParcel data;
672 MessageParcel reply;
673 MessageOption option(MessageOption::TF_ASYNC);
674 if (!data.WriteInterfaceToken(GetDescriptor())) {
675 WLOGFE("WriteInterfaceToken failed");
676 return WSError::WS_ERROR_IPC_FAILED;
677 }
678 if (!data.WriteBool(isAdd)) {
679 WLOGFE("Write isAdd failed");
680 return WSError::WS_ERROR_IPC_FAILED;
681 }
682 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_UPDATE_CUSTOM_ANIMATION),
683 data, reply, option) != ERR_NONE) {
684 WLOGFE("SendRequest failed");
685 return WSError::WS_ERROR_IPC_FAILED;
686 }
687 int32_t ret = reply.ReadInt32();
688 return static_cast<WSError>(ret);
689 }
690
TransferAbilityResult(uint32_t resultCode,const AAFwk::Want & want)691 WSError SessionProxy::TransferAbilityResult(uint32_t resultCode, const AAFwk::Want& want)
692 {
693 MessageParcel data;
694 MessageParcel reply;
695 MessageOption option(MessageOption::TF_ASYNC);
696 if (!data.WriteInterfaceToken(GetDescriptor())) {
697 WLOGFE("WriteInterfaceToken failed");
698 return WSError::WS_ERROR_IPC_FAILED;
699 }
700 if (!data.WriteUint32(resultCode)) {
701 WLOGFE("resultCode write failed.");
702 return WSError::WS_ERROR_IPC_FAILED;
703 }
704 if (!data.WriteParcelable(&want)) {
705 WLOGFE("want write failed.");
706 return WSError::WS_ERROR_IPC_FAILED;
707 }
708 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_TRANSFER_ABILITY_RESULT),
709 data, reply, option) != ERR_NONE) {
710 WLOGFE("SendRequest failed");
711 return WSError::WS_ERROR_IPC_FAILED;
712 }
713 int32_t ret = reply.ReadInt32();
714 return static_cast<WSError>(ret);
715 }
716
TransferExtensionData(const AAFwk::WantParams & wantParams)717 WSError SessionProxy::TransferExtensionData(const AAFwk::WantParams& wantParams)
718 {
719 MessageParcel data;
720 MessageParcel reply;
721 MessageOption option(MessageOption::TF_ASYNC);
722 if (!data.WriteInterfaceToken(GetDescriptor())) {
723 WLOGFE("WriteInterfaceToken failed");
724 return WSError::WS_ERROR_IPC_FAILED;
725 }
726 if (!data.WriteParcelable(&wantParams)) {
727 WLOGFE("wantParams write failed.");
728 return WSError::WS_ERROR_IPC_FAILED;
729 }
730 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_TRANSFER_EXTENSION_DATA),
731 data, reply, option) != ERR_NONE) {
732 WLOGFE("SendRequest failed");
733 return WSError::WS_ERROR_IPC_FAILED;
734 }
735 int32_t ret = reply.ReadInt32();
736 return static_cast<WSError>(ret);
737 }
738
NotifyRemoteReady()739 void SessionProxy::NotifyRemoteReady()
740 {
741 MessageParcel data;
742 MessageParcel reply;
743 MessageOption option(MessageOption::TF_ASYNC);
744 if (!data.WriteInterfaceToken(GetDescriptor())) {
745 WLOGFE("WriteInterfaceToken failed");
746 return;
747 }
748 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_NOTIFY_REMOTE_READY),
749 data, reply, option) != ERR_NONE) {
750 WLOGFE("SendRequest failed");
751 return;
752 }
753 }
754
NotifyExtensionDied()755 void SessionProxy::NotifyExtensionDied()
756 {
757 MessageParcel data;
758 MessageParcel reply;
759 MessageOption option(MessageOption::TF_ASYNC);
760 if (!data.WriteInterfaceToken(GetDescriptor())) {
761 WLOGFE("WriteInterfaceToken failed");
762 return;
763 }
764 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_NOTIFY_EXTENSION_DIED),
765 data, reply, option) != ERR_NONE) {
766 WLOGFE("SendRequest failed");
767 return;
768 }
769 }
770
UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)771 WSError SessionProxy::UpdateWindowAnimationFlag(bool needDefaultAnimationFlag)
772 {
773 MessageParcel data;
774 MessageParcel reply;
775 MessageOption option;
776 if (!data.WriteInterfaceToken(GetDescriptor())) {
777 WLOGFE("WriteInterfaceToken failed");
778 return WSError::WS_ERROR_IPC_FAILED;
779 }
780 if (!data.WriteBool(needDefaultAnimationFlag)) {
781 WLOGFE("wantParams write failed.");
782 return WSError::WS_ERROR_IPC_FAILED;
783 }
784 if (Remote()->SendRequest(static_cast<uint32_t>(SessionMessage::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG),
785 data, reply, option) != ERR_NONE) {
786 WLOGFE("SendRequest failed");
787 return WSError::WS_ERROR_IPC_FAILED;
788 }
789 int32_t ret = reply.ReadInt32();
790 return static_cast<WSError>(ret);
791 }
792 } // namespace OHOS::Rosen
793