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_lite_proxy.h"
17
18 #include "marshalling_helper.h"
19 #include "window_manager_hilog.h"
20
21 namespace OHOS::Rosen {
22 namespace {
23 constexpr int32_t CYCLE_LIMIT = 1000;
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerLiteProxy"};
25 constexpr int32_t MAX_TOPN_INFO_SIZE = 200;
26 }
27
SetSessionLabel(const sptr<IRemoteObject> & token,const std::string & label)28 WSError SceneSessionManagerLiteProxy::SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label)
29 {
30 WLOGFD("run SceneSessionManagerLiteProxy::SetSessionLabel");
31 MessageParcel data;
32 MessageParcel reply;
33 MessageOption option;
34 if (!data.WriteInterfaceToken(GetDescriptor())) {
35 WLOGFE("WriteInterfaceToken failed");
36 return WSError::WS_ERROR_IPC_FAILED;
37 }
38 if (!data.WriteRemoteObject(token)) {
39 WLOGFE("Write token failed");
40 return WSError::WS_ERROR_IPC_FAILED;
41 }
42 if (!data.WriteString(label)) {
43 WLOGFE("Write label failed");
44 return WSError::WS_ERROR_IPC_FAILED;
45 }
46
47 sptr<IRemoteObject> remote = Remote();
48 if (remote == nullptr) {
49 WLOGFE("remote is null");
50 return WSError::WS_ERROR_IPC_FAILED;
51 }
52 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_LABEL),
53 data, reply, option) != ERR_NONE) {
54 WLOGFE("SendRequest failed");
55 return WSError::WS_ERROR_IPC_FAILED;
56 }
57 return static_cast<WSError>(reply.ReadInt32());
58 }
59
SetSessionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & icon)60 WSError SceneSessionManagerLiteProxy::SetSessionIcon(const sptr<IRemoteObject>& token,
61 const std::shared_ptr<Media::PixelMap>& icon)
62 {
63 WLOGFD("run SceneSessionManagerLiteProxy::SetSessionIcon");
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option;
67 if (!data.WriteInterfaceToken(GetDescriptor())) {
68 WLOGFE("WriteInterfaceToken failed");
69 return WSError::WS_ERROR_IPC_FAILED;
70 }
71 if (!data.WriteRemoteObject(token)) {
72 WLOGFE("Write token failed");
73 return WSError::WS_ERROR_IPC_FAILED;
74 }
75 if (!data.WriteParcelable(icon.get())) {
76 WLOGFE("Write icon failed");
77 return WSError::WS_ERROR_IPC_FAILED;
78 }
79
80 sptr<IRemoteObject> remote = Remote();
81 if (remote == nullptr) {
82 WLOGFE("remote is null");
83 return WSError::WS_ERROR_IPC_FAILED;
84 }
85 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_ICON),
86 data, reply, option) != ERR_NONE) {
87 WLOGFE("SendRequest failed");
88 return WSError::WS_ERROR_IPC_FAILED;
89 }
90 return static_cast<WSError>(reply.ReadInt32());
91 }
92
IsValidSessionIds(const std::vector<int32_t> & sessionIds,std::vector<bool> & results)93 WSError SceneSessionManagerLiteProxy::IsValidSessionIds(
94 const std::vector<int32_t>& sessionIds, std::vector<bool>& results)
95 {
96 WLOGFD("run SceneSessionManagerLiteProxy::IsValidSessionIds");
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option;
100 if (!data.WriteInterfaceToken(GetDescriptor())) {
101 WLOGFE("WriteInterfaceToken failed");
102 return WSError::WS_ERROR_IPC_FAILED;
103 }
104 if (!data.WriteInt32Vector(sessionIds)) {
105 WLOGFE("Write sessionIds failed");
106 return WSError::WS_ERROR_IPC_FAILED;
107 }
108
109 sptr<IRemoteObject> remote = Remote();
110 if (remote == nullptr) {
111 WLOGFE("remote is null");
112 return WSError::WS_ERROR_IPC_FAILED;
113 }
114 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_IS_VALID_SESSION_IDS),
115 data, reply, option) != ERR_NONE) {
116 WLOGFE("SendRequest failed");
117 return WSError::WS_ERROR_IPC_FAILED;
118 }
119
120 reply.ReadBoolVector(&results);
121 return static_cast<WSError>(reply.ReadInt32());
122 }
123
PendingSessionToForeground(const sptr<IRemoteObject> & token)124 WSError SceneSessionManagerLiteProxy::PendingSessionToForeground(const sptr<IRemoteObject>& token)
125 {
126 WLOGFD("run SceneSessionManagerLiteProxy::PendingSessionToForeground");
127 MessageParcel data;
128 MessageParcel reply;
129 MessageOption option;
130 if (!data.WriteInterfaceToken(GetDescriptor())) {
131 WLOGFE("Write interfaceToken failed");
132 return WSError::WS_ERROR_IPC_FAILED;
133 }
134
135 if (!data.WriteRemoteObject(token)) {
136 WLOGFE("Write token failed");
137 return WSError::WS_ERROR_IPC_FAILED;
138 }
139
140 sptr<IRemoteObject> remote = Remote();
141 if (remote == nullptr) {
142 WLOGFE("remote is null");
143 return WSError::WS_ERROR_IPC_FAILED;
144 }
145 if (remote->SendRequest(static_cast<uint32_t>(
146 SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND),
147 data, reply, option) != ERR_NONE) {
148 WLOGFE("SendRequest failed");
149 return WSError::WS_ERROR_IPC_FAILED;
150 }
151 return static_cast<WSError>(reply.ReadInt32());
152 }
153
PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> & token,bool shouldBackToCaller)154 WSError SceneSessionManagerLiteProxy::PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject>& token,
155 bool shouldBackToCaller)
156 {
157 TLOGD(WmsLogTag::WMS_LIFE, "run");
158 MessageParcel data;
159 MessageParcel reply;
160 MessageOption option;
161 if (!data.WriteInterfaceToken(GetDescriptor())) {
162 TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
163 return WSError::WS_ERROR_IPC_FAILED;
164 }
165
166 if (!data.WriteRemoteObject(token)) {
167 TLOGE(WmsLogTag::WMS_LIFE, "Write token failed");
168 return WSError::WS_ERROR_IPC_FAILED;
169 }
170
171 if (!data.WriteBool(shouldBackToCaller)) {
172 TLOGE(WmsLogTag::WMS_LIFE, "Write shouldBackToCaller failed");
173 return WSError::WS_ERROR_IPC_FAILED;
174 }
175
176 sptr<IRemoteObject> remote = Remote();
177 if (remote == nullptr) {
178 TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
179 return WSError::WS_ERROR_IPC_FAILED;
180 }
181 if (remote->SendRequest(static_cast<uint32_t>(
182 SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR),
183 data, reply, option) != ERR_NONE) {
184 TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
185 return WSError::WS_ERROR_IPC_FAILED;
186 }
187 return static_cast<WSError>(reply.ReadInt32());
188 }
189
RegisterSessionListener(const sptr<ISessionListener> & listener)190 WSError SceneSessionManagerLiteProxy::RegisterSessionListener(const sptr<ISessionListener>& listener)
191 {
192 WLOGFD("run SceneSessionManagerLiteProxy::RegisterSessionListener");
193 MessageParcel data;
194 MessageParcel reply;
195 MessageOption option(MessageOption::TF_SYNC);
196 if (listener == nullptr) {
197 WLOGFE("register mission listener, listener is nullptr");
198 return WSError::WS_ERROR_INVALID_PARAM;
199 }
200 if (!data.WriteInterfaceToken(GetDescriptor())) {
201 WLOGFE("WriteInterfaceToken failed");
202 return WSError::WS_ERROR_IPC_FAILED;
203 }
204 if (!data.WriteRemoteObject(listener->AsObject())) {
205 WLOGFE("write mission listener failed when register mission listener.");
206 return WSError::WS_ERROR_IPC_FAILED;
207 }
208 sptr<IRemoteObject> remote = Remote();
209 if (remote == nullptr) {
210 WLOGFE("remote is null");
211 return WSError::WS_ERROR_IPC_FAILED;
212 }
213 if (remote->SendRequest(static_cast<uint32_t>(
214 SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LISTENER),
215 data, reply, option) != ERR_NONE) {
216 WLOGFE("SendRequest failed");
217 return WSError::WS_ERROR_IPC_FAILED;
218 }
219 return static_cast<WSError>(reply.ReadInt32());
220 }
221
UnRegisterSessionListener(const sptr<ISessionListener> & listener)222 WSError SceneSessionManagerLiteProxy::UnRegisterSessionListener(const sptr<ISessionListener>& listener)
223 {
224 WLOGFD("run SceneSessionManagerLiteProxy::UnRegisterSessionListener");
225 if (listener == nullptr) {
226 WLOGFE("unregister mission listener, listener is nullptr");
227 return WSError::WS_ERROR_INVALID_PARAM;
228 }
229 MessageParcel data;
230 MessageParcel reply;
231 MessageOption option(MessageOption::TF_SYNC);
232 if (!data.WriteInterfaceToken(GetDescriptor())) {
233 WLOGFE("WriteInterfaceToken failed");
234 return WSError::WS_ERROR_IPC_FAILED;
235 }
236 if (!data.WriteRemoteObject(listener->AsObject())) {
237 WLOGFE("write mission listener failed when unregister mission listener.");
238 return WSError::WS_ERROR_IPC_FAILED;
239 }
240 sptr<IRemoteObject> remote = Remote();
241 if (remote == nullptr) {
242 WLOGFE("remote is null");
243 return WSError::WS_ERROR_IPC_FAILED;
244 }
245 if (remote->SendRequest(
246 static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER),
247 data, reply, option) != ERR_NONE) {
248 WLOGFE("SendRequest failed");
249 return WSError::WS_ERROR_IPC_FAILED;
250 }
251 return static_cast<WSError>(reply.ReadInt32());
252 }
253
GetSessionInfos(const std::string & deviceId,int32_t numMax,std::vector<SessionInfoBean> & sessionInfos)254 WSError SceneSessionManagerLiteProxy::GetSessionInfos(const std::string& deviceId, int32_t numMax,
255 std::vector<SessionInfoBean>& sessionInfos)
256 {
257 WLOGFD("run SceneSessionManagerLiteProxy::GetSessionInfos");
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option(MessageOption::TF_SYNC);
261 if (!data.WriteInterfaceToken(GetDescriptor())) {
262 WLOGFE("WriteInterfaceToken failed");
263 return WSError::WS_ERROR_IPC_FAILED;
264 }
265 if (!data.WriteString16(Str8ToStr16(deviceId))) {
266 WLOGFE("GetSessionInfos write deviceId failed.");
267 return WSError::WS_ERROR_IPC_FAILED;
268 }
269 if (!data.WriteInt32(numMax)) {
270 WLOGFE("GetSessionInfos numMax write failed.");
271 return WSError::WS_ERROR_IPC_FAILED;
272 }
273 sptr<IRemoteObject> remote = Remote();
274 if (remote == nullptr) {
275 WLOGFE("remote is null");
276 return WSError::WS_ERROR_IPC_FAILED;
277 }
278 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFOS),
279 data, reply, option) != ERR_NONE) {
280 WLOGFE("SendRequest failed");
281 return WSError::WS_ERROR_IPC_FAILED;
282 }
283 WSError error = GetParcelableInfos(reply, sessionInfos);
284 if (error != WSError::WS_OK) {
285 WLOGFE("GetSessionInfos error");
286 return error;
287 }
288 return static_cast<WSError>(reply.ReadInt32());
289 }
290
GetMainWindowStatesByPid(int32_t pid,std::vector<MainWindowState> & windowStates)291 WSError SceneSessionManagerLiteProxy::GetMainWindowStatesByPid(int32_t pid, std::vector<MainWindowState>& windowStates)
292 {
293 TLOGD(WmsLogTag::WMS_LIFE, "run");
294 sptr<IRemoteObject> remote = Remote();
295 if (remote == nullptr) {
296 TLOGE(WmsLogTag::WMS_LIFE, "remote is nullptr");
297 return WSError::WS_ERROR_IPC_FAILED;
298 }
299 MessageParcel data;
300 MessageParcel reply;
301 MessageOption option(MessageOption::TF_SYNC);
302 if (!data.WriteInterfaceToken(GetDescriptor())) {
303 TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
304 return WSError::WS_ERROR_IPC_FAILED;
305 }
306 if (!data.WriteInt32(pid)) {
307 TLOGE(WmsLogTag::WMS_LIFE, "write pid failed");
308 return WSError::WS_ERROR_IPC_FAILED;
309 }
310 if (remote->SendRequest(
311 static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MAIN_WINDOW_STATES_BY_PID),
312 data, reply, option) != ERR_NONE) {
313 TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
314 return WSError::WS_ERROR_IPC_FAILED;
315 }
316 WSError error = GetParcelableInfos(reply, windowStates);
317 if (error != WSError::WS_OK) {
318 TLOGE(WmsLogTag::WMS_LIFE, "GetWindowStates error");
319 return error;
320 }
321 return static_cast<WSError>(reply.ReadInt32());
322 }
323
GetSessionInfo(const std::string & deviceId,int32_t persistentId,SessionInfoBean & sessionInfo)324 WSError SceneSessionManagerLiteProxy::GetSessionInfo(const std::string& deviceId, int32_t persistentId,
325 SessionInfoBean& sessionInfo)
326 {
327 WLOGFD("run SceneSessionManagerLiteProxy::GetSessionInfo");
328 MessageParcel data;
329 MessageParcel reply;
330 MessageOption option(MessageOption::TF_SYNC);
331 if (!data.WriteInterfaceToken(GetDescriptor())) {
332 WLOGFE("WriteInterfaceToken failed");
333 return WSError::WS_ERROR_IPC_FAILED;
334 }
335 if (!data.WriteString16(Str8ToStr16(deviceId))) {
336 WLOGFE("GetSessionInfo write deviceId failed.");
337 return WSError::WS_ERROR_IPC_FAILED;
338 }
339 if (!data.WriteInt32(persistentId)) {
340 WLOGFE("GetSessionInfo write persistentId failed.");
341 return WSError::WS_ERROR_IPC_FAILED;
342 }
343 sptr<IRemoteObject> remote = Remote();
344 if (remote == nullptr) {
345 WLOGFE("remote is null");
346 return WSError::WS_ERROR_IPC_FAILED;
347 }
348 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFO_BY_ID),
349 data, reply, option) != ERR_NONE) {
350 WLOGFE("SendRequest failed");
351 return WSError::WS_ERROR_IPC_FAILED;
352 }
353 std::unique_ptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
354 if (info == nullptr) {
355 WLOGFE("read missioninfo failed.");
356 return WSError::WS_ERROR_IPC_FAILED;
357 }
358 sessionInfo = *info;
359 return static_cast<WSError>(reply.ReadInt32());
360 }
361
GetSessionInfoByContinueSessionId(const std::string & continueSessionId,SessionInfoBean & sessionInfo)362 WSError SceneSessionManagerLiteProxy::GetSessionInfoByContinueSessionId(
363 const std::string& continueSessionId, SessionInfoBean& sessionInfo)
364 {
365 TLOGI(WmsLogTag::WMS_LIFE, "continueSessionId: %{public}s", continueSessionId.c_str());
366 MessageParcel data;
367 MessageParcel reply;
368 MessageOption option(MessageOption::TF_SYNC);
369 if (!data.WriteInterfaceToken(GetDescriptor())) {
370 TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
371 return WSError::WS_ERROR_IPC_FAILED;
372 }
373 if (!data.WriteString(continueSessionId)) {
374 TLOGE(WmsLogTag::WMS_LIFE, "GetSessionInfoByContinueSessionId write continueSessionId failed.");
375 return WSError::WS_ERROR_IPC_FAILED;
376 }
377 sptr<IRemoteObject> remote = Remote();
378 if (remote == nullptr) {
379 TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
380 return WSError::WS_ERROR_IPC_FAILED;
381 }
382 if (remote->SendRequest(static_cast<uint32_t>(
383 SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_INFO_BY_CONTINUE_SESSION_ID),
384 data, reply, option) != ERR_NONE) {
385 TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
386 return WSError::WS_ERROR_IPC_FAILED;
387 }
388 sptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
389 if (info == nullptr) {
390 TLOGE(WmsLogTag::WMS_LIFE, "read sessioninfo failed.");
391 return WSError::WS_ERROR_IPC_FAILED;
392 }
393 sessionInfo = *info;
394 return static_cast<WSError>(reply.ReadInt32());
395 }
396
397 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)398 WSError SceneSessionManagerLiteProxy::GetParcelableInfos(MessageParcel& reply, std::vector<T>& parcelableInfos)
399 {
400 int32_t infoSize = reply.ReadInt32();
401 if (infoSize > CYCLE_LIMIT) {
402 WLOGFE("infoSize is too large");
403 return WSError::WS_ERROR_IPC_FAILED;
404 }
405
406 for (int32_t i = 0; i < infoSize; i++) {
407 std::unique_ptr<T> info(reply.ReadParcelable<T>());
408 if (!info) {
409 WLOGFE("Read Parcelable infos failed.");
410 return WSError::WS_ERROR_IPC_FAILED;
411 }
412 parcelableInfos.emplace_back(*info);
413 }
414 return WSError::WS_OK;
415 }
416
TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needStartCaller,bool isFromBroker)417 WSError SceneSessionManagerLiteProxy::TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,
418 bool needStartCaller, bool isFromBroker)
419 {
420 if (abilitySessionInfo == nullptr) {
421 WLOGFE("abilitySessionInfo is null");
422 return WSError::WS_ERROR_INVALID_SESSION;
423 }
424 MessageParcel data, reply;
425 MessageOption option(MessageOption::TF_ASYNC);
426 if (!data.WriteInterfaceToken(GetDescriptor())) {
427 WLOGFE("WriteInterfaceToken failed");
428 return WSError::WS_ERROR_IPC_FAILED;
429 }
430 if (!data.WriteParcelable(abilitySessionInfo)) {
431 WLOGFE("write abilitySessionInfo failed");
432 return WSError::WS_ERROR_IPC_FAILED;
433 }
434 if (!data.WriteBool(needStartCaller)) {
435 WLOGFE("Write needStartCaller failed");
436 return WSError::WS_ERROR_IPC_FAILED;
437 }
438 if (!data.WriteBool(isFromBroker)) {
439 WLOGFE("Write isFromBroker failed");
440 return WSError::WS_ERROR_IPC_FAILED;
441 }
442 sptr<IRemoteObject> remote = Remote();
443 if (remote == nullptr) {
444 WLOGFE("remote is null");
445 return WSError::WS_ERROR_IPC_FAILED;
446 }
447 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_NEW),
448 data, reply, option) != ERR_NONE) {
449 WLOGFE("SendRequest failed");
450 return WSError::WS_ERROR_IPC_FAILED;
451 }
452 return static_cast<WSError>(reply.ReadInt32());
453 }
454
GetFocusSessionToken(sptr<IRemoteObject> & token)455 WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr<IRemoteObject>& token)
456 {
457 WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionToken");
458 MessageParcel data;
459 MessageParcel reply;
460 MessageOption option;
461 if (!data.WriteInterfaceToken(GetDescriptor())) {
462 WLOGFE("Write interfaceToken failed");
463 return WSError::WS_ERROR_IPC_FAILED;
464 }
465
466 sptr<IRemoteObject> remote = Remote();
467 if (remote == nullptr) {
468 WLOGFE("remote is null");
469 return WSError::WS_ERROR_IPC_FAILED;
470 }
471 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
472 data, reply, option) != ERR_NONE) {
473 WLOGFE("SendRequest failed");
474 return WSError::WS_ERROR_IPC_FAILED;
475 }
476 token = reply.ReadRemoteObject();
477 if (token == nullptr) {
478 WLOGFE("get token nullptr.");
479 }
480 return static_cast<WSError>(reply.ReadInt32());
481 }
482
GetFocusSessionElement(AppExecFwk::ElementName & element)483 WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::ElementName& element)
484 {
485 WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionElement");
486 MessageParcel data;
487 MessageParcel reply;
488 MessageOption option;
489 if (!data.WriteInterfaceToken(GetDescriptor())) {
490 WLOGFE("Write interfaceToken failed");
491 return WSError::WS_ERROR_IPC_FAILED;
492 }
493 sptr<IRemoteObject> remote = Remote();
494 if (remote == nullptr) {
495 WLOGFE("remote is null");
496 return WSError::WS_ERROR_IPC_FAILED;
497 }
498 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT),
499 data, reply, option) != ERR_NONE) {
500 WLOGFE("SendRequest failed");
501 return WSError::WS_ERROR_IPC_FAILED;
502 }
503 sptr<AppExecFwk::ElementName> ret = reply.ReadParcelable<AppExecFwk::ElementName>();
504 if (ret) {
505 element = *ret;
506 } else {
507 WLOGFD("get element null.");
508 }
509 return static_cast<WSError>(reply.ReadInt32());
510 }
511
GetSessionSnapshot(const std::string & deviceId,int32_t persistentId,SessionSnapshot & snapshot,bool isLowResolution)512 WSError SceneSessionManagerLiteProxy::GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
513 SessionSnapshot& snapshot, bool isLowResolution)
514 {
515 MessageParcel data;
516 MessageParcel reply;
517 MessageOption option;
518 if (!data.WriteInterfaceToken(GetDescriptor())) {
519 WLOGFE("WriteInterfaceToken failed");
520 return WSError::WS_ERROR_INVALID_PARAM;
521 }
522 if (!data.WriteString16(Str8ToStr16(deviceId))) {
523 WLOGFE("Write deviceId failed.");
524 return WSError::WS_ERROR_IPC_FAILED;
525 }
526 if (!data.WriteInt32(persistentId)) {
527 WLOGFE("Write persistentId failed");
528 return WSError::WS_ERROR_INVALID_PARAM;
529 }
530
531 if (!data.WriteBool(isLowResolution)) {
532 WLOGFE("Write isLowResolution failed");
533 return WSError::WS_ERROR_INVALID_PARAM;
534 }
535
536 sptr<IRemoteObject> remote = Remote();
537 if (remote == nullptr) {
538 WLOGFE("remote is null");
539 return WSError::WS_ERROR_IPC_FAILED;
540 }
541 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
542 data, reply, option) != ERR_NONE) {
543 WLOGFE("SendRequest failed");
544 return WSError::WS_ERROR_IPC_FAILED;
545 }
546 std::unique_ptr<SessionSnapshot> info(reply.ReadParcelable<SessionSnapshot>());
547 if (info) {
548 snapshot = *info;
549 } else {
550 WLOGFW("Read SessionSnapshot is null.");
551 }
552 return static_cast<WSError>(reply.ReadInt32());
553 }
554
SetSessionContinueState(const sptr<IRemoteObject> & token,const ContinueState & continueState)555 WSError SceneSessionManagerLiteProxy::SetSessionContinueState(const sptr<IRemoteObject>& token,
556 const ContinueState& continueState)
557 {
558 MessageParcel data;
559 MessageParcel reply;
560 MessageOption option;
561 if (!data.WriteInterfaceToken(GetDescriptor())) {
562 WLOGFE("WriteInterfaceToken failed");
563 return WSError::WS_ERROR_INVALID_PARAM;
564 }
565 if (!data.WriteRemoteObject(token)) {
566 WLOGFE("Write token failed");
567 return WSError::WS_ERROR_IPC_FAILED;
568 }
569 if (!data.WriteInt32(static_cast<int32_t>(continueState))) {
570 WLOGFE("Write continueState failed");
571 return WSError::WS_ERROR_IPC_FAILED;
572 }
573 sptr<IRemoteObject> remote = Remote();
574 if (remote == nullptr) {
575 WLOGFE("remote is null");
576 return WSError::WS_ERROR_IPC_FAILED;
577 }
578 if (remote->SendRequest(static_cast<uint32_t>(
579 SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
580 data, reply, option) != ERR_NONE) {
581 WLOGFE("SendRequest failed");
582 return WSError::WS_ERROR_IPC_FAILED;
583 }
584 return static_cast<WSError>(reply.ReadInt32());
585 }
586
LockSession(int32_t sessionId)587 WSError SceneSessionManagerLiteProxy::LockSession(int32_t sessionId)
588 {
589 WLOGFD("run SceneSessionManagerLiteProxy::LockSession");
590 MessageParcel data;
591 MessageParcel reply;
592 MessageOption option;
593
594 if (!data.WriteInterfaceToken(GetDescriptor())) {
595 WLOGFE("Write interface token failed.");
596 return WSError::WS_ERROR_INVALID_PARAM;
597 }
598 if (!data.WriteInt32(sessionId)) {
599 WLOGFE("Write persistentId failed");
600 return WSError::WS_ERROR_INVALID_PARAM;
601 }
602 sptr<IRemoteObject> remote = Remote();
603 if (remote == nullptr) {
604 WLOGFE("remote is null");
605 return WSError::WS_ERROR_IPC_FAILED;
606 }
607 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION),
608 data, reply, option) != ERR_NONE) {
609 WLOGFE("SendRequest failed");
610 return WSError::WS_ERROR_IPC_FAILED;
611 }
612 return static_cast<WSError>(reply.ReadInt32());
613 }
614
UnlockSession(int32_t sessionId)615 WSError SceneSessionManagerLiteProxy::UnlockSession(int32_t sessionId)
616 {
617 WLOGFD("run SceneSessionManagerLiteProxy::UnlockSession");
618 MessageParcel data;
619 MessageParcel reply;
620 MessageOption option;
621
622 if (!data.WriteInterfaceToken(GetDescriptor())) {
623 WLOGFE("Write interface token failed.");
624 return WSError::WS_ERROR_INVALID_PARAM;
625 }
626 if (!data.WriteInt32(sessionId)) {
627 WLOGFE("Write persistentId failed");
628 return WSError::WS_ERROR_INVALID_PARAM;
629 }
630 sptr<IRemoteObject> remote = Remote();
631 if (remote == nullptr) {
632 WLOGFE("remote is null");
633 return WSError::WS_ERROR_IPC_FAILED;
634 }
635 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION),
636 data, reply, option) != ERR_NONE) {
637 WLOGFE("SendRequest failed");
638 return WSError::WS_ERROR_IPC_FAILED;
639 }
640 return static_cast<WSError>(reply.ReadInt32());
641 }
642
MoveSessionsToForeground(const std::vector<std::int32_t> & sessionIds,int32_t topSessionId)643 WSError SceneSessionManagerLiteProxy::MoveSessionsToForeground(const std::vector<std::int32_t>& sessionIds,
644 int32_t topSessionId)
645 {
646 WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToForeground");
647 MessageParcel data;
648 MessageParcel reply;
649 MessageOption option;
650 if (!data.WriteInterfaceToken(GetDescriptor())) {
651 WLOGFE("WriteInterfaceToken failed");
652 return WSError::WS_ERROR_INVALID_PARAM;
653 }
654 if (!data.WriteInt32Vector(sessionIds)) {
655 WLOGFE("Write sessionIds failed");
656 return WSError::WS_ERROR_INVALID_PARAM;
657 }
658 if (!data.WriteInt32(topSessionId)) {
659 WLOGFE("Write topSessionId failed");
660 return WSError::WS_ERROR_INVALID_PARAM;
661 }
662 sptr<IRemoteObject> remote = Remote();
663 if (remote == nullptr) {
664 WLOGFE("remote is null");
665 return WSError::WS_ERROR_IPC_FAILED;
666 }
667 if (remote->SendRequest(static_cast<uint32_t>(
668 SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND),
669 data, reply, option) != ERR_NONE) {
670 WLOGFE("SendRequest failed");
671 return WSError::WS_ERROR_IPC_FAILED;
672 }
673 return static_cast<WSError>(reply.ReadInt32());
674 }
675
MoveSessionsToBackground(const std::vector<std::int32_t> & sessionIds,std::vector<int32_t> & result)676 WSError SceneSessionManagerLiteProxy::MoveSessionsToBackground(const std::vector<std::int32_t>& sessionIds,
677 std::vector<int32_t>& result)
678 {
679 WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToBackground");
680 MessageParcel data;
681 MessageParcel reply;
682 MessageOption option;
683 if (!data.WriteInterfaceToken(GetDescriptor())) {
684 WLOGFE("WriteInterfaceToken failed");
685 return WSError::WS_ERROR_INVALID_PARAM;
686 }
687 if (!data.WriteInt32Vector(sessionIds)) {
688 WLOGFE("Write sessionIds failed");
689 return WSError::WS_ERROR_INVALID_PARAM;
690 }
691 if (!data.WriteInt32Vector(result)) {
692 WLOGFE("Write result failed");
693 return WSError::WS_ERROR_INVALID_PARAM;
694 }
695 sptr<IRemoteObject> remote = Remote();
696 if (remote == nullptr) {
697 WLOGFE("remote is null");
698 return WSError::WS_ERROR_IPC_FAILED;
699 }
700 if (remote->SendRequest(static_cast<uint32_t>(
701 SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND),
702 data, reply, option) != ERR_NONE) {
703 WLOGFE("SendRequest failed");
704 return WSError::WS_ERROR_IPC_FAILED;
705 }
706 reply.ReadInt32Vector(&result);
707 return static_cast<WSError>(reply.ReadInt32());
708 }
709
ClearSession(int32_t persistentId)710 WSError SceneSessionManagerLiteProxy::ClearSession(int32_t persistentId)
711 {
712 WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
713 MessageParcel data;
714 MessageParcel reply;
715 MessageOption option;
716 if (!data.WriteInterfaceToken(GetDescriptor())) {
717 WLOGFE("ClearSession WriteInterfaceToken failed");
718 return WSError::WS_ERROR_INVALID_PARAM;
719 }
720
721 if (!data.WriteInt32(persistentId)) {
722 WLOGFE("Write persistentId failed");
723 return WSError::WS_ERROR_INVALID_PARAM;
724 }
725
726 sptr<IRemoteObject> remote = Remote();
727 if (remote == nullptr) {
728 WLOGFE("remote is null");
729 return WSError::WS_ERROR_IPC_FAILED;
730 }
731 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_SESSION),
732 data, reply, option) != ERR_NONE) {
733 WLOGFE("SendRequest failed");
734 return WSError::WS_ERROR_IPC_FAILED;
735 }
736 return static_cast<WSError>(reply.ReadInt32());
737 }
738
ClearAllSessions()739 WSError SceneSessionManagerLiteProxy::ClearAllSessions()
740 {
741 WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
742 MessageParcel data;
743 MessageParcel reply;
744 MessageOption option;
745 if (!data.WriteInterfaceToken(GetDescriptor())) {
746 WLOGFE("ClearAllSessions WriteInterfaceToken failed");
747 return WSError::WS_ERROR_INVALID_PARAM;
748 }
749
750 sptr<IRemoteObject> remote = Remote();
751 if (remote == nullptr) {
752 WLOGFE("remote is null");
753 return WSError::WS_ERROR_IPC_FAILED;
754 }
755 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
756 data, reply, option) != ERR_NONE) {
757 WLOGFE("SendRequest failed");
758 return WSError::WS_ERROR_IPC_FAILED;
759 }
760 return static_cast<WSError>(reply.ReadInt32());
761 }
762
GetFocusWindowInfo(FocusChangeInfo & focusInfo)763 void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo)
764 {
765 WLOGFI("get focus Winow info lite proxy");
766 MessageParcel data;
767 MessageParcel reply;
768 MessageOption option;
769 if (!data.WriteInterfaceToken(GetDescriptor())) {
770 WLOGFE("WriteInterfaceToken failed");
771 return;
772 }
773
774 sptr<IRemoteObject> remote = Remote();
775 if (remote == nullptr) {
776 WLOGFE("remote is null");
777 return;
778 }
779 if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
780 data, reply, option) != ERR_NONE) {
781 WLOGFE("SendRequest failed");
782 return;
783 }
784 sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
785 if (info) {
786 focusInfo = *info;
787 } else {
788 WLOGFE("info is null.");
789 }
790 }
791
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)792 WMError SceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
793 const sptr<IWindowManagerAgent>& windowManagerAgent)
794 {
795 MessageOption option;
796 MessageParcel reply;
797 MessageParcel data;
798 if (!data.WriteInterfaceToken(GetDescriptor())) {
799 WLOGFE("Write InterfaceToken failed");
800 return WMError::WM_ERROR_IPC_FAILED;
801 }
802
803 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
804 WLOGFE("Write type failed");
805 return WMError::WM_ERROR_IPC_FAILED;
806 }
807
808 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
809 WLOGFE("Write IWindowManagerAgent failed");
810 return WMError::WM_ERROR_IPC_FAILED;
811 }
812
813 sptr<IRemoteObject> remote = Remote();
814 if (remote == nullptr) {
815 WLOGFE("remote is nullptr");
816 return WMError::WM_ERROR_NULLPTR;
817 }
818 if (remote->SendRequest(static_cast<uint32_t>(
819 SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
820 WLOGFE("SendRequest failed");
821 return WMError::WM_ERROR_IPC_FAILED;
822 }
823
824 return static_cast<WMError>(reply.ReadInt32());
825 }
826
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)827 WMError SceneSessionManagerLiteProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
828 const sptr<IWindowManagerAgent>& windowManagerAgent)
829 {
830 MessageParcel reply;
831 MessageOption option;
832 MessageParcel data;
833 if (!data.WriteInterfaceToken(GetDescriptor())) {
834 WLOGFE("Write InterfaceToken failed");
835 return WMError::WM_ERROR_IPC_FAILED;
836 }
837
838 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
839 WLOGFE("Write type failed");
840 return WMError::WM_ERROR_IPC_FAILED;
841 }
842
843 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
844 WLOGFE("Write IWindowManagerAgent failed");
845 return WMError::WM_ERROR_IPC_FAILED;
846 }
847
848 sptr<IRemoteObject> remote = Remote();
849 if (remote == nullptr) {
850 WLOGFE("remote is nullptr");
851 return WMError::WM_ERROR_NULLPTR;
852 }
853 if (remote->SendRequest(static_cast<uint32_t>(
854 SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
855 WLOGFE("SendRequest failed");
856 return WMError::WM_ERROR_IPC_FAILED;
857 }
858
859 return static_cast<WMError>(reply.ReadInt32());
860 }
861
CheckWindowId(int32_t windowId,int32_t & pid)862 WMError SceneSessionManagerLiteProxy::CheckWindowId(int32_t windowId, int32_t& pid)
863 {
864 MessageParcel data;
865 MessageParcel reply;
866 MessageOption option;
867 if (!data.WriteInterfaceToken(GetDescriptor())) {
868 WLOGFE("Failed to write interfaceToken");
869 return WMError::WM_ERROR_IPC_FAILED;
870 }
871 if (!data.WriteInt32(windowId)) {
872 WLOGFE("Failed to write windowId");
873 return WMError::WM_ERROR_IPC_FAILED;
874 }
875 sptr<IRemoteObject> remote = Remote();
876 if (remote == nullptr) {
877 WLOGFE("remote is nullptr");
878 return WMError::WM_ERROR_NULLPTR;
879 }
880 int32_t ret = remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CHECK_WINDOW_ID),
881 data, reply, option);
882 if (ret != ERR_NONE) {
883 WLOGFE("Send request failed, ret:%{public}d", ret);
884 return WMError::WM_ERROR_IPC_FAILED;
885 }
886 if (!reply.ReadInt32(pid)) {
887 WLOGFE("Failed to read pid");
888 return WMError::WM_ERROR_IPC_FAILED;
889 }
890 return WMError::WM_OK;
891 }
892
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)893 WMError SceneSessionManagerLiteProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
894 {
895 MessageParcel data;
896 MessageParcel reply;
897 MessageOption option;
898 if (!data.WriteInterfaceToken(GetDescriptor())) {
899 WLOGFE("GetVisibilityWindowInfo Write interfaceToken failed");
900 return WMError::WM_ERROR_IPC_FAILED;
901 }
902
903 sptr<IRemoteObject> remote = Remote();
904 if (remote == nullptr) {
905 WLOGFE("remote is nullptr");
906 return WMError::WM_ERROR_NULLPTR;
907 }
908 if (remote->SendRequest(static_cast<uint32_t>(
909 SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) {
910 return WMError::WM_ERROR_IPC_FAILED;
911 }
912 if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
913 WLOGFE("read visibility window infos failed");
914 return WMError::WM_ERROR_IPC_FAILED;
915 }
916 return static_cast<WMError>(reply.ReadInt32());
917 }
918
GetWindowModeType(WindowModeType & windowModeType)919 WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowModeType)
920 {
921 WLOGFI("get Window mode type proxy");
922 MessageParcel data;
923 if (!data.WriteInterfaceToken(GetDescriptor())) {
924 WLOGFE("WriteInterfaceToken failed");
925 return WMError::WM_ERROR_IPC_FAILED;
926 }
927
928 MessageParcel reply;
929 MessageOption option;
930 sptr<IRemoteObject> remote = Remote();
931 if (remote == nullptr) {
932 WLOGFE("remote is null");
933 return WMError::WM_ERROR_IPC_FAILED;
934 }
935 if (remote->SendRequest(static_cast<uint32_t>(
936 SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE), data, reply, option) != ERR_NONE) {
937 WLOGFE("SendRequest failed");
938 return WMError::WM_ERROR_IPC_FAILED;
939 }
940
941 windowModeType = static_cast<WindowModeType>(reply.ReadUint32());
942 return static_cast<WMError>(reply.ReadInt32());
943 }
944
RaiseWindowToTop(int32_t persistentId)945 WSError SceneSessionManagerLiteProxy::RaiseWindowToTop(int32_t persistentId)
946 {
947 MessageParcel data;
948 MessageParcel reply;
949 MessageOption option(MessageOption::TF_SYNC);
950 if (!data.WriteInterfaceToken(GetDescriptor())) {
951 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
952 return WSError::WS_ERROR_IPC_FAILED;
953 }
954 if (!data.WriteInt32(persistentId)) {
955 TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
956 return WSError::WS_ERROR_IPC_FAILED;
957 }
958 sptr<IRemoteObject> remote = Remote();
959 if (remote == nullptr) {
960 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
961 return WSError::WS_ERROR_IPC_FAILED;
962 }
963 if (remote->SendRequest(static_cast<uint32_t>(
964 SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
965 data, reply, option) != ERR_NONE) {
966 TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
967 return WSError::WS_ERROR_IPC_FAILED;
968 }
969 int32_t ret = reply.ReadInt32();
970 return static_cast<WSError>(ret);
971 }
972
GetMainWindowInfos(int32_t topNum,std::vector<MainWindowInfo> & topNInfo)973 WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo)
974 {
975 TLOGI(WmsLogTag::WMS_MAIN, "get main info in %{public}d", topNum);
976 MessageParcel data;
977 MessageParcel reply;
978 MessageOption option(MessageOption::TF_SYNC);
979 if (!data.WriteInterfaceToken(GetDescriptor())) {
980 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
981 return WMError::WM_ERROR_IPC_FAILED;
982 }
983
984 if ((topNum <= 0) || (topNum >= MAX_TOPN_INFO_SIZE)) {
985 return WMError::WM_ERROR_INVALID_PARAM;
986 }
987
988 if (!data.WriteInt32(topNum)) {
989 TLOGE(WmsLogTag::WMS_MAIN, "topNum write fail");
990 return WMError::WM_ERROR_IPC_FAILED;
991 }
992
993 sptr<IRemoteObject> remote = Remote();
994 if (remote == nullptr) {
995 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
996 return WMError::WM_ERROR_IPC_FAILED;
997 }
998 if (remote->SendRequest(static_cast<int32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO),
999 data, reply, option) != ERR_NONE) {
1000 TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1001 return WMError::WM_ERROR_IPC_FAILED;
1002 }
1003
1004 WMError error = static_cast<WMError>(GetParcelableInfos(reply, topNInfo));
1005 if (error != WMError::WM_OK) {
1006 TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1007 return error;
1008 }
1009
1010 return static_cast<WMError>(reply.ReadInt32());
1011 }
1012
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)1013 WSError SceneSessionManagerLiteProxy::RegisterIAbilityManagerCollaborator(int32_t type,
1014 const sptr<AAFwk::IAbilityManagerCollaborator>& impl)
1015 {
1016 TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1017 if (!impl) {
1018 TLOGE(WmsLogTag::WMS_MAIN, "impl is nullptr");
1019 return WSError::WS_ERROR_INVALID_PARAM;
1020 }
1021 MessageParcel data;
1022 MessageParcel reply;
1023 MessageOption option;
1024
1025 if (!data.WriteInterfaceToken(GetDescriptor())) {
1026 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1027 return WSError::WS_ERROR_IPC_FAILED;
1028 }
1029 if (!data.WriteInt32(type)) {
1030 TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1031 return WSError::WS_ERROR_IPC_FAILED;
1032 }
1033 if (!data.WriteRemoteObject(impl->AsObject())) {
1034 TLOGE(WmsLogTag::WMS_MAIN, "Write impl failed");
1035 return WSError::WS_ERROR_IPC_FAILED;
1036 }
1037
1038 sptr<IRemoteObject> remote = Remote();
1039 if (remote == nullptr) {
1040 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1041 return WSError::WS_ERROR_IPC_FAILED;
1042 }
1043 if (remote->SendRequest(static_cast<uint32_t>(
1044 SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR),
1045 data, reply, option) != ERR_NONE) {
1046 TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1047 return WSError::WS_ERROR_IPC_FAILED;
1048 }
1049 return static_cast<WSError>(reply.ReadInt32());
1050 }
1051
UnregisterIAbilityManagerCollaborator(int32_t type)1052 WSError SceneSessionManagerLiteProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
1053 {
1054 TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1055 MessageParcel data;
1056 MessageParcel reply;
1057 MessageOption option;
1058
1059 if (!data.WriteInterfaceToken(GetDescriptor())) {
1060 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1061 return WSError::WS_ERROR_IPC_FAILED;
1062 }
1063 if (!data.WriteInt32(type)) {
1064 TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1065 return WSError::WS_ERROR_IPC_FAILED;
1066 }
1067
1068 sptr<IRemoteObject> remote = Remote();
1069 if (remote == nullptr) {
1070 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1071 return WSError::WS_ERROR_IPC_FAILED;
1072 }
1073 if (remote->SendRequest(static_cast<uint32_t>(
1074 SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
1075 data, reply, option) != ERR_NONE) {
1076 TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1077 return WSError::WS_ERROR_IPC_FAILED;
1078 }
1079 return static_cast<WSError>(reply.ReadInt32());
1080 }
1081
GetAllMainWindowInfos(std::vector<MainWindowInfo> & infos)1082 WMError SceneSessionManagerLiteProxy::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
1083 {
1084 MessageParcel data;
1085 MessageParcel reply;
1086 MessageOption option;
1087 if (!data.WriteInterfaceToken(GetDescriptor())) {
1088 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1089 return WMError::WM_ERROR_IPC_FAILED;
1090 }
1091 sptr<IRemoteObject> remote = Remote();
1092 if (remote == nullptr) {
1093 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1094 return WMError::WM_ERROR_IPC_FAILED;
1095 }
1096 if (remote->SendRequest(static_cast<int32_t>(
1097 SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1098 TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1099 return WMError::WM_ERROR_IPC_FAILED;
1100 }
1101
1102 WMError error = static_cast<WMError>(GetParcelableInfos(reply, infos));
1103 if (error != WMError::WM_OK) {
1104 TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1105 return error;
1106 }
1107
1108 return static_cast<WMError>(reply.ReadInt32());
1109 }
1110
ClearMainSessions(const std::vector<int32_t> & persistentIds,std::vector<int32_t> & clearFailedIds)1111 WMError SceneSessionManagerLiteProxy::ClearMainSessions(const std::vector<int32_t>& persistentIds,
1112 std::vector<int32_t>& clearFailedIds)
1113 {
1114 MessageParcel data;
1115 MessageParcel reply;
1116 MessageOption option;
1117 if (!data.WriteInterfaceToken(GetDescriptor())) {
1118 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1119 return WMError::WM_ERROR_IPC_FAILED;
1120 }
1121 if (!data.WriteInt32Vector(persistentIds)) {
1122 TLOGE(WmsLogTag::WMS_MAIN, "Write persistentIds failed");
1123 return WMError::WM_ERROR_IPC_FAILED;
1124 }
1125 sptr<IRemoteObject> remote = Remote();
1126 if (remote == nullptr) {
1127 TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1128 return WMError::WM_ERROR_IPC_FAILED;
1129 }
1130 if (remote->SendRequest(static_cast<int32_t>(
1131 SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS), data, reply, option) != ERR_NONE) {
1132 TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1133 return WMError::WM_ERROR_IPC_FAILED;
1134 }
1135 reply.ReadInt32Vector(&clearFailedIds);
1136 return static_cast<WMError>(reply.ReadInt32());
1137 }
1138
GetWindowStyleType(WindowStyleType & windowStyleType)1139 WMError SceneSessionManagerLiteProxy::GetWindowStyleType(WindowStyleType& windowStyleType)
1140 {
1141 MessageParcel data;
1142 MessageParcel reply;
1143 MessageOption option;
1144 if (!data.WriteInterfaceToken(GetDescriptor())) {
1145 TLOGE(WmsLogTag::WMS_MAIN, "GetwindowStyleType Write interfaceToken failed");
1146 return WMError::WM_ERROR_IPC_FAILED;
1147 }
1148 if (Remote()->SendRequest(static_cast<uint32_t>(
1149 SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE), data, reply, option) != ERR_NONE) {
1150 return WMError::WM_ERROR_IPC_FAILED;
1151 }
1152 windowStyleType = static_cast<WindowStyleType>(reply.ReadUint32());
1153 return static_cast<WMError>(reply.ReadInt32());
1154 }
1155
TerminateSessionByPersistentId(int32_t persistentId)1156 WMError SceneSessionManagerLiteProxy::TerminateSessionByPersistentId(int32_t persistentId)
1157 {
1158 MessageParcel data;
1159 MessageParcel reply;
1160 MessageOption option;
1161 if (!data.WriteInterfaceToken(GetDescriptor())) {
1162 TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1163 return WMError::WM_ERROR_IPC_FAILED;
1164 }
1165 if (!data.WriteInt32(persistentId)) {
1166 TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1167 return WMError::WM_ERROR_IPC_FAILED;
1168 }
1169 if (Remote()->SendRequest(static_cast<int32_t>(
1170 SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID),
1171 data, reply, option) != ERR_NONE) {
1172 TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1173 return WMError::WM_ERROR_IPC_FAILED;
1174 }
1175 return static_cast<WMError>(reply.ReadInt32());
1176 }
1177
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1178 WMError SceneSessionManagerLiteProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1179 {
1180 MessageOption option;
1181 MessageParcel reply;
1182 MessageParcel data;
1183 if (!data.WriteInterfaceToken(GetDescriptor())) {
1184 WLOGFE("Write InterfaceToken failed");
1185 return WMError::WM_ERROR_IPC_FAILED;
1186 }
1187
1188 sptr<IRemoteObject> remote = Remote();
1189 if (remote == nullptr) {
1190 WLOGFE("remote is null");
1191 return WMError::WM_ERROR_IPC_FAILED;
1192 }
1193 if (remote->SendRequest(static_cast<uint32_t>(
1194 SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO),
1195 data, reply, option) != ERR_NONE) {
1196 WLOGFE("SendRequest failed");
1197 return WMError::WM_ERROR_IPC_FAILED;
1198 }
1199
1200 if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
1201 WLOGFE("read window info failed.");
1202 return WMError::WM_ERROR_IPC_FAILED;
1203 }
1204 return static_cast<WMError>(reply.ReadInt32());
1205 }
1206
CloseTargetFloatWindow(const std::string & bundleName)1207 WMError SceneSessionManagerLiteProxy::CloseTargetFloatWindow(const std::string& bundleName)
1208 {
1209 MessageParcel data;
1210 MessageParcel reply;
1211 MessageOption option(MessageOption::TF_ASYNC);
1212 if (!data.WriteInterfaceToken(GetDescriptor())) {
1213 TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
1214 return WMError::WM_ERROR_IPC_FAILED;
1215 }
1216 if (!data.WriteString(bundleName)) {
1217 TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write bundleName failed");
1218 return WMError::WM_ERROR_IPC_FAILED;
1219 }
1220 sptr<IRemoteObject> remote = Remote();
1221 if (remote == nullptr) {
1222 TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is null");
1223 return WMError::WM_ERROR_IPC_FAILED;
1224 }
1225 if (remote->SendRequest(static_cast<int32_t>(
1226 SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_FLOAT_WINDOW),
1227 data, reply, option) != ERR_NONE) {
1228 TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "send request fail");
1229 return WMError::WM_ERROR_IPC_FAILED;
1230 }
1231 return WMError::WM_OK;
1232 }
1233
CloseTargetPiPWindow(const std::string & bundleName)1234 WMError SceneSessionManagerLiteProxy::CloseTargetPiPWindow(const std::string& bundleName)
1235 {
1236 MessageParcel data;
1237 MessageParcel reply;
1238 MessageOption option;
1239 if (!data.WriteInterfaceToken(GetDescriptor())) {
1240 TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1241 return WMError::WM_ERROR_IPC_FAILED;
1242 }
1243 if (!data.WriteString(bundleName)) {
1244 TLOGE(WmsLogTag::WMS_PIP, "Write bundleName failed");
1245 return WMError::WM_ERROR_IPC_FAILED;
1246 }
1247 sptr<IRemoteObject> remote = Remote();
1248 if (remote == nullptr) {
1249 TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1250 return WMError::WM_ERROR_IPC_FAILED;
1251 }
1252 if (remote->SendRequest(static_cast<int32_t>(
1253 SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_PIP_WINDOW),
1254 data, reply, option) != ERR_NONE) {
1255 TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1256 return WMError::WM_ERROR_IPC_FAILED;
1257 }
1258 return static_cast<WMError>(reply.ReadInt32());
1259 }
1260
GetCurrentPiPWindowInfo(std::string & bundleName)1261 WMError SceneSessionManagerLiteProxy::GetCurrentPiPWindowInfo(std::string& bundleName)
1262 {
1263 MessageParcel data;
1264 MessageParcel reply;
1265 MessageOption option;
1266 if (!data.WriteInterfaceToken(GetDescriptor())) {
1267 TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1268 return WMError::WM_ERROR_IPC_FAILED;
1269 }
1270 sptr<IRemoteObject> remote = Remote();
1271 if (remote == nullptr) {
1272 TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1273 return WMError::WM_ERROR_IPC_FAILED;
1274 }
1275 if (remote->SendRequest(static_cast<int32_t>(
1276 SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO),
1277 data, reply, option) != ERR_NONE) {
1278 TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1279 return WMError::WM_ERROR_IPC_FAILED;
1280 }
1281 WMError errorCode = static_cast<WMError>(reply.ReadInt32());
1282 bundleName = reply.ReadString();
1283 return errorCode;
1284 }
1285 } // namespace OHOS::Rosen
1286