• 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_stub.h"
17 
18 #include "marshalling_helper.h"
19 #include "window_manager_hilog.h"
20 
21 namespace OHOS::Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerLiteStub"};
24 constexpr uint32_t MAX_VECTOR_SIZE = 100;
25 constexpr uint32_t MAX_TOPN_INFO_SIZE = 200;
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int SceneSessionManagerLiteStub::OnRemoteRequest(uint32_t code,
29     MessageParcel& data, MessageParcel& reply, MessageOption& option)
30 {
31     WLOGFD("Scene session on remote request!, code: %{public}u", code);
32     if (data.ReadInterfaceToken() != GetDescriptor()) {
33         WLOGFE("Failed to check interface token!");
34         return ERR_TRANSACTION_FAILED;
35     }
36 
37     return ProcessRemoteRequest(code, data, reply, option);
38 }
39 
ProcessRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int SceneSessionManagerLiteStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
41     MessageOption& option)
42 {
43     switch (code) {
44         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_LABEL):
45             return HandleSetSessionLabel(data, reply);
46         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_ICON):
47             return HandleSetSessionIcon(data, reply);
48         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_IS_VALID_SESSION_IDS):
49             return HandleIsValidSessionIds(data, reply);
50         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND):
51             return HandlePendingSessionToForeground(data, reply);
52         case static_cast<uint32_t>(
53             SceneSessionManagerLiteMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR):
54             return HandlePendingSessionToBackgroundForDelegator(data, reply);
55         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN):
56             return HandleGetFocusSessionToken(data, reply);
57         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT):
58             return HandleGetFocusSessionElement(data, reply);
59         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LISTENER):
60             return HandleRegisterSessionListener(data, reply);
61         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER):
62             return HandleUnRegisterSessionListener(data, reply);
63         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFOS):
64             return HandleGetSessionInfos(data, reply);
65         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MAIN_WINDOW_STATES_BY_PID):
66             return HandleGetMainWindowStatesByPid(data, reply);
67         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_MISSION_INFO_BY_ID):
68             return HandleGetSessionInfo(data, reply);
69         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_INFO_BY_CONTINUE_SESSION_ID):
70             return HandleGetSessionInfoByContinueSessionId(data, reply);
71         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_NEW):
72             return HandleTerminateSessionNew(data, reply);
73         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_SESSION_SNAPSHOT):
74             return HandleGetSessionSnapshot(data, reply);
75         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE):
76             return HandleSetSessionContinueState(data, reply);
77         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_SESSION):
78             return HandleClearSession(data, reply);
79         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_ALL_SESSIONS):
80             return HandleClearAllSessions(data, reply);
81         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION):
82             return HandleLockSession(data, reply);
83         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNLOCK_SESSION):
84             return HandleUnlockSession(data, reply);
85         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND):
86             return HandleMoveSessionsToForeground(data, reply);
87         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND):
88             return HandleMoveSessionsToBackground(data, reply);
89         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_FOCUS_SESSION_INFO):
90             return HandleGetFocusSessionInfo(data, reply);
91         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT):
92             return HandleRegisterWindowManagerAgent(data, reply);
93         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT):
94             return HandleUnregisterWindowManagerAgent(data, reply);
95         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CHECK_WINDOW_ID):
96             return HandleCheckWindowId(data, reply);
97         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID):
98             return HandleGetVisibilityWindowInfo(data, reply);
99         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE):
100             return HandleGetWindowModeType(data, reply);
101         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP):
102             return HandleRaiseWindowToTop(data, reply);
103         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO):
104             return HandleGetMainWinodowInfo(data, reply);
105         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR):
106             return HandleRegisterCollaborator(data, reply);
107         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR):
108             return HandleUnregisterCollaborator(data, reply);
109         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO):
110             return HandleGetAllMainWindowInfos(data, reply);
111         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS):
112             return HandleClearMainSessions(data, reply);
113         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE):
114             return HandleGetWindowStyleType(data, reply);
115         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID):
116             return HandleTerminateSessionByPersistentId(data, reply);
117         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO):
118             return HandleGetAccessibilityWindowInfo(data, reply);
119         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_FLOAT_WINDOW):
120             return HandleCloseTargetFloatWindow(data, reply);
121         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLOSE_TARGET_PIP_WINDOW):
122             return HandleCloseTargetPiPWindow(data, reply);
123         case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_CURRENT_PIP_WINDOW_INFO):
124             return HandleGetCurrentPiPWindowInfo(data, reply);
125         default:
126             WLOGFE("Failed to find function handler!");
127             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
128     }
129 }
130 
HandleSetSessionLabel(MessageParcel & data,MessageParcel & reply)131 int SceneSessionManagerLiteStub::HandleSetSessionLabel(MessageParcel& data, MessageParcel& reply)
132 {
133     WLOGFD("run HandleSetSessionLabel!");
134     sptr<IRemoteObject> token = data.ReadRemoteObject();
135     std::string label = data.ReadString();
136     WSError errCode = SetSessionLabel(token, label);
137     reply.WriteInt32(static_cast<int32_t>(errCode));
138     return ERR_NONE;
139 }
140 
HandleSetSessionIcon(MessageParcel & data,MessageParcel & reply)141 int SceneSessionManagerLiteStub::HandleSetSessionIcon(MessageParcel& data, MessageParcel& reply)
142 {
143     WLOGFD("run HandleSetSessionIcon!");
144     sptr<IRemoteObject> token = data.ReadRemoteObject();
145     std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
146     if (icon == nullptr) {
147         WLOGFE("icon is null");
148         return ERR_INVALID_DATA;
149     }
150     WSError errCode = SetSessionIcon(token, icon);
151     reply.WriteInt32(static_cast<int32_t>(errCode));
152     return ERR_NONE;
153 }
154 
HandleIsValidSessionIds(MessageParcel & data,MessageParcel & reply)155 int SceneSessionManagerLiteStub::HandleIsValidSessionIds(MessageParcel& data, MessageParcel& reply)
156 {
157     WLOGFD("run HandleIsValidSessionIds!");
158     std::vector<int32_t> sessionIds;
159     data.ReadInt32Vector(&sessionIds);
160     std::vector<bool> results;
161     reply.WriteBoolVector(results);
162     return ERR_NONE;
163 }
164 
HandlePendingSessionToForeground(MessageParcel & data,MessageParcel & reply)165 int SceneSessionManagerLiteStub::HandlePendingSessionToForeground(MessageParcel& data, MessageParcel& reply)
166 {
167     WLOGFD("run HandlePendingSessionToForeground!");
168     sptr<IRemoteObject> token = data.ReadRemoteObject();
169     if (token == nullptr) {
170         WLOGFE("token is nullptr");
171         return ERR_INVALID_DATA;
172     }
173     WSError errCode = PendingSessionToForeground(token);
174     reply.WriteUint32(static_cast<uint32_t>(errCode));
175     return ERR_NONE;
176 }
177 
HandlePendingSessionToBackgroundForDelegator(MessageParcel & data,MessageParcel & reply)178 int SceneSessionManagerLiteStub::HandlePendingSessionToBackgroundForDelegator(MessageParcel& data, MessageParcel& reply)
179 {
180     TLOGD(WmsLogTag::WMS_LIFE, "run");
181     sptr<IRemoteObject> token = data.ReadRemoteObject();
182     if (token == nullptr) {
183         TLOGE(WmsLogTag::WMS_LIFE, "token is nullptr");
184         return ERR_INVALID_DATA;
185     }
186     bool shouldBackToCaller = true;
187     if (!data.ReadBool(shouldBackToCaller)) {
188         TLOGE(WmsLogTag::WMS_LIFE, "Read shouldBackToCaller failed");
189         return ERR_INVALID_DATA;
190     }
191     WSError errCode = PendingSessionToBackgroundForDelegator(token, shouldBackToCaller);
192     reply.WriteInt32(static_cast<int32_t>(errCode));
193     return ERR_NONE;
194 }
195 
HandleRegisterSessionListener(MessageParcel & data,MessageParcel & reply)196 int SceneSessionManagerLiteStub::HandleRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
197 {
198     WLOGFD("run HandleRegisterSessionListener!");
199     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
200     if (listener == nullptr) {
201         TLOGE(WmsLogTag::DEFAULT, "listener is nullptr!");
202         reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
203         return ERR_NONE;
204     }
205     WSError errCode = RegisterSessionListener(listener);
206     reply.WriteInt32(static_cast<int32_t>(errCode));
207     return ERR_NONE;
208 }
209 
HandleUnRegisterSessionListener(MessageParcel & data,MessageParcel & reply)210 int SceneSessionManagerLiteStub::HandleUnRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
211 {
212     WLOGFD("run HandleUnRegisterSessionListener!");
213     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
214     if (listener == nullptr) {
215         reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
216         return ERR_NONE;
217     }
218     WSError errCode = UnRegisterSessionListener(listener);
219     reply.WriteInt32(static_cast<int32_t>(errCode));
220     return ERR_NONE;
221 }
222 
HandleGetSessionInfos(MessageParcel & data,MessageParcel & reply)223 int SceneSessionManagerLiteStub::HandleGetSessionInfos(MessageParcel& data, MessageParcel& reply)
224 {
225     WLOGFD("run HandleGetSessionInfos!");
226     std::string deviceId = Str16ToStr8(data.ReadString16());
227     int numMax = data.ReadInt32();
228     std::vector<SessionInfoBean> missionInfos;
229     WSError errCode = GetSessionInfos(deviceId, numMax, missionInfos);
230     reply.WriteInt32(missionInfos.size());
231     for (auto& it : missionInfos) {
232         if (!reply.WriteParcelable(&it)) {
233             WLOGFE("GetSessionInfos error");
234             return ERR_INVALID_DATA;
235         }
236     }
237     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
238         return ERR_INVALID_DATA;
239     }
240     return ERR_NONE;
241 }
242 
HandleGetMainWindowStatesByPid(MessageParcel & data,MessageParcel & reply)243 int SceneSessionManagerLiteStub::HandleGetMainWindowStatesByPid(MessageParcel& data, MessageParcel& reply)
244 {
245     int32_t pid = 0;
246     if (!data.ReadInt32(pid)) {
247         TLOGE(WmsLogTag::WMS_LIFE, "read pid fail");
248         return ERR_INVALID_DATA;
249     }
250     std::vector<MainWindowState> windowStates;
251     WSError errCode = GetMainWindowStatesByPid(pid, windowStates);
252     if (!reply.WriteInt32(windowStates.size())) {
253         TLOGE(WmsLogTag::WMS_LIFE, "write windowStates size fail");
254         return ERR_INVALID_DATA;
255     }
256     for (auto& state : windowStates) {
257         if (!reply.WriteParcelable(&state)) {
258             TLOGE(WmsLogTag::WMS_LIFE, "write windowState fail");
259             return ERR_INVALID_DATA;
260         }
261     }
262     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
263         return ERR_INVALID_DATA;
264     }
265     return ERR_NONE;
266 }
267 
HandleGetSessionInfo(MessageParcel & data,MessageParcel & reply)268 int SceneSessionManagerLiteStub::HandleGetSessionInfo(MessageParcel& data, MessageParcel& reply)
269 {
270     WLOGFD("run HandleGetSessionInfo!");
271     SessionInfoBean info;
272     std::string deviceId = Str16ToStr8(data.ReadString16());
273     int32_t persistentId = data.ReadInt32();
274     WSError errCode = GetSessionInfo(deviceId, persistentId, info);
275     if (!reply.WriteParcelable(&info)) {
276         WLOGFE("GetSessionInfo error");
277         return ERR_INVALID_DATA;
278     }
279 
280     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
281         WLOGFE("GetSessionInfo result error");
282         return ERR_INVALID_DATA;
283     }
284     return ERR_NONE;
285 }
286 
HandleGetSessionInfoByContinueSessionId(MessageParcel & data,MessageParcel & reply)287 int SceneSessionManagerLiteStub::HandleGetSessionInfoByContinueSessionId(MessageParcel& data, MessageParcel& reply)
288 {
289     SessionInfoBean info;
290     std::string continueSessionId = data.ReadString();
291     TLOGI(WmsLogTag::WMS_LIFE, "continueSessionId: %{public}s", continueSessionId.c_str());
292     WSError errCode = GetSessionInfoByContinueSessionId(continueSessionId, info);
293     if (!reply.WriteParcelable(&info)) {
294         TLOGE(WmsLogTag::WMS_LIFE, "Get sessionInfo by continueSessionId error");
295         return ERR_INVALID_DATA;
296     }
297 
298     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
299         TLOGE(WmsLogTag::WMS_LIFE, "Get sessionInfo by continueSessionId result error");
300         return ERR_INVALID_DATA;
301     }
302     return ERR_NONE;
303 }
304 
HandleTerminateSessionNew(MessageParcel & data,MessageParcel & reply)305 int SceneSessionManagerLiteStub::HandleTerminateSessionNew(MessageParcel& data, MessageParcel& reply)
306 {
307     WLOGFD("run HandleTerminateSessionNew");
308     sptr<AAFwk::SessionInfo> abilitySessionInfo = data.ReadParcelable<AAFwk::SessionInfo>();
309     if (abilitySessionInfo == nullptr) {
310         WLOGFE("abilitySessionInfo is null");
311         return ERR_INVALID_DATA;
312     }
313     bool needStartCaller = data.ReadBool();
314     bool isFromBroker = data.ReadBool();
315     WSError errCode = TerminateSessionNew(abilitySessionInfo, needStartCaller, isFromBroker);
316     reply.WriteUint32(static_cast<uint32_t>(errCode));
317     return ERR_NONE;
318 }
319 
HandleGetFocusSessionToken(MessageParcel & data,MessageParcel & reply)320 int SceneSessionManagerLiteStub::HandleGetFocusSessionToken(MessageParcel& data, MessageParcel& reply)
321 {
322     WLOGFD("run HandleGetFocusSessionToken!");
323     sptr<IRemoteObject> token = nullptr;
324     WSError errCode = GetFocusSessionToken(token);
325     reply.WriteRemoteObject(token);
326     reply.WriteInt32(static_cast<int32_t>(errCode));
327     return ERR_NONE;
328 }
329 
HandleGetFocusSessionElement(MessageParcel & data,MessageParcel & reply)330 int SceneSessionManagerLiteStub::HandleGetFocusSessionElement(MessageParcel& data, MessageParcel& reply)
331 {
332     WLOGFD("run HandleGetFocusSessionElement!");
333     AppExecFwk::ElementName element;
334     WSError errCode = GetFocusSessionElement(element);
335     reply.WriteParcelable(&element);
336     reply.WriteInt32(static_cast<int32_t>(errCode));
337     return ERR_NONE;
338 }
339 
HandleSetSessionContinueState(MessageParcel & data,MessageParcel & reply)340 int SceneSessionManagerLiteStub::HandleSetSessionContinueState(MessageParcel& data, MessageParcel& reply)
341 {
342     WLOGFD("HandleSetSessionContinueState");
343     sptr <IRemoteObject> token = data.ReadRemoteObject();
344     auto continueState = static_cast<ContinueState>(data.ReadInt32());
345     const WSError &ret = SetSessionContinueState(token, continueState);
346     reply.WriteUint32(static_cast<uint32_t>(ret));
347     return ERR_NONE;
348 }
349 
HandleGetSessionSnapshot(MessageParcel & data,MessageParcel & reply)350 int SceneSessionManagerLiteStub::HandleGetSessionSnapshot(MessageParcel& data, MessageParcel& reply)
351 {
352     WLOGFD("run HandleGetSessionSnapshot!");
353     std::string deviceId = Str16ToStr8(data.ReadString16());
354     int32_t persistentId = data.ReadInt32();
355     bool isLowResolution = data.ReadBool();
356     std::shared_ptr<SessionSnapshot> snapshot = std::make_shared<SessionSnapshot>();
357     WSError ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution);
358     reply.WriteParcelable(snapshot.get());
359     reply.WriteUint32(static_cast<uint32_t>(ret));
360     return ERR_NONE;
361 }
362 
HandleClearSession(MessageParcel & data,MessageParcel & reply)363 int SceneSessionManagerLiteStub::HandleClearSession(MessageParcel& data, MessageParcel& reply)
364 {
365     WLOGFD("run HandleClearSession!");
366     int32_t persistentId = data.ReadInt32();
367     WSError ret = ClearSession(persistentId);
368     reply.WriteUint32(static_cast<uint32_t>(ret));
369     return ERR_NONE;
370 }
371 
HandleClearAllSessions(MessageParcel & data,MessageParcel & reply)372 int SceneSessionManagerLiteStub::HandleClearAllSessions(MessageParcel& data, MessageParcel& reply)
373 {
374     WLOGFD("run HandleClearAllSessions!");
375     WSError ret = ClearAllSessions();
376     reply.WriteUint32(static_cast<uint32_t>(ret));
377     return ERR_NONE;
378 }
379 
HandleLockSession(MessageParcel & data,MessageParcel & reply)380 int SceneSessionManagerLiteStub::HandleLockSession(MessageParcel& data, MessageParcel& reply)
381 {
382     WLOGFD("run HandleLockSession!");
383     int32_t sessionId = data.ReadInt32();
384     WSError ret = LockSession(sessionId);
385     reply.WriteUint32(static_cast<uint32_t>(ret));
386     return ERR_NONE;
387 }
388 
HandleUnlockSession(MessageParcel & data,MessageParcel & reply)389 int SceneSessionManagerLiteStub::HandleUnlockSession(MessageParcel& data, MessageParcel& reply)
390 {
391     WLOGFD("run HandleUnlockSession!");
392     int32_t sessionId = data.ReadInt32();
393     WSError ret = UnlockSession(sessionId);
394     reply.WriteUint32(static_cast<uint32_t>(ret));
395     return ERR_NONE;
396 }
397 
HandleMoveSessionsToForeground(MessageParcel & data,MessageParcel & reply)398 int SceneSessionManagerLiteStub::HandleMoveSessionsToForeground(MessageParcel& data, MessageParcel& reply)
399 {
400     WLOGFD("run HandleMoveSessionsToForeground!");
401     std::vector<int32_t> sessionIds;
402     data.ReadInt32Vector(&sessionIds);
403     int32_t topSessionId = data.ReadInt32();
404     const WSError &ret = MoveSessionsToForeground(sessionIds, topSessionId);
405     reply.WriteUint32(static_cast<uint32_t>(ret));
406     return ERR_NONE;
407 }
408 
HandleMoveSessionsToBackground(MessageParcel & data,MessageParcel & reply)409 int SceneSessionManagerLiteStub::HandleMoveSessionsToBackground(MessageParcel& data, MessageParcel& reply)
410 {
411     WLOGFD("run HandleMoveSessionsToBackground!");
412     std::vector<int32_t> sessionIds;
413     data.ReadInt32Vector(&sessionIds);
414     std::vector<int32_t> result;
415     data.ReadInt32Vector(&result);
416     const WSError &ret = MoveSessionsToBackground(sessionIds, result);
417     reply.WriteInt32Vector(result);
418     reply.WriteUint32(static_cast<uint32_t>(ret));
419     return ERR_NONE;
420 }
421 
HandleGetFocusSessionInfo(MessageParcel & data,MessageParcel & reply)422 int SceneSessionManagerLiteStub::HandleGetFocusSessionInfo(MessageParcel& data, MessageParcel& reply)
423 {
424     WLOGFD("run");
425     FocusChangeInfo focusInfo;
426     GetFocusWindowInfo(focusInfo);
427     reply.WriteParcelable(&focusInfo);
428     return ERR_NONE;
429 }
430 
HandleCheckWindowId(MessageParcel & data,MessageParcel & reply)431 int SceneSessionManagerLiteStub::HandleCheckWindowId(MessageParcel& data, MessageParcel& reply)
432 {
433     WLOGFI("run HandleCheckWindowId!");
434     int32_t windowId = INVALID_WINDOW_ID;
435     if (!data.ReadInt32(windowId)) {
436         WLOGE("Failed to readInt32 windowId");
437         return ERR_INVALID_DATA;
438     }
439     int32_t pid = INVALID_PID;
440     WMError errCode = CheckWindowId(windowId, pid);
441     if (errCode != WMError::WM_OK) {
442         WLOGE("Failed to checkWindowId(%{public}d)", pid);
443         return ERR_INVALID_DATA;
444     }
445     if (!reply.WriteInt32(pid)) {
446         WLOGE("Failed to WriteInt32 pid");
447         return ERR_INVALID_DATA;
448     }
449     return ERR_NONE;
450 }
451 
452 
HandleRegisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)453 int SceneSessionManagerLiteStub::HandleRegisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
454 {
455     auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
456     WLOGFI("run HandleRegisterWindowManagerAgent!, type=%{public}u", static_cast<uint32_t>(type));
457     sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
458     sptr<IWindowManagerAgent> windowManagerAgentProxy =
459             iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
460     WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy);
461     reply.WriteInt32(static_cast<int32_t>(errCode));
462     return ERR_NONE;
463 }
464 
HandleUnregisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)465 int SceneSessionManagerLiteStub::HandleUnregisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
466 {
467     auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
468     WLOGFI("run HandleUnregisterWindowManagerAgent!, type=%{public}u", static_cast<uint32_t>(type));
469     sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
470     sptr<IWindowManagerAgent> windowManagerAgentProxy =
471             iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
472     WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
473     reply.WriteInt32(static_cast<int32_t>(errCode));
474     return ERR_NONE;
475 }
476 
HandleGetVisibilityWindowInfo(MessageParcel & data,MessageParcel & reply)477 int SceneSessionManagerLiteStub::HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
478 {
479     std::vector<sptr<WindowVisibilityInfo>> infos;
480     WMError errCode = GetVisibilityWindowInfo(infos);
481     if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
482         WLOGFE("Write visibility window infos failed");
483         return -1;
484     }
485     reply.WriteInt32(static_cast<int32_t>(errCode));
486     return ERR_NONE;
487 }
488 
HandleGetWindowModeType(MessageParcel & data,MessageParcel & reply)489 int SceneSessionManagerLiteStub::HandleGetWindowModeType(MessageParcel& data, MessageParcel& reply)
490 {
491     WindowModeType windowModeType = Rosen::WindowModeType::WINDOW_MODE_OTHER;
492     WMError errCode = GetWindowModeType(windowModeType);
493     WLOGFI("run HandleGetWindowModeType, windowModeType:%{public}d!", static_cast<int32_t>(windowModeType));
494     if (!reply.WriteUint32(static_cast<int32_t>(windowModeType))) {
495         WLOGE("Failed to WriteBool");
496         return ERR_INVALID_DATA;
497     }
498     reply.WriteInt32(static_cast<int32_t>(errCode));
499     return ERR_NONE;
500 }
501 
HandleRaiseWindowToTop(MessageParcel & data,MessageParcel & reply)502 int SceneSessionManagerLiteStub::HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply)
503 {
504     auto persistentId = data.ReadInt32();
505     WSError errCode = RaiseWindowToTop(persistentId);
506     reply.WriteUint32(static_cast<uint32_t>(errCode));
507     return ERR_NONE;
508 }
509 
510 
HandleGetMainWinodowInfo(MessageParcel & data,MessageParcel & reply)511 int SceneSessionManagerLiteStub::HandleGetMainWinodowInfo(MessageParcel &data, MessageParcel &reply)
512 {
513     TLOGI(WmsLogTag::WMS_MAIN, "run HandleGetMainWinodowInfo lite");
514     int32_t topN = 0;
515     if (!data.ReadInt32(topN)) {
516         TLOGE(WmsLogTag::WMS_MAIN, "failed to read topN");
517         return ERR_INVALID_DATA;
518     }
519     TLOGD(WmsLogTag::WMS_MAIN, "topN :%{public}d", topN);
520     std::vector<MainWindowInfo> topNInfos;
521     WMError errCode = GetMainWindowInfos(topN, topNInfos);
522     if ((topNInfos.size() <= 0) || (topNInfos.size() >= MAX_TOPN_INFO_SIZE)) {
523         return ERR_INVALID_DATA;
524     }
525     reply.WriteInt32(topNInfos.size());
526     for (auto& it : topNInfos) {
527         if (!reply.WriteParcelable(&it)) {
528             TLOGE(WmsLogTag::WMS_MAIN, "write topNinfo fail");
529             return ERR_INVALID_DATA;
530         }
531 
532         TLOGI(WmsLogTag::WMS_MAIN, "pid %{public}d, name %{public}s",
533             it.pid_, it.bundleName_.c_str());
534     }
535 
536     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
537         return ERR_INVALID_DATA;
538     }
539 
540     return ERR_NONE;
541 }
542 
HandleRegisterCollaborator(MessageParcel & data,MessageParcel & reply)543 int SceneSessionManagerLiteStub::HandleRegisterCollaborator(MessageParcel& data, MessageParcel& reply)
544 {
545     TLOGD(WmsLogTag::WMS_MAIN, "called.");
546     int32_t type = data.ReadInt32();
547     sptr<IRemoteObject> collaboratorObject = data.ReadRemoteObject();
548     if (collaboratorObject == nullptr) {
549         TLOGE(WmsLogTag::WMS_MAIN, "collaboratorObject is null.");
550         return ERR_NULL_OBJECT;
551     }
552     sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
553         iface_cast<AAFwk::IAbilityManagerCollaborator>(collaboratorObject);
554     WSError ret = RegisterIAbilityManagerCollaborator(type, collaborator);
555     reply.WriteInt32(static_cast<int32_t>(ret));
556     return ERR_NONE;
557 }
558 
HandleUnregisterCollaborator(MessageParcel & data,MessageParcel & reply)559 int SceneSessionManagerLiteStub::HandleUnregisterCollaborator(MessageParcel& data, MessageParcel& reply)
560 {
561     TLOGD(WmsLogTag::WMS_MAIN, "called.");
562     int32_t type = data.ReadInt32();
563     WSError ret = UnregisterIAbilityManagerCollaborator(type);
564     reply.WriteInt32(static_cast<int32_t>(ret));
565     return ERR_NONE;
566 }
567 
HandleGetAllMainWindowInfos(MessageParcel & data,MessageParcel & reply)568 int SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply)
569 {
570     std::vector<MainWindowInfo> infos;
571     WMError errCode = GetAllMainWindowInfos(infos);
572     reply.WriteInt32(infos.size());
573     for (auto& info : infos) {
574         if (!reply.WriteParcelable(&info)) {
575             TLOGE(WmsLogTag::WMS_MAIN, "write main window info fail");
576             return ERR_INVALID_DATA;
577         }
578     }
579     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
580         return ERR_INVALID_DATA;
581     }
582     return ERR_NONE;
583 }
584 
HandleClearMainSessions(MessageParcel & data,MessageParcel & reply)585 int SceneSessionManagerLiteStub::HandleClearMainSessions(MessageParcel& data, MessageParcel& reply)
586 {
587     std::vector<int32_t> persistentIds;
588     std::vector<int32_t> clearFailedIds;
589     if (!data.ReadInt32Vector(&persistentIds)) {
590         TLOGE(WmsLogTag::WMS_MAIN, "failed to read persistentIds.");
591         return ERR_INVALID_DATA;
592     }
593     WMError errCode = ClearMainSessions(persistentIds, clearFailedIds);
594     if (!reply.WriteInt32Vector(clearFailedIds)) {
595         TLOGE(WmsLogTag::WMS_MAIN, "write clearFailedIds fail.");
596         return ERR_INVALID_DATA;
597     }
598     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
599         return ERR_INVALID_DATA;
600     }
601     return ERR_NONE;
602 }
603 
HandleGetWindowStyleType(MessageParcel & data,MessageParcel & reply)604 int SceneSessionManagerLiteStub::HandleGetWindowStyleType(MessageParcel& data, MessageParcel& reply)
605 {
606     WindowStyleType windowStyleType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
607     WMError errCode = GetWindowStyleType(windowStyleType);
608     TLOGI(WmsLogTag::WMS_MAIN, "windowStyleType:%{public}d!", static_cast<int32_t>(windowStyleType));
609     if (!reply.WriteUint32(static_cast<int32_t>(windowStyleType))) {
610         TLOGE(WmsLogTag::WMS_MAIN, "Failed to WriteBool");
611         return ERR_INVALID_DATA;
612     }
613     reply.WriteInt32(static_cast<int32_t>(errCode));
614     return ERR_NONE;
615 }
616 
HandleTerminateSessionByPersistentId(MessageParcel & data,MessageParcel & reply)617 int SceneSessionManagerLiteStub::HandleTerminateSessionByPersistentId(MessageParcel& data, MessageParcel& reply)
618 {
619     int32_t persistentId = data.ReadInt32();
620     WMError errCode = TerminateSessionByPersistentId(persistentId);
621     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
622         return ERR_INVALID_DATA;
623     }
624     return ERR_NONE;
625 }
626 
HandleGetAccessibilityWindowInfo(MessageParcel & data,MessageParcel & reply)627 int SceneSessionManagerLiteStub::HandleGetAccessibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
628 {
629     std::vector<sptr<AccessibilityWindowInfo>> infos;
630     WMError errCode = GetAccessibilityWindowInfo(infos);
631     if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
632         WLOGFE("Write window infos failed.");
633         return ERR_TRANSACTION_FAILED;
634     }
635     reply.WriteInt32(static_cast<int32_t>(errCode));
636     return ERR_NONE;
637 }
638 
HandleCloseTargetFloatWindow(MessageParcel & data,MessageParcel & reply)639 int SceneSessionManagerLiteStub::HandleCloseTargetFloatWindow(MessageParcel& data, MessageParcel& reply)
640 {
641     std::string bundleName = data.ReadString();
642     CloseTargetFloatWindow(bundleName);
643     return ERR_NONE;
644 }
645 
HandleCloseTargetPiPWindow(MessageParcel & data,MessageParcel & reply)646 int SceneSessionManagerLiteStub::HandleCloseTargetPiPWindow(MessageParcel& data, MessageParcel& reply)
647 {
648     std::string bundleName = data.ReadString();
649     WMError errCode = CloseTargetPiPWindow(bundleName);
650     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
651         return ERR_INVALID_DATA;
652     }
653     return ERR_NONE;
654 }
655 
HandleGetCurrentPiPWindowInfo(MessageParcel & data,MessageParcel & reply)656 int SceneSessionManagerLiteStub::HandleGetCurrentPiPWindowInfo(MessageParcel& data, MessageParcel& reply)
657 {
658     std::string bundleName;
659     WMError errCode = GetCurrentPiPWindowInfo(bundleName);
660     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
661         return ERR_INVALID_DATA;
662     }
663     if (!reply.WriteString(bundleName)) {
664         return ERR_INVALID_DATA;
665     }
666     return ERR_NONE;
667 }
668 } // namespace OHOS::Rosen
669