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 
CheckUIExtensionCreation(int32_t windowId,uint32_t tokenId,const AppExecFwk::ElementName & element,AppExecFwk::ExtensionAbilityType extensionAbilityType,int32_t & pid)893 WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId,
894     const AppExecFwk::ElementName& element, AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid)
895 {
896     MessageParcel data;
897     MessageParcel reply;
898     MessageOption option;
899     if (!data.WriteInterfaceToken(GetDescriptor())) {
900         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write interfaceToken");
901         return WMError::WM_ERROR_IPC_FAILED;
902     }
903     if (!data.WriteInt32(windowId)) {
904         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write windowId");
905         return WMError::WM_ERROR_IPC_FAILED;
906     }
907     if (!data.WriteUint32(tokenId)) {
908         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write tokenId");
909         return WMError::WM_ERROR_IPC_FAILED;
910     }
911     if (!data.WriteInt32(static_cast<int32_t>(extensionAbilityType))) {
912         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write extensionAbilityType");
913         return WMError::WM_ERROR_IPC_FAILED;
914     }
915     data.WriteParcelable(&element);
916     sptr<IRemoteObject> remote = Remote();
917     if (remote == nullptr) {
918         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
919         return WMError::WM_ERROR_NULLPTR;
920     }
921     int32_t ret =
922         remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UI_EXTENSION_CREATION_CHECK),
923             data, reply, option);
924     if (ret != ERR_NONE) {
925         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Send request failed, ret:%{public}d", ret);
926         return WMError::WM_ERROR_IPC_FAILED;
927     }
928     int32_t errCode = 0;
929     if (!reply.ReadInt32(errCode)) {
930         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read errcode");
931         return WMError::WM_ERROR_IPC_FAILED;
932     }
933     if (!reply.ReadInt32(pid)) {
934         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read pid");
935         return WMError::WM_ERROR_IPC_FAILED;
936     }
937     TLOGI(WmsLogTag::WMS_UIEXT, "UIExtOnLock: errcode %{public}u", errCode);
938     return static_cast<WMError>(errCode);
939 }
940 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)941 WMError SceneSessionManagerLiteProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
942 {
943     MessageParcel data;
944     MessageParcel reply;
945     MessageOption option;
946     if (!data.WriteInterfaceToken(GetDescriptor())) {
947         WLOGFE("GetVisibilityWindowInfo Write interfaceToken failed");
948         return WMError::WM_ERROR_IPC_FAILED;
949     }
950 
951     sptr<IRemoteObject> remote = Remote();
952     if (remote == nullptr) {
953         WLOGFE("remote is nullptr");
954         return WMError::WM_ERROR_NULLPTR;
955     }
956     if (remote->SendRequest(static_cast<uint32_t>(
957         SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) {
958         return WMError::WM_ERROR_IPC_FAILED;
959     }
960     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
961         WLOGFE("read visibility window infos failed");
962         return WMError::WM_ERROR_IPC_FAILED;
963     }
964     return static_cast<WMError>(reply.ReadInt32());
965 }
966 
GetWindowModeType(WindowModeType & windowModeType)967 WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowModeType)
968 {
969     WLOGFI("get Window mode type proxy");
970     MessageParcel data;
971     if (!data.WriteInterfaceToken(GetDescriptor())) {
972         WLOGFE("WriteInterfaceToken failed");
973         return WMError::WM_ERROR_IPC_FAILED;
974     }
975 
976     MessageParcel reply;
977     MessageOption option;
978     sptr<IRemoteObject> remote = Remote();
979     if (remote == nullptr) {
980         WLOGFE("remote is null");
981         return WMError::WM_ERROR_IPC_FAILED;
982     }
983     if (remote->SendRequest(static_cast<uint32_t>(
984         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE), data, reply, option) != ERR_NONE) {
985         WLOGFE("SendRequest failed");
986         return WMError::WM_ERROR_IPC_FAILED;
987     }
988 
989     windowModeType = static_cast<WindowModeType>(reply.ReadUint32());
990     return static_cast<WMError>(reply.ReadInt32());
991 }
992 
RaiseWindowToTop(int32_t persistentId)993 WSError SceneSessionManagerLiteProxy::RaiseWindowToTop(int32_t persistentId)
994 {
995     MessageParcel data;
996     MessageParcel reply;
997     MessageOption option(MessageOption::TF_SYNC);
998     if (!data.WriteInterfaceToken(GetDescriptor())) {
999         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1000         return WSError::WS_ERROR_IPC_FAILED;
1001     }
1002     if (!data.WriteInt32(persistentId)) {
1003         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1004         return WSError::WS_ERROR_IPC_FAILED;
1005     }
1006     sptr<IRemoteObject> remote = Remote();
1007     if (remote == nullptr) {
1008         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1009         return WSError::WS_ERROR_IPC_FAILED;
1010     }
1011     if (remote->SendRequest(static_cast<uint32_t>(
1012         SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
1013         data, reply, option) != ERR_NONE) {
1014         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1015         return WSError::WS_ERROR_IPC_FAILED;
1016     }
1017     int32_t ret = reply.ReadInt32();
1018     return static_cast<WSError>(ret);
1019 }
1020 
GetMainWindowInfos(int32_t topNum,std::vector<MainWindowInfo> & topNInfo)1021 WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo)
1022 {
1023     TLOGI(WmsLogTag::WMS_MAIN, "get main info in %{public}d", topNum);
1024     MessageParcel data;
1025     MessageParcel reply;
1026     MessageOption option(MessageOption::TF_SYNC);
1027     if (!data.WriteInterfaceToken(GetDescriptor())) {
1028         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1029         return WMError::WM_ERROR_IPC_FAILED;
1030     }
1031 
1032     if ((topNum <= 0) || (topNum >= MAX_TOPN_INFO_SIZE)) {
1033         return WMError::WM_ERROR_INVALID_PARAM;
1034     }
1035 
1036     if (!data.WriteInt32(topNum)) {
1037         TLOGE(WmsLogTag::WMS_MAIN, "topNum write fail");
1038         return WMError::WM_ERROR_IPC_FAILED;
1039     }
1040 
1041     sptr<IRemoteObject> remote = Remote();
1042     if (remote == nullptr) {
1043         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1044         return WMError::WM_ERROR_IPC_FAILED;
1045     }
1046     if (remote->SendRequest(static_cast<int32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO),
1047                             data, reply, option) != ERR_NONE) {
1048         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1049         return WMError::WM_ERROR_IPC_FAILED;
1050     }
1051 
1052     WMError error = static_cast<WMError>(GetParcelableInfos(reply, topNInfo));
1053     if (error != WMError::WM_OK) {
1054         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1055         return error;
1056     }
1057 
1058     return static_cast<WMError>(reply.ReadInt32());
1059 }
1060 
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)1061 WSError SceneSessionManagerLiteProxy::RegisterIAbilityManagerCollaborator(int32_t type,
1062     const sptr<AAFwk::IAbilityManagerCollaborator>& impl)
1063 {
1064     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1065     if (!impl) {
1066         TLOGE(WmsLogTag::WMS_MAIN, "impl is nullptr");
1067         return WSError::WS_ERROR_INVALID_PARAM;
1068     }
1069     MessageParcel data;
1070     MessageParcel reply;
1071     MessageOption option;
1072 
1073     if (!data.WriteInterfaceToken(GetDescriptor())) {
1074         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1075         return WSError::WS_ERROR_IPC_FAILED;
1076     }
1077     if (!data.WriteInt32(type)) {
1078         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1079         return WSError::WS_ERROR_IPC_FAILED;
1080     }
1081     if (!data.WriteRemoteObject(impl->AsObject())) {
1082         TLOGE(WmsLogTag::WMS_MAIN, "Write impl failed");
1083         return WSError::WS_ERROR_IPC_FAILED;
1084     }
1085 
1086     sptr<IRemoteObject> remote = Remote();
1087     if (remote == nullptr) {
1088         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1089         return WSError::WS_ERROR_IPC_FAILED;
1090     }
1091     if (remote->SendRequest(static_cast<uint32_t>(
1092         SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR),
1093         data, reply, option) != ERR_NONE) {
1094         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1095         return WSError::WS_ERROR_IPC_FAILED;
1096     }
1097     return static_cast<WSError>(reply.ReadInt32());
1098 }
1099 
UnregisterIAbilityManagerCollaborator(int32_t type)1100 WSError SceneSessionManagerLiteProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
1101 {
1102     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1103     MessageParcel data;
1104     MessageParcel reply;
1105     MessageOption option;
1106 
1107     if (!data.WriteInterfaceToken(GetDescriptor())) {
1108         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1109         return WSError::WS_ERROR_IPC_FAILED;
1110     }
1111     if (!data.WriteInt32(type)) {
1112         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1113         return WSError::WS_ERROR_IPC_FAILED;
1114     }
1115 
1116     sptr<IRemoteObject> remote = Remote();
1117     if (remote == nullptr) {
1118         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1119         return WSError::WS_ERROR_IPC_FAILED;
1120     }
1121     if (remote->SendRequest(static_cast<uint32_t>(
1122         SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
1123         data, reply, option) != ERR_NONE) {
1124         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1125         return WSError::WS_ERROR_IPC_FAILED;
1126     }
1127     return static_cast<WSError>(reply.ReadInt32());
1128 }
1129 
GetAllMainWindowInfos(std::vector<MainWindowInfo> & infos)1130 WMError SceneSessionManagerLiteProxy::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
1131 {
1132     MessageParcel data;
1133     MessageParcel reply;
1134     MessageOption option;
1135     if (!data.WriteInterfaceToken(GetDescriptor())) {
1136         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1137         return WMError::WM_ERROR_IPC_FAILED;
1138     }
1139     sptr<IRemoteObject> remote = Remote();
1140     if (remote == nullptr) {
1141         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1142         return WMError::WM_ERROR_IPC_FAILED;
1143     }
1144     if (remote->SendRequest(static_cast<int32_t>(
1145         SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1146         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1147         return WMError::WM_ERROR_IPC_FAILED;
1148     }
1149 
1150     WMError error = static_cast<WMError>(GetParcelableInfos(reply, infos));
1151     if (error != WMError::WM_OK) {
1152         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1153         return error;
1154     }
1155 
1156     return static_cast<WMError>(reply.ReadInt32());
1157 }
1158 
ClearMainSessions(const std::vector<int32_t> & persistentIds,std::vector<int32_t> & clearFailedIds)1159 WMError SceneSessionManagerLiteProxy::ClearMainSessions(const std::vector<int32_t>& persistentIds,
1160     std::vector<int32_t>& clearFailedIds)
1161 {
1162     MessageParcel data;
1163     MessageParcel reply;
1164     MessageOption option;
1165     if (!data.WriteInterfaceToken(GetDescriptor())) {
1166         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1167         return WMError::WM_ERROR_IPC_FAILED;
1168     }
1169     if (!data.WriteInt32Vector(persistentIds)) {
1170         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentIds failed");
1171         return WMError::WM_ERROR_IPC_FAILED;
1172     }
1173     sptr<IRemoteObject> remote = Remote();
1174     if (remote == nullptr) {
1175         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1176         return WMError::WM_ERROR_IPC_FAILED;
1177     }
1178     if (remote->SendRequest(static_cast<int32_t>(
1179         SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS), data, reply, option) != ERR_NONE) {
1180         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1181         return WMError::WM_ERROR_IPC_FAILED;
1182     }
1183     reply.ReadInt32Vector(&clearFailedIds);
1184     return static_cast<WMError>(reply.ReadInt32());
1185 }
1186 
GetWindowStyleType(WindowStyleType & windowStyleType)1187 WMError SceneSessionManagerLiteProxy::GetWindowStyleType(WindowStyleType& windowStyleType)
1188 {
1189     MessageParcel data;
1190     MessageParcel reply;
1191     MessageOption option;
1192     if (!data.WriteInterfaceToken(GetDescriptor())) {
1193         TLOGE(WmsLogTag::WMS_MAIN, "GetwindowStyleType Write interfaceToken failed");
1194         return WMError::WM_ERROR_IPC_FAILED;
1195     }
1196     if (Remote()->SendRequest(static_cast<uint32_t>(
1197         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE), data, reply, option) != ERR_NONE) {
1198         return WMError::WM_ERROR_IPC_FAILED;
1199     }
1200     windowStyleType = static_cast<WindowStyleType>(reply.ReadUint32());
1201     return static_cast<WMError>(reply.ReadInt32());
1202 }
1203 
TerminateSessionByPersistentId(int32_t persistentId)1204 WMError SceneSessionManagerLiteProxy::TerminateSessionByPersistentId(int32_t persistentId)
1205 {
1206     MessageParcel data;
1207     MessageParcel reply;
1208     MessageOption option;
1209     if (!data.WriteInterfaceToken(GetDescriptor())) {
1210         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1211         return WMError::WM_ERROR_IPC_FAILED;
1212     }
1213     if (!data.WriteInt32(persistentId)) {
1214         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1215         return WMError::WM_ERROR_IPC_FAILED;
1216     }
1217     if (Remote()->SendRequest(static_cast<int32_t>(
1218         SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID),
1219         data, reply, option) != ERR_NONE) {
1220         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1221         return WMError::WM_ERROR_IPC_FAILED;
1222     }
1223     return static_cast<WMError>(reply.ReadInt32());
1224 }
1225 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1226 WMError SceneSessionManagerLiteProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1227 {
1228     MessageOption option;
1229     MessageParcel reply;
1230     MessageParcel data;
1231     if (!data.WriteInterfaceToken(GetDescriptor())) {
1232         WLOGFE("Write InterfaceToken failed");
1233         return WMError::WM_ERROR_IPC_FAILED;
1234     }
1235 
1236     sptr<IRemoteObject> remote = Remote();
1237     if (remote == nullptr) {
1238         WLOGFE("remote is null");
1239         return WMError::WM_ERROR_IPC_FAILED;
1240     }
1241     if (remote->SendRequest(static_cast<uint32_t>(
1242         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO),
1243         data, reply, option) != ERR_NONE) {
1244         WLOGFE("SendRequest failed");
1245         return WMError::WM_ERROR_IPC_FAILED;
1246     }
1247 
1248     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
1249         WLOGFE("read window info failed.");
1250         return WMError::WM_ERROR_IPC_FAILED;
1251     }
1252     return static_cast<WMError>(reply.ReadInt32());
1253 }
1254 
CloseTargetFloatWindow(const std::string & bundleName)1255 WMError SceneSessionManagerLiteProxy::CloseTargetFloatWindow(const std::string& bundleName)
1256 {
1257     MessageParcel data;
1258     MessageParcel reply;
1259     MessageOption option(MessageOption::TF_ASYNC);
1260     if (!data.WriteInterfaceToken(GetDescriptor())) {
1261         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
1262         return WMError::WM_ERROR_IPC_FAILED;
1263     }
1264     if (!data.WriteString(bundleName)) {
1265         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write bundleName failed");
1266         return WMError::WM_ERROR_IPC_FAILED;
1267     }
1268     sptr<IRemoteObject> remote = Remote();
1269     if (remote == nullptr) {
1270         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is null");
1271         return WMError::WM_ERROR_IPC_FAILED;
1272     }
1273     if (remote->SendRequest(static_cast<int32_t>(
1274         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_FLOAT_WINDOW),
1275         data, reply, option) != ERR_NONE) {
1276         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "send request fail");
1277         return WMError::WM_ERROR_IPC_FAILED;
1278     }
1279     return WMError::WM_OK;
1280 }
1281 
CloseTargetPiPWindow(const std::string & bundleName)1282 WMError SceneSessionManagerLiteProxy::CloseTargetPiPWindow(const std::string& bundleName)
1283 {
1284     MessageParcel data;
1285     MessageParcel reply;
1286     MessageOption option;
1287     if (!data.WriteInterfaceToken(GetDescriptor())) {
1288         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1289         return WMError::WM_ERROR_IPC_FAILED;
1290     }
1291     if (!data.WriteString(bundleName)) {
1292         TLOGE(WmsLogTag::WMS_PIP, "Write bundleName failed");
1293         return WMError::WM_ERROR_IPC_FAILED;
1294     }
1295     sptr<IRemoteObject> remote = Remote();
1296     if (remote == nullptr) {
1297         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1298         return WMError::WM_ERROR_IPC_FAILED;
1299     }
1300     if (remote->SendRequest(static_cast<int32_t>(
1301         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_PIP_WINDOW),
1302         data, reply, option) != ERR_NONE) {
1303         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1304         return WMError::WM_ERROR_IPC_FAILED;
1305     }
1306     return static_cast<WMError>(reply.ReadInt32());
1307 }
1308 
GetCurrentPiPWindowInfo(std::string & bundleName)1309 WMError SceneSessionManagerLiteProxy::GetCurrentPiPWindowInfo(std::string& bundleName)
1310 {
1311     MessageParcel data;
1312     MessageParcel reply;
1313     MessageOption option;
1314     if (!data.WriteInterfaceToken(GetDescriptor())) {
1315         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1316         return WMError::WM_ERROR_IPC_FAILED;
1317     }
1318     sptr<IRemoteObject> remote = Remote();
1319     if (remote == nullptr) {
1320         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1321         return WMError::WM_ERROR_IPC_FAILED;
1322     }
1323     if (remote->SendRequest(static_cast<int32_t>(
1324         SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO),
1325         data, reply, option) != ERR_NONE) {
1326         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1327         return WMError::WM_ERROR_IPC_FAILED;
1328     }
1329     WMError errorCode = static_cast<WMError>(reply.ReadInt32());
1330     bundleName = reply.ReadString();
1331     return errorCode;
1332 }
1333 
NotifyAppUseControlList(ControlAppType type,int32_t userId,const std::vector<AppUseControlInfo> & controlList)1334 WSError SceneSessionManagerLiteProxy::NotifyAppUseControlList(
1335     ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)
1336 {
1337     TLOGD(WmsLogTag::WMS_LIFE, "in");
1338     MessageParcel data;
1339     MessageParcel reply;
1340     MessageOption option;
1341     if (!data.WriteInterfaceToken(GetDescriptor())) {
1342         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
1343         return WSError::WS_ERROR_INVALID_PARAM;
1344     }
1345 
1346     if (!data.WriteUint8(static_cast<uint8_t>(type))) {
1347         TLOGE(WmsLogTag::WMS_LIFE, "Write type failed");
1348         return WSError::WS_ERROR_INVALID_PARAM;
1349     }
1350 
1351     if (!data.WriteInt32(userId)) {
1352         TLOGE(WmsLogTag::WMS_LIFE, "Write userId failed");
1353         return WSError::WS_ERROR_INVALID_PARAM;
1354     }
1355 
1356     if (!data.WriteInt32(static_cast<int32_t>(controlList.size()))) {
1357         TLOGE(WmsLogTag::WMS_LIFE, "Write controlList size failed");
1358         return WSError::WS_ERROR_INVALID_PARAM;
1359     }
1360 
1361     for (const auto& control : controlList) {
1362         if (!data.WriteString(control.bundleName_) || !data.WriteInt32(control.appIndex_) ||
1363             !data.WriteBool(control.isNeedControl_)) {
1364             TLOGE(WmsLogTag::WMS_LIFE, "Write controlList failed");
1365             return WSError::WS_ERROR_INVALID_PARAM;
1366         }
1367     }
1368 
1369     sptr<IRemoteObject> remote = Remote();
1370     if (remote == nullptr) {
1371         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1372         return WSError::WS_ERROR_IPC_FAILED;
1373     }
1374     if (remote->SendRequest(static_cast<uint32_t>(
1375         SceneSessionManagerLiteMessage::TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST),
1376         data, reply, option) != ERR_NONE) {
1377         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1378         return WSError::WS_ERROR_IPC_FAILED;
1379     }
1380     return static_cast<WSError>(reply.ReadInt32());
1381 }
1382 
GetRootMainWindowId(int32_t persistentId,int32_t & hostWindowId)1383 WMError SceneSessionManagerLiteProxy::GetRootMainWindowId(int32_t persistentId, int32_t& hostWindowId)
1384 {
1385     MessageParcel data;
1386     MessageParcel reply;
1387     MessageOption option;
1388     if (!data.WriteInterfaceToken(GetDescriptor())) {
1389         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1390         return WMError::WM_ERROR_IPC_FAILED;
1391     }
1392     if (!data.WriteInt32(persistentId)) {
1393         TLOGE(WmsLogTag::WMS_MAIN, "Failed to write persistentId");
1394         return WMError::WM_ERROR_IPC_FAILED;
1395     }
1396     sptr<IRemoteObject> remote = Remote();
1397     if (remote == nullptr) {
1398         TLOGE(WmsLogTag::WMS_MAIN, "remote is nullptr");
1399         return WMError::WM_ERROR_NULLPTR;
1400     }
1401     int32_t ret = remote->SendRequest(static_cast<uint32_t>(
1402         SceneSessionManagerLiteMessage::TRANS_ID_GET_ROOT_MAIN_WINDOW_ID), data, reply, option);
1403     if (ret != ERR_NONE) {
1404         TLOGE(WmsLogTag::WMS_MAIN, "Send request failed, ret:%{public}d", ret);
1405         return WMError::WM_ERROR_IPC_FAILED;
1406     }
1407     if (!reply.ReadInt32(hostWindowId)) {
1408         TLOGE(WmsLogTag::WMS_MAIN, "Failed to read hostWindowId");
1409         return WMError::WM_ERROR_IPC_FAILED;
1410     }
1411     return WMError::WM_OK;
1412 }
1413 } // namespace OHOS::Rosen
1414