• 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 "pointer_event.h"
20 #include "window_manager_hilog.h"
21 
22 namespace OHOS::Rosen {
23 namespace {
24 constexpr int32_t CYCLE_LIMIT = 1000;
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerLiteProxy"};
26 constexpr int32_t MAX_TOPN_INFO_SIZE = 200;
27 }
28 
SetSessionLabel(const sptr<IRemoteObject> & token,const std::string & label)29 WSError SceneSessionManagerLiteProxy::SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label)
30 {
31     WLOGFD("run SceneSessionManagerLiteProxy::SetSessionLabel");
32     MessageParcel data;
33     MessageParcel reply;
34     MessageOption option;
35     if (!data.WriteInterfaceToken(GetDescriptor())) {
36         WLOGFE("WriteInterfaceToken failed");
37         return WSError::WS_ERROR_IPC_FAILED;
38     }
39     if (!data.WriteRemoteObject(token)) {
40         WLOGFE("Write token failed");
41         return WSError::WS_ERROR_IPC_FAILED;
42     }
43     if (!data.WriteString(label)) {
44         WLOGFE("Write label failed");
45         return WSError::WS_ERROR_IPC_FAILED;
46     }
47 
48     sptr<IRemoteObject> remote = Remote();
49     if (remote == nullptr) {
50         WLOGFE("remote is null");
51         return WSError::WS_ERROR_IPC_FAILED;
52     }
53     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_LABEL),
54         data, reply, option) != ERR_NONE) {
55         WLOGFE("SendRequest failed");
56         return WSError::WS_ERROR_IPC_FAILED;
57     }
58     return static_cast<WSError>(reply.ReadInt32());
59 }
60 
SetSessionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & icon)61 WSError SceneSessionManagerLiteProxy::SetSessionIcon(const sptr<IRemoteObject>& token,
62     const std::shared_ptr<Media::PixelMap>& icon)
63 {
64     WLOGFD("run SceneSessionManagerLiteProxy::SetSessionIcon");
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68     if (!data.WriteInterfaceToken(GetDescriptor())) {
69         WLOGFE("WriteInterfaceToken failed");
70         return WSError::WS_ERROR_IPC_FAILED;
71     }
72     if (!data.WriteRemoteObject(token)) {
73         WLOGFE("Write token failed");
74         return WSError::WS_ERROR_IPC_FAILED;
75     }
76     if (!data.WriteParcelable(icon.get())) {
77         WLOGFE("Write icon failed");
78         return WSError::WS_ERROR_IPC_FAILED;
79     }
80 
81     sptr<IRemoteObject> remote = Remote();
82     if (remote == nullptr) {
83         WLOGFE("remote is null");
84         return WSError::WS_ERROR_IPC_FAILED;
85     }
86     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_ICON),
87         data, reply, option) != ERR_NONE) {
88         WLOGFE("SendRequest failed");
89         return WSError::WS_ERROR_IPC_FAILED;
90     }
91     return static_cast<WSError>(reply.ReadInt32());
92 }
93 
IsValidSessionIds(const std::vector<int32_t> & sessionIds,std::vector<bool> & results)94 WSError SceneSessionManagerLiteProxy::IsValidSessionIds(
95     const std::vector<int32_t>& sessionIds, std::vector<bool>& results)
96 {
97     WLOGFD("run SceneSessionManagerLiteProxy::IsValidSessionIds");
98     MessageParcel data;
99     MessageParcel reply;
100     MessageOption option;
101     if (!data.WriteInterfaceToken(GetDescriptor())) {
102         WLOGFE("WriteInterfaceToken failed");
103         return WSError::WS_ERROR_IPC_FAILED;
104     }
105     if (!data.WriteInt32Vector(sessionIds)) {
106         WLOGFE("Write sessionIds failed");
107         return WSError::WS_ERROR_IPC_FAILED;
108     }
109 
110     sptr<IRemoteObject> remote = Remote();
111     if (remote == nullptr) {
112         WLOGFE("remote is null");
113         return WSError::WS_ERROR_IPC_FAILED;
114     }
115     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_IS_VALID_SESSION_IDS),
116         data, reply, option) != ERR_NONE) {
117         WLOGFE("SendRequest failed");
118         return WSError::WS_ERROR_IPC_FAILED;
119     }
120 
121     reply.ReadBoolVector(&results);
122     return static_cast<WSError>(reply.ReadInt32());
123 }
124 
PendingSessionToForeground(const sptr<IRemoteObject> & token)125 WSError SceneSessionManagerLiteProxy::PendingSessionToForeground(const sptr<IRemoteObject>& token)
126 {
127     WLOGFD("run SceneSessionManagerLiteProxy::PendingSessionToForeground");
128     MessageParcel data;
129     MessageParcel reply;
130     MessageOption option;
131     if (!data.WriteInterfaceToken(GetDescriptor())) {
132         WLOGFE("Write interfaceToken failed");
133         return WSError::WS_ERROR_IPC_FAILED;
134     }
135 
136     if (!data.WriteRemoteObject(token)) {
137         WLOGFE("Write token failed");
138         return WSError::WS_ERROR_IPC_FAILED;
139     }
140 
141     sptr<IRemoteObject> remote = Remote();
142     if (remote == nullptr) {
143         WLOGFE("remote is null");
144         return WSError::WS_ERROR_IPC_FAILED;
145     }
146     if (remote->SendRequest(static_cast<uint32_t>(
147         SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND),
148         data, reply, option) != ERR_NONE) {
149         WLOGFE("SendRequest failed");
150         return WSError::WS_ERROR_IPC_FAILED;
151     }
152     return static_cast<WSError>(reply.ReadInt32());
153 }
154 
PendingSessionToBackground(const sptr<IRemoteObject> & token,const BackgroundParams & params)155 WSError SceneSessionManagerLiteProxy::PendingSessionToBackground(const sptr<IRemoteObject>& token,
156     const BackgroundParams& params)
157 {
158     TLOGD(WmsLogTag::WMS_LIFE, "run");
159     MessageParcel data;
160     MessageParcel reply;
161     MessageOption option;
162     if (!data.WriteInterfaceToken(GetDescriptor())) {
163         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
164         return WSError::WS_ERROR_IPC_FAILED;
165     }
166     if (!data.WriteRemoteObject(token)) {
167         TLOGE(WmsLogTag::WMS_LIFE, "Write token failed");
168         return WSError::WS_ERROR_IPC_FAILED;
169     }
170     if (!data.WriteInt32(params.persistentId)) {
171         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentId failed");
172         return WSError::WS_ERROR_IPC_FAILED;
173     }
174     if (!data.WriteBool(params.shouldBackToCaller)) {
175         TLOGE(WmsLogTag::WMS_LIFE, "Write shouldBackToCaller failed");
176         return WSError::WS_ERROR_IPC_FAILED;
177     }
178     if (!data.WriteParcelable(&params.wantParams)) {
179         TLOGE(WmsLogTag::WMS_LIFE, "Write wantParams failed");
180         return WSError::WS_ERROR_IPC_FAILED;
181     }
182     sptr<IRemoteObject> remote = Remote();
183     if (remote == nullptr) {
184         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
185         return WSError::WS_ERROR_IPC_FAILED;
186     }
187     if (remote->SendRequest(static_cast<uint32_t>(
188         SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND),
189         data, reply, option) != ERR_NONE) {
190         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
191         return WSError::WS_ERROR_IPC_FAILED;
192     }
193     int32_t ret = 0;
194     if (!reply.ReadInt32(ret)) {
195         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
196         return WSError::WS_ERROR_IPC_FAILED;
197     }
198     return static_cast<WSError>(ret);
199 }
200 
PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> & token,bool shouldBackToCaller)201 WSError SceneSessionManagerLiteProxy::PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject>& token,
202     bool shouldBackToCaller)
203 {
204     TLOGD(WmsLogTag::WMS_LIFE, "run");
205     MessageParcel data;
206     MessageParcel reply;
207     MessageOption option;
208     if (!data.WriteInterfaceToken(GetDescriptor())) {
209         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
210         return WSError::WS_ERROR_IPC_FAILED;
211     }
212 
213     if (!data.WriteRemoteObject(token)) {
214         TLOGE(WmsLogTag::WMS_LIFE, "Write token failed");
215         return WSError::WS_ERROR_IPC_FAILED;
216     }
217 
218     if (!data.WriteBool(shouldBackToCaller)) {
219         TLOGE(WmsLogTag::WMS_LIFE, "Write shouldBackToCaller failed");
220         return WSError::WS_ERROR_IPC_FAILED;
221     }
222 
223     sptr<IRemoteObject> remote = Remote();
224     if (remote == nullptr) {
225         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
226         return WSError::WS_ERROR_IPC_FAILED;
227     }
228     if (remote->SendRequest(static_cast<uint32_t>(
229         SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR),
230         data, reply, option) != ERR_NONE) {
231         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
232         return WSError::WS_ERROR_IPC_FAILED;
233     }
234     return static_cast<WSError>(reply.ReadInt32());
235 }
236 
RegisterSessionListener(const sptr<ISessionListener> & listener,bool isRecover)237 WSError SceneSessionManagerLiteProxy::RegisterSessionListener(const sptr<ISessionListener>& listener, bool isRecover)
238 {
239     WLOGFD("run SceneSessionManagerLiteProxy::RegisterSessionListener");
240     MessageParcel data;
241     MessageParcel reply;
242     MessageOption option(MessageOption::TF_SYNC);
243     if (listener == nullptr) {
244         WLOGFE("register mission listener, listener is nullptr");
245         return WSError::WS_ERROR_INVALID_PARAM;
246     }
247     if (!data.WriteInterfaceToken(GetDescriptor())) {
248         WLOGFE("WriteInterfaceToken failed");
249         return WSError::WS_ERROR_IPC_FAILED;
250     }
251     if (!data.WriteRemoteObject(listener->AsObject())) {
252         WLOGFE("write mission listener failed when register mission listener.");
253         return WSError::WS_ERROR_IPC_FAILED;
254     }
255     sptr<IRemoteObject> remote = Remote();
256     if (remote == nullptr) {
257         WLOGFE("remote is null");
258         return WSError::WS_ERROR_IPC_FAILED;
259     }
260     if (remote->SendRequest(static_cast<uint32_t>(
261         SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LISTENER),
262         data, reply, option) != ERR_NONE) {
263         WLOGFE("SendRequest failed");
264         return WSError::WS_ERROR_IPC_FAILED;
265     }
266     return static_cast<WSError>(reply.ReadInt32());
267 }
268 
UnRegisterSessionListener(const sptr<ISessionListener> & listener)269 WSError SceneSessionManagerLiteProxy::UnRegisterSessionListener(const sptr<ISessionListener>& listener)
270 {
271     WLOGFD("run SceneSessionManagerLiteProxy::UnRegisterSessionListener");
272     if (listener == nullptr) {
273         WLOGFE("unregister mission listener, listener is nullptr");
274         return WSError::WS_ERROR_INVALID_PARAM;
275     }
276     MessageParcel data;
277     MessageParcel reply;
278     MessageOption option(MessageOption::TF_SYNC);
279     if (!data.WriteInterfaceToken(GetDescriptor())) {
280         WLOGFE("WriteInterfaceToken failed");
281         return WSError::WS_ERROR_IPC_FAILED;
282     }
283     if (!data.WriteRemoteObject(listener->AsObject())) {
284         WLOGFE("write mission listener failed when unregister mission listener.");
285         return WSError::WS_ERROR_IPC_FAILED;
286     }
287     sptr<IRemoteObject> remote = Remote();
288     if (remote == nullptr) {
289         WLOGFE("remote is null");
290         return WSError::WS_ERROR_IPC_FAILED;
291     }
292     if (remote->SendRequest(
293         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER),
294         data, reply, option) != ERR_NONE) {
295         WLOGFE("SendRequest failed");
296         return WSError::WS_ERROR_IPC_FAILED;
297     }
298     return static_cast<WSError>(reply.ReadInt32());
299 }
300 
GetSessionInfos(const std::string & deviceId,int32_t numMax,std::vector<SessionInfoBean> & sessionInfos)301 WSError SceneSessionManagerLiteProxy::GetSessionInfos(const std::string& deviceId, int32_t numMax,
302     std::vector<SessionInfoBean>& sessionInfos)
303 {
304     WLOGFD("run SceneSessionManagerLiteProxy::GetSessionInfos");
305     MessageParcel data;
306     MessageParcel reply;
307     MessageOption option(MessageOption::TF_SYNC);
308     if (!data.WriteInterfaceToken(GetDescriptor())) {
309         WLOGFE("WriteInterfaceToken failed");
310         return WSError::WS_ERROR_IPC_FAILED;
311     }
312     if (!data.WriteString16(Str8ToStr16(deviceId))) {
313         WLOGFE("GetSessionInfos write deviceId failed.");
314         return WSError::WS_ERROR_IPC_FAILED;
315     }
316     if (!data.WriteInt32(numMax)) {
317         WLOGFE("GetSessionInfos numMax write failed.");
318         return WSError::WS_ERROR_IPC_FAILED;
319     }
320     sptr<IRemoteObject> remote = Remote();
321     if (remote == nullptr) {
322         WLOGFE("remote is null");
323         return WSError::WS_ERROR_IPC_FAILED;
324     }
325     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFOS),
326         data, reply, option) != ERR_NONE) {
327         WLOGFE("SendRequest failed");
328         return WSError::WS_ERROR_IPC_FAILED;
329     }
330     WSError error = GetParcelableInfos(reply, sessionInfos);
331     if (error != WSError::WS_OK) {
332         WLOGFE("GetSessionInfos error");
333         return error;
334     }
335     return static_cast<WSError>(reply.ReadInt32());
336 }
337 
GetMainWindowStatesByPid(int32_t pid,std::vector<MainWindowState> & windowStates)338 WSError SceneSessionManagerLiteProxy::GetMainWindowStatesByPid(int32_t pid, std::vector<MainWindowState>& windowStates)
339 {
340     TLOGD(WmsLogTag::WMS_LIFE, "run");
341     sptr<IRemoteObject> remote = Remote();
342     if (remote == nullptr) {
343         TLOGE(WmsLogTag::WMS_LIFE, "remote is nullptr");
344         return WSError::WS_ERROR_IPC_FAILED;
345     }
346     MessageParcel data;
347     MessageParcel reply;
348     MessageOption option(MessageOption::TF_SYNC);
349     if (!data.WriteInterfaceToken(GetDescriptor())) {
350         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
351         return WSError::WS_ERROR_IPC_FAILED;
352     }
353     if (!data.WriteInt32(pid)) {
354         TLOGE(WmsLogTag::WMS_LIFE, "write pid failed");
355         return WSError::WS_ERROR_IPC_FAILED;
356     }
357     if (remote->SendRequest(
358         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MAIN_WINDOW_STATES_BY_PID),
359         data, reply, option) != ERR_NONE) {
360         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
361         return WSError::WS_ERROR_IPC_FAILED;
362     }
363     WSError error = GetParcelableInfos(reply, windowStates);
364     if (error != WSError::WS_OK) {
365         TLOGE(WmsLogTag::WMS_LIFE, "GetWindowStates error");
366         return error;
367     }
368     return static_cast<WSError>(reply.ReadInt32());
369 }
370 
GetSessionInfo(const std::string & deviceId,int32_t persistentId,SessionInfoBean & sessionInfo)371 WSError SceneSessionManagerLiteProxy::GetSessionInfo(const std::string& deviceId, int32_t persistentId,
372     SessionInfoBean& sessionInfo)
373 {
374     WLOGFD("run SceneSessionManagerLiteProxy::GetSessionInfo");
375     MessageParcel data;
376     MessageParcel reply;
377     MessageOption option(MessageOption::TF_SYNC);
378     if (!data.WriteInterfaceToken(GetDescriptor())) {
379         WLOGFE("WriteInterfaceToken failed");
380         return WSError::WS_ERROR_IPC_FAILED;
381     }
382     if (!data.WriteString16(Str8ToStr16(deviceId))) {
383         WLOGFE("GetSessionInfo write deviceId failed.");
384         return WSError::WS_ERROR_IPC_FAILED;
385     }
386     if (!data.WriteInt32(persistentId)) {
387         WLOGFE("GetSessionInfo write persistentId failed.");
388         return WSError::WS_ERROR_IPC_FAILED;
389     }
390     sptr<IRemoteObject> remote = Remote();
391     if (remote == nullptr) {
392         WLOGFE("remote is null");
393         return WSError::WS_ERROR_IPC_FAILED;
394     }
395     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFO_BY_ID),
396         data, reply, option) != ERR_NONE) {
397         WLOGFE("SendRequest failed");
398         return WSError::WS_ERROR_IPC_FAILED;
399     }
400     std::unique_ptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
401     if (info == nullptr) {
402         WLOGFE("read missioninfo failed.");
403         return WSError::WS_ERROR_IPC_FAILED;
404     }
405     sessionInfo = *info;
406     return static_cast<WSError>(reply.ReadInt32());
407 }
408 
GetSessionInfoByContinueSessionId(const std::string & continueSessionId,SessionInfoBean & sessionInfo)409 WSError SceneSessionManagerLiteProxy::GetSessionInfoByContinueSessionId(
410     const std::string& continueSessionId, SessionInfoBean& sessionInfo)
411 {
412     TLOGI(WmsLogTag::WMS_LIFE, "continueSessionId: %{public}s", continueSessionId.c_str());
413     MessageParcel data;
414     MessageParcel reply;
415     MessageOption option(MessageOption::TF_SYNC);
416     if (!data.WriteInterfaceToken(GetDescriptor())) {
417         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
418         return WSError::WS_ERROR_IPC_FAILED;
419     }
420     if (!data.WriteString(continueSessionId)) {
421         TLOGE(WmsLogTag::WMS_LIFE, "GetSessionInfoByContinueSessionId write continueSessionId failed.");
422         return WSError::WS_ERROR_IPC_FAILED;
423     }
424     sptr<IRemoteObject> remote = Remote();
425     if (remote == nullptr) {
426         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
427         return WSError::WS_ERROR_IPC_FAILED;
428     }
429     if (remote->SendRequest(static_cast<uint32_t>(
430         SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_INFO_BY_CONTINUE_SESSION_ID),
431         data, reply, option) != ERR_NONE) {
432         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
433         return WSError::WS_ERROR_IPC_FAILED;
434     }
435     sptr<SessionInfoBean> info(reply.ReadParcelable<SessionInfoBean>());
436     if (info == nullptr) {
437         TLOGE(WmsLogTag::WMS_LIFE, "read sessioninfo failed.");
438         return WSError::WS_ERROR_IPC_FAILED;
439     }
440     sessionInfo = *info;
441     return static_cast<WSError>(reply.ReadInt32());
442 }
443 
444 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)445 WSError SceneSessionManagerLiteProxy::GetParcelableInfos(MessageParcel& reply, std::vector<T>& parcelableInfos)
446 {
447     int32_t infoSize = reply.ReadInt32();
448     if (infoSize > CYCLE_LIMIT || infoSize < 0) {
449         WLOGFE("infoSize is too large or negative");
450         return WSError::WS_ERROR_IPC_FAILED;
451     }
452 
453     for (int32_t i = 0; i < infoSize; i++) {
454         std::unique_ptr<T> info(reply.ReadParcelable<T>());
455         if (!info) {
456             WLOGFE("Read Parcelable infos failed.");
457             return WSError::WS_ERROR_IPC_FAILED;
458         }
459         parcelableInfos.emplace_back(*info);
460     }
461     return WSError::WS_OK;
462 }
463 
TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,bool needStartCaller,bool isFromBroker)464 WSError SceneSessionManagerLiteProxy::TerminateSessionNew(const sptr<AAFwk::SessionInfo> abilitySessionInfo,
465     bool needStartCaller, bool isFromBroker)
466 {
467     if (abilitySessionInfo == nullptr) {
468         WLOGFE("abilitySessionInfo is null");
469         return WSError::WS_ERROR_INVALID_SESSION;
470     }
471     MessageParcel data, reply;
472     MessageOption option(MessageOption::TF_ASYNC);
473     if (!data.WriteInterfaceToken(GetDescriptor())) {
474         WLOGFE("WriteInterfaceToken failed");
475         return WSError::WS_ERROR_IPC_FAILED;
476     }
477     if (!data.WriteParcelable(abilitySessionInfo)) {
478         WLOGFE("write abilitySessionInfo failed");
479         return WSError::WS_ERROR_IPC_FAILED;
480     }
481     if (!data.WriteBool(needStartCaller)) {
482         WLOGFE("Write needStartCaller failed");
483         return WSError::WS_ERROR_IPC_FAILED;
484     }
485     if (!data.WriteBool(isFromBroker)) {
486         WLOGFE("Write isFromBroker failed");
487         return WSError::WS_ERROR_IPC_FAILED;
488     }
489     sptr<IRemoteObject> remote = Remote();
490     if (remote == nullptr) {
491         WLOGFE("remote is null");
492         return WSError::WS_ERROR_IPC_FAILED;
493     }
494     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_NEW),
495         data, reply, option) != ERR_NONE) {
496         WLOGFE("SendRequest failed");
497         return WSError::WS_ERROR_IPC_FAILED;
498     }
499     return static_cast<WSError>(reply.ReadInt32());
500 }
501 
GetFocusSessionToken(sptr<IRemoteObject> & token,DisplayId displayId)502 WSError SceneSessionManagerLiteProxy::GetFocusSessionToken(sptr<IRemoteObject>& token, DisplayId displayId)
503 {
504     WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionToken");
505     MessageParcel data;
506     MessageParcel reply;
507     MessageOption option;
508     if (!data.WriteInterfaceToken(GetDescriptor())) {
509         WLOGFE("Write interfaceToken failed");
510         return WSError::WS_ERROR_IPC_FAILED;
511     }
512     if (!data.WriteUint64(displayId)) {
513         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
514         return WSError::WS_ERROR_IPC_FAILED;
515     }
516     sptr<IRemoteObject> remote = Remote();
517     if (remote == nullptr) {
518         WLOGFE("remote is null");
519         return WSError::WS_ERROR_IPC_FAILED;
520     }
521     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
522         data, reply, option) != ERR_NONE) {
523         WLOGFE("SendRequest failed");
524         return WSError::WS_ERROR_IPC_FAILED;
525     }
526     token = reply.ReadRemoteObject();
527     if (token == nullptr) {
528         WLOGFE("get token nullptr.");
529     }
530     return static_cast<WSError>(reply.ReadInt32());
531 }
532 
GetFocusSessionElement(AppExecFwk::ElementName & element,DisplayId displayId)533 WSError SceneSessionManagerLiteProxy::GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId)
534 {
535     WLOGFD("run SceneSessionManagerLiteProxy::GetFocusSessionElement");
536     MessageParcel data;
537     MessageParcel reply;
538     MessageOption option;
539     if (!data.WriteInterfaceToken(GetDescriptor())) {
540         WLOGFE("Write interfaceToken failed");
541         return WSError::WS_ERROR_IPC_FAILED;
542     }
543     if (!data.WriteUint64(displayId)) {
544         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
545         return WSError::WS_ERROR_IPC_FAILED;
546     }
547     sptr<IRemoteObject> remote = Remote();
548     if (remote == nullptr) {
549         WLOGFE("remote is null");
550         return WSError::WS_ERROR_IPC_FAILED;
551     }
552     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT),
553         data, reply, option) != ERR_NONE) {
554         WLOGFE("SendRequest failed");
555         return WSError::WS_ERROR_IPC_FAILED;
556     }
557     sptr<AppExecFwk::ElementName> ret = reply.ReadParcelable<AppExecFwk::ElementName>();
558     if (ret) {
559         element = *ret;
560     } else {
561         WLOGFD("get element null.");
562     }
563     return static_cast<WSError>(reply.ReadInt32());
564 }
565 
IsFocusWindowParent(const sptr<IRemoteObject> & token,bool & isParent)566 WSError SceneSessionManagerLiteProxy::IsFocusWindowParent(const sptr<IRemoteObject>& token, bool& isParent)
567 {
568     TLOGD(WmsLogTag::WMS_FOCUS, "run");
569     MessageParcel data;
570     MessageParcel reply;
571     MessageOption option;
572     if (token == nullptr) {
573         TLOGE(WmsLogTag::WMS_FOCUS, "Token is nullptr");
574         return WSError::WS_ERROR_INVALID_PARAM;
575     }
576     if (!data.WriteInterfaceToken(GetDescriptor())) {
577         TLOGE(WmsLogTag::WMS_FOCUS, "Write interfaceToken failed");
578         return WSError::WS_ERROR_IPC_FAILED;
579     }
580     if (!data.WriteRemoteObject(token)) {
581         TLOGE(WmsLogTag::WMS_FOCUS, "Write token failed");
582         return WSError::WS_ERROR_IPC_FAILED;
583     }
584     sptr<IRemoteObject> remote = Remote();
585     if (remote == nullptr) {
586         TLOGE(WmsLogTag::WMS_FOCUS, "Remote is null");
587         return WSError::WS_ERROR_IPC_FAILED;
588     }
589     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_IS_FOCUS_WINDOW_PARENT),
590         data, reply, option) != ERR_NONE) {
591         TLOGE(WmsLogTag::WMS_FOCUS, "SendRequest failed");
592         return WSError::WS_ERROR_IPC_FAILED;
593     }
594     bool value = false;
595     if (!reply.ReadBool(value)) {
596         TLOGE(WmsLogTag::WMS_FOCUS, "Read result failed");
597         return WSError::WS_ERROR_IPC_FAILED;
598     }
599     int32_t ret = 0;
600     if (!reply.ReadInt32(ret)) {
601         TLOGE(WmsLogTag::WMS_FOCUS, "Read ret failed");
602         return WSError::WS_ERROR_IPC_FAILED;
603     }
604     isParent = value;
605     TLOGD(WmsLogTag::WMS_FOCUS, "isParent: %{public}d", isParent);
606     return static_cast<WSError>(ret);
607 }
608 
GetSessionSnapshot(const std::string & deviceId,int32_t persistentId,SessionSnapshot & snapshot,bool isLowResolution)609 WSError SceneSessionManagerLiteProxy::GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
610     SessionSnapshot& snapshot, bool isLowResolution)
611 {
612     MessageParcel data;
613     MessageParcel reply;
614     MessageOption option;
615     if (!data.WriteInterfaceToken(GetDescriptor())) {
616         WLOGFE("WriteInterfaceToken failed");
617         return WSError::WS_ERROR_INVALID_PARAM;
618     }
619     if (!data.WriteString16(Str8ToStr16(deviceId))) {
620         WLOGFE("Write deviceId failed.");
621         return WSError::WS_ERROR_IPC_FAILED;
622     }
623     if (!data.WriteInt32(persistentId)) {
624         WLOGFE("Write persistentId failed");
625         return WSError::WS_ERROR_INVALID_PARAM;
626     }
627 
628     if (!data.WriteBool(isLowResolution)) {
629         WLOGFE("Write isLowResolution failed");
630         return WSError::WS_ERROR_INVALID_PARAM;
631     }
632 
633     sptr<IRemoteObject> remote = Remote();
634     if (remote == nullptr) {
635         WLOGFE("remote is null");
636         return WSError::WS_ERROR_IPC_FAILED;
637     }
638     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
639         data, reply, option) != ERR_NONE) {
640         WLOGFE("SendRequest failed");
641         return WSError::WS_ERROR_IPC_FAILED;
642     }
643     std::unique_ptr<SessionSnapshot> info(reply.ReadParcelable<SessionSnapshot>());
644     if (info) {
645         snapshot = *info;
646     } else {
647         WLOGFW("Read SessionSnapshot is null.");
648     }
649     return static_cast<WSError>(reply.ReadInt32());
650 }
651 
SetSessionContinueState(const sptr<IRemoteObject> & token,const ContinueState & continueState)652 WSError SceneSessionManagerLiteProxy::SetSessionContinueState(const sptr<IRemoteObject>& token,
653     const ContinueState& continueState)
654 {
655     MessageParcel data;
656     MessageParcel reply;
657     MessageOption option;
658     if (!data.WriteInterfaceToken(GetDescriptor())) {
659         WLOGFE("WriteInterfaceToken failed");
660         return WSError::WS_ERROR_INVALID_PARAM;
661     }
662     if (!data.WriteRemoteObject(token)) {
663         WLOGFE("Write token failed");
664         return WSError::WS_ERROR_IPC_FAILED;
665     }
666     if (!data.WriteInt32(static_cast<int32_t>(continueState))) {
667         WLOGFE("Write continueState failed");
668         return WSError::WS_ERROR_IPC_FAILED;
669     }
670     sptr<IRemoteObject> remote = Remote();
671     if (remote == nullptr) {
672         WLOGFE("remote is null");
673         return WSError::WS_ERROR_IPC_FAILED;
674     }
675     if (remote->SendRequest(static_cast<uint32_t>(
676         SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
677         data, reply, option) != ERR_NONE) {
678         WLOGFE("SendRequest failed");
679         return WSError::WS_ERROR_IPC_FAILED;
680     }
681     return static_cast<WSError>(reply.ReadInt32());
682 }
683 
LockSession(int32_t sessionId)684 WSError SceneSessionManagerLiteProxy::LockSession(int32_t sessionId)
685 {
686     WLOGFD("run SceneSessionManagerLiteProxy::LockSession");
687     MessageParcel data;
688     MessageParcel reply;
689     MessageOption option;
690 
691     if (!data.WriteInterfaceToken(GetDescriptor())) {
692         WLOGFE("Write interface token failed.");
693         return WSError::WS_ERROR_INVALID_PARAM;
694     }
695     if (!data.WriteInt32(sessionId)) {
696         WLOGFE("Write persistentId failed");
697         return WSError::WS_ERROR_INVALID_PARAM;
698     }
699     sptr<IRemoteObject> remote = Remote();
700     if (remote == nullptr) {
701         WLOGFE("remote is null");
702         return WSError::WS_ERROR_IPC_FAILED;
703     }
704     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION),
705         data, reply, option) != ERR_NONE) {
706         WLOGFE("SendRequest failed");
707         return WSError::WS_ERROR_IPC_FAILED;
708     }
709     return static_cast<WSError>(reply.ReadInt32());
710 }
711 
UnlockSession(int32_t sessionId)712 WSError SceneSessionManagerLiteProxy::UnlockSession(int32_t sessionId)
713 {
714     WLOGFD("run SceneSessionManagerLiteProxy::UnlockSession");
715     MessageParcel data;
716     MessageParcel reply;
717     MessageOption option;
718 
719     if (!data.WriteInterfaceToken(GetDescriptor())) {
720         WLOGFE("Write interface token failed.");
721         return WSError::WS_ERROR_INVALID_PARAM;
722     }
723     if (!data.WriteInt32(sessionId)) {
724         WLOGFE("Write persistentId failed");
725         return WSError::WS_ERROR_INVALID_PARAM;
726     }
727     sptr<IRemoteObject> remote = Remote();
728     if (remote == nullptr) {
729         WLOGFE("remote is null");
730         return WSError::WS_ERROR_IPC_FAILED;
731     }
732     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION),
733         data, reply, option) != ERR_NONE) {
734         WLOGFE("SendRequest failed");
735         return WSError::WS_ERROR_IPC_FAILED;
736     }
737     return static_cast<WSError>(reply.ReadInt32());
738 }
739 
MoveSessionsToForeground(const std::vector<std::int32_t> & sessionIds,int32_t topSessionId)740 WSError SceneSessionManagerLiteProxy::MoveSessionsToForeground(const std::vector<std::int32_t>& sessionIds,
741     int32_t topSessionId)
742 {
743     WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToForeground");
744     MessageParcel data;
745     MessageParcel reply;
746     MessageOption option;
747     if (!data.WriteInterfaceToken(GetDescriptor())) {
748         WLOGFE("WriteInterfaceToken failed");
749         return WSError::WS_ERROR_INVALID_PARAM;
750     }
751     if (!data.WriteInt32Vector(sessionIds)) {
752         WLOGFE("Write sessionIds failed");
753         return WSError::WS_ERROR_INVALID_PARAM;
754     }
755     if (!data.WriteInt32(topSessionId)) {
756         WLOGFE("Write topSessionId failed");
757         return WSError::WS_ERROR_INVALID_PARAM;
758     }
759     sptr<IRemoteObject> remote = Remote();
760     if (remote == nullptr) {
761         WLOGFE("remote is null");
762         return WSError::WS_ERROR_IPC_FAILED;
763     }
764     if (remote->SendRequest(static_cast<uint32_t>(
765         SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND),
766         data, reply, option) != ERR_NONE) {
767         WLOGFE("SendRequest failed");
768         return WSError::WS_ERROR_IPC_FAILED;
769     }
770     return static_cast<WSError>(reply.ReadInt32());
771 }
772 
MoveSessionsToBackground(const std::vector<std::int32_t> & sessionIds,std::vector<int32_t> & result)773 WSError SceneSessionManagerLiteProxy::MoveSessionsToBackground(const std::vector<std::int32_t>& sessionIds,
774     std::vector<int32_t>& result)
775 {
776     WLOGFD("run SceneSessionManagerLiteProxy::MoveSessionsToBackground");
777     MessageParcel data;
778     MessageParcel reply;
779     MessageOption option;
780     if (!data.WriteInterfaceToken(GetDescriptor())) {
781         WLOGFE("WriteInterfaceToken failed");
782         return WSError::WS_ERROR_INVALID_PARAM;
783     }
784     if (!data.WriteInt32Vector(sessionIds)) {
785         WLOGFE("Write sessionIds failed");
786         return WSError::WS_ERROR_INVALID_PARAM;
787     }
788     if (!data.WriteInt32Vector(result)) {
789         WLOGFE("Write result failed");
790         return WSError::WS_ERROR_INVALID_PARAM;
791     }
792     sptr<IRemoteObject> remote = Remote();
793     if (remote == nullptr) {
794         WLOGFE("remote is null");
795         return WSError::WS_ERROR_IPC_FAILED;
796     }
797     if (remote->SendRequest(static_cast<uint32_t>(
798         SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND),
799         data, reply, option) != ERR_NONE) {
800         WLOGFE("SendRequest failed");
801         return WSError::WS_ERROR_IPC_FAILED;
802     }
803     reply.ReadInt32Vector(&result);
804     return static_cast<WSError>(reply.ReadInt32());
805 }
806 
ClearSession(int32_t persistentId)807 WSError SceneSessionManagerLiteProxy::ClearSession(int32_t persistentId)
808 {
809     WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
810     MessageParcel data;
811     MessageParcel reply;
812     MessageOption option;
813     if (!data.WriteInterfaceToken(GetDescriptor())) {
814         WLOGFE("ClearSession WriteInterfaceToken failed");
815         return WSError::WS_ERROR_INVALID_PARAM;
816     }
817 
818     if (!data.WriteInt32(persistentId)) {
819         WLOGFE("Write persistentId failed");
820         return WSError::WS_ERROR_INVALID_PARAM;
821     }
822 
823     sptr<IRemoteObject> remote = Remote();
824     if (remote == nullptr) {
825         WLOGFE("remote is null");
826         return WSError::WS_ERROR_IPC_FAILED;
827     }
828     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_SESSION),
829         data, reply, option) != ERR_NONE) {
830         WLOGFE("SendRequest failed");
831         return WSError::WS_ERROR_IPC_FAILED;
832     }
833     return static_cast<WSError>(reply.ReadInt32());
834 }
835 
ClearAllSessions()836 WSError SceneSessionManagerLiteProxy::ClearAllSessions()
837 {
838     WLOGFD("run SceneSessionManagerLiteProxy::ClearSession");
839     MessageParcel data;
840     MessageParcel reply;
841     MessageOption option;
842     if (!data.WriteInterfaceToken(GetDescriptor())) {
843         WLOGFE("ClearAllSessions WriteInterfaceToken failed");
844         return WSError::WS_ERROR_INVALID_PARAM;
845     }
846 
847     sptr<IRemoteObject> remote = Remote();
848     if (remote == nullptr) {
849         WLOGFE("remote is null");
850         return WSError::WS_ERROR_IPC_FAILED;
851     }
852     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
853         data, reply, option) != ERR_NONE) {
854         WLOGFE("SendRequest failed");
855         return WSError::WS_ERROR_IPC_FAILED;
856     }
857     return static_cast<WSError>(reply.ReadInt32());
858 }
859 
UpdateWindowModeByIdForUITest(int32_t windowId,int32_t updateMode)860 WMError SceneSessionManagerLiteProxy::UpdateWindowModeByIdForUITest(int32_t windowId, int32_t updateMode)
861 {
862     TLOGD(WmsLogTag::WMS_LAYOUT, "in");
863     MessageParcel data;
864     MessageParcel reply;
865     MessageOption option;
866     if (!data.WriteInterfaceToken(GetDescriptor())) {
867         TLOGE(WmsLogTag::WMS_LAYOUT, "write interfaceToken failed");
868         return WMError::WM_ERROR_IPC_FAILED;
869     }
870     if (!data.WriteInt32(windowId)) {
871         TLOGE(WmsLogTag::WMS_LAYOUT, "write windowId failed");
872         return WMError::WM_ERROR_IPC_FAILED;
873     }
874     if (!data.WriteInt32(updateMode)) {
875         TLOGE(WmsLogTag::WMS_LAYOUT, "write updateMode failed");
876         return WMError::WM_ERROR_IPC_FAILED;
877     }
878     sptr<IRemoteObject> remote = Remote();
879     if (remote == nullptr) {
880         TLOGE(WmsLogTag::WMS_LAYOUT, "remote is nullptr");
881         return WMError::WM_ERROR_NULLPTR;
882     }
883     int32_t ret = remote->SendRequest(
884         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UPDATE_WINDOW_MODE_BY_ID_FOR_UI_TEST),
885         data, reply, option);
886     if (ret != ERR_NONE) {
887         TLOGE(WmsLogTag::WMS_LAYOUT, "Send request failed, ret:%{public}d", ret);
888         return WMError::WM_ERROR_IPC_FAILED;
889     }
890     return WMError::WM_OK;
891 }
892 
GetFocusWindowInfo(FocusChangeInfo & focusInfo,DisplayId displayId)893 void SceneSessionManagerLiteProxy::GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId)
894 {
895     WLOGFD("get focus Winow info lite proxy");
896     MessageParcel data;
897     MessageParcel reply;
898     MessageOption option;
899     if (!data.WriteInterfaceToken(GetDescriptor())) {
900         WLOGFE("WriteInterfaceToken failed");
901         return;
902     }
903     if (!data.WriteUint64(displayId)) {
904         TLOGE(WmsLogTag::WMS_FOCUS, "write displayId failed");
905         return;
906     }
907     sptr<IRemoteObject> remote = Remote();
908     if (remote == nullptr) {
909         WLOGFE("remote is null");
910         return;
911     }
912     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
913         data, reply, option) != ERR_NONE) {
914         WLOGFE("SendRequest failed");
915         return;
916     }
917     sptr<FocusChangeInfo> info = reply.ReadParcelable<FocusChangeInfo>();
918     if (info) {
919         focusInfo = *info;
920     } else {
921         WLOGFE("info is null.");
922     }
923 }
924 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)925 WMError SceneSessionManagerLiteProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
926     const sptr<IWindowManagerAgent>& windowManagerAgent)
927 {
928     MessageOption option;
929     MessageParcel reply;
930     MessageParcel data;
931     if (!data.WriteInterfaceToken(GetDescriptor())) {
932         WLOGFE("Write InterfaceToken failed");
933         return WMError::WM_ERROR_IPC_FAILED;
934     }
935 
936     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
937         WLOGFE("Write type failed");
938         return WMError::WM_ERROR_IPC_FAILED;
939     }
940 
941     if (windowManagerAgent == nullptr) {
942         TLOGE(WmsLogTag::DEFAULT, "windowManagerAgent is null");
943         return WMError::WM_ERROR_NULLPTR;
944     }
945 
946     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
947         WLOGFE("Write IWindowManagerAgent 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_REGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
958         WLOGFE("SendRequest failed");
959         return WMError::WM_ERROR_IPC_FAILED;
960     }
961 
962     return static_cast<WMError>(reply.ReadInt32());
963 }
964 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)965 WMError SceneSessionManagerLiteProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
966     const sptr<IWindowManagerAgent>& windowManagerAgent)
967 {
968     MessageParcel reply;
969     MessageOption option;
970     MessageParcel data;
971     if (!data.WriteInterfaceToken(GetDescriptor())) {
972         WLOGFE("Write InterfaceToken failed");
973         return WMError::WM_ERROR_IPC_FAILED;
974     }
975 
976     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
977         WLOGFE("Write type failed");
978         return WMError::WM_ERROR_IPC_FAILED;
979     }
980 
981     if (windowManagerAgent == nullptr) {
982         TLOGE(WmsLogTag::DEFAULT, "windowManagerAgent is null");
983         return WMError::WM_ERROR_NULLPTR;
984     }
985 
986     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
987         WLOGFE("Write IWindowManagerAgent failed");
988         return WMError::WM_ERROR_IPC_FAILED;
989     }
990 
991     sptr<IRemoteObject> remote = Remote();
992     if (remote == nullptr) {
993         WLOGFE("remote is nullptr");
994         return WMError::WM_ERROR_NULLPTR;
995     }
996     if (remote->SendRequest(static_cast<uint32_t>(
997         SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT), data, reply, option) != ERR_NONE) {
998         WLOGFE("SendRequest failed");
999         return WMError::WM_ERROR_IPC_FAILED;
1000     }
1001 
1002     return static_cast<WMError>(reply.ReadInt32());
1003 }
1004 
CheckWindowId(int32_t windowId,int32_t & pid)1005 WMError SceneSessionManagerLiteProxy::CheckWindowId(int32_t windowId, int32_t& pid)
1006 {
1007     MessageParcel data;
1008     MessageParcel reply;
1009     MessageOption option;
1010     if (!data.WriteInterfaceToken(GetDescriptor())) {
1011         WLOGFE("Failed to write interfaceToken");
1012         return WMError::WM_ERROR_IPC_FAILED;
1013     }
1014     if (!data.WriteInt32(windowId)) {
1015         WLOGFE("Failed to write windowId");
1016         return WMError::WM_ERROR_IPC_FAILED;
1017     }
1018     sptr<IRemoteObject> remote = Remote();
1019     if (remote == nullptr) {
1020         WLOGFE("remote is nullptr");
1021         return WMError::WM_ERROR_NULLPTR;
1022     }
1023     int32_t ret = remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CHECK_WINDOW_ID),
1024         data, reply, option);
1025     if (ret != ERR_NONE) {
1026         WLOGFE("Send request failed, ret:%{public}d", ret);
1027         return WMError::WM_ERROR_IPC_FAILED;
1028     }
1029     if (!reply.ReadInt32(pid)) {
1030         WLOGFE("Failed to read pid");
1031         return WMError::WM_ERROR_IPC_FAILED;
1032     }
1033     return WMError::WM_OK;
1034 }
1035 
CheckUIExtensionCreation(int32_t windowId,uint32_t tokenId,const AppExecFwk::ElementName & element,AppExecFwk::ExtensionAbilityType extensionAbilityType,int32_t & pid)1036 WMError SceneSessionManagerLiteProxy::CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId,
1037     const AppExecFwk::ElementName& element, AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid)
1038 {
1039     MessageParcel data;
1040     MessageParcel reply;
1041     MessageOption option;
1042     if (!data.WriteInterfaceToken(GetDescriptor())) {
1043         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write interfaceToken");
1044         return WMError::WM_ERROR_IPC_FAILED;
1045     }
1046 
1047     if (!data.WriteInt32(windowId)) {
1048         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write windowId");
1049         return WMError::WM_ERROR_IPC_FAILED;
1050     }
1051 
1052     if (!data.WriteUint32(tokenId)) {
1053         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write tokenId");
1054         return WMError::WM_ERROR_IPC_FAILED;
1055     }
1056 
1057     if (!data.WriteInt32(static_cast<int32_t>(extensionAbilityType))) {
1058         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write extensionAbilityType");
1059         return WMError::WM_ERROR_IPC_FAILED;
1060     }
1061 
1062     data.WriteParcelable(&element);
1063 
1064     sptr<IRemoteObject> remote = Remote();
1065     if (remote == nullptr) {
1066         TLOGE(WmsLogTag::WMS_UIEXT, "remote is null");
1067         return WMError::WM_ERROR_NULLPTR;
1068     }
1069 
1070     int32_t ret =
1071         remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UI_EXTENSION_CREATION_CHECK),
1072             data, reply, option);
1073     if (ret != ERR_NONE) {
1074         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Send request failed, ret:%{public}d", ret);
1075         return WMError::WM_ERROR_IPC_FAILED;
1076     }
1077 
1078     int32_t errCode = 0;
1079     if (!reply.ReadInt32(errCode)) {
1080         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read errcode");
1081         return WMError::WM_ERROR_IPC_FAILED;
1082     }
1083 
1084     if (!reply.ReadInt32(pid)) {
1085         TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to read pid");
1086         return WMError::WM_ERROR_IPC_FAILED;
1087     }
1088 
1089     TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: errcode %{public}u", errCode);
1090     return static_cast<WMError>(errCode);
1091 }
1092 
GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>> & infos)1093 WMError SceneSessionManagerLiteProxy::GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos)
1094 {
1095     MessageParcel data;
1096     MessageParcel reply;
1097     MessageOption option;
1098     if (!data.WriteInterfaceToken(GetDescriptor())) {
1099         WLOGFE("GetVisibilityWindowInfo Write interfaceToken failed");
1100         return WMError::WM_ERROR_IPC_FAILED;
1101     }
1102 
1103     sptr<IRemoteObject> remote = Remote();
1104     if (remote == nullptr) {
1105         WLOGFE("remote is nullptr");
1106         return WMError::WM_ERROR_NULLPTR;
1107     }
1108     if (remote->SendRequest(static_cast<uint32_t>(
1109         SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID), data, reply, option) != ERR_NONE) {
1110         return WMError::WM_ERROR_IPC_FAILED;
1111     }
1112     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
1113         WLOGFE("read visibility window infos failed");
1114         return WMError::WM_ERROR_IPC_FAILED;
1115     }
1116     return static_cast<WMError>(reply.ReadInt32());
1117 }
1118 
GetWindowModeType(WindowModeType & windowModeType)1119 WMError SceneSessionManagerLiteProxy::GetWindowModeType(WindowModeType& windowModeType)
1120 {
1121     WLOGFI("get Window mode type proxy");
1122     MessageParcel data;
1123     if (!data.WriteInterfaceToken(GetDescriptor())) {
1124         WLOGFE("WriteInterfaceToken failed");
1125         return WMError::WM_ERROR_IPC_FAILED;
1126     }
1127     MessageParcel reply;
1128     MessageOption option;
1129     sptr<IRemoteObject> remote = Remote();
1130     if (remote == nullptr) {
1131         WLOGFE("remote is null");
1132         return WMError::WM_ERROR_IPC_FAILED;
1133     }
1134     if (remote->SendRequest(static_cast<uint32_t>(
1135         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE), data, reply, option) != ERR_NONE) {
1136         WLOGFE("SendRequest failed");
1137         return WMError::WM_ERROR_IPC_FAILED;
1138     }
1139 
1140     windowModeType = static_cast<WindowModeType>(reply.ReadUint32());
1141     return static_cast<WMError>(reply.ReadInt32());
1142 }
1143 
GetMainWindowInfos(int32_t topNum,std::vector<MainWindowInfo> & topNInfo)1144 WMError SceneSessionManagerLiteProxy::GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo)
1145 {
1146     TLOGI(WmsLogTag::WMS_MAIN, "get main info in %{public}d", topNum);
1147     MessageParcel data;
1148     MessageParcel reply;
1149     MessageOption option(MessageOption::TF_SYNC);
1150     if (!data.WriteInterfaceToken(GetDescriptor())) {
1151         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1152         return WMError::WM_ERROR_IPC_FAILED;
1153     }
1154 
1155     if ((topNum <= 0) || (topNum >= MAX_TOPN_INFO_SIZE)) {
1156         return WMError::WM_ERROR_INVALID_PARAM;
1157     }
1158 
1159     if (!data.WriteInt32(topNum)) {
1160         TLOGE(WmsLogTag::WMS_MAIN, "topNum write fail");
1161         return WMError::WM_ERROR_IPC_FAILED;
1162     }
1163 
1164     sptr<IRemoteObject> remote = Remote();
1165     if (remote == nullptr) {
1166         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1167         return WMError::WM_ERROR_IPC_FAILED;
1168     }
1169     if (remote->SendRequest(static_cast<int32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO),
1170                             data, reply, option) != ERR_NONE) {
1171         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1172         return WMError::WM_ERROR_IPC_FAILED;
1173     }
1174 
1175     WMError error = static_cast<WMError>(GetParcelableInfos(reply, topNInfo));
1176     if (error != WMError::WM_OK) {
1177         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1178         return error;
1179     }
1180 
1181     return static_cast<WMError>(reply.ReadInt32());
1182 }
1183 
GetCallingWindowInfo(CallingWindowInfo & callingWindowInfo)1184 WMError SceneSessionManagerLiteProxy::GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo)
1185 {
1186     MessageParcel data;
1187     MessageParcel reply;
1188     MessageOption option(MessageOption::TF_SYNC);
1189     if (!data.WriteInterfaceToken(GetDescriptor())) {
1190         TLOGE(WmsLogTag::WMS_KEYBOARD, "WriteInterfaceToken failed");
1191         return WMError::WM_ERROR_IPC_FAILED;
1192     }
1193     if (!data.WriteParcelable(&callingWindowInfo)) {
1194         TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowInfo failed, id: %{public}d, userId: %{public}d",
1195             callingWindowInfo.windowId_, callingWindowInfo.userId_);
1196         return WMError::WM_ERROR_IPC_FAILED;
1197     }
1198     sptr<IRemoteObject> remote = Remote();
1199     if (remote == nullptr) {
1200         TLOGE(WmsLogTag::WMS_KEYBOARD, "remote is null");
1201         return WMError::WM_ERROR_IPC_FAILED;
1202     }
1203     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_CALLING_WINDOW_INFO),
1204         data, reply, option) != ERR_NONE) {
1205         TLOGE(WmsLogTag::WMS_KEYBOARD, "SendRequest failed");
1206         return WMError::WM_ERROR_IPC_FAILED;
1207     }
1208     auto ret = static_cast<WMError>(reply.ReadInt32());
1209     if (ret == WMError::WM_OK) {
1210         sptr<CallingWindowInfo> info = reply.ReadParcelable<CallingWindowInfo>();
1211         if (info == nullptr) {
1212             TLOGE(WmsLogTag::WMS_KEYBOARD, "Read callingWindowInfo failed");
1213             return WMError::WM_ERROR_IPC_FAILED;
1214         }
1215         callingWindowInfo = *info;
1216     }
1217     return ret;
1218 }
1219 
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<AAFwk::IAbilityManagerCollaborator> & impl)1220 WSError SceneSessionManagerLiteProxy::RegisterIAbilityManagerCollaborator(int32_t type,
1221     const sptr<AAFwk::IAbilityManagerCollaborator>& impl)
1222 {
1223     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1224     if (!impl) {
1225         TLOGE(WmsLogTag::WMS_MAIN, "impl is nullptr");
1226         return WSError::WS_ERROR_INVALID_PARAM;
1227     }
1228     MessageParcel data;
1229     MessageParcel reply;
1230     MessageOption option;
1231 
1232     if (!data.WriteInterfaceToken(GetDescriptor())) {
1233         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1234         return WSError::WS_ERROR_IPC_FAILED;
1235     }
1236     if (!data.WriteInt32(type)) {
1237         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1238         return WSError::WS_ERROR_IPC_FAILED;
1239     }
1240     if (!data.WriteRemoteObject(impl->AsObject())) {
1241         TLOGE(WmsLogTag::WMS_MAIN, "Write impl failed");
1242         return WSError::WS_ERROR_IPC_FAILED;
1243     }
1244 
1245     sptr<IRemoteObject> remote = Remote();
1246     if (remote == nullptr) {
1247         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1248         return WSError::WS_ERROR_IPC_FAILED;
1249     }
1250     if (remote->SendRequest(static_cast<uint32_t>(
1251         SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR),
1252         data, reply, option) != ERR_NONE) {
1253         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1254         return WSError::WS_ERROR_IPC_FAILED;
1255     }
1256     return static_cast<WSError>(reply.ReadInt32());
1257 }
1258 
UnregisterIAbilityManagerCollaborator(int32_t type)1259 WSError SceneSessionManagerLiteProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
1260 {
1261     TLOGI(WmsLogTag::WMS_MAIN, "type:%{public}d", type);
1262     MessageParcel data;
1263     MessageParcel reply;
1264     MessageOption option;
1265 
1266     if (!data.WriteInterfaceToken(GetDescriptor())) {
1267         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1268         return WSError::WS_ERROR_IPC_FAILED;
1269     }
1270     if (!data.WriteInt32(type)) {
1271         TLOGE(WmsLogTag::WMS_MAIN, "Write type failed");
1272         return WSError::WS_ERROR_IPC_FAILED;
1273     }
1274 
1275     sptr<IRemoteObject> remote = Remote();
1276     if (remote == nullptr) {
1277         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1278         return WSError::WS_ERROR_IPC_FAILED;
1279     }
1280     if (remote->SendRequest(static_cast<uint32_t>(
1281         SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
1282         data, reply, option) != ERR_NONE) {
1283         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1284         return WSError::WS_ERROR_IPC_FAILED;
1285     }
1286     return static_cast<WSError>(reply.ReadInt32());
1287 }
1288 
GetAllMainWindowInfos(std::vector<MainWindowInfo> & infos)1289 WMError SceneSessionManagerLiteProxy::GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos)
1290 {
1291     MessageParcel data;
1292     MessageParcel reply;
1293     MessageOption option;
1294     if (!data.WriteInterfaceToken(GetDescriptor())) {
1295         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1296         return WMError::WM_ERROR_IPC_FAILED;
1297     }
1298     sptr<IRemoteObject> remote = Remote();
1299     if (remote == nullptr) {
1300         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1301         return WMError::WM_ERROR_IPC_FAILED;
1302     }
1303     if (remote->SendRequest(static_cast<int32_t>(
1304         SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1305         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1306         return WMError::WM_ERROR_IPC_FAILED;
1307     }
1308 
1309     WMError error = static_cast<WMError>(GetParcelableInfos(reply, infos));
1310     if (error != WMError::WM_OK) {
1311         TLOGE(WmsLogTag::WMS_MAIN, "get info error");
1312         return error;
1313     }
1314 
1315     return static_cast<WMError>(reply.ReadInt32());
1316 }
1317 
ClearMainSessions(const std::vector<int32_t> & persistentIds,std::vector<int32_t> & clearFailedIds)1318 WMError SceneSessionManagerLiteProxy::ClearMainSessions(const std::vector<int32_t>& persistentIds,
1319     std::vector<int32_t>& clearFailedIds)
1320 {
1321     MessageParcel data;
1322     MessageParcel reply;
1323     MessageOption option;
1324     if (!data.WriteInterfaceToken(GetDescriptor())) {
1325         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1326         return WMError::WM_ERROR_IPC_FAILED;
1327     }
1328     if (!data.WriteInt32Vector(persistentIds)) {
1329         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentIds failed");
1330         return WMError::WM_ERROR_IPC_FAILED;
1331     }
1332     sptr<IRemoteObject> remote = Remote();
1333     if (remote == nullptr) {
1334         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1335         return WMError::WM_ERROR_IPC_FAILED;
1336     }
1337     if (remote->SendRequest(static_cast<int32_t>(
1338         SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS), data, reply, option) != ERR_NONE) {
1339         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1340         return WMError::WM_ERROR_IPC_FAILED;
1341     }
1342     reply.ReadInt32Vector(&clearFailedIds);
1343     return static_cast<WMError>(reply.ReadInt32());
1344 }
1345 
RaiseWindowToTop(int32_t persistentId)1346 WSError SceneSessionManagerLiteProxy::RaiseWindowToTop(int32_t persistentId)
1347 {
1348     MessageParcel data;
1349     MessageParcel reply;
1350     MessageOption option(MessageOption::TF_SYNC);
1351     if (!data.WriteInterfaceToken(GetDescriptor())) {
1352         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1353         return WSError::WS_ERROR_IPC_FAILED;
1354     }
1355     if (!data.WriteInt32(persistentId)) {
1356         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1357         return WSError::WS_ERROR_IPC_FAILED;
1358     }
1359 
1360     sptr<IRemoteObject> remote = Remote();
1361     if (remote == nullptr) {
1362         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1363         return WSError::WS_ERROR_IPC_FAILED;
1364     }
1365     if (remote->SendRequest(static_cast<uint32_t>(
1366         SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
1367         data, reply, option) != ERR_NONE) {
1368         TLOGE(WmsLogTag::WMS_MAIN, "SendRequest failed");
1369         return WSError::WS_ERROR_IPC_FAILED;
1370     }
1371     int32_t ret = reply.ReadInt32();
1372     return static_cast<WSError>(ret);
1373 }
1374 
GetWindowStyleType(WindowStyleType & windowStyleType)1375 WMError SceneSessionManagerLiteProxy::GetWindowStyleType(WindowStyleType& windowStyleType)
1376 {
1377     MessageParcel data;
1378     MessageParcel reply;
1379     MessageOption option;
1380     if (!data.WriteInterfaceToken(GetDescriptor())) {
1381         TLOGE(WmsLogTag::WMS_MAIN, "GetwindowStyleType Write interfaceToken failed");
1382         return WMError::WM_ERROR_IPC_FAILED;
1383     }
1384     sptr<IRemoteObject> remote = Remote();
1385     if (remote == nullptr) {
1386         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1387         return WMError::WM_ERROR_IPC_FAILED;
1388     }
1389     if (remote->SendRequest(static_cast<uint32_t>(
1390         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE), data, reply, option) != ERR_NONE) {
1391         return WMError::WM_ERROR_IPC_FAILED;
1392     }
1393     windowStyleType = static_cast<WindowStyleType>(reply.ReadUint32());
1394     return static_cast<WMError>(reply.ReadInt32());
1395 }
1396 
TerminateSessionByPersistentId(int32_t persistentId)1397 WMError SceneSessionManagerLiteProxy::TerminateSessionByPersistentId(int32_t persistentId)
1398 {
1399     MessageParcel data;
1400     MessageParcel reply;
1401     MessageOption option;
1402     if (!data.WriteInterfaceToken(GetDescriptor())) {
1403         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1404         return WMError::WM_ERROR_IPC_FAILED;
1405     }
1406     if (!data.WriteInt32(persistentId)) {
1407         TLOGE(WmsLogTag::WMS_MAIN, "Write persistentId failed");
1408         return WMError::WM_ERROR_IPC_FAILED;
1409     }
1410     sptr<IRemoteObject> remote = Remote();
1411     if (remote == nullptr) {
1412         TLOGE(WmsLogTag::WMS_MAIN, "remote is null");
1413         return WMError::WM_ERROR_IPC_FAILED;
1414     }
1415     if (remote->SendRequest(static_cast<int32_t>(
1416         SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID),
1417         data, reply, option) != ERR_NONE) {
1418         TLOGE(WmsLogTag::WMS_MAIN, "send request fail");
1419         return WMError::WM_ERROR_IPC_FAILED;
1420     }
1421     return static_cast<WMError>(reply.ReadInt32());
1422 }
1423 
CloseTargetFloatWindow(const std::string & bundleName)1424 WMError SceneSessionManagerLiteProxy::CloseTargetFloatWindow(const std::string& bundleName)
1425 {
1426     MessageParcel data;
1427     MessageParcel reply;
1428     MessageOption option(MessageOption::TF_ASYNC);
1429     if (!data.WriteInterfaceToken(GetDescriptor())) {
1430         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "WriteInterfaceToken failed");
1431         return WMError::WM_ERROR_IPC_FAILED;
1432     }
1433     if (!data.WriteString(bundleName)) {
1434         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write bundleName failed");
1435         return WMError::WM_ERROR_IPC_FAILED;
1436     }
1437     sptr<IRemoteObject> remote = Remote();
1438     if (remote == nullptr) {
1439         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is null");
1440         return WMError::WM_ERROR_IPC_FAILED;
1441     }
1442     if (remote->SendRequest(static_cast<int32_t>(
1443         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_FLOAT_WINDOW),
1444         data, reply, option) != ERR_NONE) {
1445         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "send request fail");
1446         return WMError::WM_ERROR_IPC_FAILED;
1447     }
1448     return WMError::WM_OK;
1449 }
1450 
CloseTargetPiPWindow(const std::string & bundleName)1451 WMError SceneSessionManagerLiteProxy::CloseTargetPiPWindow(const std::string& bundleName)
1452 {
1453     MessageParcel data;
1454     MessageParcel reply;
1455     MessageOption option;
1456     if (!data.WriteInterfaceToken(GetDescriptor())) {
1457         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1458         return WMError::WM_ERROR_IPC_FAILED;
1459     }
1460     if (!data.WriteString(bundleName)) {
1461         TLOGE(WmsLogTag::WMS_PIP, "Write bundleName failed");
1462         return WMError::WM_ERROR_IPC_FAILED;
1463     }
1464     sptr<IRemoteObject> remote = Remote();
1465     if (remote == nullptr) {
1466         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1467         return WMError::WM_ERROR_IPC_FAILED;
1468     }
1469     if (remote->SendRequest(static_cast<int32_t>(
1470         SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_PIP_WINDOW),
1471         data, reply, option) != ERR_NONE) {
1472         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1473         return WMError::WM_ERROR_IPC_FAILED;
1474     }
1475     return static_cast<WMError>(reply.ReadInt32());
1476 }
1477 
GetCurrentPiPWindowInfo(std::string & bundleName)1478 WMError SceneSessionManagerLiteProxy::GetCurrentPiPWindowInfo(std::string& bundleName)
1479 {
1480     MessageParcel data;
1481     MessageParcel reply;
1482     MessageOption option;
1483     if (!data.WriteInterfaceToken(GetDescriptor())) {
1484         TLOGE(WmsLogTag::WMS_PIP, "WriteInterfaceToken failed");
1485         return WMError::WM_ERROR_IPC_FAILED;
1486     }
1487     sptr<IRemoteObject> remote = Remote();
1488     if (remote == nullptr) {
1489         TLOGE(WmsLogTag::WMS_PIP, "remote is null");
1490         return WMError::WM_ERROR_IPC_FAILED;
1491     }
1492     if (remote->SendRequest(static_cast<int32_t>(
1493         SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO),
1494         data, reply, option) != ERR_NONE) {
1495         TLOGE(WmsLogTag::WMS_PIP, "send request fail");
1496         return WMError::WM_ERROR_IPC_FAILED;
1497     }
1498     WMError errorCode = static_cast<WMError>(reply.ReadInt32());
1499     bundleName = reply.ReadString();
1500     return errorCode;
1501 }
1502 
GetRootMainWindowId(int32_t persistentId,int32_t & hostWindowId)1503 WMError SceneSessionManagerLiteProxy::GetRootMainWindowId(int32_t persistentId, int32_t& hostWindowId)
1504 {
1505     MessageParcel data;
1506     MessageParcel reply;
1507     MessageOption option;
1508     if (!data.WriteInterfaceToken(GetDescriptor())) {
1509         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1510         return WMError::WM_ERROR_IPC_FAILED;
1511     }
1512     if (!data.WriteInt32(persistentId)) {
1513         TLOGE(WmsLogTag::WMS_MAIN, "Failed to write persistentId");
1514         return WMError::WM_ERROR_IPC_FAILED;
1515     }
1516     sptr<IRemoteObject> remote = Remote();
1517     if (remote == nullptr) {
1518         TLOGE(WmsLogTag::WMS_MAIN, "remote is nullptr");
1519         return WMError::WM_ERROR_NULLPTR;
1520     }
1521     int32_t ret = remote->SendRequest(static_cast<uint32_t>(
1522         SceneSessionManagerLiteMessage::TRANS_ID_GET_ROOT_MAIN_WINDOW_ID), data, reply, option);
1523     if (ret != ERR_NONE) {
1524         TLOGE(WmsLogTag::WMS_MAIN, "Send request failed, ret:%{public}d", ret);
1525         return WMError::WM_ERROR_IPC_FAILED;
1526     }
1527     if (!reply.ReadInt32(hostWindowId)) {
1528         TLOGE(WmsLogTag::WMS_MAIN, "Failed to read hostWindowId");
1529         return WMError::WM_ERROR_IPC_FAILED;
1530     }
1531     return WMError::WM_OK;
1532 }
1533 
GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>> & infos)1534 WMError SceneSessionManagerLiteProxy::GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos)
1535 {
1536     MessageOption option;
1537     MessageParcel reply;
1538     MessageParcel data;
1539     if (!data.WriteInterfaceToken(GetDescriptor())) {
1540         WLOGFE("Write InterfaceToken failed");
1541         return WMError::WM_ERROR_IPC_FAILED;
1542     }
1543 
1544     sptr<IRemoteObject> remote = Remote();
1545     if (remote == nullptr) {
1546         WLOGFE("remote is null");
1547         return WMError::WM_ERROR_IPC_FAILED;
1548     }
1549     if (remote->SendRequest(static_cast<uint32_t>(
1550         SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO),
1551         data, reply, option) != ERR_NONE) {
1552         WLOGFE("SendRequest failed");
1553         return WMError::WM_ERROR_IPC_FAILED;
1554     }
1555 
1556     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
1557         WLOGFE("read window info failed.");
1558         return WMError::WM_ERROR_IPC_FAILED;
1559     }
1560     return static_cast<WMError>(reply.ReadInt32());
1561 }
1562 
NotifyAppUseControlList(ControlAppType type,int32_t userId,const std::vector<AppUseControlInfo> & controlList)1563 WSError SceneSessionManagerLiteProxy::NotifyAppUseControlList(
1564     ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)
1565 {
1566     TLOGD(WmsLogTag::WMS_LIFE, "in");
1567     MessageParcel data;
1568     MessageParcel reply;
1569     MessageOption option;
1570     if (!data.WriteInterfaceToken(GetDescriptor())) {
1571         TLOGE(WmsLogTag::WMS_LIFE, "WriteInterfaceToken failed");
1572         return WSError::WS_ERROR_INVALID_PARAM;
1573     }
1574 
1575     if (!data.WriteUint8(static_cast<uint8_t>(type))) {
1576         TLOGE(WmsLogTag::WMS_LIFE, "Write type failed");
1577         return WSError::WS_ERROR_INVALID_PARAM;
1578     }
1579 
1580     if (!data.WriteInt32(userId)) {
1581         TLOGE(WmsLogTag::WMS_LIFE, "Write userId failed");
1582         return WSError::WS_ERROR_INVALID_PARAM;
1583     }
1584 
1585     if (!data.WriteInt32(static_cast<int32_t>(controlList.size()))) {
1586         TLOGE(WmsLogTag::WMS_LIFE, "Write controlList size failed");
1587         return WSError::WS_ERROR_INVALID_PARAM;
1588     }
1589 
1590     for (const auto& control : controlList) {
1591         if (!data.WriteString(control.bundleName_) || !data.WriteInt32(control.appIndex_) ||
1592             !data.WriteBool(control.isNeedControl_) || !data.WriteBool(control.isControlRecentOnly_)) {
1593             TLOGE(WmsLogTag::WMS_LIFE, "Write controlList failed");
1594             return WSError::WS_ERROR_INVALID_PARAM;
1595         }
1596     }
1597 
1598     sptr<IRemoteObject> remote = Remote();
1599     if (remote == nullptr) {
1600         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1601         return WSError::WS_ERROR_IPC_FAILED;
1602     }
1603     if (remote->SendRequest(static_cast<uint32_t>(
1604         SceneSessionManagerLiteMessage::TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST),
1605         data, reply, option) != ERR_NONE) {
1606         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1607         return WSError::WS_ERROR_IPC_FAILED;
1608     }
1609     return static_cast<WSError>(reply.ReadInt32());
1610 }
1611 
MinimizeMainSession(const std::string & bundleName,int32_t appIndex,int32_t userId)1612 WMError SceneSessionManagerLiteProxy::MinimizeMainSession(
1613     const std::string& bundleName, int32_t appIndex, int32_t userId)
1614 {
1615     TLOGD(WmsLogTag::WMS_LIFE, "in");
1616     MessageParcel data;
1617     MessageParcel reply;
1618     MessageOption option;
1619     if (!data.WriteInterfaceToken(GetDescriptor())) {
1620         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1621         return WMError::WM_ERROR_IPC_FAILED;
1622     }
1623     if (!data.WriteString(bundleName)) {
1624         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
1625         return WMError::WM_ERROR_IPC_FAILED;
1626     }
1627     if (!data.WriteInt32(appIndex)) {
1628         TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
1629         return WMError::WM_ERROR_IPC_FAILED;
1630     }
1631     if (!data.WriteInt32(userId)) {
1632         TLOGE(WmsLogTag::WMS_LIFE, "write userId failed.");
1633         return WMError::WM_ERROR_IPC_FAILED;
1634     }
1635     sptr<IRemoteObject> remote = Remote();
1636     if (remote == nullptr) {
1637         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1638         return WMError::WM_ERROR_IPC_FAILED;
1639     }
1640     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_MINIMIZE_MAIN_SESSION),
1641         data, reply, option) != ERR_NONE) {
1642         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1643         return WMError::WM_ERROR_IPC_FAILED;
1644     }
1645     int32_t ret = 0;
1646     if (!reply.ReadInt32(ret)) {
1647         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
1648         return WMError::WM_ERROR_IPC_FAILED;
1649     }
1650     return static_cast<WMError>(ret);
1651 }
1652 
LockSessionByAbilityInfo(const AbilityInfoBase & abilityInfo,bool isLock)1653 WMError SceneSessionManagerLiteProxy::LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock)
1654 {
1655     TLOGD(WmsLogTag::WMS_LIFE, "in");
1656     MessageParcel data;
1657     MessageParcel reply;
1658     MessageOption option;
1659     if (!data.WriteInterfaceToken(GetDescriptor())) {
1660         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1661         return WMError::WM_ERROR_IPC_FAILED;
1662     }
1663     if (!data.WriteString(abilityInfo.bundleName)) {
1664         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
1665         return WMError::WM_ERROR_IPC_FAILED;
1666     }
1667     if (!data.WriteString(abilityInfo.moduleName)) {
1668         TLOGE(WmsLogTag::WMS_LIFE, "write moduleName failed.");
1669         return WMError::WM_ERROR_IPC_FAILED;
1670     }
1671     if (!data.WriteString(abilityInfo.abilityName)) {
1672         TLOGE(WmsLogTag::WMS_LIFE, "write abilityName failed.");
1673         return WMError::WM_ERROR_IPC_FAILED;
1674     }
1675     if (!data.WriteInt32(abilityInfo.appIndex)) {
1676         TLOGE(WmsLogTag::WMS_LIFE, "write appIndex failed.");
1677         return WMError::WM_ERROR_IPC_FAILED;
1678     }
1679     if (!data.WriteBool(isLock)) {
1680         TLOGE(WmsLogTag::WMS_LIFE, "write isLock failed.");
1681         return WMError::WM_ERROR_IPC_FAILED;
1682     }
1683     sptr<IRemoteObject> remote = Remote();
1684     if (remote == nullptr) {
1685         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1686         return WMError::WM_ERROR_IPC_FAILED;
1687     }
1688     if (remote->SendRequest(
1689         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO),
1690         data, reply, option) != ERR_NONE) {
1691         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1692         return WMError::WM_ERROR_IPC_FAILED;
1693     }
1694     int32_t ret = 0;
1695     if (!reply.ReadInt32(ret)) {
1696         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
1697         return WMError::WM_ERROR_IPC_FAILED;
1698     }
1699     return static_cast<WMError>(ret);
1700 }
1701 
HasFloatingWindowForeground(const sptr<IRemoteObject> & abilityToken,bool & hasOrNot)1702 WMError SceneSessionManagerLiteProxy::HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
1703     bool& hasOrNot)
1704 {
1705     if (!abilityToken) {
1706         TLOGE(WmsLogTag::WMS_SYSTEM, "AbilityToken is null");
1707         return WMError::WM_ERROR_INVALID_PARAM;
1708     }
1709     MessageParcel data;
1710     MessageParcel reply;
1711     MessageOption option;
1712     if (!data.WriteInterfaceToken(GetDescriptor())) {
1713         TLOGE(WmsLogTag::WMS_SYSTEM, "Write interfaceToken failed");
1714         return WMError::WM_ERROR_IPC_FAILED;
1715     }
1716     if (!data.WriteRemoteObject(abilityToken)) {
1717         TLOGE(WmsLogTag::WMS_SYSTEM, "Write abilityToken failed");
1718         return WMError::WM_ERROR_IPC_FAILED;
1719     }
1720     sptr<IRemoteObject> remote = Remote();
1721     if (remote == nullptr) {
1722         TLOGE(WmsLogTag::WMS_SYSTEM, "Remote is null");
1723         return WMError::WM_ERROR_IPC_FAILED;
1724     }
1725     if (remote->SendRequest(static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_HAS_FLOAT_FOREGROUND),
1726         data, reply, option) != ERR_NONE) {
1727         TLOGE(WmsLogTag::WMS_SYSTEM, "SendRequest failed");
1728         return WMError::WM_ERROR_IPC_FAILED;
1729     }
1730     if (!reply.ReadBool(hasOrNot)) {
1731         TLOGE(WmsLogTag::WMS_SYSTEM, "Read result failed");
1732         return WMError::WM_ERROR_IPC_FAILED;
1733     }
1734     uint32_t ret = 0;
1735     if (!reply.ReadUint32(ret)) {
1736         TLOGE(WmsLogTag::WMS_SYSTEM, "Read ret failed");
1737         return WMError::WM_ERROR_IPC_FAILED;
1738     }
1739     return static_cast<WMError>(ret);
1740 }
1741 
RegisterSessionLifecycleListenerByIds(const sptr<ISessionLifecycleListener> & listener,const std::vector<int32_t> & persistentIdList)1742 WMError SceneSessionManagerLiteProxy::RegisterSessionLifecycleListenerByIds(
1743     const sptr<ISessionLifecycleListener>& listener, const std::vector<int32_t>& persistentIdList)
1744 {
1745     TLOGD(WmsLogTag::WMS_LIFE, "in");
1746     MessageParcel data;
1747     MessageParcel reply;
1748     MessageOption option(MessageOption::TF_SYNC);
1749     if (!data.WriteInterfaceToken(GetDescriptor())) {
1750         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1751         return WMError::WM_ERROR_IPC_FAILED;
1752     }
1753     if (listener == nullptr || listener->AsObject() == nullptr) {
1754         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1755         return WMError::WM_ERROR_IPC_FAILED;
1756     }
1757     if (!data.WriteRemoteObject(listener->AsObject())) {
1758         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1759         return WMError::WM_ERROR_IPC_FAILED;
1760     }
1761     if (!data.WriteInt32Vector(persistentIdList)) {
1762         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentIdList failed.");
1763         return WMError::WM_ERROR_IPC_FAILED;
1764     }
1765     sptr<IRemoteObject> remote = Remote();
1766     if (remote == nullptr) {
1767         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1768         return WMError::WM_ERROR_IPC_FAILED;
1769     }
1770     if (remote->SendRequest(
1771         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_IDS),
1772         data, reply, option) != ERR_NONE) {
1773         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1774         return WMError::WM_ERROR_IPC_FAILED;
1775     }
1776     int32_t ret = 0;
1777     if (!reply.ReadInt32(ret)) {
1778         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1779         return WMError::WM_ERROR_IPC_FAILED;
1780     }
1781     return static_cast<WMError>(ret);
1782 }
1783 
RegisterSessionLifecycleListenerByBundles(const sptr<ISessionLifecycleListener> & listener,const std::vector<std::string> & bundleNameList)1784 WMError SceneSessionManagerLiteProxy::RegisterSessionLifecycleListenerByBundles(
1785     const sptr<ISessionLifecycleListener>& listener, const std::vector<std::string>& bundleNameList)
1786 {
1787     TLOGD(WmsLogTag::WMS_LIFE, "in");
1788     MessageParcel data;
1789     MessageParcel reply;
1790     MessageOption option(MessageOption::TF_SYNC);
1791     if (!data.WriteInterfaceToken(GetDescriptor())) {
1792         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1793         return WMError::WM_ERROR_IPC_FAILED;
1794     }
1795     if (listener == nullptr || listener->AsObject() == nullptr) {
1796         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1797         return WMError::WM_ERROR_IPC_FAILED;
1798     }
1799     if (!data.WriteRemoteObject(listener->AsObject())) {
1800         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1801         return WMError::WM_ERROR_IPC_FAILED;
1802     }
1803     if (!data.WriteStringVector(bundleNameList)) {
1804         TLOGE(WmsLogTag::WMS_LIFE, "Write bundleNameList failed.");
1805         return WMError::WM_ERROR_IPC_FAILED;
1806     }
1807     sptr<IRemoteObject> remote = Remote();
1808     if (remote == nullptr) {
1809         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1810         return WMError::WM_ERROR_IPC_FAILED;
1811     }
1812     if (remote->SendRequest(
1813         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_BUNDLES),
1814         data, reply, option) != ERR_NONE) {
1815         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1816         return WMError::WM_ERROR_IPC_FAILED;
1817     }
1818     int32_t ret = 0;
1819     if (!reply.ReadInt32(ret)) {
1820         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1821         return WMError::WM_ERROR_IPC_FAILED;
1822     }
1823     return static_cast<WMError>(ret);
1824 }
1825 
UnregisterSessionLifecycleListener(const sptr<ISessionLifecycleListener> & listener)1826 WMError SceneSessionManagerLiteProxy::UnregisterSessionLifecycleListener(
1827     const sptr<ISessionLifecycleListener>& listener)
1828 {
1829     TLOGD(WmsLogTag::WMS_LIFE, "in");
1830     MessageParcel data;
1831     MessageParcel reply;
1832     MessageOption option(MessageOption::TF_SYNC);
1833     if (!data.WriteInterfaceToken(GetDescriptor())) {
1834         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1835         return WMError::WM_ERROR_IPC_FAILED;
1836     }
1837     if (listener == nullptr || listener->AsObject() == nullptr) {
1838         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
1839         return WMError::WM_ERROR_IPC_FAILED;
1840     }
1841     if (!data.WriteRemoteObject(listener->AsObject())) {
1842         TLOGE(WmsLogTag::WMS_LIFE, "Write lifecycle listener failed.");
1843         return WMError::WM_ERROR_IPC_FAILED;
1844     }
1845     sptr<IRemoteObject> remote = Remote();
1846     if (remote == nullptr) {
1847         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1848         return WMError::WM_ERROR_IPC_FAILED;
1849     }
1850     if (remote->SendRequest(
1851         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LIFECYCLE_LISTENER),
1852         data, reply, option) != ERR_NONE) {
1853         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1854         return WMError::WM_ERROR_IPC_FAILED;
1855     }
1856     int32_t ret = 0;
1857     if (!reply.ReadInt32(ret)) {
1858         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1859         return WMError::WM_ERROR_IPC_FAILED;
1860     }
1861     return static_cast<WMError>(ret);
1862 }
1863 
ListWindowInfo(const WindowInfoOption & windowInfoOption,std::vector<sptr<WindowInfo>> & infos)1864 WMError SceneSessionManagerLiteProxy::ListWindowInfo(const WindowInfoOption& windowInfoOption,
1865     std::vector<sptr<WindowInfo>>& infos)
1866 {
1867     MessageParcel data;
1868     MessageParcel reply;
1869     MessageOption option;
1870     if (!data.WriteInterfaceToken(GetDescriptor())) {
1871         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write interfaceToken failed");
1872         return WMError::WM_ERROR_IPC_FAILED;
1873     }
1874     if (!data.WriteUint8(static_cast<WindowInfoFilterOptionDataType>(windowInfoOption.windowInfoFilterOption))) {
1875         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowInfoFilterOption failed");
1876         return WMError::WM_ERROR_IPC_FAILED;
1877     }
1878     if (!data.WriteUint8(static_cast<WindowInfoTypeOptionDataType>(windowInfoOption.windowInfoTypeOption))) {
1879         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowInfoTypeOption failed");
1880         return WMError::WM_ERROR_IPC_FAILED;
1881     }
1882     if (!data.WriteUint64(windowInfoOption.displayId)) {
1883         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write displayId failed");
1884         return WMError::WM_ERROR_IPC_FAILED;
1885     }
1886     if (!data.WriteInt32(windowInfoOption.windowId)) {
1887         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "write windowId failed");
1888         return WMError::WM_ERROR_IPC_FAILED;
1889     }
1890     sptr<IRemoteObject> remote = Remote();
1891     if (remote == nullptr) {
1892         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "remote is null");
1893         return WMError::WM_ERROR_IPC_FAILED;
1894     }
1895     if (remote->SendRequest(static_cast<uint32_t>(
1896         SceneSessionManagerLiteMessage::TRANS_ID_LIST_WINDOW_INFO), data, reply, option) != ERR_NONE) {
1897         return WMError::WM_ERROR_IPC_FAILED;
1898     }
1899     if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowInfo>(reply, infos)) {
1900         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read window info failed");
1901         return WMError::WM_ERROR_IPC_FAILED;
1902     }
1903     int32_t errCode = 0;
1904     if (!reply.ReadInt32(errCode)) {
1905         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read errcode failed");
1906         return WMError::WM_ERROR_IPC_FAILED;
1907     }
1908     return static_cast<WMError>(errCode);
1909 }
1910 
GetRecentMainSessionInfoList(std::vector<RecentSessionInfo> & recentSessionInfoList)1911 WSError SceneSessionManagerLiteProxy::GetRecentMainSessionInfoList(
1912     std::vector<RecentSessionInfo>& recentSessionInfoList)
1913 {
1914     TLOGD(WmsLogTag::WMS_LIFE, "in");
1915     MessageParcel data;
1916     MessageParcel reply;
1917     MessageOption option(MessageOption::TF_SYNC);
1918     if (!data.WriteInterfaceToken(GetDescriptor())) {
1919         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1920         return WSError::WS_ERROR_IPC_FAILED;
1921     }
1922     sptr<IRemoteObject> remote = Remote();
1923     if (remote == nullptr) {
1924         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1925         return WSError::WS_ERROR_IPC_FAILED;
1926     }
1927     if (remote->SendRequest(
1928         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_RECENT_MAIN_SESSION_INFO_LIST),
1929         data, reply, option) != ERR_NONE) {
1930         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
1931         return WSError::WS_ERROR_IPC_FAILED;
1932     }
1933     WSError error = static_cast<WSError>(GetParcelableInfos(reply, recentSessionInfoList));
1934     if (error != WSError::WS_OK) {
1935         TLOGE(WmsLogTag::WMS_LIFE, "get info error");
1936         return error;
1937     }
1938     int32_t errCode = 0;
1939     if (!reply.ReadInt32(errCode)) {
1940         TLOGE(WmsLogTag::WMS_LIFE, "read errcode failed");
1941         return WSError::WS_ERROR_IPC_FAILED;
1942     }
1943     return static_cast<WSError>(errCode);
1944 }
1945 
PendingSessionToBackgroundByPersistentId(const int32_t persistentId,bool shouldBackToCaller)1946 WSError SceneSessionManagerLiteProxy::PendingSessionToBackgroundByPersistentId(const int32_t persistentId,
1947     bool shouldBackToCaller)
1948 {
1949     TLOGD(WmsLogTag::WMS_LIFE, "in");
1950     MessageParcel data;
1951     MessageParcel reply;
1952     MessageOption option;
1953     if (!data.WriteInterfaceToken(GetDescriptor())) {
1954         TLOGE(WmsLogTag::WMS_MAIN, "WriteInterfaceToken failed");
1955         return WSError::WS_ERROR_INVALID_PARAM;
1956     }
1957     if (!data.WriteInt32(persistentId)) {
1958         TLOGE(WmsLogTag::WMS_MAIN, "Failed to write persistentId");
1959         return WSError::WS_ERROR_IPC_FAILED;
1960     }
1961     if (!data.WriteBool(shouldBackToCaller)) {
1962         TLOGE(WmsLogTag::WMS_LIFE, "Write shouldBackToCaller failed");
1963         return WSError::WS_ERROR_IPC_FAILED;
1964     }
1965     sptr<IRemoteObject> remote = Remote();
1966     if (remote == nullptr) {
1967         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
1968         return WSError::WS_ERROR_IPC_FAILED;
1969     }
1970     if (remote->SendRequest(static_cast<uint32_t>(
1971         SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_BY_PERSISTENTID),
1972         data, reply, option) != ERR_NONE) {
1973         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
1974         return WSError::WS_ERROR_IPC_FAILED;
1975     }
1976     int32_t ret = 0;
1977     if (!reply.ReadInt32(ret)) {
1978         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed.");
1979         return WSError::WS_ERROR_IPC_FAILED;
1980     }
1981     return static_cast<WSError>(ret);
1982 }
1983 
CreateNewInstanceKey(const std::string & bundleName,std::string & instanceKey)1984 WMError SceneSessionManagerLiteProxy::CreateNewInstanceKey(const std::string& bundleName, std::string& instanceKey)
1985 {
1986     TLOGD(WmsLogTag::WMS_LIFE, "in");
1987     MessageParcel data;
1988     MessageParcel reply;
1989     MessageOption option(MessageOption::TF_SYNC);
1990     if (!data.WriteInterfaceToken(GetDescriptor())) {
1991         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
1992         return WMError::WM_ERROR_IPC_FAILED;
1993     }
1994     if (!data.WriteString(bundleName)) {
1995         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
1996         return WMError::WM_ERROR_IPC_FAILED;
1997     }
1998     sptr<IRemoteObject> remote = Remote();
1999     if (remote == nullptr) {
2000         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2001         return WMError::WM_ERROR_IPC_FAILED;
2002     }
2003     if (remote->SendRequest(
2004         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CREATE_NEW_INSTANCE_KEY),
2005         data, reply, option) != ERR_NONE) {
2006         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2007         return WMError::WM_ERROR_IPC_FAILED;
2008     }
2009     int32_t ret = 0;
2010     if (!reply.ReadInt32(ret)) {
2011         TLOGE(WmsLogTag::WMS_LIFE, "read ret failed");
2012         return WMError::WM_ERROR_IPC_FAILED;
2013     }
2014     if (!reply.ReadString(instanceKey)) {
2015         TLOGE(WmsLogTag::WMS_LIFE, "read instanceKey failed");
2016         return WMError::WM_ERROR_IPC_FAILED;
2017     }
2018     return static_cast<WMError>(ret);
2019 }
2020 
GetRouterStackInfo(int32_t persistentId,const sptr<ISessionRouterStackListener> & listener)2021 WMError SceneSessionManagerLiteProxy::GetRouterStackInfo(
2022     int32_t persistentId, const sptr<ISessionRouterStackListener>& listener)
2023 {
2024     TLOGD(WmsLogTag::WMS_LIFE, "in");
2025     MessageParcel data;
2026     MessageParcel reply;
2027     MessageOption option(MessageOption::TF_ASYNC);
2028     if (!data.WriteInterfaceToken(GetDescriptor())) {
2029         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2030         return WMError::WM_ERROR_IPC_FAILED;
2031     }
2032     if (!data.WriteInt32(persistentId)) {
2033         TLOGE(WmsLogTag::WMS_LIFE, "write persistentId failed.");
2034         return WMError::WM_ERROR_IPC_FAILED;
2035     }
2036     if (listener == nullptr || listener->AsObject() == nullptr) {
2037         TLOGE(WmsLogTag::WMS_LIFE, "listener is null");
2038         return WMError::WM_ERROR_IPC_FAILED;
2039     }
2040     if (!data.WriteRemoteObject(listener->AsObject())) {
2041         TLOGE(WmsLogTag::WMS_LIFE, "Write session router stack listener failed.");
2042         return WMError::WM_ERROR_IPC_FAILED;
2043     }
2044     sptr<IRemoteObject> remote = Remote();
2045     if (remote == nullptr) {
2046         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2047         return WMError::WM_ERROR_IPC_FAILED;
2048     }
2049     if (remote->SendRequest(
2050         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_ROUTER_STACK_INFO),
2051         data, reply, option) != ERR_NONE) {
2052         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2053         return WMError::WM_ERROR_IPC_FAILED;
2054     }
2055     return WMError::WM_OK;
2056 }
2057 
RemoveInstanceKey(const std::string & bundleName,const std::string & instanceKey)2058 WMError SceneSessionManagerLiteProxy::RemoveInstanceKey(const std::string& bundleName, const std::string& instanceKey)
2059 {
2060     TLOGD(WmsLogTag::WMS_LIFE, "in");
2061     MessageParcel data;
2062     MessageParcel reply;
2063     MessageOption option;
2064     if (!data.WriteInterfaceToken(GetDescriptor())) {
2065         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2066         return WMError::WM_ERROR_IPC_FAILED;
2067     }
2068     if (!data.WriteString(bundleName)) {
2069         TLOGE(WmsLogTag::WMS_LIFE, "write bundleName failed.");
2070         return WMError::WM_ERROR_IPC_FAILED;
2071     }
2072     if (!data.WriteString(instanceKey)) {
2073         TLOGE(WmsLogTag::WMS_LIFE, "write instanceKey failed.");
2074         return WMError::WM_ERROR_IPC_FAILED;
2075     }
2076     sptr<IRemoteObject> remote = Remote();
2077     if (remote == nullptr) {
2078         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2079         return WMError::WM_ERROR_IPC_FAILED;
2080     }
2081     if (remote->SendRequest(
2082         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REMOVE_INSTANCE_KEY),
2083         data, reply, option) != ERR_NONE) {
2084         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2085         return WMError::WM_ERROR_IPC_FAILED;
2086     }
2087     int32_t ret = 0;
2088     if (!reply.ReadInt32(ret)) {
2089         TLOGE(WmsLogTag::WMS_LIFE, "read ret failed");
2090         return WMError::WM_ERROR_IPC_FAILED;
2091     }
2092     return static_cast<WMError>(ret);
2093 }
2094 
TransferSessionToTargetScreen(const TransferSessionInfo & info)2095 WMError SceneSessionManagerLiteProxy::TransferSessionToTargetScreen(
2096     const TransferSessionInfo& info)
2097 {
2098     TLOGD(WmsLogTag::WMS_LIFE, "in");
2099     if (info.persistentId < 0 || info.toScreenId < 0) {
2100         TLOGE(WmsLogTag::WMS_LIFE, "Invalid param");
2101         return WMError::WM_ERROR_INVALID_PARAM;
2102     }
2103     MessageParcel data;
2104     MessageParcel reply;
2105     MessageOption option(MessageOption::TF_SYNC);
2106     if (!data.WriteInterfaceToken(GetDescriptor())) {
2107         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2108         return WMError::WM_ERROR_IPC_FAILED;
2109     }
2110     if (!data.WriteInt32(info.persistentId)) {
2111         TLOGE(WmsLogTag::WMS_LIFE, "Write persistentId failed");
2112         return WMError::WM_ERROR_IPC_FAILED;
2113     }
2114     if (!data.WriteInt32(info.toScreenId)) {
2115         TLOGE(WmsLogTag::WMS_LIFE, "Write toScreenId failed");
2116         return WMError::WM_ERROR_IPC_FAILED;
2117     }
2118     if (!data.WriteParcelable(&info.wantParams)) {
2119         TLOGE(WmsLogTag::WMS_LIFE, "Write wantParams failed");
2120         return WMError::WM_ERROR_IPC_FAILED;
2121     }
2122     sptr<IRemoteObject> remote = Remote();
2123     if (remote == nullptr) {
2124         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2125         return WMError::WM_ERROR_IPC_FAILED;
2126     }
2127     if (remote->SendRequest(
2128         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TRANSFER_SESSION_TO_TARGET_SCREEN),
2129         data, reply, option) != ERR_NONE) {
2130         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed");
2131         return WMError::WM_ERROR_IPC_FAILED;
2132     }
2133     int32_t ret = 0;
2134     if (!reply.ReadInt32(ret)) {
2135         TLOGE(WmsLogTag::WMS_LIFE, "Read ret failed");
2136         return WMError::WM_ERROR_IPC_FAILED;
2137     }
2138     return static_cast<WMError>(ret);
2139 }
2140 
UpdateKioskAppList(const std::vector<std::string> & kioskAppList)2141 WMError SceneSessionManagerLiteProxy::UpdateKioskAppList(const std::vector<std::string>& kioskAppList)
2142 {
2143     TLOGD(WmsLogTag::WMS_LIFE, "in");
2144     MessageParcel data;
2145     MessageParcel reply;
2146     MessageOption option;
2147     if (!data.WriteInterfaceToken(GetDescriptor())) {
2148         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2149         return WMError::WM_ERROR_IPC_FAILED;
2150     }
2151     if (!data.WriteStringVector(kioskAppList)) {
2152         TLOGE(WmsLogTag::WMS_LIFE, "Write kioskAppList failed");
2153         return WMError::WM_ERROR_IPC_FAILED;
2154     }
2155     sptr<IRemoteObject> remote = Remote();
2156     if (remote == nullptr) {
2157         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2158         return WMError::WM_ERROR_IPC_FAILED;
2159     }
2160     if (remote->SendRequest(
2161         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UPDATE_KIOSK_APP_LIST),
2162         data, reply, option) != ERR_NONE) {
2163         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2164         return WMError::WM_ERROR_IPC_FAILED;
2165     }
2166     int32_t ret = 0;
2167     if (!reply.ReadInt32(ret)) {
2168         TLOGE(WmsLogTag::WMS_LIFE, "read ret failed");
2169         return WMError::WM_ERROR_IPC_FAILED;
2170     }
2171     return static_cast<WMError>(ret);
2172 }
2173 
EnterKioskMode(const sptr<IRemoteObject> & token)2174 WMError SceneSessionManagerLiteProxy::EnterKioskMode(const sptr<IRemoteObject>& token)
2175 {
2176     TLOGD(WmsLogTag::WMS_LIFE, "in");
2177     MessageParcel data;
2178     MessageParcel reply;
2179     MessageOption option;
2180     if (!data.WriteInterfaceToken(GetDescriptor())) {
2181         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2182         return WMError::WM_ERROR_IPC_FAILED;
2183     }
2184     if (!data.WriteRemoteObject(token)) {
2185         TLOGE(WmsLogTag::WMS_LIFE, "Write token failed");
2186         return WMError::WM_ERROR_IPC_FAILED;
2187     }
2188     sptr<IRemoteObject> remote = Remote();
2189     if (remote == nullptr) {
2190         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2191         return WMError::WM_ERROR_IPC_FAILED;
2192     }
2193     if (remote->SendRequest(
2194         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_ENTER_KIOSK_MODE),
2195         data, reply, option) != ERR_NONE) {
2196         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2197         return WMError::WM_ERROR_IPC_FAILED;
2198     }
2199     int32_t ret = 0;
2200     if (!reply.ReadInt32(ret)) {
2201         TLOGE(WmsLogTag::WMS_LIFE, "read ret failed");
2202         return WMError::WM_ERROR_IPC_FAILED;
2203     }
2204     return static_cast<WMError>(ret);
2205 }
2206 
ExitKioskMode(const sptr<IRemoteObject> & token)2207 WMError SceneSessionManagerLiteProxy::ExitKioskMode(const sptr<IRemoteObject>& token)
2208 {
2209     TLOGD(WmsLogTag::WMS_LIFE, "in");
2210     MessageParcel data;
2211     MessageParcel reply;
2212     MessageOption option;
2213     if (!data.WriteInterfaceToken(GetDescriptor())) {
2214         TLOGE(WmsLogTag::WMS_LIFE, "Write interfaceToken failed");
2215         return WMError::WM_ERROR_IPC_FAILED;
2216     }
2217     sptr<IRemoteObject> remote = Remote();
2218     if (remote == nullptr) {
2219         TLOGE(WmsLogTag::WMS_LIFE, "remote is null");
2220         return WMError::WM_ERROR_IPC_FAILED;
2221     }
2222     if (remote->SendRequest(
2223         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_EXIT_KIOSK_MODE),
2224         data, reply, option) != ERR_NONE) {
2225         TLOGE(WmsLogTag::WMS_LIFE, "SendRequest failed.");
2226         return WMError::WM_ERROR_IPC_FAILED;
2227     }
2228     int32_t ret = 0;
2229     if (!reply.ReadInt32(ret)) {
2230         TLOGE(WmsLogTag::WMS_LIFE, "read ret failed");
2231         return WMError::WM_ERROR_IPC_FAILED;
2232     }
2233     return static_cast<WMError>(ret);
2234 }
2235 
SendPointerEventForHover(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)2236 WSError SceneSessionManagerLiteProxy::SendPointerEventForHover(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
2237 {
2238     MessageParcel data;
2239     MessageParcel reply;
2240     MessageOption option;
2241     if (!data.WriteInterfaceToken(GetDescriptor())) {
2242         TLOGE(WmsLogTag::WMS_EVENT, "Write interfaceToken failed");
2243         return WSError::WS_ERROR_IPC_FAILED;
2244     }
2245     if (!pointerEvent->WriteToParcel(data)) {
2246         TLOGE(WmsLogTag::WMS_EVENT, "Write pointer event failed");
2247         return WSError::WS_ERROR_IPC_FAILED;
2248     }
2249     sptr<IRemoteObject> remote = Remote();
2250     if (remote == nullptr) {
2251         TLOGE(WmsLogTag::WMS_EVENT, "Remote is null");
2252         return WSError::WS_ERROR_IPC_FAILED;
2253     }
2254     if (remote->SendRequest(
2255         static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SEND_POINTER_EVENT_FOR_HOVER),
2256         data, reply, option) != ERR_NONE) {
2257         TLOGE(WmsLogTag::WMS_EVENT, "SendRequest failed.");
2258         return WSError::WS_ERROR_IPC_FAILED;
2259     }
2260     int32_t ret = 0;
2261     if (!reply.ReadInt32(ret)) {
2262         TLOGE(WmsLogTag::WMS_EVENT, "Read ret failed");
2263         return WSError::WS_ERROR_IPC_FAILED;
2264     }
2265     return static_cast<WSError>(ret);
2266 }
2267 } // namespace OHOS::Rosen
2268