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_manager/include/zidl/scene_session_manager_proxy.h"
17
18 #include <ipc_types.h>
19 #include <message_option.h>
20 #include <message_parcel.h>
21 #include <ui/rs_surface_node.h>
22
23 #include "marshalling_helper.h"
24 #include "window_manager.h"
25 #include "window_manager_hilog.h"
26
27 namespace OHOS::Rosen {
28 namespace {
29 constexpr int32_t CYCLE_LIMIT = 1000;
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerProxy"};
31 }
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)32 WSError SceneSessionManagerProxy::CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
33 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
34 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, sptr<IRemoteObject> token)
35 {
36 MessageOption option(MessageOption::TF_SYNC);
37 MessageParcel data;
38 MessageParcel reply;
39 if (!data.WriteInterfaceToken(GetDescriptor())) {
40 WLOGFE("Write InterfaceToken failed!");
41 return WSError::WS_ERROR_IPC_FAILED;
42 }
43 if (!data.WriteRemoteObject(sessionStage->AsObject())) {
44 WLOGFE("Write ISessionStage failed!");
45 return WSError::WS_ERROR_IPC_FAILED;
46 }
47 if (!data.WriteRemoteObject(eventChannel->AsObject())) {
48 WLOGFE("Write IWindowEventChannel failed!");
49 return WSError::WS_ERROR_IPC_FAILED;
50 }
51 if (!surfaceNode->Marshalling(data)) {
52 WLOGFE("Write surfaceNode failed");
53 return WSError::WS_ERROR_IPC_FAILED;
54 }
55
56 if (property) {
57 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
58 return WSError::WS_ERROR_IPC_FAILED;
59 }
60 } else {
61 if (!data.WriteBool(false)) {
62 return WSError::WS_ERROR_IPC_FAILED;
63 }
64 }
65 if (token != nullptr) {
66 if (!data.WriteRemoteObject(token)) {
67 return WSError::WS_ERROR_IPC_FAILED;
68 }
69 }
70
71 if (Remote()->SendRequest(static_cast<uint32_t>(
72 SceneSessionManagerMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION),
73 data, reply, option) != ERR_NONE) {
74 WLOGFE("SendRequest failed");
75 return WSError::WS_ERROR_IPC_FAILED;
76 }
77 persistentId = reply.ReadInt32();
78 sptr<IRemoteObject> sessionObject = reply.ReadRemoteObject();
79 if (sessionObject == nullptr) {
80 WLOGFE("ReadRemoteObject failed");
81 return WSError::WS_ERROR_IPC_FAILED;
82 }
83 session = iface_cast<ISession>(sessionObject);
84 int32_t ret = reply.ReadInt32();
85 return static_cast<WSError>(ret);
86 }
87
DestroyAndDisconnectSpecificSession(const int32_t & persistentId)88 WSError SceneSessionManagerProxy::DestroyAndDisconnectSpecificSession(const int32_t& persistentId)
89 {
90 MessageParcel data;
91 MessageParcel reply;
92 MessageOption option(MessageOption::TF_SYNC);
93 if (!data.WriteInterfaceToken(GetDescriptor())) {
94 WLOGFE("WriteInterfaceToken failed");
95 return WSError::WS_ERROR_IPC_FAILED;
96 }
97 if (!data.WriteInt32(persistentId)) {
98 WLOGFE("Write persistentId failed");
99 }
100 if (Remote()->SendRequest(static_cast<uint32_t>(
101 SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION),
102 data, reply, option) != ERR_NONE) {
103 WLOGFE("SendRequest failed");
104 return WSError::WS_ERROR_IPC_FAILED;
105 }
106 int32_t ret = reply.ReadInt32();
107 return static_cast<WSError>(ret);
108 }
109
UpdateProperty(sptr<WindowSessionProperty> & property,WSPropertyChangeAction action)110 WMError SceneSessionManagerProxy::UpdateProperty(sptr<WindowSessionProperty>& property, WSPropertyChangeAction action)
111 {
112 MessageParcel data;
113 MessageParcel reply;
114 MessageOption option(MessageOption::TF_SYNC);
115 if (!data.WriteInterfaceToken(GetDescriptor())) {
116 WLOGFE("WriteInterfaceToken failed");
117 return WMError::WM_ERROR_IPC_FAILED;
118 }
119 if (!data.WriteUint32(static_cast<uint32_t>(action))) {
120 WLOGFE("Write PropertyChangeAction failed");
121 return WMError::WM_ERROR_IPC_FAILED;
122 }
123 if (property) {
124 if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) {
125 WLOGFE("Write property failed");
126 return WMError::WM_ERROR_IPC_FAILED;
127 }
128 } else {
129 if (!data.WriteBool(false)) {
130 WLOGFE("Write property failed");
131 return WMError::WM_ERROR_IPC_FAILED;
132 }
133 }
134
135 if (Remote()->SendRequest(static_cast<uint32_t>(
136 SceneSessionManagerMessage::TRANS_ID_UPDATE_PROPERTY),
137 data, reply, option) != ERR_NONE) {
138 WLOGFE("SendRequest failed");
139 return WMError::WM_ERROR_IPC_FAILED;
140 }
141 int32_t ret = reply.ReadInt32();
142 return static_cast<WMError>(ret);
143 }
BindDialogTarget(uint64_t persistentId,sptr<IRemoteObject> targetToken)144 WSError SceneSessionManagerProxy::BindDialogTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken)
145 {
146 MessageParcel data;
147 MessageParcel reply;
148 MessageOption option(MessageOption::TF_SYNC);
149 if (!data.WriteInterfaceToken(GetDescriptor())) {
150 WLOGFE("WriteInterfaceToken failed");
151 return WSError::WS_ERROR_IPC_FAILED;
152 }
153 if (!data.WriteUint64(persistentId)) {
154 WLOGFE("Write PropertyChangeAction failed");
155 return WSError::WS_ERROR_IPC_FAILED;
156 }
157 if (targetToken != nullptr) {
158 if (!data.WriteRemoteObject(targetToken)) {
159 WLOGFE("Write targetToken failed");
160 return WSError::WS_ERROR_IPC_FAILED;
161 }
162 }
163
164 if (Remote()->SendRequest(static_cast<uint32_t>(
165 SceneSessionManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
166 data, reply, option) != ERR_NONE) {
167 WLOGFE("SendRequest failed");
168 return WSError::WS_ERROR_IPC_FAILED;
169 }
170 int32_t ret = reply.ReadInt32();
171 return static_cast<WSError>(ret);
172 }
173
UpdateSessionAvoidAreaListener(int32_t & persistentId,bool haveListener)174 WSError SceneSessionManagerProxy::UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener)
175 {
176 MessageParcel data;
177 MessageParcel reply;
178 MessageOption option(MessageOption::TF_SYNC);
179
180 if (!data.WriteInterfaceToken(GetDescriptor())) {
181 WLOGFE("WriteInterfaceToken failed");
182 return WSError::WS_ERROR_IPC_FAILED;
183 }
184 if (!data.WriteInt32(persistentId)) {
185 WLOGFE("Write persistentId failed");
186 return WSError::WS_ERROR_IPC_FAILED;
187 }
188 if (!data.WriteBool(haveListener)) {
189 WLOGFE("Write avoid area listener failed");
190 return WSError::WS_ERROR_IPC_FAILED;
191 }
192 if (Remote()->SendRequest(static_cast<uint32_t>(
193 SceneSessionManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
194 data, reply, option) != ERR_NONE) {
195 return WSError::WS_ERROR_IPC_FAILED;
196 }
197 return static_cast<WSError>(reply.ReadInt32());
198 }
199
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)200 WMError SceneSessionManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
201 const sptr<IWindowManagerAgent>& windowManagerAgent)
202 {
203 MessageOption option;
204 MessageParcel reply;
205 MessageParcel data;
206 if (!data.WriteInterfaceToken(GetDescriptor())) {
207 WLOGFE("Write InterfaceToken failed");
208 return WMError::WM_ERROR_IPC_FAILED;
209 }
210
211 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
212 WLOGFE("Write type failed");
213 return WMError::WM_ERROR_IPC_FAILED;
214 }
215
216 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
217 WLOGFE("Write IWindowManagerAgent failed");
218 return WMError::WM_ERROR_IPC_FAILED;
219 }
220
221 if (Remote()->SendRequest(static_cast<uint32_t>(
222 SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
223 data, reply, option) != ERR_NONE) {
224 WLOGFE("SendRequest failed");
225 return WMError::WM_ERROR_IPC_FAILED;
226 }
227
228 return static_cast<WMError>(reply.ReadInt32());
229 }
230
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)231 WMError SceneSessionManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
232 const sptr<IWindowManagerAgent>& windowManagerAgent)
233 {
234 MessageParcel reply;
235 MessageOption option;
236 MessageParcel data;
237 if (!data.WriteInterfaceToken(GetDescriptor())) {
238 WLOGFE("Write InterfaceToken failed");
239 return WMError::WM_ERROR_IPC_FAILED;
240 }
241
242 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
243 WLOGFE("Write type failed");
244 return WMError::WM_ERROR_IPC_FAILED;
245 }
246
247 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
248 WLOGFE("Write IWindowManagerAgent failed");
249 return WMError::WM_ERROR_IPC_FAILED;
250 }
251
252 if (Remote()->SendRequest(static_cast<uint32_t>(
253 SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
254 data, reply, option) != ERR_NONE) {
255 WLOGFE("SendRequest failed");
256 return WMError::WM_ERROR_IPC_FAILED;
257 }
258
259 return static_cast<WMError>(reply.ReadInt32());
260 }
261
GetFocusWindowInfo(FocusChangeInfo & focusInfo)262 void SceneSessionManagerProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
263 {
264 MessageParcel data;
265 MessageParcel reply;
266 MessageOption option;
267 if (!data.WriteInterfaceToken(GetDescriptor())) {
268 WLOGFE("WriteInterfaceToken failed");
269 return;
270 }
271
272 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
273 data, reply, option) != ERR_NONE) {
274 WLOGFE("SendRequest failed");
275 return;
276 }
277 sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
278 if (info) {
279 focusInfo = *info;
280 } else {
281 WLOGFE("info is null.");
282 }
283 }
284
SetSessionGravity(int32_t persistentId,SessionGravity gravity,uint32_t percent)285 WSError SceneSessionManagerProxy::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent)
286 {
287 MessageParcel data;
288 MessageParcel reply;
289 MessageOption option;
290 if (!data.WriteInterfaceToken(GetDescriptor())) {
291 WLOGFE("WriteInterfaceToken failed");
292 return WSError::WS_ERROR_IPC_FAILED;
293 }
294 if (!data.WriteInt32(persistentId)) {
295 WLOGFE("Write persistentId failed");
296 return WSError::WS_ERROR_IPC_FAILED;
297 }
298 if (!data.WriteUint32(static_cast<uint32_t>(gravity))) {
299 WLOGFE("Write gravity failed");
300 return WSError::WS_ERROR_IPC_FAILED;
301 }
302 if (!data.WriteUint32(percent)) {
303 WLOGFE("Write percent failed");
304 return WSError::WS_ERROR_IPC_FAILED;
305 }
306 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_GRAVITY),
307 data, reply, option) != ERR_NONE) {
308 WLOGFE("SendRequest failed");
309 return WSError::WS_ERROR_IPC_FAILED;
310 }
311 return static_cast<WSError>(reply.ReadInt32());
312 }
313
SetGestureNavigaionEnabled(bool enable)314 WMError SceneSessionManagerProxy::SetGestureNavigaionEnabled(bool enable)
315 {
316 MessageParcel data;
317 MessageParcel reply;
318 MessageOption option(MessageOption::TF_SYNC);
319 if (!data.WriteInterfaceToken(GetDescriptor())) {
320 WLOGFE("Write InterfaceToken failed");
321 return WMError::WM_ERROR_IPC_FAILED;
322 }
323
324 if (!data.WriteBool(enable)) {
325 WLOGFE("Write enable failed");
326 return WMError::WM_ERROR_IPC_FAILED;
327 }
328
329 if (Remote()->SendRequest(static_cast<uint32_t>(
330 SceneSessionManagerMessage::TRANS_ID_SET_GESTURE_NAVIGATION_ENABLED), data, reply, option) != ERR_NONE) {
331 WLOGFE("SendRequest failed");
332 return WMError::WM_ERROR_IPC_FAILED;
333 }
334 int32_t ret = reply.ReadInt32();
335 return static_cast<WMError>(ret);
336 }
337
SetSessionLabel(const sptr<IRemoteObject> & token,const std::string & label)338 WSError SceneSessionManagerProxy::SetSessionLabel(const sptr<IRemoteObject> &token, const std::string &label)
339 {
340 WLOGFI("run SceneSessionManagerProxy::SetSessionLabel");
341 MessageParcel data;
342 MessageParcel reply;
343 MessageOption option;
344 if (!data.WriteInterfaceToken(GetDescriptor())) {
345 WLOGFE("WriteInterfaceToken failed");
346 return WSError::WS_ERROR_IPC_FAILED;
347 }
348 if (!data.WriteRemoteObject(token)) {
349 WLOGFE("Write token failed");
350 return WSError::WS_ERROR_IPC_FAILED;
351 }
352 if (!data.WriteString(label)) {
353 WLOGFE("Write label failed");
354 return WSError::WS_ERROR_IPC_FAILED;
355 }
356
357 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_LABEL),
358 data, reply, option) != ERR_NONE) {
359 WLOGFE("SendRequest failed");
360 return WSError::WS_ERROR_IPC_FAILED;
361 }
362 return static_cast<WSError>(reply.ReadInt32());
363 }
364
SetSessionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & icon)365 WSError SceneSessionManagerProxy::SetSessionIcon(const sptr<IRemoteObject> &token,
366 const std::shared_ptr<Media::PixelMap> &icon)
367 {
368 WLOGFI("run SceneSessionManagerProxy::SetSessionIcon");
369 MessageParcel data;
370 MessageParcel reply;
371 MessageOption option;
372 if (!data.WriteInterfaceToken(GetDescriptor())) {
373 WLOGFE("WriteInterfaceToken failed");
374 return WSError::WS_ERROR_IPC_FAILED;
375 }
376 if (!data.WriteRemoteObject(token)) {
377 WLOGFE("Write token failed");
378 return WSError::WS_ERROR_IPC_FAILED;
379 }
380 if (!data.WriteParcelable(icon.get())) {
381 WLOGFE("Write icon failed");
382 return WSError::WS_ERROR_IPC_FAILED;
383 }
384
385 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_ICON),
386 data, reply, option) != ERR_NONE) {
387 WLOGFE("SendRequest failed");
388 return WSError::WS_ERROR_IPC_FAILED;
389 }
390 return static_cast<WSError>(reply.ReadInt32());
391 }
392
IsValidSessionIds(const std::vector<int32_t> & sessionIds,std::vector<bool> & results)393 WSError SceneSessionManagerProxy::IsValidSessionIds(
394 const std::vector<int32_t> &sessionIds, std::vector<bool> &results)
395 {
396 WLOGFI("run SceneSessionManagerProxy::IsValidSessionIds");
397 MessageParcel data;
398 MessageParcel reply;
399 MessageOption option;
400 if (!data.WriteInterfaceToken(GetDescriptor())) {
401 WLOGFE("WriteInterfaceToken failed");
402 return WSError::WS_ERROR_IPC_FAILED;
403 }
404 if (!data.WriteInt32Vector(sessionIds)) {
405 WLOGFE("Write sessionIds failed");
406 return WSError::WS_ERROR_IPC_FAILED;
407 }
408
409 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_VALID_SESSION_IDS),
410 data, reply, option) != ERR_NONE) {
411 WLOGFE("SendRequest failed");
412 return WSError::WS_ERROR_IPC_FAILED;
413 }
414
415 reply.ReadBoolVector(&results);
416 return static_cast<WSError>(reply.ReadInt32());
417 }
418
RegisterSessionListener(const sptr<ISessionChangeListener> sessionListener)419 WSError SceneSessionManagerProxy::RegisterSessionListener(const sptr<ISessionChangeListener> sessionListener)
420 {
421 WLOGFI("run SceneSessionManagerProxy::RegisterSessionListener");
422 MessageParcel data;
423 MessageParcel reply;
424 MessageOption option;
425 if (sessionListener == nullptr) {
426 WLOGFE("sessionListener is null");
427 return WSError::WS_ERROR_IPC_FAILED;
428 }
429
430 if (!data.WriteInterfaceToken(GetDescriptor())) {
431 WLOGFE("Write interfaceToken failed");
432 return WSError::WS_ERROR_IPC_FAILED;
433 }
434
435 if (!data.WriteRemoteObject(sessionListener->AsObject())) {
436 WLOGFE("Write sessionListener failed");
437 return WSError::WS_ERROR_IPC_FAILED;
438 }
439
440 if (Remote()->SendRequest(
441 static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_CHANGE_LISTENER), data, reply,
442 option) != ERR_NONE) {
443 WLOGFE("SendRequest failed");
444 return WSError::WS_ERROR_IPC_FAILED;
445 }
446 return static_cast<WSError>(reply.ReadInt32());
447 }
448
UnregisterSessionListener()449 void SceneSessionManagerProxy::UnregisterSessionListener()
450 {
451 WLOGFI("run SceneSessionManagerProxy::UnregisterSessionListener");
452 MessageParcel data;
453 MessageParcel reply;
454 MessageOption option;
455 if (!data.WriteInterfaceToken(GetDescriptor())) {
456 WLOGFE("UnregisterSessionListener WriteInterfaceToken failed");
457 return;
458 }
459
460 if (Remote()->SendRequest(
461 static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_CHANGE_LISTENER), data, reply,
462 option) != ERR_NONE) {
463 WLOGFE("SendRequest failed");
464 return;
465 }
466 }
467
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)468 WMError SceneSessionManagerProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
469 {
470 MessageOption option;
471 MessageParcel reply;
472 MessageParcel data;
473 if (!data.WriteInterfaceToken(GetDescriptor())) {
474 WLOGFE("Write InterfaceToken failed");
475 return WMError::WM_ERROR_IPC_FAILED;
476 }
477
478 if (Remote()->SendRequest(static_cast<uint32_t>(
479 SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_INFO),
480 data, reply, option) != ERR_NONE) {
481 WLOGFE("SendRequest failed");
482 return WMError::WM_ERROR_IPC_FAILED;
483 }
484
485 if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
486 WLOGFE("read window info failed.");
487 return WMError::WM_ERROR_IPC_FAILED;
488 }
489 return static_cast<WMError>(reply.ReadUint32());
490 }
491
PendingSessionToForeground(const sptr<IRemoteObject> & token)492 WSError SceneSessionManagerProxy::PendingSessionToForeground(const sptr<IRemoteObject> &token)
493 {
494 WLOGFI("run SceneSessionManagerProxy::PendingSessionToForeground");
495 MessageParcel data;
496 MessageParcel reply;
497 MessageOption option;
498 if (!data.WriteInterfaceToken(GetDescriptor())) {
499 WLOGFE("Write interfaceToken failed");
500 return WSError::WS_ERROR_IPC_FAILED;
501 }
502
503 if (!data.WriteRemoteObject(token)) {
504 WLOGFE("Write token failed");
505 return WSError::WS_ERROR_IPC_FAILED;
506 }
507
508 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND),
509 data, reply, option) != ERR_NONE) {
510 WLOGFE("SendRequest failed");
511 return WSError::WS_ERROR_IPC_FAILED;
512 }
513 return static_cast<WSError>(reply.ReadInt32());
514 }
515
PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> & token)516 WSError SceneSessionManagerProxy::PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> &token)
517 {
518 WLOGFI("run SceneSessionManagerProxy::PendingSessionToBackgroundForDelegator");
519 MessageParcel data;
520 MessageParcel reply;
521 MessageOption option;
522 if (!data.WriteInterfaceToken(GetDescriptor())) {
523 WLOGFE("Write interfaceToken failed");
524 return WSError::WS_ERROR_IPC_FAILED;
525 }
526
527 if (!data.WriteRemoteObject(token)) {
528 WLOGFE("Write token failed");
529 return WSError::WS_ERROR_IPC_FAILED;
530 }
531
532 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR),
533 data, reply, option) != ERR_NONE) {
534 WLOGFE("SendRequest failed");
535 return WSError::WS_ERROR_IPC_FAILED;
536 }
537 return static_cast<WSError>(reply.ReadInt32());
538 }
539
RegisterSessionListener(const sptr<ISessionListener> & listener)540 WSError SceneSessionManagerProxy::RegisterSessionListener(const sptr<ISessionListener>& listener)
541 {
542 WLOGFI("run SceneSessionManagerProxy::RegisterSessionListener");
543 MessageParcel data;
544 MessageParcel reply;
545 MessageOption option(MessageOption::TF_SYNC);
546 if (listener == nullptr) {
547 WLOGFE("register mission listener, listener is nullptr");
548 return WSError::WS_ERROR_INVALID_PARAM;
549 }
550 if (!data.WriteInterfaceToken(GetDescriptor())) {
551 WLOGFE("WriteInterfaceToken failed");
552 return WSError::WS_ERROR_IPC_FAILED;
553 }
554 if (!data.WriteRemoteObject(listener->AsObject())) {
555 WLOGFE("write mission listener failed when register mission listener.");
556 return WSError::WS_ERROR_IPC_FAILED;
557 }
558 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_LISTENER),
559 data, reply, option) != ERR_NONE) {
560 WLOGFE("SendRequest failed");
561 return WSError::WS_ERROR_IPC_FAILED;
562 }
563 return static_cast<WSError>(reply.ReadInt32());
564 }
565
UnRegisterSessionListener(const sptr<ISessionListener> & listener)566 WSError SceneSessionManagerProxy::UnRegisterSessionListener(const sptr<ISessionListener>& listener)
567 {
568 WLOGFI("run SceneSessionManagerProxy::UnRegisterSessionListener");
569 if (listener == nullptr) {
570 WLOGFE("unregister mission listener, listener is nullptr");
571 return WSError::WS_ERROR_INVALID_PARAM;
572 }
573 MessageParcel data;
574 MessageParcel reply;
575 MessageOption option(MessageOption::TF_SYNC);
576 if (!data.WriteInterfaceToken(GetDescriptor())) {
577 WLOGFE("WriteInterfaceToken failed");
578 return WSError::WS_ERROR_IPC_FAILED;
579 }
580 if (!data.WriteRemoteObject(listener->AsObject())) {
581 WLOGFE("write mission listener failed when unregister mission listener.");
582 return WSError::WS_ERROR_IPC_FAILED;
583 }
584 if (Remote()->SendRequest(
585 static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER),
586 data, reply, option) != ERR_NONE) {
587 WLOGFE("SendRequest failed");
588 return WSError::WS_ERROR_IPC_FAILED;
589 }
590 return static_cast<WSError>(reply.ReadInt32());
591 }
592
GetSessionInfos(const std::string & deviceId,int32_t numMax,std::vector<SessionInfoBean> & sessionInfos)593 WSError SceneSessionManagerProxy::GetSessionInfos(const std::string& deviceId, int32_t numMax,
594 std::vector<SessionInfoBean>& sessionInfos)
595 {
596 WLOGFI("run SceneSessionManagerProxy::GetSessionInfos");
597 MessageParcel data;
598 MessageParcel reply;
599 MessageOption option(MessageOption::TF_SYNC);
600 if (!data.WriteInterfaceToken(GetDescriptor())) {
601 WLOGFE("WriteInterfaceToken failed");
602 return WSError::WS_ERROR_IPC_FAILED;
603 }
604 if (!data.WriteString(deviceId)) {
605 WLOGFE("GetSessionInfos write deviceId failed.");
606 return WSError::WS_ERROR_IPC_FAILED;
607 }
608 if (!data.WriteInt32(numMax)) {
609 WLOGFE("GetSessionInfos numMax write failed.");
610 return WSError::WS_ERROR_IPC_FAILED;
611 }
612 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFOS),
613 data, reply, option) != ERR_NONE) {
614 WLOGFE("SendRequest failed");
615 return WSError::WS_ERROR_IPC_FAILED;
616 }
617 WSError error = GetParcelableInfos(reply, sessionInfos);
618 if (error != WSError::WS_OK) {
619 WLOGFE("GetSessionInfos error");
620 return error;
621 }
622 return static_cast<WSError>(reply.ReadInt32());
623 }
624
GetSessionInfo(const std::string & deviceId,int32_t persistentId,SessionInfoBean & sessionInfo)625 WSError SceneSessionManagerProxy::GetSessionInfo(const std::string& deviceId, int32_t persistentId,
626 SessionInfoBean& sessionInfo)
627 {
628 WLOGFI("run SceneSessionManagerProxy::GetSessionInfo");
629 MessageParcel data;
630 MessageParcel reply;
631 MessageOption option(MessageOption::TF_SYNC);
632 if (!data.WriteInterfaceToken(GetDescriptor())) {
633 WLOGFE("WriteInterfaceToken failed");
634 return WSError::WS_ERROR_IPC_FAILED;
635 }
636 if (!data.WriteString(deviceId)) {
637 WLOGFE("GetSessionInfo write deviceId failed.");
638 return WSError::WS_ERROR_IPC_FAILED;
639 }
640 if (!data.WriteInt32(persistentId)) {
641 WLOGFE("GetSessionInfo write persistentId failed.");
642 return WSError::WS_ERROR_IPC_FAILED;
643 }
644 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFO_BY_ID),
645 data, reply, option) != ERR_NONE) {
646 WLOGFE("SendRequest failed");
647 return WSError::WS_ERROR_IPC_FAILED;
648 }
649 std::unique_ptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
650 if (info == nullptr) {
651 WLOGFE("read missioninfo failed.");
652 return WSError::WS_ERROR_IPC_FAILED;
653 }
654 sessionInfo = *info;
655 return static_cast<WSError>(reply.ReadInt32());
656 }
657
658 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)659 WSError SceneSessionManagerProxy::GetParcelableInfos(MessageParcel& reply, std::vector<T>& parcelableInfos)
660 {
661 int32_t infoSize = reply.ReadInt32();
662 if (infoSize > CYCLE_LIMIT) {
663 WLOGFE("infoSize is too large");
664 return WSError::WS_ERROR_IPC_FAILED;
665 }
666
667 for (int32_t i = 0; i < infoSize; i++) {
668 std::unique_ptr<T> info(reply.ReadParcelable<T>());
669 if (!info) {
670 WLOGFE("Read Parcelable infos failed.");
671 return WSError::WS_ERROR_IPC_FAILED;
672 }
673 parcelableInfos.emplace_back(*info);
674 }
675 return WSError::WS_OK;
676 }
677
TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needStartCaller)678 WSError SceneSessionManagerProxy::TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,
679 bool needStartCaller)
680 {
681 if (abilitySessionInfo == nullptr) {
682 WLOGFE("abilitySessionInfo is null");
683 return WSError::WS_ERROR_INVALID_SESSION;
684 }
685 MessageParcel data, reply;
686 MessageOption option(MessageOption::TF_ASYNC);
687 if (!data.WriteInterfaceToken(GetDescriptor())) {
688 WLOGFE("WriteInterfaceToken failed");
689 return WSError::WS_ERROR_IPC_FAILED;
690 }
691 if (!data.WriteParcelable(&(abilitySessionInfo->want))) {
692 WLOGFE("Write want info failed");
693 return WSError::WS_ERROR_IPC_FAILED;
694 }
695 if (abilitySessionInfo->callerToken) {
696 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->callerToken)) {
697 WLOGFE("Write ability info failed");
698 return WSError::WS_ERROR_IPC_FAILED;
699 }
700 } else {
701 if (!data.WriteBool(false)) {
702 WLOGFE("Write ability info failed");
703 return WSError::WS_ERROR_IPC_FAILED;
704 }
705 }
706 if (abilitySessionInfo->sessionToken) {
707 if (!data.WriteBool(true) || !data.WriteRemoteObject(abilitySessionInfo->sessionToken)) {
708 WLOGFE("Write ability sessionToken failed");
709 return WSError::WS_ERROR_IPC_FAILED;
710 }
711 } else {
712 if (!data.WriteBool(false)) {
713 WLOGFE("Write ability sessionToken failed");
714 return WSError::WS_ERROR_IPC_FAILED;
715 }
716 }
717 if (!data.WriteBool(needStartCaller) || !data.WriteInt32(abilitySessionInfo->resultCode)) {
718 WLOGFE("Write needStartCaller or result code failed");
719 return WSError::WS_ERROR_IPC_FAILED;
720 }
721 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_TERMINATE_SESSION_NEW),
722 data, reply, option) != ERR_NONE) {
723 WLOGFE("SendRequest failed");
724 return WSError::WS_ERROR_IPC_FAILED;
725 }
726 return static_cast<WSError>(reply.ReadInt32());
727 }
728
GetFocusSessionToken(sptr<IRemoteObject> & token)729 WSError SceneSessionManagerProxy::GetFocusSessionToken(sptr<IRemoteObject> &token)
730 {
731 WLOGFI("run SceneSessionManagerProxy::GetFocusSessionToken");
732 MessageParcel data;
733 MessageParcel reply;
734 MessageOption option;
735 if (!data.WriteInterfaceToken(GetDescriptor())) {
736 WLOGFE("Write interfaceToken failed");
737 return WSError::WS_ERROR_IPC_FAILED;
738 }
739
740 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
741 data, reply, option) != ERR_NONE) {
742 WLOGFE("SendRequest failed");
743 return WSError::WS_ERROR_IPC_FAILED;
744 }
745
746 token = reply.ReadRemoteObject();
747 if (token == nullptr) {
748 WLOGFE("get token nullptr.");
749 }
750 return static_cast<WSError>(reply.ReadInt32());
751 }
752
GetSessionDumpInfo(const std::vector<std::string> & params,std::string & info)753 WSError SceneSessionManagerProxy::GetSessionDumpInfo(const std::vector<std::string>& params, std::string& info)
754 {
755 MessageParcel data;
756 MessageParcel reply;
757 MessageOption option;
758 if (!data.WriteInterfaceToken(GetDescriptor())) {
759 WLOGFE("WriteInterfaceToken failed");
760 return WSError::WS_ERROR_INVALID_PARAM;
761 }
762 if (!data.WriteStringVector(params)) {
763 WLOGFE("Write params failed");
764 return WSError::WS_ERROR_IPC_FAILED;
765 }
766 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_DUMP_INFO),
767 data, reply, option) != ERR_NONE) {
768 WLOGFE("SendRequest failed");
769 return WSError::WS_ERROR_IPC_FAILED;
770 }
771 info = reply.ReadString();
772 return static_cast<WSError>(reply.ReadInt32());
773 }
774
GetSessionSnapshot(const std::string & deviceId,int32_t persistentId,std::shared_ptr<Media::PixelMap> & snapshot,bool isLowResolution)775 WSError SceneSessionManagerProxy::GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
776 std::shared_ptr<Media::PixelMap> &snapshot, bool isLowResolution)
777 {
778 MessageParcel data;
779 MessageParcel reply;
780 MessageOption option;
781 if (!data.WriteInterfaceToken(GetDescriptor())) {
782 WLOGFE("WriteInterfaceToken failed");
783 return WSError::WS_ERROR_INVALID_PARAM;
784 }
785 if (!data.WriteString(deviceId)) {
786 WLOGFE("Write deviceId failed.");
787 return WSError::WS_ERROR_IPC_FAILED;
788 }
789 if (!data.WriteInt32(persistentId)) {
790 WLOGFE("Write persistentId failed");
791 return WSError::WS_ERROR_INVALID_PARAM;
792 }
793
794 if (!data.WriteBool(isLowResolution)) {
795 WLOGFE("Write isLowResolution failed");
796 return WSError::WS_ERROR_INVALID_PARAM;
797 }
798
799 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
800 data, reply, option) != ERR_NONE) {
801 WLOGFE("SendRequest failed");
802 return WSError::WS_ERROR_IPC_FAILED;
803 }
804 std::shared_ptr<Media::PixelMap> sessionSnapshot(reply.ReadParcelable<Media::PixelMap>());
805 snapshot = sessionSnapshot;
806 return static_cast<WSError>(reply.ReadInt32());
807 }
808
SetSessionContinueState(const sptr<IRemoteObject> & token,const ContinueState & continueState)809 WSError SceneSessionManagerProxy::SetSessionContinueState(const sptr<IRemoteObject> &token,
810 const ContinueState& continueState)
811 {
812 MessageParcel data;
813 MessageParcel reply;
814 MessageOption option;
815 if (!data.WriteInterfaceToken(GetDescriptor())) {
816 WLOGFE("WriteInterfaceToken failed");
817 return WSError::WS_ERROR_INVALID_PARAM;
818 }
819 if (!data.WriteRemoteObject(token)) {
820 WLOGFE("Write token failed");
821 return WSError::WS_ERROR_IPC_FAILED;
822 }
823 if (!data.WriteInt32(static_cast<int32_t>(continueState))) {
824 WLOGFE("Write continueState failed");
825 return WSError::WS_ERROR_IPC_FAILED;
826 }
827 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
828 data, reply, option) != ERR_NONE) {
829 WLOGFE("SendRequest failed");
830 return WSError::WS_ERROR_IPC_FAILED;
831 }
832 return static_cast<WSError>(reply.ReadInt32());
833 }
834
NotifyDumpInfoResult(const std::vector<std::string> & info)835 void SceneSessionManagerProxy::NotifyDumpInfoResult(const std::vector<std::string>& info)
836 {
837 MessageParcel data;
838 MessageParcel reply;
839 MessageOption option(MessageOption::TF_ASYNC);
840 if (!data.WriteInterfaceToken(GetDescriptor())) {
841 WLOGFE("WriteInterfaceToken pfailed");
842 return;
843 }
844 if (!data.WriteStringVector(info)) {
845 WLOGFE("Write info failed");
846 return;
847 }
848 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
849 data, reply, option) != ERR_NONE) {
850 WLOGFE("SendRequest failed");
851 return;
852 }
853 }
854
ClearSession(int32_t persistentId)855 WSError SceneSessionManagerProxy::ClearSession(int32_t persistentId)
856 {
857 WLOGFI("run SceneSessionManagerProxy::ClearSession");
858 MessageParcel data;
859 MessageParcel reply;
860 MessageOption option;
861 if (!data.WriteInterfaceToken(GetDescriptor())) {
862 WLOGFE("ClearSession WriteInterfaceToken failed");
863 return WSError::WS_ERROR_INVALID_PARAM;
864 }
865
866 if (!data.WriteInt32(persistentId)) {
867 WLOGFE("Write persistentId failed");
868 return WSError::WS_ERROR_INVALID_PARAM;
869 }
870
871 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_SESSION),
872 data, reply, option) != ERR_NONE) {
873 WLOGFE("SendRequest failed");
874 return WSError::WS_ERROR_IPC_FAILED;
875 }
876 return static_cast<WSError>(reply.ReadInt32());
877 }
878
ClearAllSessions()879 WSError SceneSessionManagerProxy::ClearAllSessions()
880 {
881 WLOGFI("run SceneSessionManagerProxy::ClearSession");
882 MessageParcel data;
883 MessageParcel reply;
884 MessageOption option;
885 if (!data.WriteInterfaceToken(GetDescriptor())) {
886 WLOGFE("ClearAllSessions WriteInterfaceToken failed");
887 return WSError::WS_ERROR_INVALID_PARAM;
888 }
889
890 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
891 data, reply, option) != ERR_NONE) {
892 WLOGFE("SendRequest failed");
893 return WSError::WS_ERROR_IPC_FAILED;
894 }
895 return static_cast<WSError>(reply.ReadInt32());
896 }
897
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)898 WSError SceneSessionManagerProxy::RegisterIAbilityManagerCollaborator(int32_t type, const sptr<AAFwk::IAbilityManagerCollaborator> &impl)
899 {
900 WLOGFI("run SceneSessionManagerProxy::RegisterIAbilityManagerCollaborator");
901 if (!impl) {
902 WLOGFE("impl is nullptr");
903 return WSError::WS_ERROR_INVALID_PARAM;
904 }
905 MessageParcel data;
906 MessageParcel reply;
907 MessageOption option;
908
909 if (!data.WriteInterfaceToken(GetDescriptor())) {
910 WLOGFE("Write interface token failed.");
911 return WSError::WS_ERROR_INVALID_PARAM;
912 }
913 if (!data.WriteInt32(type)) {
914 WLOGFE("type write failed.");
915 return WSError::WS_ERROR_INVALID_PARAM;
916 }
917 if (!data.WriteRemoteObject(impl->AsObject())) {
918 WLOGFE("impl write failed.");
919 return WSError::WS_ERROR_INVALID_PARAM;
920 }
921
922 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_COLLABORATOR),
923 data, reply, option) != ERR_NONE) {
924 WLOGFE("SendRequest failed");
925 return WSError::WS_ERROR_IPC_FAILED;
926 }
927 return static_cast<WSError>(reply.ReadInt32());
928 }
929
UnregisterIAbilityManagerCollaborator(int32_t type)930 WSError SceneSessionManagerProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
931 {
932 WLOGFI("run SceneSessionManagerProxy::UnregisterIAbilityManagerCollaborator");
933 MessageParcel data;
934 MessageParcel reply;
935 MessageOption option;
936
937 if (!data.WriteInterfaceToken(GetDescriptor())) {
938 WLOGFE("Write interface token failed.");
939 return WSError::WS_ERROR_INVALID_PARAM;
940 }
941 if (!data.WriteInt32(type)) {
942 WLOGFE("type write failed.");
943 return WSError::WS_ERROR_INVALID_PARAM;
944 }
945
946 if (Remote()->SendRequest(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
947 data, reply, option) != ERR_NONE) {
948 WLOGFE("SendRequest failed");
949 return WSError::WS_ERROR_IPC_FAILED;
950 }
951 return static_cast<WSError>(reply.ReadInt32());
952 }
953 } // namespace OHOS::Rosen
954