• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,bool isRecover)190 WSError SceneSessionManagerLiteProxy::RegisterSessionListener(const sptr<ISessionListener>& listener, bool isRecover)
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 || infoSize < 0) {
402         WLOGFE("infoSize is too large or negative");
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,DisplayId displayId)455 WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr<IRemoteObject>& token, DisplayId displayId)
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     if (!data.WriteUint64(displayId)) {
466         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
467         return WSError::WS_ERROR_IPC_FAILED;
468     }
469     sptr<IRemoteObject> remote = Remote();
470     if (remote == nullptr) {
471         WLOGFE("remote is null");
472         return WSError::WS_ERROR_IPC_FAILED;
473     }
474     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
475         data, reply, option) != ERR_NONE) {
476         WLOGFE("SendRequest failed");
477         return WSError::WS_ERROR_IPC_FAILED;
478     }
479     token = reply.ReadRemoteObject();
480     if (token == nullptr) {
481         WLOGFE("get token nullptr.");
482     }
483     return static_cast<WSError>(reply.ReadInt32());
484 }
485 
GetFocusSessionElement(AppExecFwk::ElementName & element,DisplayId displayId)486 WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId)
487 {
488     WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionElement");
489     MessageParcel data;
490     MessageParcel reply;
491     MessageOption option;
492     if (!data.WriteInterfaceToken(GetDescriptor())) {
493         WLOGFE("Write interfaceToken failed");
494         return WSError::WS_ERROR_IPC_FAILED;
495     }
496     if (!data.WriteUint64(displayId)) {
497         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
498         return WSError::WS_ERROR_IPC_FAILED;
499     }
500     sptr<IRemoteObject> remote = Remote();
501     if (remote == nullptr) {
502         WLOGFE("remote is null");
503         return WSError::WS_ERROR_IPC_FAILED;
504     }
505     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT),
506         data, reply, option) != ERR_NONE) {
507         WLOGFE("SendRequest failed");
508         return WSError::WS_ERROR_IPC_FAILED;
509     }
510     sptr<AppExecFwk::ElementName> ret = reply.ReadParcelable<AppExecFwk::ElementName>();
511     if (ret) {
512         element = *ret;
513     } else {
514         WLOGFD("get element null.");
515     }
516     return static_cast<WSError>(reply.ReadInt32());
517 }
518 
GetSessionSnapshot(const std::string & deviceId,int32_t persistentId,SessionSnapshot & snapshot,bool isLowResolution)519 WSError SceneSessionManagerLiteProxy::GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
520     SessionSnapshot& snapshot, bool isLowResolution)
521 {
522     MessageParcel data;
523     MessageParcel reply;
524     MessageOption option;
525     if (!data.WriteInterfaceToken(GetDescriptor())) {
526         WLOGFE("WriteInterfaceToken failed");
527         return WSError::WS_ERROR_INVALID_PARAM;
528     }
529     if (!data.WriteString16(Str8ToStr16(deviceId))) {
530         WLOGFE("Write deviceId failed.");
531         return WSError::WS_ERROR_IPC_FAILED;
532     }
533     if (!data.WriteInt32(persistentId)) {
534         WLOGFE("Write persistentId failed");
535         return WSError::WS_ERROR_INVALID_PARAM;
536     }
537 
538     if (!data.WriteBool(isLowResolution)) {
539         WLOGFE("Write isLowResolution failed");
540         return WSError::WS_ERROR_INVALID_PARAM;
541     }
542 
543     sptr<IRemoteObject> remote = Remote();
544     if (remote == nullptr) {
545         WLOGFE("remote is null");
546         return WSError::WS_ERROR_IPC_FAILED;
547     }
548     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
549         data, reply, option) != ERR_NONE) {
550         WLOGFE("SendRequest failed");
551         return WSError::WS_ERROR_IPC_FAILED;
552     }
553     std::unique_ptr<SessionSnapshot> info(reply.ReadParcelable<SessionSnapshot>());
554     if (info) {
555         snapshot = *info;
556     } else {
557         WLOGFW("Read SessionSnapshot is null.");
558     }
559     return static_cast<WSError>(reply.ReadInt32());
560 }
561 
SetSessionContinueState(const sptr<IRemoteObject> & token,const ContinueState & continueState)562 WSError SceneSessionManagerLiteProxy::SetSessionContinueState(const sptr<IRemoteObject>& token,
563     const ContinueState& continueState)
564 {
565     MessageParcel data;
566     MessageParcel reply;
567     MessageOption option;
568     if (!data.WriteInterfaceToken(GetDescriptor())) {
569         WLOGFE("WriteInterfaceToken failed");
570         return WSError::WS_ERROR_INVALID_PARAM;
571     }
572     if (!data.WriteRemoteObject(token)) {
573         WLOGFE("Write token failed");
574         return WSError::WS_ERROR_IPC_FAILED;
575     }
576     if (!data.WriteInt32(static_cast<int32_t>(continueState))) {
577         WLOGFE("Write continueState failed");
578         return WSError::WS_ERROR_IPC_FAILED;
579     }
580     sptr<IRemoteObject> remote = Remote();
581     if (remote == nullptr) {
582         WLOGFE("remote is null");
583         return WSError::WS_ERROR_IPC_FAILED;
584     }
585     if (remote->SendRequest(static_cast<uint32_t>(
586         SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
587         data, reply, option) != ERR_NONE) {
588         WLOGFE("SendRequest failed");
589         return WSError::WS_ERROR_IPC_FAILED;
590     }
591     return static_cast<WSError>(reply.ReadInt32());
592 }
593 
LockSession(int32_t sessionId)594 WSError SceneSessionManagerLiteProxy::LockSession(int32_t sessionId)
595 {
596     WLOGFD("run SceneSessionManagerLiteProxy::LockSession");
597     MessageParcel data;
598     MessageParcel reply;
599     MessageOption option;
600 
601     if (!data.WriteInterfaceToken(GetDescriptor())) {
602         WLOGFE("Write interface token failed.");
603         return WSError::WS_ERROR_INVALID_PARAM;
604     }
605     if (!data.WriteInt32(sessionId)) {
606         WLOGFE("Write persistentId failed");
607         return WSError::WS_ERROR_INVALID_PARAM;
608     }
609     sptr<IRemoteObject> remote = Remote();
610     if (remote == nullptr) {
611         WLOGFE("remote is null");
612         return WSError::WS_ERROR_IPC_FAILED;
613     }
614     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION),
615         data, reply, option) != ERR_NONE) {
616         WLOGFE("SendRequest failed");
617         return WSError::WS_ERROR_IPC_FAILED;
618     }
619     return static_cast<WSError>(reply.ReadInt32());
620 }
621 
UnlockSession(int32_t sessionId)622 WSError SceneSessionManagerLiteProxy::UnlockSession(int32_t sessionId)
623 {
624     WLOGFD("run SceneSessionManagerLiteProxy::UnlockSession");
625     MessageParcel data;
626     MessageParcel reply;
627     MessageOption option;
628 
629     if (!data.WriteInterfaceToken(GetDescriptor())) {
630         WLOGFE("Write interface token failed.");
631         return WSError::WS_ERROR_INVALID_PARAM;
632     }
633     if (!data.WriteInt32(sessionId)) {
634         WLOGFE("Write persistentId failed");
635         return WSError::WS_ERROR_INVALID_PARAM;
636     }
637     sptr<IRemoteObject> remote = Remote();
638     if (remote == nullptr) {
639         WLOGFE("remote is null");
640         return WSError::WS_ERROR_IPC_FAILED;
641     }
642     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION),
643         data, reply, option) != ERR_NONE) {
644         WLOGFE("SendRequest failed");
645         return WSError::WS_ERROR_IPC_FAILED;
646     }
647     return static_cast<WSError>(reply.ReadInt32());
648 }
649 
MoveSessionsToForeground(const std::vector<std::int32_t> & sessionIds,int32_t topSessionId)650 WSError SceneSessionManagerLiteProxy::MoveSessionsToForeground(const std::vector<std::int32_t>& sessionIds,
651     int32_t topSessionId)
652 {
653     WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToForeground");
654     MessageParcel data;
655     MessageParcel reply;
656     MessageOption option;
657     if (!data.WriteInterfaceToken(GetDescriptor())) {
658         WLOGFE("WriteInterfaceToken failed");
659         return WSError::WS_ERROR_INVALID_PARAM;
660     }
661     if (!data.WriteInt32Vector(sessionIds)) {
662         WLOGFE("Write sessionIds failed");
663         return WSError::WS_ERROR_INVALID_PARAM;
664     }
665     if (!data.WriteInt32(topSessionId)) {
666         WLOGFE("Write topSessionId failed");
667         return WSError::WS_ERROR_INVALID_PARAM;
668     }
669     sptr<IRemoteObject> remote = Remote();
670     if (remote == nullptr) {
671         WLOGFE("remote is null");
672         return WSError::WS_ERROR_IPC_FAILED;
673     }
674     if (remote->SendRequest(static_cast<uint32_t>(
675         SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND),
676         data, reply, option) != ERR_NONE) {
677         WLOGFE("SendRequest failed");
678         return WSError::WS_ERROR_IPC_FAILED;
679     }
680     return static_cast<WSError>(reply.ReadInt32());
681 }
682 
MoveSessionsToBackground(const std::vector<std::int32_t> & sessionIds,std::vector<int32_t> & result)683 WSError SceneSessionManagerLiteProxy::MoveSessionsToBackground(const std::vector<std::int32_t>& sessionIds,
684     std::vector<int32_t>& result)
685 {
686     WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToBackground");
687     MessageParcel data;
688     MessageParcel reply;
689     MessageOption option;
690     if (!data.WriteInterfaceToken(GetDescriptor())) {
691         WLOGFE("WriteInterfaceToken failed");
692         return WSError::WS_ERROR_INVALID_PARAM;
693     }
694     if (!data.WriteInt32Vector(sessionIds)) {
695         WLOGFE("Write sessionIds failed");
696         return WSError::WS_ERROR_INVALID_PARAM;
697     }
698     if (!data.WriteInt32Vector(result)) {
699         WLOGFE("Write result failed");
700         return WSError::WS_ERROR_INVALID_PARAM;
701     }
702     sptr<IRemoteObject> remote = Remote();
703     if (remote == nullptr) {
704         WLOGFE("remote is null");
705         return WSError::WS_ERROR_IPC_FAILED;
706     }
707     if (remote->SendRequest(static_cast<uint32_t>(
708         SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND),
709         data, reply, option) != ERR_NONE) {
710         WLOGFE("SendRequest failed");
711         return WSError::WS_ERROR_IPC_FAILED;
712     }
713     reply.ReadInt32Vector(&result);
714     return static_cast<WSError>(reply.ReadInt32());
715 }
716 
ClearSession(int32_t persistentId)717 WSError SceneSessionManagerLiteProxy::ClearSession(int32_t persistentId)
718 {
719     WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
720     MessageParcel data;
721     MessageParcel reply;
722     MessageOption option;
723     if (!data.WriteInterfaceToken(GetDescriptor())) {
724         WLOGFE("ClearSession WriteInterfaceToken failed");
725         return WSError::WS_ERROR_INVALID_PARAM;
726     }
727 
728     if (!data.WriteInt32(persistentId)) {
729         WLOGFE("Write persistentId failed");
730         return WSError::WS_ERROR_INVALID_PARAM;
731     }
732 
733     sptr<IRemoteObject> remote = Remote();
734     if (remote == nullptr) {
735         WLOGFE("remote is null");
736         return WSError::WS_ERROR_IPC_FAILED;
737     }
738     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_SESSION),
739         data, reply, option) != ERR_NONE) {
740         WLOGFE("SendRequest failed");
741         return WSError::WS_ERROR_IPC_FAILED;
742     }
743     return static_cast<WSError>(reply.ReadInt32());
744 }
745 
ClearAllSessions()746 WSError SceneSessionManagerLiteProxy::ClearAllSessions()
747 {
748     WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
749     MessageParcel data;
750     MessageParcel reply;
751     MessageOption option;
752     if (!data.WriteInterfaceToken(GetDescriptor())) {
753         WLOGFE("ClearAllSessions WriteInterfaceToken failed");
754         return WSError::WS_ERROR_INVALID_PARAM;
755     }
756 
757     sptr<IRemoteObject> remote = Remote();
758     if (remote == nullptr) {
759         WLOGFE("remote is null");
760         return WSError::WS_ERROR_IPC_FAILED;
761     }
762     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
763         data, reply, option) != ERR_NONE) {
764         WLOGFE("SendRequest failed");
765         return WSError::WS_ERROR_IPC_FAILED;
766     }
767     return static_cast<WSError>(reply.ReadInt32());
768 }
769 
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)770 void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
771 {
772     WLOGFD("get focus Winow info lite proxy");
773     MessageParcel data;
774     MessageParcel reply;
775     MessageOption option;
776     if (!data.WriteInterfaceToken(GetDescriptor())) {
777         WLOGFE("WriteInterfaceToken failed");
778         return;
779     }
780     if (!data.WriteUint64(displayId)) {
781         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
782         return;
783     }
784     sptr<IRemoteObject> remote = Remote();
785     if (remote == nullptr) {
786         WLOGFE("remote is null");
787         return;
788     }
789     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
790         data, reply, option) != ERR_NONE) {
791         WLOGFE("SendRequest failed");
792         return;
793     }
794     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
795     if (info) {
796         focusInfo = *info;
797     } else {
798         WLOGFE("info is null.");
799     }
800 }
801 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)802 WMError SceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
803     const sptr<IWindowManagerAgent>& windowManagerAgent)
804 {
805     MessageOption option;
806     MessageParcel reply;
807     MessageParcel data;
808     if (!data.WriteInterfaceToken(GetDescriptor())) {
809         WLOGFE("Write InterfaceToken failed");
810         return WMError::WM_ERROR_IPC_FAILED;
811     }
812 
813     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
814         WLOGFE("Write type failed");
815         return WMError::WM_ERROR_IPC_FAILED;
816     }
817 
818     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
819         WLOGFE("Write IWindowManagerAgent failed");
820         return WMError::WM_ERROR_IPC_FAILED;
821     }
822 
823     sptr<IRemoteObject> remote = Remote();
824     if (remote == nullptr) {
825         WLOGFE("remote is nullptr");
826         return WMError::WM_ERROR_NULLPTR;
827     }
828     if (remote->SendRequest(static_cast<uint32_t>(
829         SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
830         WLOGFE("SendRequest failed");
831         return WMError::WM_ERROR_IPC_FAILED;
832     }
833 
834     return static_cast<WMError>(reply.ReadInt32());
835 }
836 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)837 WMError SceneSessionManagerLiteProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
838     const sptr<IWindowManagerAgent>& windowManagerAgent)
839 {
840     MessageParcel reply;
841     MessageOption option;
842     MessageParcel data;
843     if (!data.WriteInterfaceToken(GetDescriptor())) {
844         WLOGFE("Write InterfaceToken failed");
845         return WMError::WM_ERROR_IPC_FAILED;
846     }
847 
848     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
849         WLOGFE("Write type failed");
850         return WMError::WM_ERROR_IPC_FAILED;
851     }
852 
853     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
854         WLOGFE("Write IWindowManagerAgent failed");
855         return WMError::WM_ERROR_IPC_FAILED;
856     }
857 
858     sptr<IRemoteObject> remote = Remote();
859     if (remote == nullptr) {
860         WLOGFE("remote is nullptr");
861         return WMError::WM_ERROR_NULLPTR;
862     }
863     if (remote->SendRequest(static_cast<uint32_t>(
864         SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
865         WLOGFE("SendRequest failed");
866         return WMError::WM_ERROR_IPC_FAILED;
867     }
868 
869     return static_cast<WMError>(reply.ReadInt32());
870 }
871 
CheckWindowId(int32_t windowId,int32_t & pid)872 WMError SceneSessionManagerLiteProxy::CheckWindowId(int32_t windowId, int32_t& pid)
873 {
874     MessageParcel data;
875     MessageParcel reply;
876     MessageOption option;
877     if (!data.WriteInterfaceToken(GetDescriptor())) {
878         WLOGFE("Failed to write interfaceToken");
879         return WMError::WM_ERROR_IPC_FAILED;
880     }
881     if (!data.WriteInt32(windowId)) {
882         WLOGFE("Failed to write windowId");
883         return WMError::WM_ERROR_IPC_FAILED;
884     }
885     sptr<IRemoteObject> remote = Remote();
886     if (remote == nullptr) {
887         WLOGFE("remote is nullptr");
888         return WMError::WM_ERROR_NULLPTR;
889     }
890     int32_t ret = remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CHECK_WINDOW_ID),
891         data, reply, option);
892     if (ret != ERR_NONE) {
893         WLOGFE("Send request failed, ret:%{public}d", ret);
894         return WMError::WM_ERROR_IPC_FAILED;
895     }
896     if (!reply.ReadInt32(pid)) {
897         WLOGFE("Failed to read pid");
898         return WMError::WM_ERROR_IPC_FAILED;
899     }
900     return WMError::WM_OK;
901 }
902 
CheckUIExtensionCreation(int32_t windowId,uint32_t tokenId,const AppExecFwk::ElementName & element,AppExecFwk::ExtensionAbilityType extensionAbilityType,int32_t & pid)903 WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId,
904     const AppExecFwk::ElementName& element, AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid)
905 {
906     MessageParcel data;
907     MessageParcel reply;
908     MessageOption option;
909     if (!data.WriteInterfaceToken(GetDescriptor())) {
910         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write interfaceToken");
911         return WMError::WM_ERROR_IPC_FAILED;
912     }
913 
914     if (!data.WriteInt32(windowId)) {
915         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write windowId");
916         return WMError::WM_ERROR_IPC_FAILED;
917     }
918 
919     if (!data.WriteUint32(tokenId)) {
920         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write tokenId");
921         return WMError::WM_ERROR_IPC_FAILED;
922     }
923 
924     if (!data.WriteInt32(static_cast<int32_t>(extensionAbilityType))) {
925         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write extensionAbilityType");
926         return WMError::WM_ERROR_IPC_FAILED;
927     }
928 
929     data.WriteParcelable(&element);
930 
931     sptr<IRemoteObject> remote = Remote();
932     if (remote == nullptr) {
933         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
934         return WMError::WM_ERROR_NULLPTR;
935     }
936 
937     int32_t ret =
938         remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UI_EXTENSION_CREATION_CHECK),
939             data, reply, option);
940     if (ret != ERR_NONE) {
941         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Send request failed, ret:%{public}d", ret);
942         return WMError::WM_ERROR_IPC_FAILED;
943     }
944 
945     int32_t errCode = 0;
946     if (!reply.ReadInt32(errCode)) {
947         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read errcode");
948         return WMError::WM_ERROR_IPC_FAILED;
949     }
950 
951     if (!reply.ReadInt32(pid)) {
952         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read pid");
953         return WMError::WM_ERROR_IPC_FAILED;
954     }
955 
956     TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: errcode %{public}u", errCode);
957     return static_cast<WMError>(errCode);
958 }
959 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)960 WMError SceneSessionManagerLiteProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
961 {
962     MessageParcel data;
963     MessageParcel reply;
964     MessageOption option;
965     if (!data.WriteInterfaceToken(GetDescriptor())) {
966         WLOGFE("GetVisibilityWindowInfo Write interfaceToken failed");
967         return WMError::WM_ERROR_IPC_FAILED;
968     }
969 
970     sptr<IRemoteObject> remote = Remote();
971     if (remote == nullptr) {
972         WLOGFE("remote is nullptr");
973         return WMError::WM_ERROR_NULLPTR;
974     }
975     if (remote->SendRequest(static_cast<uint32_t>(
976         SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) {
977         return WMError::WM_ERROR_IPC_FAILED;
978     }
979     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
980         WLOGFE("read visibility window infos failed");
981         return WMError::WM_ERROR_IPC_FAILED;
982     }
983     return static_cast<WMError>(reply.ReadInt32());
984 }
985 
GetWindowModeType(WindowModeType & windowModeType)986 WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowModeType)
987 {
988     WLOGFI("get Window mode type proxy");
989     MessageParcel data;
990     if (!data.WriteInterfaceToken(GetDescriptor())) {
991         WLOGFE("WriteInterfaceToken failed");
992         return WMError::WM_ERROR_IPC_FAILED;
993     }
994     MessageParcel reply;
995     MessageOption option;
996     sptr<IRemoteObject> remote = Remote();
997     if (remote == nullptr) {
998         WLOGFE("remote is null");
999         return WMError::WM_ERROR_IPC_FAILED;
1000     }
1001     if (remote->SendRequest(static_cast<uint32_t>(
1002         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE), data, reply, option) != ERR_NONE) {
1003         WLOGFE("SendRequest failed");
1004         return WMError::WM_ERROR_IPC_FAILED;
1005     }
1006 
1007     windowModeType = static_cast<WindowModeType>(reply.ReadUint32());
1008     return static_cast<WMError>(reply.ReadInt32());
1009 }
1010 
GetMainWindowInfos(int32_t topNum,std::vector<MainWindowInfo> & topNInfo)1011 WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo)
1012 {
1013     TLOGI(WmsLogTag::WMS_MAIN, "get main info in %{public}d", topNum);
1014     MessageParcel data;
1015     MessageParcel reply;
1016     MessageOption option(MessageOption::TF_SYNC);
1017     if (!data.WriteInterfaceToken(GetDescriptor())) {
1018         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1019         return WMError::WM_ERROR_IPC_FAILED;
1020     }
1021 
1022     if ((topNum <= 0) || (topNum >= MAX_TOPN_INFO_SIZE)) {
1023         return WMError::WM_ERROR_INVALID_PARAM;
1024     }
1025 
1026     if (!data.WriteInt32(topNum)) {
1027         TLOGE(WmsLogTag::WMS_MAIN, "topNum write fail");
1028         return WMError::WM_ERROR_IPC_FAILED;
1029     }
1030 
1031     sptr<IRemoteObject> remote = Remote();
1032     if (remote == nullptr) {
1033         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1034         return WMError::WM_ERROR_IPC_FAILED;
1035     }
1036     if (remote->SendRequest(static_cast<int32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO),
1037                             data, reply, option) != ERR_NONE) {
1038         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1039         return WMError::WM_ERROR_IPC_FAILED;
1040     }
1041 
1042     WMError error = static_cast<WMError>(GetParcelableInfos(reply, topNInfo));
1043     if (error != WMError::WM_OK) {
1044         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1045         return error;
1046     }
1047 
1048     return static_cast<WMError>(reply.ReadInt32());
1049 }
1050 
GetCallingWindowInfo(CallingWindowInfo & callingWindowInfo)1051 WMError SceneSessionManagerLiteProxy::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo)
1052 {
1053     MessageParcel data;
1054     MessageParcel reply;
1055     MessageOption option(MessageOption::TF_SYNC);
1056     if (!data.WriteInterfaceToken(GetDescriptor())) {
1057         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
1058         return WMError::WM_ERROR_IPC_FAILED;
1059     }
1060     if (!data.WriteParcelable(&callingWindowInfo)) {
1061         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowInfo failed, id: %{public}d, userId: %{public}d",
1062             callingWindowInfo.windowId_, callingWindowInfo.userId_);
1063         return WMError::WM_ERROR_IPC_FAILED;
1064     }
1065     sptr<IRemoteObject> remote = Remote();
1066     if (remote == nullptr) {
1067         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
1068         return WMError::WM_ERROR_IPC_FAILED;
1069     }
1070     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_CALLING_WINDOW_INFO),
1071         data, reply, option) != ERR_NONE) {
1072         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
1073         return WMError::WM_ERROR_IPC_FAILED;
1074     }
1075     auto ret = static_cast<WMError>(reply.ReadInt32());
1076     if (ret == WMError::WM_OK) {
1077         sptr<CallingWindowInfo> info = reply.ReadParcelable<CallingWindowInfo>();
1078         if (info == nullptr) {
1079             TLOGE(WmsLogTag::WMS_KEYBOARD, "Read callingWindowInfo failed");
1080             return WMError::WM_ERROR_IPC_FAILED;
1081         }
1082         callingWindowInfo = *info;
1083     }
1084     return ret;
1085 }
1086 
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)1087 WSError SceneSessionManagerLiteProxy::RegisterIAbilityManagerCollaborator(int32_t type,
1088     const sptr<AAFwk::IAbilityManagerCollaborator>& impl)
1089 {
1090     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1091     if (!impl) {
1092         TLOGE(WmsLogTag::WMS_MAIN, "impl is nullptr");
1093         return WSError::WS_ERROR_INVALID_PARAM;
1094     }
1095     MessageParcel data;
1096     MessageParcel reply;
1097     MessageOption option;
1098 
1099     if (!data.WriteInterfaceToken(GetDescriptor())) {
1100         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1101         return WSError::WS_ERROR_IPC_FAILED;
1102     }
1103     if (!data.WriteInt32(type)) {
1104         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1105         return WSError::WS_ERROR_IPC_FAILED;
1106     }
1107     if (!data.WriteRemoteObject(impl->AsObject())) {
1108         TLOGE(WmsLogTag::WMS_MAIN, "Write impl failed");
1109         return WSError::WS_ERROR_IPC_FAILED;
1110     }
1111 
1112     sptr<IRemoteObject> remote = Remote();
1113     if (remote == nullptr) {
1114         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1115         return WSError::WS_ERROR_IPC_FAILED;
1116     }
1117     if (remote->SendRequest(static_cast<uint32_t>(
1118         SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR),
1119         data, reply, option) != ERR_NONE) {
1120         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1121         return WSError::WS_ERROR_IPC_FAILED;
1122     }
1123     return static_cast<WSError>(reply.ReadInt32());
1124 }
1125 
UnregisterIAbilityManagerCollaborator(int32_t type)1126 WSError SceneSessionManagerLiteProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
1127 {
1128     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1129     MessageParcel data;
1130     MessageParcel reply;
1131     MessageOption option;
1132 
1133     if (!data.WriteInterfaceToken(GetDescriptor())) {
1134         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1135         return WSError::WS_ERROR_IPC_FAILED;
1136     }
1137     if (!data.WriteInt32(type)) {
1138         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1139         return WSError::WS_ERROR_IPC_FAILED;
1140     }
1141 
1142     sptr<IRemoteObject> remote = Remote();
1143     if (remote == nullptr) {
1144         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1145         return WSError::WS_ERROR_IPC_FAILED;
1146     }
1147     if (remote->SendRequest(static_cast<uint32_t>(
1148         SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
1149         data, reply, option) != ERR_NONE) {
1150         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1151         return WSError::WS_ERROR_IPC_FAILED;
1152     }
1153     return static_cast<WSError>(reply.ReadInt32());
1154 }
1155 
GetAllMainWindowInfos(std::vector<MainWindowInfo> & infos)1156 WMError SceneSessionManagerLiteProxy::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
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     sptr<IRemoteObject> remote = Remote();
1166     if (remote == nullptr) {
1167         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1168         return WMError::WM_ERROR_IPC_FAILED;
1169     }
1170     if (remote->SendRequest(static_cast<int32_t>(
1171         SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1172         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1173         return WMError::WM_ERROR_IPC_FAILED;
1174     }
1175 
1176     WMError error = static_cast<WMError>(GetParcelableInfos(reply, infos));
1177     if (error != WMError::WM_OK) {
1178         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1179         return error;
1180     }
1181 
1182     return static_cast<WMError>(reply.ReadInt32());
1183 }
1184 
ClearMainSessions(const std::vector<int32_t> & persistentIds,std::vector<int32_t> & clearFailedIds)1185 WMError SceneSessionManagerLiteProxy::ClearMainSessions(const std::vector<int32_t>& persistentIds,
1186     std::vector<int32_t>& clearFailedIds)
1187 {
1188     MessageParcel data;
1189     MessageParcel reply;
1190     MessageOption option;
1191     if (!data.WriteInterfaceToken(GetDescriptor())) {
1192         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1193         return WMError::WM_ERROR_IPC_FAILED;
1194     }
1195     if (!data.WriteInt32Vector(persistentIds)) {
1196         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentIds failed");
1197         return WMError::WM_ERROR_IPC_FAILED;
1198     }
1199     sptr<IRemoteObject> remote = Remote();
1200     if (remote == nullptr) {
1201         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1202         return WMError::WM_ERROR_IPC_FAILED;
1203     }
1204     if (remote->SendRequest(static_cast<int32_t>(
1205         SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS), data, reply, option) != ERR_NONE) {
1206         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1207         return WMError::WM_ERROR_IPC_FAILED;
1208     }
1209     reply.ReadInt32Vector(&clearFailedIds);
1210     return static_cast<WMError>(reply.ReadInt32());
1211 }
1212 
RaiseWindowToTop(int32_t persistentId)1213 WSError SceneSessionManagerLiteProxy::RaiseWindowToTop(int32_t persistentId)
1214 {
1215     MessageParcel data;
1216     MessageParcel reply;
1217     MessageOption option(MessageOption::TF_SYNC);
1218     if (!data.WriteInterfaceToken(GetDescriptor())) {
1219         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1220         return WSError::WS_ERROR_IPC_FAILED;
1221     }
1222     if (!data.WriteInt32(persistentId)) {
1223         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1224         return WSError::WS_ERROR_IPC_FAILED;
1225     }
1226 
1227     sptr<IRemoteObject> remote = Remote();
1228     if (remote == nullptr) {
1229         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1230         return WSError::WS_ERROR_IPC_FAILED;
1231     }
1232     if (remote->SendRequest(static_cast<uint32_t>(
1233         SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
1234         data, reply, option) != ERR_NONE) {
1235         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1236         return WSError::WS_ERROR_IPC_FAILED;
1237     }
1238     int32_t ret = reply.ReadInt32();
1239     return static_cast<WSError>(ret);
1240 }
1241 
GetWindowStyleType(WindowStyleType & windowStyleType)1242 WMError SceneSessionManagerLiteProxy::GetWindowStyleType(WindowStyleType& windowStyleType)
1243 {
1244     MessageParcel data;
1245     MessageParcel reply;
1246     MessageOption option;
1247     if (!data.WriteInterfaceToken(GetDescriptor())) {
1248         TLOGE(WmsLogTag::WMS_MAIN, "GetwindowStyleType Write interfaceToken failed");
1249         return WMError::WM_ERROR_IPC_FAILED;
1250     }
1251     sptr<IRemoteObject> remote = Remote();
1252     if (remote == nullptr) {
1253         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1254         return WMError::WM_ERROR_IPC_FAILED;
1255     }
1256     if (remote->SendRequest(static_cast<uint32_t>(
1257         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE), data, reply, option) != ERR_NONE) {
1258         return WMError::WM_ERROR_IPC_FAILED;
1259     }
1260     windowStyleType = static_cast<WindowStyleType>(reply.ReadUint32());
1261     return static_cast<WMError>(reply.ReadInt32());
1262 }
1263 
TerminateSessionByPersistentId(int32_t persistentId)1264 WMError SceneSessionManagerLiteProxy::TerminateSessionByPersistentId(int32_t persistentId)
1265 {
1266     MessageParcel data;
1267     MessageParcel reply;
1268     MessageOption option;
1269     if (!data.WriteInterfaceToken(GetDescriptor())) {
1270         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1271         return WMError::WM_ERROR_IPC_FAILED;
1272     }
1273     if (!data.WriteInt32(persistentId)) {
1274         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1275         return WMError::WM_ERROR_IPC_FAILED;
1276     }
1277     sptr<IRemoteObject> remote = Remote();
1278     if (remote == nullptr) {
1279         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1280         return WMError::WM_ERROR_IPC_FAILED;
1281     }
1282     if (remote->SendRequest(static_cast<int32_t>(
1283         SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID),
1284         data, reply, option) != ERR_NONE) {
1285         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1286         return WMError::WM_ERROR_IPC_FAILED;
1287     }
1288     return static_cast<WMError>(reply.ReadInt32());
1289 }
1290 
CloseTargetFloatWindow(const std::string & bundleName)1291 WMError SceneSessionManagerLiteProxy::CloseTargetFloatWindow(const std::string& bundleName)
1292 {
1293     MessageParcel data;
1294     MessageParcel reply;
1295     MessageOption option(MessageOption::TF_ASYNC);
1296     if (!data.WriteInterfaceToken(GetDescriptor())) {
1297         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
1298         return WMError::WM_ERROR_IPC_FAILED;
1299     }
1300     if (!data.WriteString(bundleName)) {
1301         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write bundleName failed");
1302         return WMError::WM_ERROR_IPC_FAILED;
1303     }
1304     sptr<IRemoteObject> remote = Remote();
1305     if (remote == nullptr) {
1306         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is null");
1307         return WMError::WM_ERROR_IPC_FAILED;
1308     }
1309     if (remote->SendRequest(static_cast<int32_t>(
1310         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_FLOAT_WINDOW),
1311         data, reply, option) != ERR_NONE) {
1312         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "send request fail");
1313         return WMError::WM_ERROR_IPC_FAILED;
1314     }
1315     return WMError::WM_OK;
1316 }
1317 
CloseTargetPiPWindow(const std::string & bundleName)1318 WMError SceneSessionManagerLiteProxy::CloseTargetPiPWindow(const std::string& bundleName)
1319 {
1320     MessageParcel data;
1321     MessageParcel reply;
1322     MessageOption option;
1323     if (!data.WriteInterfaceToken(GetDescriptor())) {
1324         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1325         return WMError::WM_ERROR_IPC_FAILED;
1326     }
1327     if (!data.WriteString(bundleName)) {
1328         TLOGE(WmsLogTag::WMS_PIP, "Write bundleName failed");
1329         return WMError::WM_ERROR_IPC_FAILED;
1330     }
1331     sptr<IRemoteObject> remote = Remote();
1332     if (remote == nullptr) {
1333         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1334         return WMError::WM_ERROR_IPC_FAILED;
1335     }
1336     if (remote->SendRequest(static_cast<int32_t>(
1337         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_PIP_WINDOW),
1338         data, reply, option) != ERR_NONE) {
1339         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1340         return WMError::WM_ERROR_IPC_FAILED;
1341     }
1342     return static_cast<WMError>(reply.ReadInt32());
1343 }
1344 
GetCurrentPiPWindowInfo(std::string & bundleName)1345 WMError SceneSessionManagerLiteProxy::GetCurrentPiPWindowInfo(std::string& bundleName)
1346 {
1347     MessageParcel data;
1348     MessageParcel reply;
1349     MessageOption option;
1350     if (!data.WriteInterfaceToken(GetDescriptor())) {
1351         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1352         return WMError::WM_ERROR_IPC_FAILED;
1353     }
1354     sptr<IRemoteObject> remote = Remote();
1355     if (remote == nullptr) {
1356         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1357         return WMError::WM_ERROR_IPC_FAILED;
1358     }
1359     if (remote->SendRequest(static_cast<int32_t>(
1360         SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO),
1361         data, reply, option) != ERR_NONE) {
1362         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1363         return WMError::WM_ERROR_IPC_FAILED;
1364     }
1365     WMError errorCode = static_cast<WMError>(reply.ReadInt32());
1366     bundleName = reply.ReadString();
1367     return errorCode;
1368 }
1369 
GetRootMainWindowId(int32_t persistentId,int32_t & hostWindowId)1370 WMError SceneSessionManagerLiteProxy::GetRootMainWindowId(int32_t persistentId, int32_t& hostWindowId)
1371 {
1372     MessageParcel data;
1373     MessageParcel reply;
1374     MessageOption option;
1375     if (!data.WriteInterfaceToken(GetDescriptor())) {
1376         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1377         return WMError::WM_ERROR_IPC_FAILED;
1378     }
1379     if (!data.WriteInt32(persistentId)) {
1380         TLOGE(WmsLogTag::WMS_MAIN, "Failed to write persistentId");
1381         return WMError::WM_ERROR_IPC_FAILED;
1382     }
1383     sptr<IRemoteObject> remote = Remote();
1384     if (remote == nullptr) {
1385         TLOGE(WmsLogTag::WMS_MAIN, "remote is nullptr");
1386         return WMError::WM_ERROR_NULLPTR;
1387     }
1388     int32_t ret = remote->SendRequest(static_cast<uint32_t>(
1389         SceneSessionManagerLiteMessage::TRANS_ID_GET_ROOT_MAIN_WINDOW_ID), data, reply, option);
1390     if (ret != ERR_NONE) {
1391         TLOGE(WmsLogTag::WMS_MAIN, "Send request failed, ret:%{public}d", ret);
1392         return WMError::WM_ERROR_IPC_FAILED;
1393     }
1394     if (!reply.ReadInt32(hostWindowId)) {
1395         TLOGE(WmsLogTag::WMS_MAIN, "Failed to read hostWindowId");
1396         return WMError::WM_ERROR_IPC_FAILED;
1397     }
1398     return WMError::WM_OK;
1399 }
1400 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1401 WMError SceneSessionManagerLiteProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1402 {
1403     MessageOption option;
1404     MessageParcel reply;
1405     MessageParcel data;
1406     if (!data.WriteInterfaceToken(GetDescriptor())) {
1407         WLOGFE("Write InterfaceToken failed");
1408         return WMError::WM_ERROR_IPC_FAILED;
1409     }
1410 
1411     sptr<IRemoteObject> remote = Remote();
1412     if (remote == nullptr) {
1413         WLOGFE("remote is null");
1414         return WMError::WM_ERROR_IPC_FAILED;
1415     }
1416     if (remote->SendRequest(static_cast<uint32_t>(
1417         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO),
1418         data, reply, option) != ERR_NONE) {
1419         WLOGFE("SendRequest failed");
1420         return WMError::WM_ERROR_IPC_FAILED;
1421     }
1422 
1423     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
1424         WLOGFE("read window info failed.");
1425         return WMError::WM_ERROR_IPC_FAILED;
1426     }
1427     return static_cast<WMError>(reply.ReadInt32());
1428 }
1429 
NotifyAppUseControlList(ControlAppType type,int32_t userId,const std::vector<AppUseControlInfo> & controlList)1430 WSError SceneSessionManagerLiteProxy::NotifyAppUseControlList(
1431     ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)
1432 {
1433     TLOGD(WmsLogTag::WMS_LIFE, "in");
1434     MessageParcel data;
1435     MessageParcel reply;
1436     MessageOption option;
1437     if (!data.WriteInterfaceToken(GetDescriptor())) {
1438         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
1439         return WSError::WS_ERROR_INVALID_PARAM;
1440     }
1441 
1442     if (!data.WriteUint8(static_cast<uint8_t>(type))) {
1443         TLOGE(WmsLogTag::WMS_LIFE, "Write type failed");
1444         return WSError::WS_ERROR_INVALID_PARAM;
1445     }
1446 
1447     if (!data.WriteInt32(userId)) {
1448         TLOGE(WmsLogTag::WMS_LIFE, "Write userId failed");
1449         return WSError::WS_ERROR_INVALID_PARAM;
1450     }
1451 
1452     if (!data.WriteInt32(static_cast<int32_t>(controlList.size()))) {
1453         TLOGE(WmsLogTag::WMS_LIFE, "Write controlList size failed");
1454         return WSError::WS_ERROR_INVALID_PARAM;
1455     }
1456 
1457     for (const auto& control : controlList) {
1458         if (!data.WriteString(control.bundleName_) || !data.WriteInt32(control.appIndex_) ||
1459             !data.WriteBool(control.isNeedControl_) || !data.WriteBool(control.isControlRecentOnly_)) {
1460             TLOGE(WmsLogTag::WMS_LIFE, "Write controlList failed");
1461             return WSError::WS_ERROR_INVALID_PARAM;
1462         }
1463     }
1464 
1465     sptr<IRemoteObject> remote = Remote();
1466     if (remote == nullptr) {
1467         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1468         return WSError::WS_ERROR_IPC_FAILED;
1469     }
1470     if (remote->SendRequest(static_cast<uint32_t>(
1471         SceneSessionManagerLiteMessage::TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST),
1472         data, reply, option) != ERR_NONE) {
1473         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1474         return WSError::WS_ERROR_IPC_FAILED;
1475     }
1476     return static_cast<WSError>(reply.ReadInt32());
1477 }
1478 
MinimizeMainSession(const std::string & bundleName,int32_t appIndex,int32_t userId)1479 WMError SceneSessionManagerLiteProxy::MinimizeMainSession(
1480     const std::string& bundleName, int32_t appIndex, int32_t userId)
1481 {
1482     TLOGD(WmsLogTag::WMS_LIFE, "in");
1483     MessageParcel data;
1484     MessageParcel reply;
1485     MessageOption option;
1486     if (!data.WriteInterfaceToken(GetDescriptor())) {
1487         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1488         return WMError::WM_ERROR_IPC_FAILED;
1489     }
1490     if (!data.WriteString(bundleName)) {
1491         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
1492         return WMError::WM_ERROR_IPC_FAILED;
1493     }
1494     if (!data.WriteInt32(appIndex)) {
1495         TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
1496         return WMError::WM_ERROR_IPC_FAILED;
1497     }
1498     if (!data.WriteInt32(userId)) {
1499         TLOGE(WmsLogTag::WMS_LIFE, "write userId failed.");
1500         return WMError::WM_ERROR_IPC_FAILED;
1501     }
1502     sptr<IRemoteObject> remote = Remote();
1503     if (remote == nullptr) {
1504         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1505         return WMError::WM_ERROR_IPC_FAILED;
1506     }
1507     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_MINIMIZE_MAIN_SESSION),
1508         data, reply, option) != ERR_NONE) {
1509         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1510         return WMError::WM_ERROR_IPC_FAILED;
1511     }
1512     int32_t ret = 0;
1513     if (!reply.ReadInt32(ret)) {
1514         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
1515         return WMError::WM_ERROR_IPC_FAILED;
1516     }
1517     return static_cast<WMError>(ret);
1518 }
1519 
LockSessionByAbilityInfo(const AbilityInfoBase & abilityInfo,bool isLock)1520 WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock)
1521 {
1522     TLOGD(WmsLogTag::WMS_LIFE, "in");
1523     MessageParcel data;
1524     MessageParcel reply;
1525     MessageOption option;
1526     if (!data.WriteInterfaceToken(GetDescriptor())) {
1527         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1528         return WMError::WM_ERROR_IPC_FAILED;
1529     }
1530     if (!data.WriteString(abilityInfo.bundleName)) {
1531         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
1532         return WMError::WM_ERROR_IPC_FAILED;
1533     }
1534     if (!data.WriteString(abilityInfo.moduleName)) {
1535         TLOGE(WmsLogTag::WMS_LIFE, "write moduleName failed.");
1536         return WMError::WM_ERROR_IPC_FAILED;
1537     }
1538     if (!data.WriteString(abilityInfo.abilityName)) {
1539         TLOGE(WmsLogTag::WMS_LIFE, "write abilityName failed.");
1540         return WMError::WM_ERROR_IPC_FAILED;
1541     }
1542     if (!data.WriteInt32(abilityInfo.appIndex)) {
1543         TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
1544         return WMError::WM_ERROR_IPC_FAILED;
1545     }
1546     if (!data.WriteBool(isLock)) {
1547         TLOGE(WmsLogTag::WMS_LIFE, "write isLock failed.");
1548         return WMError::WM_ERROR_IPC_FAILED;
1549     }
1550     sptr<IRemoteObject> remote = Remote();
1551     if (remote == nullptr) {
1552         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1553         return WMError::WM_ERROR_IPC_FAILED;
1554     }
1555     if (remote->SendRequest(
1556         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO),
1557         data, reply, option) != ERR_NONE) {
1558         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1559         return WMError::WM_ERROR_IPC_FAILED;
1560     }
1561     int32_t ret = 0;
1562     if (!reply.ReadInt32(ret)) {
1563         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
1564         return WMError::WM_ERROR_IPC_FAILED;
1565     }
1566     return static_cast<WMError>(ret);
1567 }
1568 
HasFloatingWindowForeground(const sptr<IRemoteObject> & abilityToken,bool & hasOrNot)1569 WMError SceneSessionManagerLiteProxy::HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
1570     bool& hasOrNot)
1571 {
1572     if (!abilityToken) {
1573         TLOGE(WmsLogTag::WMS_SYSTEM, "AbilityToken is null");
1574         return WMError::WM_ERROR_INVALID_PARAM;
1575     }
1576     MessageParcel data;
1577     MessageParcel reply;
1578     MessageOption option;
1579     if (!data.WriteInterfaceToken(GetDescriptor())) {
1580         TLOGE(WmsLogTag::WMS_SYSTEM, "Write interfaceToken failed");
1581         return WMError::WM_ERROR_IPC_FAILED;
1582     }
1583     if (!data.WriteRemoteObject(abilityToken)) {
1584         TLOGE(WmsLogTag::WMS_SYSTEM, "Write abilityToken failed");
1585         return WMError::WM_ERROR_IPC_FAILED;
1586     }
1587     sptr<IRemoteObject> remote = Remote();
1588     if (remote == nullptr) {
1589         TLOGE(WmsLogTag::WMS_SYSTEM, "Remote is null");
1590         return WMError::WM_ERROR_IPC_FAILED;
1591     }
1592     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_HAS_FLOAT_FOREGROUND),
1593         data, reply, option) != ERR_NONE) {
1594         TLOGE(WmsLogTag::WMS_SYSTEM, "SendRequest failed");
1595         return WMError::WM_ERROR_IPC_FAILED;
1596     }
1597     if (!reply.ReadBool(hasOrNot)) {
1598         TLOGE(WmsLogTag::WMS_SYSTEM, "Read result failed");
1599         return WMError::WM_ERROR_IPC_FAILED;
1600     }
1601     uint32_t ret = 0;
1602     if (!reply.ReadUint32(ret)) {
1603         TLOGE(WmsLogTag::WMS_SYSTEM, "Read ret failed");
1604         return WMError::WM_ERROR_IPC_FAILED;
1605     }
1606     return static_cast<WMError>(ret);
1607 }
1608 
RegisterSessionLifecycleListenerByIds(const sptr<ISessionLifecycleListener> & listener,const std::vector<int32_t> & persistentIdList)1609 WMError SceneSessionManagerLiteProxy::RegisterSessionLifecycleListenerByIds(
1610     const sptr<ISessionLifecycleListener>& listener, const std::vector<int32_t>& persistentIdList)
1611 {
1612     TLOGD(WmsLogTag::WMS_LIFE, "in");
1613     MessageParcel data;
1614     MessageParcel reply;
1615     MessageOption option;
1616     if (!data.WriteInterfaceToken(GetDescriptor())) {
1617         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1618         return WMError::WM_ERROR_IPC_FAILED;
1619     }
1620     if (listener == nullptr || listener->AsObject() == nullptr) {
1621         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1622         return WMError::WM_ERROR_IPC_FAILED;
1623     }
1624     if (!data.WriteRemoteObject(listener->AsObject())) {
1625         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1626         return WMError::WM_ERROR_IPC_FAILED;
1627     }
1628     if (!data.WriteInt32Vector(persistentIdList)) {
1629         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentIdList failed.");
1630         return WMError::WM_ERROR_IPC_FAILED;
1631     }
1632     sptr<IRemoteObject> remote = Remote();
1633     if (remote == nullptr) {
1634         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1635         return WMError::WM_ERROR_IPC_FAILED;
1636     }
1637     if (remote->SendRequest(
1638         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_IDS),
1639         data, reply, option) != ERR_NONE) {
1640         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1641         return WMError::WM_ERROR_IPC_FAILED;
1642     }
1643     int32_t ret = 0;
1644     if (!reply.ReadInt32(ret)) {
1645         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1646         return WMError::WM_ERROR_IPC_FAILED;
1647     }
1648     return static_cast<WMError>(ret);
1649 }
1650 
RegisterSessionLifecycleListenerByBundles(const sptr<ISessionLifecycleListener> & listener,const std::vector<std::string> & bundleNameList)1651 WMError SceneSessionManagerLiteProxy::RegisterSessionLifecycleListenerByBundles(
1652     const sptr<ISessionLifecycleListener>& listener, const std::vector<std::string>& bundleNameList)
1653 {
1654     TLOGD(WmsLogTag::WMS_LIFE, "in");
1655     MessageParcel data;
1656     MessageParcel reply;
1657     MessageOption option;
1658     if (!data.WriteInterfaceToken(GetDescriptor())) {
1659         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1660         return WMError::WM_ERROR_IPC_FAILED;
1661     }
1662     if (listener == nullptr || listener->AsObject() == nullptr) {
1663         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1664         return WMError::WM_ERROR_IPC_FAILED;
1665     }
1666     if (!data.WriteRemoteObject(listener->AsObject())) {
1667         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1668         return WMError::WM_ERROR_IPC_FAILED;
1669     }
1670     if (!data.WriteStringVector(bundleNameList)) {
1671         TLOGE(WmsLogTag::WMS_LIFE, "Write bundleNameList failed.");
1672         return WMError::WM_ERROR_IPC_FAILED;
1673     }
1674     sptr<IRemoteObject> remote = Remote();
1675     if (remote == nullptr) {
1676         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1677         return WMError::WM_ERROR_IPC_FAILED;
1678     }
1679     if (remote->SendRequest(
1680         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_BUNDLES),
1681         data, reply, option) != ERR_NONE) {
1682         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1683         return WMError::WM_ERROR_IPC_FAILED;
1684     }
1685     int32_t ret = 0;
1686     if (!reply.ReadInt32(ret)) {
1687         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1688         return WMError::WM_ERROR_IPC_FAILED;
1689     }
1690     return static_cast<WMError>(ret);
1691 }
1692 
UnregisterSessionLifecycleListener(const sptr<ISessionLifecycleListener> & listener)1693 WMError SceneSessionManagerLiteProxy::UnregisterSessionLifecycleListener(
1694     const sptr<ISessionLifecycleListener>& listener)
1695 {
1696     TLOGD(WmsLogTag::WMS_LIFE, "in");
1697     MessageParcel data;
1698     MessageParcel reply;
1699     MessageOption option;
1700     if (!data.WriteInterfaceToken(GetDescriptor())) {
1701         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1702         return WMError::WM_ERROR_IPC_FAILED;
1703     }
1704     if (listener == nullptr || listener->AsObject() == nullptr) {
1705         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1706         return WMError::WM_ERROR_IPC_FAILED;
1707     }
1708     if (!data.WriteRemoteObject(listener->AsObject())) {
1709         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1710         return WMError::WM_ERROR_IPC_FAILED;
1711     }
1712     sptr<IRemoteObject> remote = Remote();
1713     if (remote == nullptr) {
1714         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1715         return WMError::WM_ERROR_IPC_FAILED;
1716     }
1717     if (remote->SendRequest(
1718         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LIFECYCLE_LISTENER),
1719         data, reply, option) != ERR_NONE) {
1720         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1721         return WMError::WM_ERROR_IPC_FAILED;
1722     }
1723     int32_t ret = 0;
1724     if (!reply.ReadInt32(ret)) {
1725         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1726         return WMError::WM_ERROR_IPC_FAILED;
1727     }
1728     return static_cast<WMError>(ret);
1729 }
1730 
ListWindowInfo(const WindowInfoOption & windowInfoOption,std::vector<sptr<WindowInfo>> & infos)1731 WMError SceneSessionManagerLiteProxy::ListWindowInfo(const WindowInfoOption& windowInfoOption,
1732     std::vector<sptr<WindowInfo>>& infos)
1733 {
1734     MessageParcel data;
1735     MessageParcel reply;
1736     MessageOption option;
1737     if (!data.WriteInterfaceToken(GetDescriptor())) {
1738         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write interfaceToken failed");
1739         return WMError::WM_ERROR_IPC_FAILED;
1740     }
1741     if (!data.WriteUint8(static_cast<WindowInfoFilterOptionDataType>(windowInfoOption.windowInfoFilterOption))) {
1742         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowInfoFilterOption failed");
1743         return WMError::WM_ERROR_IPC_FAILED;
1744     }
1745     if (!data.WriteUint8(static_cast<WindowInfoTypeOptionDataType>(windowInfoOption.windowInfoTypeOption))) {
1746         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowInfoTypeOption failed");
1747         return WMError::WM_ERROR_IPC_FAILED;
1748     }
1749     if (!data.WriteUint64(windowInfoOption.displayId)) {
1750         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed");
1751         return WMError::WM_ERROR_IPC_FAILED;
1752     }
1753     if (!data.WriteInt32(windowInfoOption.windowId)) {
1754         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowId failed");
1755         return WMError::WM_ERROR_IPC_FAILED;
1756     }
1757     sptr<IRemoteObject> remote = Remote();
1758     if (remote == nullptr) {
1759         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null");
1760         return WMError::WM_ERROR_IPC_FAILED;
1761     }
1762     if (remote->SendRequest(static_cast<uint32_t>(
1763         SceneSessionManagerLiteMessage::TRANS_ID_LIST_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1764         return WMError::WM_ERROR_IPC_FAILED;
1765     }
1766     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowInfo>(reply, infos)) {
1767         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read window info failed");
1768         return WMError::WM_ERROR_IPC_FAILED;
1769     }
1770     int32_t errCode = 0;
1771     if (!reply.ReadInt32(errCode)) {
1772         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read errcode failed");
1773         return WMError::WM_ERROR_IPC_FAILED;
1774     }
1775     return static_cast<WMError>(errCode);
1776 }
1777 } // namespace OHOS::Rosen
1778