• 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_stub.h"
17 
18 #include <ui/rs_surface_node.h>
19 #include "marshalling_helper.h"
20 
21 namespace OHOS::Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerStub"};
24 constexpr uint32_t MAX_VECTOR_SIZE = 100;
25 }
26 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int SceneSessionManagerStub::OnRemoteRequest(uint32_t code,
28     MessageParcel& data, MessageParcel& reply, MessageOption& option)
29 {
30     WLOGFD("Scene session on remote request!, code: %{public}u", code);
31     if (data.ReadInterfaceToken() != GetDescriptor()) {
32         WLOGFE("Failed to check interface token!");
33         return ERR_TRANSACTION_FAILED;
34     }
35     return ProcessRemoteRequest(code, data, reply, option);
36 }
37 
ProcessRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int SceneSessionManagerStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
39     MessageOption& option)
40 {
41     switch (code) {
42         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION):
43             return HandleCreateAndConnectSpecificSession(data, reply);
44         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_CONNECT_SPECIFIC_SESSION):
45             return HandleRecoverAndConnectSpecificSession(data, reply);
46         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_RECONNECT_SCENE_SESSION):
47             return HandleRecoverAndReconnectSceneSession(data, reply);
48         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION):
49             return HandleDestroyAndDisconnectSpcificSession(data, reply);
50         case static_cast<uint32_t>(
51             SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION_WITH_DETACH_CALLBACK):
52             return HandleDestroyAndDisconnectSpcificSessionWithDetachCallback(data, reply);
53         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REQUEST_FOCUS):
54             return HandleRequestFocusStatus(data, reply);
55         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REQUEST_FOCUS_STATUS_BY_SA):
56             return HandleRequestFocusStatusBySA(data, reply);
57         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT):
58             return HandleRegisterWindowManagerAgent(data, reply);
59         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT):
60             return HandleUnregisterWindowManagerAgent(data, reply);
61         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_INFO):
62             return HandleGetFocusSessionInfo(data, reply);
63         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_LABEL):
64             return HandleSetSessionLabel(data, reply);
65         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_ICON):
66             return HandleSetSessionIcon(data, reply);
67         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_VALID_SESSION_IDS):
68             return HandleIsValidSessionIds(data, reply);
69         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND):
70             return HandlePendingSessionToForeground(data, reply);
71         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR):
72             return HandlePendingSessionToBackgroundForDelegator(data, reply);
73         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN):
74             return HandleGetFocusSessionToken(data, reply);
75         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_ELEMENT):
76             return HandleGetFocusSessionElement(data, reply);
77         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CHECK_WINDOW_ID):
78             return HandleCheckWindowId(data, reply);
79         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_GESTURE_NAVIGATION_ENABLED):
80             return HandleSetGestureNavigationEnabled(data, reply);
81         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_INFO):
82             return HandleGetAccessibilityWindowInfo(data, reply);
83         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO):
84             return HandleGetUnreliableWindowInfo(data, reply);
85         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_LISTENER):
86             return HandleRegisterSessionListener(data, reply);
87         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER):
88             return HandleUnRegisterSessionListener(data, reply);
89         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFOS):
90             return HandleGetSessionInfos(data, reply);
91         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFO_BY_ID):
92             return HandleGetSessionInfo(data, reply);
93         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_INFO_BY_CONTINUE_SESSION_ID):
94             return HandleGetSessionInfoByContinueSessionId(data, reply);
95         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_ALL):
96             return HandleDumpSessionAll(data, reply);
97         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_WITH_ID):
98             return HandleDumpSessionWithId(data, reply);
99         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_TERMINATE_SESSION_NEW):
100             return HandleTerminateSessionNew(data, reply);
101         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER):
102             return HandleUpdateSessionAvoidAreaListener(data, reply);
103         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_DUMP_INFO):
104             return HandleGetSessionDump(data, reply);
105         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT):
106             return HandleGetSessionSnapshot(data, reply);
107         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT_BY_ID):
108             return HandleGetSessionSnapshotById(data, reply);
109         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_UI_CONTENT_REMOTE_OBJ):
110             return HandleGetUIContentRemoteObj(data, reply);
111         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_BIND_DIALOG_TARGET):
112             return HandleBindDialogTarget(data, reply);
113         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT):
114             return HandleNotifyDumpInfoResult(data, reply);
115         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE):
116             return HandleSetSessionContinueState(data, reply);
117         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_SESSION):
118             return HandleClearSession(data, reply);
119         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_ALL_SESSIONS):
120             return HandleClearAllSessions(data, reply);
121         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_LOCK_SESSION):
122             return HandleLockSession(data, reply);
123         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNLOCK_SESSION):
124             return HandleUnlockSession(data, reply);
125         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND):
126             return HandleMoveSessionsToForeground(data, reply);
127         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND):
128             return HandleMoveSessionsToBackground(data, reply);
129         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_COLLABORATOR):
130             return HandleRegisterCollaborator(data, reply);
131         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_COLLABORATOR):
132             return HandleUnregisterCollaborator(data, reply);
133         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_TOUCHOUTSIDE_LISTENER):
134             return HandleUpdateSessionTouchOutsideListener(data, reply);
135         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RAISE_WINDOW_TO_TOP):
136             return HandleRaiseWindowToTop(data, reply);
137         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID):
138             return HandleGetTopWindowId(data, reply);
139         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_PARENT_MAIN_WINDOW_ID):
140             return HandleGetParentMainWindowId(data, reply);
141         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_NOTIFY_WINDOW_EXTENSION_VISIBILITY_CHANGE):
142             return HandleNotifyWindowExtensionVisibilityChange(data, reply);
143         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_WINDOW_VISIBILITY_LISTENER):
144             return HandleUpdateSessionWindowVisibilityListener(data, reply);
145         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_FOCUS):
146             return HandleShiftAppWindowFocus(data, reply);
147         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_LIST_WINDOW_INFO):
148             return HandleListWindowInfo(data, reply);
149         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_LAYOUT_INFO):
150             return HandleGetAllWindowLayoutInfo(data, reply);
151         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID):
152             return HandleGetVisibilityWindowInfo(data, reply);
153         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_ADD_EXTENSION_WINDOW_STAGE_TO_SCB):
154             return HandleAddExtensionWindowStageToSCB(data, reply);
155         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REMOVE_EXTENSION_WINDOW_STAGE_FROM_SCB):
156             return HandleRemoveExtensionWindowStageFromSCB(data, reply);
157         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_MODALEXTENSION_RECT_TO_SCB):
158             return HandleUpdateModalExtensionRect(data, reply);
159         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PROCESS_MODALEXTENSION_POINTDOWN_TO_SCB):
160             return HandleProcessModalExtensionPointDown(data, reply);
161         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_ADD_OR_REMOVE_SECURE_SESSION):
162             return HandleAddOrRemoveSecureSession(data, reply);
163         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_EXTENSION_WINDOW_FLAGS):
164             return HandleUpdateExtWindowFlags(data, reply);
165         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_HOST_WINDOW_RECT):
166             return HandleGetHostWindowRect(data, reply);
167         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_STATUS):
168             return HandleGetCallingWindowWindowStatus(data, reply);
169         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_RECT):
170             return HandleGetCallingWindowRect(data, reply);
171         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_MODE_TYPE):
172             return HandleGetWindowModeType(data, reply);
173         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FREE_MULTI_WINDOW_ENABLE_STATE):
174             return HandleGetFreeMultiWindowEnableState(data, reply);
175         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE):
176             return HandleGetWindowStyleType(data, reply);
177         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_PROCESS_SURFACENODEID_BY_PERSISTENTID):
178             return HandleGetProcessSurfaceNodeIdByPersistentId(data, reply);
179         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_PROCESS_SNAPSHOT_SKIP):
180             return HandleSkipSnapshotForAppProcess(data, reply);
181         case static_cast<uint32_t>
182             (SceneSessionManagerMessage::TRANS_ID_SET_SNAPSHOT_SKIP_BY_USERID_AND_BUNDLENAMES):
183             return HandleSkipSnapshotByUserIdAndBundleNames(data, reply);
184         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_PROCESS_WATERMARK):
185             return HandleSetProcessWatermark(data, reply);
186         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_IDS_BY_COORDINATE):
187             return HandleGetWindowIdsByCoordinate(data, reply);
188         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_SESSION_SCREEN_LOCK):
189             return HandleUpdateSessionScreenLock(data, reply);
190         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_ADD_SKIP_SELF_ON_VIRTUAL_SCREEN):
191             return HandleAddSkipSelfWhenShowOnVirtualScreenList(data, reply);
192         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REMOVE_SKIP_SELF_ON_VIRTUAL_SCREEN):
193             return HandleRemoveSkipSelfWhenShowOnVirtualScreenList(data, reply);
194         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_PC_WINDOW):
195             return HandleIsPcWindow(data, reply);
196         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_PC_OR_PAD_FREE_MULTI_WINDOW_MODE):
197             return HandleIsPcOrPadFreeMultiWindowMode(data, reply);
198         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_DISPLAYID_BY_WINDOWID):
199             return HandleGetDisplayIdByWindowId(data, reply);
200         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_WINDOW_RECT_AUTO_SAVE):
201             return HandleIsWindowRectAutoSave(data, reply);
202         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_GLOBAL_DRAG_RESIZE_TYPE):
203             return HandleSetGlobalDragResizeType(data, reply);
204         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_GLOBAL_DRAG_RESIZE_TYPE):
205             return HandleGetGlobalDragResizeType(data, reply);
206         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_APP_DRAG_RESIZE_TYPE):
207             return HandleSetAppDragResizeType(data, reply);
208         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_APP_DRAG_RESIZE_TYPE):
209             return HandleGetAppDragResizeType(data, reply);
210         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_WATCH_GESTURE_CONSUME_RESULT):
211             return HandleWatchGestureConsumeResult(data, reply);
212         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_WATCH_FOCUS_ACTIVE_CHANGE):
213             return HandleWatchFocusActiveChange(data, reply);
214         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_POINTER_EVENT):
215             return HandleShiftAppWindowPointerEvent(data, reply);
216         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MINIMIZE_BY_WINDOW_ID):
217             return HandleMinimizeByWindowId(data, reply);
218         case static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_PARENT_WINDOW):
219             return HandleSetParentWindow(data, reply);
220         default:
221             WLOGFE("Failed to find function handler!");
222             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
223     }
224 }
225 
HandleCreateAndConnectSpecificSession(MessageParcel & data,MessageParcel & reply)226 int SceneSessionManagerStub::HandleCreateAndConnectSpecificSession(MessageParcel& data, MessageParcel& reply)
227 {
228     TLOGD(WmsLogTag::WMS_LIFE, "run");
229     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
230     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
231     sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
232     sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
233     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
234     if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
235         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read scene session stage object or event channel object!");
236         return ERR_INVALID_DATA;
237     }
238     sptr<WindowSessionProperty> property = data.ReadStrongParcelable<WindowSessionProperty>();
239     if (property == nullptr) {
240         TLOGE(WmsLogTag::WMS_LIFE, "property is nullptr");
241         return ERR_INVALID_DATA;
242     }
243 
244     sptr<IRemoteObject> token = nullptr;
245     if (property->GetTokenState()) {
246         token = data.ReadRemoteObject();
247     } else {
248         TLOGW(WmsLogTag::WMS_LIFE, "accept token is nullptr");
249     }
250 
251     auto persistentId = INVALID_SESSION_ID;
252     sptr<ISession> sceneSession;
253     SystemSessionConfig systemConfig;
254     CreateAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode,
255         property, persistentId, sceneSession, systemConfig, token);
256     if (sceneSession== nullptr) {
257         return ERR_INVALID_STATE;
258     }
259     reply.WriteInt32(persistentId);
260     reply.WriteRemoteObject(sceneSession->AsObject());
261     reply.WriteParcelable(&systemConfig);
262     reply.WriteUint32(property->GetSubWindowLevel());
263     reply.WriteFloat(property->GetWindowCornerRadius());
264     reply.WriteUint64(property->GetDisplayId());
265     reply.WriteUint32(static_cast<uint32_t>(WSError::WS_OK));
266     return ERR_NONE;
267 }
268 
HandleRecoverAndConnectSpecificSession(MessageParcel & data,MessageParcel & reply)269 int SceneSessionManagerStub::HandleRecoverAndConnectSpecificSession(MessageParcel& data, MessageParcel& reply)
270 {
271     TLOGI(WmsLogTag::WMS_RECOVER, "run!");
272     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
273     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
274     sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
275     sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
276     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
277     if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
278         TLOGE(WmsLogTag::WMS_RECOVER, "Failed to read scene session stage object or event channel object!");
279         return ERR_INVALID_DATA;
280     }
281     bool hasProperty = false;
282     if (!data.ReadBool(hasProperty)) {
283         TLOGE(WmsLogTag::WMS_RECOVER, "Read hasProperty failed!");
284         return ERR_TRANSACTION_FAILED;
285     }
286     sptr<WindowSessionProperty> property = nullptr;
287     if (hasProperty) {
288         property = data.ReadStrongParcelable<WindowSessionProperty>();
289     } else {
290         TLOGW(WmsLogTag::WMS_RECOVER, "Property not exist!");
291     }
292 
293     sptr<IRemoteObject> token = nullptr;
294     if (property && property->GetTokenState()) {
295         token = data.ReadRemoteObject();
296     } else {
297         TLOGI(WmsLogTag::WMS_RECOVER, "accept token is nullptr");
298     }
299 
300     sptr<ISession> sceneSession;
301     auto ret = RecoverAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode, property, sceneSession, token);
302     if (sceneSession== nullptr) {
303         return ERR_INVALID_STATE;
304     }
305     reply.WriteRemoteObject(sceneSession->AsObject());
306     reply.WriteUint32(static_cast<uint32_t>(ret));
307     return ERR_NONE;
308 }
309 
HandleRecoverAndReconnectSceneSession(MessageParcel & data,MessageParcel & reply)310 int SceneSessionManagerStub::HandleRecoverAndReconnectSceneSession(MessageParcel& data, MessageParcel& reply)
311 {
312     TLOGI(WmsLogTag::WMS_RECOVER, "run");
313     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
314     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
315     sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
316     sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
317     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
318     if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
319         TLOGE(WmsLogTag::WMS_RECOVER, "Failed to read scene session stage object or event channel object!");
320         return ERR_INVALID_DATA;
321     }
322     bool hasProperty = false;
323     if (!data.ReadBool(hasProperty)) {
324         TLOGE(WmsLogTag::WMS_RECOVER, "Read hasProperty failed!");
325         return ERR_TRANSACTION_FAILED;
326     }
327     sptr<WindowSessionProperty> property = nullptr;
328     if (hasProperty) {
329         property = data.ReadStrongParcelable<WindowSessionProperty>();
330     } else {
331         TLOGW(WmsLogTag::WMS_RECOVER, "Property not exist!");
332     }
333 
334     sptr<IRemoteObject> token = nullptr;
335     if (property && property->GetTokenState()) {
336         token = data.ReadRemoteObject();
337     } else {
338         TLOGI(WmsLogTag::WMS_RECOVER, "accept token is nullptr");
339     }
340 
341     sptr<ISession> sceneSession;
342     RecoverAndReconnectSceneSession(sessionStage, eventChannel, surfaceNode, sceneSession, property, token);
343     if (sceneSession == nullptr) {
344         return ERR_INVALID_STATE;
345     }
346     reply.WriteRemoteObject(sceneSession->AsObject());
347     reply.WriteUint32(static_cast<uint32_t>(WSError::WS_OK));
348     return ERR_NONE;
349 }
350 
HandleDestroyAndDisconnectSpcificSession(MessageParcel & data,MessageParcel & reply)351 int SceneSessionManagerStub::HandleDestroyAndDisconnectSpcificSession(MessageParcel& data, MessageParcel& reply)
352 {
353     int32_t persistentId = 0;
354     if (!data.ReadInt32(persistentId)) {
355         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed");
356         return ERR_TRANSACTION_FAILED;
357     }
358     TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d", persistentId);
359     WSError ret = DestroyAndDisconnectSpecificSession(persistentId);
360     reply.WriteUint32(static_cast<uint32_t>(ret));
361     return ERR_NONE;
362 }
363 
HandleDestroyAndDisconnectSpcificSessionWithDetachCallback(MessageParcel & data,MessageParcel & reply)364 int SceneSessionManagerStub::HandleDestroyAndDisconnectSpcificSessionWithDetachCallback(MessageParcel& data,
365     MessageParcel& reply)
366 {
367     int32_t persistentId = 0;
368     if (!data.ReadInt32(persistentId)) {
369         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed");
370         return ERR_TRANSACTION_FAILED;
371     }
372     TLOGI(WmsLogTag::WMS_LIFE, "id:%{public}d", persistentId);
373     sptr<IRemoteObject> callback = data.ReadRemoteObject();
374     const WSError ret = DestroyAndDisconnectSpecificSessionWithDetachCallback(persistentId, callback);
375     reply.WriteUint32(static_cast<uint32_t>(ret));
376     return ERR_NONE;
377 }
378 
HandleSetParentWindow(MessageParcel & data,MessageParcel & reply)379 int SceneSessionManagerStub::HandleSetParentWindow(MessageParcel& data, MessageParcel& reply)
380 {
381     int32_t subWindowId = INVALID_WINDOW_ID;
382     if (!data.ReadInt32(subWindowId)) {
383         TLOGE(WmsLogTag::WMS_SUB, "read subWindowId failed");
384         return ERR_INVALID_DATA;
385     }
386     int32_t newParentWindowId = INVALID_WINDOW_ID;
387     if (!data.ReadInt32(newParentWindowId)) {
388         TLOGE(WmsLogTag::WMS_SUB, "read newParentWindowId failed");
389         return ERR_INVALID_DATA;
390     }
391     TLOGD(WmsLogTag::WMS_SUB, "subWindowId: %{public}d, newParentWindowId: %{public}d",
392         subWindowId, newParentWindowId);
393     WMError errCode = SetParentWindow(subWindowId, newParentWindowId);
394     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
395         TLOGE(WmsLogTag::WMS_SUB, "Write errCode failed.");
396         return ERR_INVALID_DATA;
397     }
398     return ERR_NONE;
399 }
400 
HandleRequestFocusStatus(MessageParcel & data,MessageParcel & reply)401 int SceneSessionManagerStub::HandleRequestFocusStatus(MessageParcel& data, MessageParcel& reply)
402 {
403     TLOGD(WmsLogTag::WMS_FOCUS, "run");
404     int32_t persistentId = 0;
405     if (!data.ReadInt32(persistentId)) {
406         TLOGE(WmsLogTag::WMS_FOCUS, "read persistentId failed");
407         return ERR_INVALID_DATA;
408     }
409     bool isFocused = false;
410     if (!data.ReadBool(isFocused)) {
411         TLOGE(WmsLogTag::WMS_FOCUS, "read isFocused failed");
412         return ERR_INVALID_DATA;
413     }
414     WMError ret = RequestFocusStatus(persistentId, isFocused, true, FocusChangeReason::CLIENT_REQUEST);
415     reply.WriteInt32(static_cast<int32_t>(ret));
416     return ERR_NONE;
417 }
418 
HandleRequestFocusStatusBySA(MessageParcel & data,MessageParcel & reply)419 int SceneSessionManagerStub::HandleRequestFocusStatusBySA(MessageParcel& data, MessageParcel& reply)
420 {
421     TLOGD(WmsLogTag::WMS_FOCUS, "run");
422     int32_t persistentId = 0;
423     if (!data.ReadInt32(persistentId)) {
424         TLOGE(WmsLogTag::WMS_FOCUS, "read persistentId failed");
425         return ERR_INVALID_DATA;
426     }
427     bool isFocused = false;
428     if (!data.ReadBool(isFocused)) {
429         TLOGE(WmsLogTag::WMS_FOCUS, "read isFocused failed");
430         return ERR_INVALID_DATA;
431     }
432     bool byForeground = false;
433     if (!data.ReadBool(byForeground)) {
434         TLOGE(WmsLogTag::WMS_FOCUS, "read byForeground failed");
435         return ERR_INVALID_DATA;
436     }
437     int32_t reason = static_cast<int32_t>(FocusChangeReason::SA_REQUEST);
438     if (!data.ReadInt32(reason)) {
439         TLOGE(WmsLogTag::WMS_FOCUS, "read reason failed");
440         return ERR_INVALID_DATA;
441     }
442     WMError ret = RequestFocusStatusBySA(persistentId, isFocused, byForeground,
443         static_cast<FocusChangeReason>(reason));
444     reply.WriteInt32(static_cast<int32_t>(ret));
445     return ERR_NONE;
446 }
447 
HandleRegisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)448 int SceneSessionManagerStub::HandleRegisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
449 {
450     uint32_t typeId = 0;
451     if (!data.ReadUint32(typeId) ||
452         typeId < static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS) ||
453         typeId >= static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) {
454         return ERR_INVALID_DATA;
455     }
456     WindowManagerAgentType type = static_cast<WindowManagerAgentType>(typeId);
457     TLOGI(WmsLogTag::DEFAULT, "type=%{public}u", typeId);
458     sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
459     sptr<IWindowManagerAgent> windowManagerAgentProxy =
460         iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
461     WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy);
462     reply.WriteInt32(static_cast<int32_t>(errCode));
463     return ERR_NONE;
464 }
465 
HandleUnregisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)466 int SceneSessionManagerStub::HandleUnregisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
467 {
468     uint32_t typeId = 0;
469     if (!data.ReadUint32(typeId) ||
470         typeId < static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS) ||
471         typeId >= static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) {
472         return ERR_INVALID_DATA;
473     }
474     WindowManagerAgentType type = static_cast<WindowManagerAgentType>(typeId);
475     TLOGI(WmsLogTag::DEFAULT, "type=%{public}u", typeId);
476     sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
477     sptr<IWindowManagerAgent> windowManagerAgentProxy =
478         iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
479     WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
480     reply.WriteInt32(static_cast<int32_t>(errCode));
481     return ERR_NONE;
482 }
483 
HandleGetFocusSessionInfo(MessageParcel & data,MessageParcel & reply)484 int SceneSessionManagerStub::HandleGetFocusSessionInfo(MessageParcel& data, MessageParcel& reply)
485 {
486     TLOGD(WmsLogTag::WMS_FOCUS, "Run");
487     FocusChangeInfo focusInfo;
488     uint64_t displayId = 0;
489     if (!data.ReadUint64(displayId)) {
490         TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
491         return ERR_INVALID_DATA;
492     }
493     GetFocusWindowInfo(focusInfo, displayId);
494     reply.WriteParcelable(&focusInfo);
495     return ERR_NONE;
496 }
497 
HandleSetSessionLabel(MessageParcel & data,MessageParcel & reply)498 int SceneSessionManagerStub::HandleSetSessionLabel(MessageParcel& data, MessageParcel& reply)
499 {
500     TLOGD(WmsLogTag::DEFAULT, "In");
501     sptr<IRemoteObject> token = data.ReadRemoteObject();
502     std::string label;
503     if (!data.ReadString(label)) {
504         TLOGE(WmsLogTag::DEFAULT, "read label failed");
505         return ERR_INVALID_DATA;
506     }
507     WSError errCode = SetSessionLabel(token, label);
508     reply.WriteInt32(static_cast<int32_t>(errCode));
509     return ERR_NONE;
510 }
511 
HandleSetSessionIcon(MessageParcel & data,MessageParcel & reply)512 int SceneSessionManagerStub::HandleSetSessionIcon(MessageParcel& data, MessageParcel& reply)
513 {
514     TLOGD(WmsLogTag::DEFAULT, "In");
515     sptr<IRemoteObject> token = data.ReadRemoteObject();
516     std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
517     if (icon == nullptr) {
518         TLOGE(WmsLogTag::DEFAULT, "icon is null");
519         return ERR_INVALID_DATA;
520     }
521     WSError errCode = SetSessionIcon(token, icon);
522     reply.WriteInt32(static_cast<int32_t>(errCode));
523     return ERR_NONE;
524 }
525 
HandleIsValidSessionIds(MessageParcel & data,MessageParcel & reply)526 int SceneSessionManagerStub::HandleIsValidSessionIds(MessageParcel& data, MessageParcel& reply)
527 {
528     WLOGFI("run HandleIsValidSessionIds!");
529     std::vector<int32_t> sessionIds;
530     data.ReadInt32Vector(&sessionIds);
531     std::vector<bool> results;
532     reply.WriteBoolVector(results);
533     return ERR_NONE;
534 }
535 
HandlePendingSessionToForeground(MessageParcel & data,MessageParcel & reply)536 int SceneSessionManagerStub::HandlePendingSessionToForeground(MessageParcel& data, MessageParcel& reply)
537 {
538     WLOGFI("run HandlePendingSessionToForeground!");
539     sptr<IRemoteObject> token = data.ReadRemoteObject();
540     if (token == nullptr) {
541         WLOGFE("token is nullptr");
542         return ERR_INVALID_DATA;
543     }
544     WSError errCode = PendingSessionToForeground(token);
545     reply.WriteUint32(static_cast<uint32_t>(errCode));
546     return ERR_NONE;
547 }
548 
HandlePendingSessionToBackgroundForDelegator(MessageParcel & data,MessageParcel & reply)549 int SceneSessionManagerStub::HandlePendingSessionToBackgroundForDelegator(MessageParcel& data, MessageParcel& reply)
550 {
551     TLOGD(WmsLogTag::WMS_LIFE, "run");
552     sptr<IRemoteObject> token = data.ReadRemoteObject();
553     if (token == nullptr) {
554         TLOGE(WmsLogTag::WMS_LIFE, "token is nullptr");
555         return ERR_INVALID_DATA;
556     }
557     bool shouldBackToCaller = true;
558     if (!data.ReadBool(shouldBackToCaller)) {
559         TLOGE(WmsLogTag::WMS_LIFE, "Read shouldBackToCaller failed");
560         return ERR_INVALID_DATA;
561     }
562     WSError errCode = PendingSessionToBackgroundForDelegator(token, shouldBackToCaller);
563     reply.WriteInt32(static_cast<int32_t>(errCode));
564     return ERR_NONE;
565 }
566 
HandleRegisterSessionListener(MessageParcel & data,MessageParcel & reply)567 int SceneSessionManagerStub::HandleRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
568 {
569     WLOGFI("run HandleRegisterSessionListener!");
570     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
571     if (listener == nullptr) {
572         reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
573         WLOGFI("listener is nullptr");
574         return ERR_NONE;
575     }
576     WSError errCode = RegisterSessionListener(listener);
577     reply.WriteInt32(static_cast<int32_t>(errCode));
578     return ERR_NONE;
579 }
580 
HandleUnRegisterSessionListener(MessageParcel & data,MessageParcel & reply)581 int SceneSessionManagerStub::HandleUnRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
582 {
583     WLOGFI("run HandleUnRegisterSessionListener!");
584     sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
585     if (listener == nullptr) {
586         reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
587         WLOGFI("listener is nullptr");
588         return ERR_NONE;
589     }
590     WSError errCode = UnRegisterSessionListener(listener);
591     reply.WriteInt32(static_cast<int32_t>(errCode));
592     return ERR_NONE;
593 }
594 
HandleGetSessionInfos(MessageParcel & data,MessageParcel & reply)595 int SceneSessionManagerStub::HandleGetSessionInfos(MessageParcel& data, MessageParcel& reply)
596 {
597     TLOGD(WmsLogTag::WMS_LIFE, "In!");
598     std::string deviceId = Str16ToStr8(data.ReadString16());
599     int32_t numMax = 0;
600     if (!data.ReadInt32(numMax)) {
601         TLOGE(WmsLogTag::WMS_LIFE, "Read numMax failed");
602         return ERR_INVALID_DATA;
603     }
604     std::vector<SessionInfoBean> missionInfos;
605     WSError errCode = GetSessionInfos(deviceId, numMax, missionInfos);
606     reply.WriteInt32(missionInfos.size());
607     for (auto& it : missionInfos) {
608         if (!reply.WriteParcelable(&it)) {
609             TLOGE(WmsLogTag::WMS_LIFE, "Write missionInfos error");
610             return ERR_INVALID_DATA;
611         }
612     }
613     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
614         TLOGE(WmsLogTag::WMS_LIFE, "Write result error");
615         return ERR_INVALID_DATA;
616     }
617     return ERR_NONE;
618 }
619 
HandleGetSessionInfo(MessageParcel & data,MessageParcel & reply)620 int SceneSessionManagerStub::HandleGetSessionInfo(MessageParcel& data, MessageParcel& reply)
621 {
622     TLOGD(WmsLogTag::WMS_LIFE, "In!");
623     std::string deviceId = Str16ToStr8(data.ReadString16());
624     int32_t persistentId;
625     if (!data.ReadInt32(persistentId)) {
626         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed");
627         return ERR_INVALID_DATA;
628     }
629     SessionInfoBean info;
630     WSError errCode = GetSessionInfo(deviceId, persistentId, info);
631     if (!reply.WriteParcelable(&info)) {
632         TLOGE(WmsLogTag::WMS_LIFE, "Write sessionInfo error");
633         return ERR_INVALID_DATA;
634     }
635 
636     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
637         TLOGE(WmsLogTag::WMS_LIFE, "Write result error");
638         return ERR_INVALID_DATA;
639     }
640     return ERR_NONE;
641 }
642 
643 
HandleGetSessionInfoByContinueSessionId(MessageParcel & data,MessageParcel & reply)644 int SceneSessionManagerStub::HandleGetSessionInfoByContinueSessionId(MessageParcel& data, MessageParcel& reply)
645 {
646     TLOGD(WmsLogTag::WMS_LIFE, "In!");
647     SessionInfoBean info;
648     std::string continueSessionId;
649     if (!data.ReadString(continueSessionId)) {
650         TLOGE(WmsLogTag::WMS_LIFE, "Read continueSessionId failed");
651         return ERR_INVALID_DATA;
652     }
653     TLOGI(WmsLogTag::WMS_LIFE, "continueSessionId: %{public}s", continueSessionId.c_str());
654     WSError errCode = GetSessionInfoByContinueSessionId(continueSessionId, info);
655     if (!reply.WriteParcelable(&info)) {
656         TLOGE(WmsLogTag::WMS_LIFE, "GetSessionInfo error");
657         return ERR_INVALID_DATA;
658     }
659 
660     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
661         TLOGE(WmsLogTag::WMS_LIFE, "GetSessionInfo result error");
662         return ERR_INVALID_DATA;
663     }
664     return ERR_NONE;
665 }
666 
HandleDumpSessionAll(MessageParcel & data,MessageParcel & reply)667 int SceneSessionManagerStub::HandleDumpSessionAll(MessageParcel& data, MessageParcel& reply)
668 {
669     WLOGFI("run HandleDumpSessionAll!");
670     std::vector<std::string> infos;
671     WSError errCode = DumpSessionAll(infos);
672     if (!reply.WriteStringVector(infos)) {
673         WLOGFE("HandleDumpSessionAll write info failed.");
674         return ERR_TRANSACTION_FAILED;
675     }
676 
677     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
678         WLOGFE("HandleDumpSessionAll write errcode failed.");
679         return ERR_TRANSACTION_FAILED;
680     }
681     return ERR_NONE;
682 }
683 
HandleDumpSessionWithId(MessageParcel & data,MessageParcel & reply)684 int SceneSessionManagerStub::HandleDumpSessionWithId(MessageParcel& data, MessageParcel& reply)
685 {
686     TLOGD(WmsLogTag::DEFAULT, "In!");
687     int32_t persistentId;
688     if (!data.ReadInt32(persistentId)) {
689         TLOGE(WmsLogTag::DEFAULT, "read persistentId failed.");
690         return ERR_INVALID_DATA;
691     }
692     std::vector<std::string> infos;
693     WSError errCode = DumpSessionWithId(persistentId, infos);
694     if (!reply.WriteStringVector(infos)) {
695         TLOGE(WmsLogTag::DEFAULT, "write info failed.");
696         return ERR_TRANSACTION_FAILED;
697     }
698 
699     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
700         TLOGE(WmsLogTag::DEFAULT, "write errcode failed.");
701         return ERR_TRANSACTION_FAILED;
702     }
703     return ERR_NONE;
704 }
705 
HandleTerminateSessionNew(MessageParcel & data,MessageParcel & reply)706 int SceneSessionManagerStub::HandleTerminateSessionNew(MessageParcel& data, MessageParcel& reply)
707 {
708     TLOGD(WmsLogTag::WMS_LIFE, "in");
709     sptr<AAFwk::SessionInfo> abilitySessionInfo = data.ReadParcelable<AAFwk::SessionInfo>();
710     if (abilitySessionInfo == nullptr) {
711         TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfo is null");
712         return ERR_INVALID_DATA;
713     }
714     bool needStartCaller = false;
715     if (!data.ReadBool(needStartCaller)) {
716         TLOGE(WmsLogTag::WMS_LIFE, "Read needStartCaller failed.");
717         return ERR_INVALID_DATA;
718     }
719     bool isFromBroker = false;
720     if (!data.ReadBool(isFromBroker)) {
721         TLOGE(WmsLogTag::WMS_LIFE, "Read isFromBroker failed.");
722         return ERR_INVALID_DATA;
723     }
724     WSError errCode = TerminateSessionNew(abilitySessionInfo, needStartCaller, isFromBroker);
725     reply.WriteUint32(static_cast<uint32_t>(errCode));
726     return ERR_NONE;
727 }
728 
HandleGetFocusSessionToken(MessageParcel & data,MessageParcel & reply)729 int SceneSessionManagerStub::HandleGetFocusSessionToken(MessageParcel& data, MessageParcel& reply)
730 {
731     WLOGFD("run HandleGetFocusSessionToken!");
732     sptr<IRemoteObject> token = nullptr;
733     uint64_t displayId = 0;
734     if (!data.ReadUint64(displayId)) {
735         TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
736         return ERR_INVALID_DATA;
737     }
738     WSError errCode = GetFocusSessionToken(token, displayId);
739     reply.WriteRemoteObject(token);
740     reply.WriteInt32(static_cast<int32_t>(errCode));
741     return ERR_NONE;
742 }
743 
HandleGetFocusSessionElement(MessageParcel & data,MessageParcel & reply)744 int SceneSessionManagerStub::HandleGetFocusSessionElement(MessageParcel& data, MessageParcel& reply)
745 {
746     WLOGFD("run HandleGetFocusSessionElement!");
747     AppExecFwk::ElementName element;
748     uint64_t displayId = 0;
749     if (!data.ReadUint64(displayId)) {
750         TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
751         return ERR_INVALID_DATA;
752     }
753     WSError errCode = GetFocusSessionElement(element, displayId);
754     reply.WriteParcelable(&element);
755     reply.WriteInt32(static_cast<int32_t>(errCode));
756     return ERR_NONE;
757 }
758 
HandleCheckWindowId(MessageParcel & data,MessageParcel & reply)759 int SceneSessionManagerStub::HandleCheckWindowId(MessageParcel& data, MessageParcel& reply)
760 {
761     WLOGFI("run HandleCheckWindowId!");
762     int32_t windowId = INVALID_WINDOW_ID;
763     if (!data.ReadInt32(windowId)) {
764         WLOGE("Failed to readInt32 windowId");
765         return ERR_INVALID_DATA;
766     }
767     int32_t pid = INVALID_PID;
768     WMError errCode = CheckWindowId(windowId, pid);
769     if (errCode != WMError::WM_OK) {
770         WLOGE("Failed to checkWindowId(%{public}d)", pid);
771         return ERR_INVALID_DATA;
772     }
773     if (!reply.WriteInt32(pid)) {
774         WLOGE("Failed to WriteInt32 pid");
775         return ERR_INVALID_DATA;
776     }
777     return ERR_NONE;
778 }
779 
HandleSetGestureNavigationEnabled(MessageParcel & data,MessageParcel & reply)780 int SceneSessionManagerStub::HandleSetGestureNavigationEnabled(MessageParcel& data, MessageParcel& reply)
781 {
782     TLOGD(WmsLogTag::DEFAULT, "Run");
783     bool enable = false;
784     if (!data.ReadBool(enable)) {
785         return ERR_INVALID_DATA;
786     }
787     const WMError &ret = SetGestureNavigationEnabled(enable);
788     reply.WriteInt32(static_cast<int32_t>(ret));
789     return ERR_NONE;
790 }
791 
HandleGetAccessibilityWindowInfo(MessageParcel & data,MessageParcel & reply)792 int SceneSessionManagerStub::HandleGetAccessibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
793 {
794     std::vector<sptr<AccessibilityWindowInfo>> infos;
795     WMError errCode = GetAccessibilityWindowInfo(infos);
796     if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
797         WLOGFE("Write window infos failed.");
798         return ERR_TRANSACTION_FAILED;
799     }
800     reply.WriteInt32(static_cast<int32_t>(errCode));
801     return ERR_NONE;
802 }
803 
HandleGetUnreliableWindowInfo(MessageParcel & data,MessageParcel & reply)804 int SceneSessionManagerStub::HandleGetUnreliableWindowInfo(MessageParcel& data, MessageParcel& reply)
805 {
806     TLOGD(WmsLogTag::DEFAULT, "run!");
807     std::vector<sptr<UnreliableWindowInfo>> infos;
808     int32_t windowId = INVALID_WINDOW_ID;
809     if (!data.ReadInt32(windowId)) {
810         TLOGE(WmsLogTag::DEFAULT, "Failed to readInt32 windowId");
811         return ERR_INVALID_DATA;
812     }
813     WMError errCode = GetUnreliableWindowInfo(windowId, infos);
814     if (!MarshallingHelper::MarshallingVectorParcelableObj<UnreliableWindowInfo>(reply, infos)) {
815         TLOGE(WmsLogTag::DEFAULT, "Write unreliable window infos failed.");
816         return ERR_TRANSACTION_FAILED;
817     }
818     reply.WriteInt32(static_cast<int32_t>(errCode));
819     return ERR_NONE;
820 }
821 
HandleSetSessionContinueState(MessageParcel & data,MessageParcel & reply)822 int SceneSessionManagerStub::HandleSetSessionContinueState(MessageParcel& data, MessageParcel& reply)
823 {
824     WLOGFI("HandleSetSessionContinueState");
825     sptr <IRemoteObject> token = data.ReadRemoteObject();
826     auto continueState = static_cast<ContinueState>(data.ReadInt32());
827     const WSError &ret = SetSessionContinueState(token, continueState);
828     reply.WriteUint32(static_cast<uint32_t>(ret));
829     return ERR_NONE;
830 }
831 
HandleGetSessionDump(MessageParcel & data,MessageParcel & reply)832 int SceneSessionManagerStub::HandleGetSessionDump(MessageParcel& data, MessageParcel& reply)
833 {
834     std::vector<std::string> params;
835     if (!data.ReadStringVector(&params)) {
836         WLOGFE("Fail to read params");
837         return ERR_INVALID_DATA;
838     }
839     std::string dumpInfo;
840     WSError errCode = GetSessionDumpInfo(params, dumpInfo);
841     uint32_t infoSize = static_cast<uint32_t>(dumpInfo.length());
842     TLOGD(WmsLogTag::DEFAULT, "HandleGetSessionDump, infoSize: %{public}d", infoSize);
843     reply.WriteUint32(infoSize);
844     if (infoSize != 0) {
845         if (!reply.WriteRawData(dumpInfo.c_str(), infoSize)) {
846             WLOGFE("Fail to write dumpInfo");
847             return ERR_INVALID_DATA;
848         }
849     }
850     reply.WriteInt32(static_cast<int32_t>(errCode));
851     return ERR_NONE;
852 }
853 
HandleUpdateSessionAvoidAreaListener(MessageParcel & data,MessageParcel & reply)854 int SceneSessionManagerStub::HandleUpdateSessionAvoidAreaListener(MessageParcel& data, MessageParcel& reply)
855 {
856     int32_t persistentId = 0;
857     if (!data.ReadInt32(persistentId)) {
858         return ERR_INVALID_DATA;
859     }
860     bool haveAvoidAreaListener = false;
861     if (!data.ReadBool(haveAvoidAreaListener)) {
862         return ERR_INVALID_DATA;
863     }
864     WSError errCode = UpdateSessionAvoidAreaListener(persistentId, haveAvoidAreaListener);
865     reply.WriteUint32(static_cast<uint32_t>(errCode));
866     return ERR_NONE;
867 }
868 
HandleGetSessionSnapshot(MessageParcel & data,MessageParcel & reply)869 int SceneSessionManagerStub::HandleGetSessionSnapshot(MessageParcel& data, MessageParcel& reply)
870 {
871     TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!");
872     std::u16string deviceIdData;
873     if (!data.ReadString16(deviceIdData)) {
874         TLOGE(WmsLogTag::WMS_SYSTEM, "read deviceId fail");
875         return ERR_INVALID_DATA;
876     }
877     std::string deviceId = Str16ToStr8(deviceIdData);
878     int32_t persistentId = 0;
879     if (!data.ReadInt32(persistentId)) {
880         TLOGE(WmsLogTag::WMS_SYSTEM, "read persistentId fail");
881         return ERR_INVALID_DATA;
882     }
883     bool isLowResolution = false;
884     if (!data.ReadBool(isLowResolution)) {
885         TLOGE(WmsLogTag::WMS_SYSTEM, "read isLowResolution fail");
886         return ERR_INVALID_DATA;
887     }
888     std::shared_ptr<SessionSnapshot> snapshot = std::make_shared<SessionSnapshot>();
889     WSError ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution);
890     reply.WriteParcelable(snapshot.get());
891     reply.WriteUint32(static_cast<uint32_t>(ret));
892     return ERR_NONE;
893 }
894 
HandleGetSessionSnapshotById(MessageParcel & data,MessageParcel & reply)895 int SceneSessionManagerStub::HandleGetSessionSnapshotById(MessageParcel& data, MessageParcel& reply)
896 {
897     TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!");
898     int32_t persistentId = 0;
899     if (!data.ReadInt32(persistentId)) {
900         TLOGE(WmsLogTag::WMS_SYSTEM, "read persistentId fail");
901         return ERR_INVALID_DATA;
902     }
903     std::shared_ptr<SessionSnapshot> snapshot = std::make_shared<SessionSnapshot>();
904     const WMError ret = GetSessionSnapshotById(persistentId, *snapshot);
905     reply.WriteParcelable(snapshot.get());
906     reply.WriteInt32(static_cast<int32_t>(ret));
907     return ERR_NONE;
908 }
909 
HandleGetUIContentRemoteObj(MessageParcel & data,MessageParcel & reply)910 int SceneSessionManagerStub::HandleGetUIContentRemoteObj(MessageParcel& data, MessageParcel& reply)
911 {
912     TLOGD(WmsLogTag::WMS_ATTRIBUTE, "In!");
913     int32_t persistentId;
914     if (!data.ReadInt32(persistentId)) {
915         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read persistentId");
916         return ERR_INVALID_DATA;
917     }
918     sptr<IRemoteObject> uiContentRemoteObj;
919     WSError ret = GetUIContentRemoteObj(persistentId, uiContentRemoteObj);
920     reply.WriteRemoteObject(uiContentRemoteObj);
921     reply.WriteUint32(static_cast<uint32_t>(ret));
922     return ERR_NONE;
923 }
924 
HandleBindDialogTarget(MessageParcel & data,MessageParcel & reply)925 int SceneSessionManagerStub::HandleBindDialogTarget(MessageParcel& data, MessageParcel& reply)
926 {
927     WLOGFI("run HandleBindDialogTarget!");
928     uint64_t persistentId = 0;
929     if (!data.ReadUint64(persistentId)) {
930         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed");
931         return ERR_TRANSACTION_FAILED;
932     }
933     sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
934     WSError ret = BindDialogSessionTarget(persistentId, remoteObject);
935     reply.WriteUint32(static_cast<uint32_t>(ret));
936     return ERR_NONE;
937 }
938 
HandleNotifyDumpInfoResult(MessageParcel & data,MessageParcel & reply)939 int SceneSessionManagerStub::HandleNotifyDumpInfoResult(MessageParcel& data, MessageParcel& reply)
940 {
941     TLOGD(WmsLogTag::DEFAULT, "Enter");
942     uint32_t vectorSize;
943     if (!data.ReadUint32(vectorSize)) {
944         TLOGE(WmsLogTag::DEFAULT, "Failed to read vectorSize");
945         return ERR_INVALID_DATA;
946     }
947     if (vectorSize > MAX_VECTOR_SIZE) {
948         TLOGE(WmsLogTag::DEFAULT, "Vector is too big!");
949         return ERR_INVALID_DATA;
950     }
951     std::vector<std::string> info;
952     for (uint32_t i = 0; i < vectorSize; i++) {
953         uint32_t curSize = data.ReadUint32();
954         std::string curInfo = "";
955         if (curSize != 0) {
956             const char* infoPtr = nullptr;
957             infoPtr = reinterpret_cast<const char*>(data.ReadRawData(curSize));
958             curInfo = (infoPtr) ? std::string(infoPtr, curSize) : "";
959         }
960         info.emplace_back(curInfo);
961         TLOGD(WmsLogTag::DEFAULT, "InfoResult count: %{public}u, infoSize: %{public}u", i, curSize);
962     }
963     NotifyDumpInfoResult(info);
964     return ERR_NONE;
965 }
966 
HandleClearSession(MessageParcel & data,MessageParcel & reply)967 int SceneSessionManagerStub::HandleClearSession(MessageParcel& data, MessageParcel& reply)
968 {
969     TLOGD(WmsLogTag::WMS_LIFE, "In!");
970     int32_t persistentId;
971     if (!data.ReadInt32(persistentId)) {
972         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read persistentId");
973         return ERR_INVALID_DATA;
974     }
975     WSError ret = ClearSession(persistentId);
976     reply.WriteUint32(static_cast<uint32_t>(ret));
977     return ERR_NONE;
978 }
979 
HandleClearAllSessions(MessageParcel & data,MessageParcel & reply)980 int SceneSessionManagerStub::HandleClearAllSessions(MessageParcel& data, MessageParcel& reply)
981 {
982     WLOGFI("run HandleClearAllSessions!");
983     WSError ret = ClearAllSessions();
984     reply.WriteUint32(static_cast<uint32_t>(ret));
985     return ERR_NONE;
986 }
987 
HandleLockSession(MessageParcel & data,MessageParcel & reply)988 int SceneSessionManagerStub::HandleLockSession(MessageParcel& data, MessageParcel& reply)
989 {
990     TLOGD(WmsLogTag::WMS_LIFE, "In!");
991     int32_t sessionId;
992     if (!data.ReadInt32(sessionId)) {
993         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read sessionId");
994         return ERR_INVALID_DATA;
995     }
996     WSError ret = LockSession(sessionId);
997     reply.WriteUint32(static_cast<uint32_t>(ret));
998     return ERR_NONE;
999 }
HandleUnlockSession(MessageParcel & data,MessageParcel & reply)1000 int SceneSessionManagerStub::HandleUnlockSession(MessageParcel& data, MessageParcel& reply)
1001 {
1002     TLOGD(WmsLogTag::WMS_LIFE, "In!");
1003     int32_t sessionId;
1004     if (!data.ReadInt32(sessionId)) {
1005         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read sessionId");
1006         return ERR_INVALID_DATA;
1007     }
1008     WSError ret = UnlockSession(sessionId);
1009     reply.WriteUint32(static_cast<uint32_t>(ret));
1010     return ERR_NONE;
1011 }
HandleMoveSessionsToForeground(MessageParcel & data,MessageParcel & reply)1012 int SceneSessionManagerStub::HandleMoveSessionsToForeground(MessageParcel& data, MessageParcel& reply)
1013 {
1014     TLOGD(WmsLogTag::WMS_LIFE, "In!");
1015     std::vector<int32_t> sessionIds;
1016     data.ReadInt32Vector(&sessionIds);
1017     int32_t topSessionId;
1018     if (!data.ReadInt32(topSessionId)) {
1019         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read topSessionId");
1020         return ERR_INVALID_DATA;
1021     }
1022     const WSError &ret = MoveSessionsToForeground(sessionIds, topSessionId);
1023     reply.WriteUint32(static_cast<uint32_t>(ret));
1024     return ERR_NONE;
1025 }
HandleMoveSessionsToBackground(MessageParcel & data,MessageParcel & reply)1026 int SceneSessionManagerStub::HandleMoveSessionsToBackground(MessageParcel& data, MessageParcel& reply)
1027 {
1028     WLOGFI("run HandleMoveSessionsToBackground!");
1029     std::vector<int32_t> sessionIds;
1030     data.ReadInt32Vector(&sessionIds);
1031     std::vector<int32_t> result;
1032     data.ReadInt32Vector(&result);
1033     const WSError &ret = MoveSessionsToBackground(sessionIds, result);
1034     reply.WriteInt32Vector(result);
1035     reply.WriteUint32(static_cast<uint32_t>(ret));
1036     return ERR_NONE;
1037 }
1038 
HandleRegisterCollaborator(MessageParcel & data,MessageParcel & reply)1039 int SceneSessionManagerStub::HandleRegisterCollaborator(MessageParcel& data, MessageParcel& reply)
1040 {
1041     TLOGD(WmsLogTag::WMS_LIFE, "In!");
1042     int32_t type;
1043     if (!data.ReadInt32(type)) {
1044         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read type");
1045         return ERR_INVALID_DATA;
1046     }
1047     sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
1048         iface_cast<AAFwk::IAbilityManagerCollaborator>(data.ReadRemoteObject());
1049     if (collaborator == nullptr) {
1050         TLOGE(WmsLogTag::WMS_LIFE, "collaborator is nullptr");
1051         return ERR_INVALID_DATA;
1052     }
1053     WSError ret = RegisterIAbilityManagerCollaborator(type, collaborator);
1054     reply.WriteUint32(static_cast<uint32_t>(ret));
1055     return ERR_NONE;
1056 }
1057 
HandleUnregisterCollaborator(MessageParcel & data,MessageParcel & reply)1058 int SceneSessionManagerStub::HandleUnregisterCollaborator(MessageParcel& data, MessageParcel& reply)
1059 {
1060     TLOGD(WmsLogTag::WMS_LIFE, "In!");
1061     int32_t type;
1062     if (!data.ReadInt32(type)) {
1063         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read type");
1064         return ERR_INVALID_DATA;
1065     }
1066     WSError ret = UnregisterIAbilityManagerCollaborator(type);
1067     reply.WriteUint32(static_cast<uint32_t>(ret));
1068     return ERR_NONE;
1069 }
1070 
HandleUpdateSessionTouchOutsideListener(MessageParcel & data,MessageParcel & reply)1071 int SceneSessionManagerStub::HandleUpdateSessionTouchOutsideListener(MessageParcel& data, MessageParcel& reply)
1072 {
1073     int32_t persistentId = 0;
1074     if (!data.ReadInt32(persistentId)) {
1075         TLOGE(WmsLogTag::WMS_INPUT_KEY_FLOW, "read persistentId failed");
1076         return ERR_INVALID_DATA;
1077     }
1078     bool haveAvoidAreaListener = false;
1079     if (!data.ReadBool(haveAvoidAreaListener)) {
1080         TLOGE(WmsLogTag::WMS_INPUT_KEY_FLOW, "read haveAvoidAreaListener fail");
1081         return ERR_INVALID_DATA;
1082     }
1083     WSError errCode = UpdateSessionTouchOutsideListener(persistentId, haveAvoidAreaListener);
1084     reply.WriteUint32(static_cast<uint32_t>(errCode));
1085     return ERR_NONE;
1086 }
1087 
HandleRaiseWindowToTop(MessageParcel & data,MessageParcel & reply)1088 int SceneSessionManagerStub::HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply)
1089 {
1090     auto persistentId = 0;
1091     if (!data.ReadInt32(persistentId)) {
1092         TLOGE(WmsLogTag::WMS_HIERARCHY, "read persistentId failed");
1093         return ERR_INVALID_DATA;
1094     }
1095     WSError errCode = RaiseWindowToTop(persistentId);
1096     reply.WriteUint32(static_cast<uint32_t>(errCode));
1097     return ERR_NONE;
1098 }
1099 
HandleNotifyWindowExtensionVisibilityChange(MessageParcel & data,MessageParcel & reply)1100 int SceneSessionManagerStub::HandleNotifyWindowExtensionVisibilityChange(MessageParcel& data, MessageParcel& reply)
1101 {
1102     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1103     int32_t pid;
1104     if (!data.ReadInt32(pid)) {
1105         TLOGE(WmsLogTag::WMS_UIEXT, "read pid failed");
1106         return ERR_INVALID_DATA;
1107     }
1108     int32_t uid;
1109     if (!data.ReadInt32(uid)) {
1110         TLOGE(WmsLogTag::WMS_UIEXT, "read uid failed");
1111         return ERR_INVALID_DATA;
1112     }
1113     bool visible;
1114     if (!data.ReadBool(visible)) {
1115         TLOGE(WmsLogTag::WMS_UIEXT, "read visible failed");
1116         return ERR_INVALID_DATA;
1117     }
1118     TLOGD(WmsLogTag::WMS_UIEXT, "pid:%{public}d, uid:%{public}d, visible:%{public}d", pid, uid, visible);
1119     WSError ret = NotifyWindowExtensionVisibilityChange(pid, uid, visible);
1120     reply.WriteUint32(static_cast<uint32_t>(ret));
1121     return ERR_NONE;
1122 }
1123 
HandleGetTopWindowId(MessageParcel & data,MessageParcel & reply)1124 int SceneSessionManagerStub::HandleGetTopWindowId(MessageParcel& data, MessageParcel& reply)
1125 {
1126     uint32_t mainWinId = 0;
1127     if (!data.ReadUint32(mainWinId)) {
1128         TLOGE(WmsLogTag::WMS_HIERARCHY, "read mainWinId failed");
1129         return ERR_INVALID_DATA;
1130     }
1131     uint32_t topWinId;
1132     WMError ret = GetTopWindowId(mainWinId, topWinId);
1133     reply.WriteUint32(topWinId);
1134     reply.WriteUint32(static_cast<uint32_t>(ret));
1135     return ERR_NONE;
1136 }
1137 
HandleGetParentMainWindowId(MessageParcel & data,MessageParcel & reply)1138 int SceneSessionManagerStub::HandleGetParentMainWindowId(MessageParcel& data, MessageParcel& reply)
1139 {
1140     int32_t windowId = INVALID_SESSION_ID;
1141     if (!data.ReadInt32(windowId)) {
1142         TLOGE(WmsLogTag::WMS_FOCUS, "read windowId failed");
1143         return ERR_INVALID_DATA;
1144     }
1145     int32_t mainWindowId = INVALID_SESSION_ID;
1146     WMError errCode = GetParentMainWindowId(windowId, mainWindowId);
1147     if (!reply.WriteInt32(mainWindowId)) {
1148         return ERR_INVALID_DATA;
1149     }
1150     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1151         return ERR_INVALID_DATA;
1152     }
1153     return ERR_NONE;
1154 }
1155 
HandleWatchGestureConsumeResult(MessageParcel & data,MessageParcel & reply)1156 int SceneSessionManagerStub::HandleWatchGestureConsumeResult(MessageParcel& data, MessageParcel& reply)
1157 {
1158     int32_t keyCode = 0;
1159     if (!data.ReadInt32(keyCode)) {
1160         TLOGE(WmsLogTag::WMS_EVENT, "read keyCode failed");
1161         return ERR_INVALID_DATA;
1162     }
1163     bool isConsumed = false;
1164     if (!data.ReadBool(isConsumed)) {
1165         TLOGE(WmsLogTag::WMS_EVENT, "read isConsumed failed");
1166         return ERR_INVALID_DATA;
1167     }
1168     TLOGD(WmsLogTag::WMS_EVENT, "keyCode:%{public}d isConsumed:%{public}d", keyCode, isConsumed);
1169     WMError ret = NotifyWatchGestureConsumeResult(keyCode, isConsumed);
1170     if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1171         return ERR_INVALID_DATA;
1172     }
1173     return ERR_NONE;
1174 }
1175 
HandleWatchFocusActiveChange(MessageParcel & data,MessageParcel & reply)1176 int SceneSessionManagerStub::HandleWatchFocusActiveChange(MessageParcel& data, MessageParcel& reply)
1177 {
1178     bool isActive = false;
1179     if (!data.ReadBool(isActive)) {
1180         TLOGE(WmsLogTag::WMS_FOCUS, "read isActive failed");
1181         return ERR_INVALID_DATA;
1182     }
1183     TLOGD(WmsLogTag::WMS_EVENT, "isActive:%{public}d", isActive);
1184     WMError ret = NotifyWatchFocusActiveChange(isActive);
1185     if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1186         return ERR_INVALID_DATA;
1187     }
1188     return ERR_NONE;
1189 }
1190 
HandleUpdateSessionWindowVisibilityListener(MessageParcel & data,MessageParcel & reply)1191 int SceneSessionManagerStub::HandleUpdateSessionWindowVisibilityListener(MessageParcel& data, MessageParcel& reply)
1192 {
1193     TLOGD(WmsLogTag::WMS_ATTRIBUTE, "Handled!");
1194     int32_t persistentId = 0;
1195     if (!data.ReadInt32(persistentId)) {
1196         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read persistentId fail");
1197         return ERR_INVALID_DATA;
1198     }
1199     bool haveListener = false;
1200     if (!data.ReadBool(haveListener)) {
1201         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read haveListener fail");
1202         return ERR_INVALID_DATA;
1203     }
1204     WSError ret = UpdateSessionWindowVisibilityListener(persistentId, haveListener);
1205     reply.WriteUint32(static_cast<uint32_t>(ret));
1206     return ERR_NONE;
1207 }
1208 
HandleShiftAppWindowFocus(MessageParcel & data,MessageParcel & reply)1209 int SceneSessionManagerStub::HandleShiftAppWindowFocus(MessageParcel& data, MessageParcel& reply)
1210 {
1211     int32_t sourcePersistentId = 0;
1212     int32_t targetPersistentId = 0;
1213     if (!data.ReadInt32(sourcePersistentId) || !data.ReadInt32(targetPersistentId)) {
1214         TLOGE(WmsLogTag::WMS_FOCUS, "read sourcePersistentId or targetPersistentId failed");
1215         return ERR_INVALID_DATA;
1216     }
1217     WSError ret = ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
1218     reply.WriteUint32(static_cast<uint32_t>(ret));
1219     return ERR_NONE;
1220 }
1221 
HandleListWindowInfo(MessageParcel & data,MessageParcel & reply)1222 int SceneSessionManagerStub::HandleListWindowInfo(MessageParcel& data, MessageParcel& reply)
1223 {
1224     WindowInfoOption windowInfoOption;
1225     uint8_t windowInfoFilterOptionValue = static_cast<WindowInfoFilterOptionDataType>(WindowInfoFilterOption::ALL);
1226     if (!data.ReadUint8(windowInfoFilterOptionValue)) {
1227         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowInfoFilterOption");
1228         return ERR_INVALID_DATA;
1229     }
1230     windowInfoOption.windowInfoFilterOption = static_cast<WindowInfoFilterOption>(windowInfoFilterOptionValue);
1231     uint8_t windowInfoTypeOptionValue = static_cast<WindowInfoTypeOptionDataType>(WindowInfoTypeOption::ALL);
1232     if (!data.ReadUint8(windowInfoTypeOptionValue)) {
1233         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowInfoTypeOption");
1234         return ERR_INVALID_DATA;
1235     }
1236     windowInfoOption.windowInfoTypeOption = static_cast<WindowInfoTypeOption>(windowInfoTypeOptionValue);
1237     if (!data.ReadUint64(windowInfoOption.displayId)) {
1238         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read displayId");
1239         return ERR_INVALID_DATA;
1240     }
1241     if (!data.ReadInt32(windowInfoOption.windowId)) {
1242         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowId");
1243         return ERR_INVALID_DATA;
1244     }
1245     std::vector<sptr<WindowInfo>> infos;
1246     WMError errCode = ListWindowInfo(windowInfoOption, infos);
1247     if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowInfo>(reply, infos)) {
1248         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to write window info");
1249         return ERR_INVALID_DATA;
1250     }
1251     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1252         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write errCode fail");
1253         return ERR_INVALID_DATA;
1254     }
1255     return ERR_NONE;
1256 }
1257 
HandleGetAllWindowLayoutInfo(MessageParcel & data,MessageParcel & reply)1258 int SceneSessionManagerStub::HandleGetAllWindowLayoutInfo(MessageParcel& data, MessageParcel& reply)
1259 {
1260     uint64_t displayId = 0;
1261     if (!data.ReadUint64(displayId)) {
1262         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read displayId");
1263         return ERR_INVALID_DATA;
1264     }
1265     std::vector<sptr<WindowLayoutInfo>> infos;
1266     WMError errCode = GetAllWindowLayoutInfo(displayId, infos);
1267     if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowLayoutInfo>(reply, infos)) {
1268         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to write window layout info");
1269         return ERR_INVALID_DATA;
1270     }
1271     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1272         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write errCode fail");
1273         return ERR_INVALID_DATA;
1274     }
1275     return ERR_NONE;
1276 }
1277 
HandleGetVisibilityWindowInfo(MessageParcel & data,MessageParcel & reply)1278 int SceneSessionManagerStub::HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
1279 {
1280     std::vector<sptr<WindowVisibilityInfo>> infos;
1281     WMError errCode = GetVisibilityWindowInfo(infos);
1282     if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
1283         WLOGFE("Write visibility window infos failed");
1284         return ERR_INVALID_DATA;
1285     }
1286     reply.WriteInt32(static_cast<int32_t>(errCode));
1287     return ERR_NONE;
1288 }
1289 
HandleAddExtensionWindowStageToSCB(MessageParcel & data,MessageParcel & reply)1290 int SceneSessionManagerStub::HandleAddExtensionWindowStageToSCB(MessageParcel& data, MessageParcel& reply)
1291 {
1292     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1293     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
1294     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
1295     if (sessionStage == nullptr) {
1296         TLOGE(WmsLogTag::WMS_UIEXT, "sessionStage is nullptr");
1297         return ERR_INVALID_DATA;
1298     }
1299     sptr<IRemoteObject> token = data.ReadRemoteObject();
1300     uint64_t surfaceNodeId;
1301     if (!data.ReadUint64(surfaceNodeId)) {
1302         TLOGE(WmsLogTag::WMS_UIEXT, "read surfaceNodeId failed");
1303         return ERR_INVALID_DATA;
1304     }
1305     bool isConstrainedModal = false;
1306     if (!data.ReadBool(isConstrainedModal)) {
1307         TLOGE(WmsLogTag::WMS_UIEXT, "read isConstrainedModal failed");
1308         return ERR_INVALID_DATA;
1309     }
1310     AddExtensionWindowStageToSCB(sessionStage, token, surfaceNodeId, isConstrainedModal);
1311     return ERR_NONE;
1312 }
1313 
HandleRemoveExtensionWindowStageFromSCB(MessageParcel & data,MessageParcel & reply)1314 int SceneSessionManagerStub::HandleRemoveExtensionWindowStageFromSCB(MessageParcel& data, MessageParcel& reply)
1315 {
1316     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
1317     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
1318     if (sessionStage == nullptr) {
1319         WLOGFE("sessionStage is nullptr");
1320         return ERR_INVALID_DATA;
1321     }
1322     sptr<IRemoteObject> token = data.ReadRemoteObject();
1323     bool isConstrainedModal = false;
1324     if (!data.ReadBool(isConstrainedModal)) {
1325         TLOGE(WmsLogTag::WMS_UIEXT, "read isConstrainedModal failed");
1326         return ERR_INVALID_DATA;
1327     }
1328     RemoveExtensionWindowStageFromSCB(sessionStage, token, isConstrainedModal);
1329     return ERR_NONE;
1330 }
1331 
HandleUpdateModalExtensionRect(MessageParcel & data,MessageParcel & reply)1332 int SceneSessionManagerStub::HandleUpdateModalExtensionRect(MessageParcel& data, MessageParcel& reply)
1333 {
1334     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1335     sptr<IRemoteObject> token = data.ReadRemoteObject();
1336     if (token == nullptr) {
1337         TLOGE(WmsLogTag::WMS_UIEXT, "token is nullptr");
1338         return ERR_INVALID_DATA;
1339     }
1340     int32_t rectX;
1341     if (!data.ReadInt32(rectX)) {
1342         TLOGE(WmsLogTag::WMS_UIEXT, "read rectX failed");
1343         return ERR_INVALID_DATA;
1344     }
1345     int32_t rectY;
1346     if (!data.ReadInt32(rectY)) {
1347         TLOGE(WmsLogTag::WMS_UIEXT, "read rectY failed");
1348         return ERR_INVALID_DATA;
1349     }
1350     int32_t rectWidth;
1351     if (!data.ReadInt32(rectWidth)) {
1352         TLOGE(WmsLogTag::WMS_UIEXT, "read rectWidth failed");
1353         return ERR_INVALID_DATA;
1354     }
1355     int32_t rectHeight;
1356     if (!data.ReadInt32(rectHeight)) {
1357         TLOGE(WmsLogTag::WMS_UIEXT, "read rectHeight failed");
1358         return ERR_INVALID_DATA;
1359     }
1360     Rect windowRect{rectX, rectY, rectWidth, rectHeight};
1361     UpdateModalExtensionRect(token, windowRect);
1362     return ERR_NONE;
1363 }
1364 
HandleProcessModalExtensionPointDown(MessageParcel & data,MessageParcel & reply)1365 int SceneSessionManagerStub::HandleProcessModalExtensionPointDown(MessageParcel& data, MessageParcel& reply)
1366 {
1367     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1368     sptr<IRemoteObject> token = data.ReadRemoteObject();
1369     if (token == nullptr) {
1370         TLOGE(WmsLogTag::WMS_UIEXT, "token is nullptr");
1371         return ERR_INVALID_DATA;
1372     }
1373     int32_t posX;
1374     if (!data.ReadInt32(posX)) {
1375         TLOGE(WmsLogTag::WMS_UIEXT, "read posX failed");
1376         return ERR_INVALID_DATA;
1377     }
1378     int32_t posY;
1379     if (!data.ReadInt32(posY)) {
1380         TLOGE(WmsLogTag::WMS_UIEXT, "read posY failed");
1381         return ERR_INVALID_DATA;
1382     }
1383     ProcessModalExtensionPointDown(token, posX, posY);
1384     return ERR_NONE;
1385 }
1386 
HandleAddOrRemoveSecureSession(MessageParcel & data,MessageParcel & reply)1387 int SceneSessionManagerStub::HandleAddOrRemoveSecureSession(MessageParcel& data, MessageParcel& reply)
1388 {
1389     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1390     int32_t persistentId;
1391     if (!data.ReadInt32(persistentId)) {
1392         TLOGE(WmsLogTag::WMS_UIEXT, "read persistentId failed");
1393         return ERR_INVALID_DATA;
1394     }
1395     bool shouldHide;
1396     if (!data.ReadBool(shouldHide)) {
1397         TLOGE(WmsLogTag::WMS_UIEXT, "read shouldHide failed");
1398         return ERR_INVALID_DATA;
1399     }
1400     WSError ret = AddOrRemoveSecureSession(persistentId, shouldHide);
1401     reply.WriteInt32(static_cast<int32_t>(ret));
1402     return ERR_NONE;
1403 }
1404 
HandleUpdateExtWindowFlags(MessageParcel & data,MessageParcel & reply)1405 int SceneSessionManagerStub::HandleUpdateExtWindowFlags(MessageParcel& data, MessageParcel& reply)
1406 {
1407     TLOGD(WmsLogTag::WMS_UIEXT, "In!");
1408     sptr<IRemoteObject> token = data.ReadRemoteObject();
1409     if (token == nullptr) {
1410         TLOGE(WmsLogTag::WMS_UIEXT, "token is nullptr");
1411         return ERR_INVALID_DATA;
1412     }
1413     uint32_t extWindowFlags;
1414     if (!data.ReadUint32(extWindowFlags)) {
1415         TLOGE(WmsLogTag::WMS_UIEXT, "read extWindowFlags failed");
1416         return ERR_INVALID_DATA;
1417     }
1418     uint32_t extWindowActions;
1419     if (!data.ReadUint32(extWindowActions)) {
1420         TLOGE(WmsLogTag::WMS_UIEXT, "read extWindowActions failed");
1421         return ERR_INVALID_DATA;
1422     }
1423     WSError ret = UpdateExtWindowFlags(token, extWindowFlags, extWindowActions);
1424     reply.WriteInt32(static_cast<int32_t>(ret));
1425     return ERR_NONE;
1426 }
1427 
HandleGetHostWindowRect(MessageParcel & data,MessageParcel & reply)1428 int SceneSessionManagerStub::HandleGetHostWindowRect(MessageParcel& data, MessageParcel& reply)
1429 {
1430     TLOGD(WmsLogTag::WMS_UIEXT, "Handled!");
1431     int32_t hostWindowId = 0;
1432     if (!data.ReadInt32(hostWindowId)) {
1433         TLOGE(WmsLogTag::WMS_UIEXT, "read hostWindowId fail");
1434         return ERR_INVALID_DATA;
1435     }
1436     Rect rect;
1437     WSError ret = GetHostWindowRect(hostWindowId, rect);
1438     reply.WriteInt32(rect.posX_);
1439     reply.WriteInt32(rect.posY_);
1440     reply.WriteUint32(rect.width_);
1441     reply.WriteUint32(rect.height_);
1442     reply.WriteInt32(static_cast<int32_t>(ret));
1443     return ERR_NONE;
1444 }
1445 
HandleGetFreeMultiWindowEnableState(MessageParcel & data,MessageParcel & reply)1446 int SceneSessionManagerStub::HandleGetFreeMultiWindowEnableState(MessageParcel& data, MessageParcel& reply)
1447 {
1448     TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "run HandleGetFreeMultiWindowEnableState!");
1449     bool enable = false;
1450     WSError ret = GetFreeMultiWindowEnableState(enable);
1451     reply.WriteBool(enable);
1452     reply.WriteInt32(static_cast<int32_t>(ret));
1453     return ERR_NONE;
1454 }
1455 
HandleGetCallingWindowWindowStatus(MessageParcel & data,MessageParcel & reply)1456 int SceneSessionManagerStub::HandleGetCallingWindowWindowStatus(MessageParcel&data, MessageParcel&reply)
1457 {
1458     TLOGD(WmsLogTag::WMS_KEYBOARD, "In!");
1459     int32_t persistentId;
1460     if (!data.ReadInt32(persistentId)) {
1461         TLOGE(WmsLogTag::WMS_KEYBOARD, "read persistentId failed");
1462         return ERR_INVALID_DATA;
1463     }
1464     WindowStatus windowStatus = WindowStatus::WINDOW_STATUS_UNDEFINED;
1465     WMError ret = GetCallingWindowWindowStatus(persistentId, windowStatus);
1466     reply.WriteUint32(static_cast<int32_t>(ret));
1467     if (ret != WMError::WM_OK) {
1468         TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowWindowStatus(%{public}d)", persistentId);
1469         return ERR_INVALID_DATA;
1470     }
1471     reply.WriteUint32(static_cast<uint32_t>(windowStatus));
1472     return ERR_NONE;
1473 }
1474 
HandleGetCallingWindowRect(MessageParcel & data,MessageParcel & reply)1475 int SceneSessionManagerStub::HandleGetCallingWindowRect(MessageParcel&data, MessageParcel& reply)
1476 {
1477     TLOGD(WmsLogTag::WMS_KEYBOARD, "In!");
1478     int32_t persistentId;
1479     if (!data.ReadInt32(persistentId)) {
1480         TLOGE(WmsLogTag::WMS_KEYBOARD, "read persistentId failed");
1481         return ERR_INVALID_DATA;
1482     }
1483     Rect rect = {0, 0, 0, 0};
1484     WMError ret = GetCallingWindowRect(persistentId, rect);
1485     reply.WriteInt32(static_cast<int32_t>(ret));
1486     if (ret != WMError::WM_OK) {
1487         TLOGE(WmsLogTag::WMS_KEYBOARD, "Failed to GetCallingWindowRect(%{public}d)", persistentId);
1488         return ERR_INVALID_DATA;
1489     }
1490     reply.WriteInt32(rect.posX_);
1491     reply.WriteInt32(rect.posY_);
1492     reply.WriteUint32(rect.width_);
1493     reply.WriteUint32(rect.height_);
1494     return ERR_NONE;
1495 }
1496 
HandleGetWindowModeType(MessageParcel & data,MessageParcel & reply)1497 int SceneSessionManagerStub::HandleGetWindowModeType(MessageParcel& data, MessageParcel& reply)
1498 {
1499     WindowModeType windowModeType = Rosen::WindowModeType::WINDOW_MODE_OTHER;
1500     WMError errCode = GetWindowModeType(windowModeType);
1501     WLOGFI("run HandleGetWindowModeType, windowModeType:%{public}d!", static_cast<int32_t>(windowModeType));
1502     if (!reply.WriteUint32(static_cast<int32_t>(windowModeType))) {
1503         WLOGE("Failed to WriteBool");
1504         return ERR_INVALID_DATA;
1505     }
1506     reply.WriteInt32(static_cast<int32_t>(errCode));
1507     return ERR_NONE;
1508 }
1509 
HandleGetWindowStyleType(MessageParcel & data,MessageParcel & reply)1510 int SceneSessionManagerStub::HandleGetWindowStyleType(MessageParcel& data, MessageParcel& reply)
1511 {
1512     WindowStyleType windowStyleType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
1513     WMError errCode = GetWindowStyleType(windowStyleType);
1514     TLOGI(WmsLogTag::WMS_LIFE, "windowStyleType:%{public}d!", static_cast<int32_t>(windowStyleType));
1515     if (!reply.WriteUint32(static_cast<int32_t>(windowStyleType))) {
1516         TLOGE(WmsLogTag::WMS_LIFE, "Failed to WriteBool");
1517         return ERR_INVALID_DATA;
1518     }
1519     reply.WriteInt32(static_cast<int32_t>(errCode));
1520     return ERR_NONE;
1521 }
1522 
HandleGetProcessSurfaceNodeIdByPersistentId(MessageParcel & data,MessageParcel & reply)1523 int SceneSessionManagerStub::HandleGetProcessSurfaceNodeIdByPersistentId(MessageParcel& data, MessageParcel& reply)
1524 {
1525     TLOGD(WmsLogTag::WMS_ATTRIBUTE, "Handled!");
1526     int32_t pid = 0;
1527     if (!data.ReadInt32(pid)) {
1528         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readInt32 pid");
1529         return ERR_INVALID_DATA;
1530     }
1531     std::vector<int32_t> persistentIds;
1532     if (!data.ReadInt32Vector(&persistentIds)) {
1533         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readInt32Vector persistentIds");
1534         return ERR_INVALID_DATA;
1535     }
1536     std::vector<uint64_t> surfaceNodeIds;
1537     WMError errCode = GetProcessSurfaceNodeIdByPersistentId(pid, persistentIds, surfaceNodeIds);
1538     if (!reply.WriteUInt64Vector(surfaceNodeIds)) {
1539         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write surfaceNodeIds fail.");
1540         return ERR_INVALID_DATA;
1541     }
1542     reply.WriteInt32(static_cast<int32_t>(errCode));
1543     return ERR_NONE;
1544 }
1545 
HandleSkipSnapshotForAppProcess(MessageParcel & data,MessageParcel & reply)1546 int SceneSessionManagerStub::HandleSkipSnapshotForAppProcess(MessageParcel& data, MessageParcel& reply)
1547 {
1548     int32_t pid = INVALID_PID;
1549     if (!data.ReadInt32(pid)) {
1550         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readInt32 pid");
1551         return ERR_INVALID_DATA;
1552     }
1553     bool skip = false;
1554     if (!data.ReadBool(skip)) {
1555         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readBool skip");
1556         return ERR_INVALID_DATA;
1557     }
1558     WMError errCode = SkipSnapshotForAppProcess(pid, skip);
1559     reply.WriteInt32(static_cast<int32_t>(errCode));
1560     return ERR_NONE;
1561 }
1562 
HandleSkipSnapshotByUserIdAndBundleNames(MessageParcel & data,MessageParcel & reply)1563 int SceneSessionManagerStub::HandleSkipSnapshotByUserIdAndBundleNames(MessageParcel& data, MessageParcel& reply)
1564 {
1565     int32_t userId = -1;
1566     if (!data.ReadInt32(userId)) {
1567         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readInt32 userId");
1568         return ERR_INVALID_DATA;
1569     }
1570     std::vector<std::string> bundleNameList;
1571     if (!data.ReadStringVector(&bundleNameList)) {
1572         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Fail to read bundleNameList");
1573         return ERR_INVALID_DATA;
1574     }
1575     WMError errCode = SkipSnapshotByUserIdAndBundleNames(userId, bundleNameList);
1576     reply.WriteInt32(static_cast<int32_t>(errCode));
1577     return ERR_NONE;
1578 }
1579 
HandleSetProcessWatermark(MessageParcel & data,MessageParcel & reply)1580 int SceneSessionManagerStub::HandleSetProcessWatermark(MessageParcel& data, MessageParcel& reply)
1581 {
1582     int32_t pid = INVALID_PID;
1583     if (!data.ReadInt32(pid)) {
1584         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readInt32 pid");
1585         return ERR_INVALID_DATA;
1586     }
1587     std::string watermarkName;
1588     if (!data.ReadString(watermarkName)) {
1589         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readString watermarkName");
1590         return ERR_INVALID_DATA;
1591     }
1592     bool isEnabled = false;
1593     if (!data.ReadBool(isEnabled)) {
1594         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to readBool isEnabled");
1595         return ERR_INVALID_DATA;
1596     }
1597     WMError errCode = SetProcessWatermark(pid, watermarkName, isEnabled);
1598     reply.WriteInt32(static_cast<int32_t>(errCode));
1599     return ERR_NONE;
1600 }
1601 
HandleGetWindowIdsByCoordinate(MessageParcel & data,MessageParcel & reply)1602 int SceneSessionManagerStub::HandleGetWindowIdsByCoordinate(MessageParcel& data, MessageParcel& reply)
1603 {
1604     uint64_t displayId;
1605     if (!data.ReadUint64(displayId)) {
1606         TLOGE(WmsLogTag::DEFAULT, "read displayId failed");
1607         return ERR_INVALID_DATA;
1608     }
1609     int32_t windowNumber;
1610     if (!data.ReadInt32(windowNumber)) {
1611         TLOGE(WmsLogTag::DEFAULT, "read windowNumber failed");
1612         return ERR_INVALID_DATA;
1613     }
1614     int32_t x;
1615     int32_t y;
1616     if (!data.ReadInt32(x) || !data.ReadInt32(y)) {
1617         TLOGE(WmsLogTag::DEFAULT, "read coordinate failed");
1618         return ERR_INVALID_DATA;
1619     }
1620     std::vector<int32_t> windowIds;
1621     WMError errCode = GetWindowIdsByCoordinate(displayId, windowNumber, x, y, windowIds);
1622     reply.WriteInt32(static_cast<int32_t>(errCode));
1623     if (errCode != WMError::WM_OK) {
1624         TLOGE(WmsLogTag::DEFAULT, "failed.");
1625         return ERR_INVALID_DATA;
1626     }
1627     reply.WriteInt32Vector(windowIds);
1628     return ERR_NONE;
1629 }
1630 
HandleUpdateSessionScreenLock(MessageParcel & data,MessageParcel & reply)1631 int SceneSessionManagerStub::HandleUpdateSessionScreenLock(MessageParcel& data, MessageParcel& reply)
1632 {
1633     std::string bundleName;
1634     if (!data.ReadString(bundleName)) {
1635         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read bundleName failed.");
1636         return ERR_INVALID_DATA;
1637     }
1638     bool isRelease = false;
1639     if (!data.ReadBool(isRelease)) {
1640         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read isRelease failed.");
1641         return ERR_INVALID_DATA;
1642     }
1643     WMError errCode = UpdateScreenLockStatusForApp(bundleName, isRelease);
1644     reply.WriteInt32(static_cast<int32_t>(errCode));
1645     return ERR_NONE;
1646 }
1647 
HandleAddSkipSelfWhenShowOnVirtualScreenList(MessageParcel & data,MessageParcel & reply)1648 int SceneSessionManagerStub::HandleAddSkipSelfWhenShowOnVirtualScreenList(MessageParcel& data, MessageParcel& reply)
1649 {
1650     uint64_t size = 0;
1651     if (!data.ReadUint64(size)) {
1652         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read size failed.");
1653         return ERR_INVALID_DATA;
1654     }
1655     std::vector<int32_t> persistentIds;
1656     for (uint64_t i = 0; i < size; i++) {
1657         int32_t persistentId = 0;
1658         if (!data.ReadInt32(persistentId)) {
1659             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read persistentId failed.");
1660             return ERR_INVALID_DATA;
1661         }
1662         persistentIds.push_back(persistentId);
1663     }
1664     WMError errCode = AddSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1665     reply.WriteInt32(static_cast<int32_t>(errCode));
1666     return ERR_NONE;
1667 }
1668 
HandleRemoveSkipSelfWhenShowOnVirtualScreenList(MessageParcel & data,MessageParcel & reply)1669 int SceneSessionManagerStub::HandleRemoveSkipSelfWhenShowOnVirtualScreenList(MessageParcel& data, MessageParcel& reply)
1670 {
1671     uint64_t size = 0;
1672     if (!data.ReadUint64(size)) {
1673         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read size failed.");
1674         return ERR_INVALID_DATA;
1675     }
1676     std::vector<int32_t> persistentIds;
1677     for (uint64_t i = 0; i < size; i++) {
1678         int32_t persistentId = 0;
1679         if (!data.ReadInt32(persistentId)) {
1680             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read persistentId failed.");
1681             return ERR_INVALID_DATA;
1682         }
1683         persistentIds.push_back(persistentId);
1684     }
1685     WMError errCode = RemoveSkipSelfWhenShowOnVirtualScreenList(persistentIds);
1686     reply.WriteInt32(static_cast<int32_t>(errCode));
1687     return ERR_NONE;
1688 }
1689 
HandleIsPcWindow(MessageParcel & data,MessageParcel & reply)1690 int SceneSessionManagerStub::HandleIsPcWindow(MessageParcel& data, MessageParcel& reply)
1691 {
1692     bool isPcWindow = false;
1693     WMError errCode = IsPcWindow(isPcWindow);
1694     if (!reply.WriteBool(isPcWindow)) {
1695         TLOGE(WmsLogTag::WMS_UIEXT, "Write isPcWindow fail.");
1696         return ERR_INVALID_DATA;
1697     }
1698     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1699         TLOGE(WmsLogTag::WMS_UIEXT, "Write errCode fail.");
1700         return ERR_INVALID_DATA;
1701     }
1702     return ERR_NONE;
1703 }
1704 
HandleIsPcOrPadFreeMultiWindowMode(MessageParcel & data,MessageParcel & reply)1705 int SceneSessionManagerStub::HandleIsPcOrPadFreeMultiWindowMode(MessageParcel& data, MessageParcel& reply)
1706 {
1707     bool isPcOrPadFreeMultiWindowMode = false;
1708     WMError errCode = IsPcOrPadFreeMultiWindowMode(isPcOrPadFreeMultiWindowMode);
1709     if (!reply.WriteBool(isPcOrPadFreeMultiWindowMode)) {
1710         TLOGE(WmsLogTag::WMS_SUB, "Write isPcOrPadFreeMultiWindowMode fail.");
1711         return ERR_INVALID_DATA;
1712     }
1713     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1714         TLOGE(WmsLogTag::WMS_SUB, "Write errCode fail.");
1715         return ERR_INVALID_DATA;
1716     }
1717     return ERR_NONE;
1718 }
1719 
HandleGetDisplayIdByWindowId(MessageParcel & data,MessageParcel & reply)1720 int SceneSessionManagerStub::HandleGetDisplayIdByWindowId(MessageParcel& data, MessageParcel& reply)
1721 {
1722     std::vector<uint64_t> windowIds;
1723     if (!data.ReadUInt64Vector(&windowIds)) {
1724         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read windowIds Failed");
1725         return ERR_INVALID_DATA;
1726     }
1727     std::unordered_map<uint64_t, DisplayId> windowDisplayIdMap;
1728     WMError errCode = GetDisplayIdByWindowId(windowIds, windowDisplayIdMap);
1729     if (!reply.WriteInt32(static_cast<int32_t>(windowDisplayIdMap.size()))) {
1730         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write windowDisplayIdMap size faild");
1731         return ERR_INVALID_DATA;
1732     }
1733     for (auto it = windowDisplayIdMap.begin(); it != windowDisplayIdMap.end(); ++it) {
1734         if (!reply.WriteUint64(it->first)) {
1735             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write windowId failed");
1736             return ERR_INVALID_DATA;
1737         }
1738         if (!reply.WriteUint64(it->second)) {
1739             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write displayId failed");
1740             return ERR_INVALID_DATA;
1741         }
1742     }
1743     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1744         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write errCode fail.");
1745         return ERR_INVALID_DATA;
1746     }
1747     return ERR_NONE;
1748 }
1749 
HandleIsWindowRectAutoSave(MessageParcel & data,MessageParcel & reply)1750 int SceneSessionManagerStub::HandleIsWindowRectAutoSave(MessageParcel& data, MessageParcel& reply)
1751 {
1752     std::string key;
1753     if (!data.ReadString(key)) {
1754         TLOGE(WmsLogTag::WMS_MAIN, "Read key failed.");
1755         return ERR_INVALID_DATA;
1756     }
1757     int persistentId = 0;
1758     if (!data.ReadInt32(persistentId)) {
1759         TLOGE(WmsLogTag::WMS_MAIN, "Read persistentId failed.");
1760         return ERR_INVALID_DATA;
1761     }
1762     bool enabled = false;
1763     WMError errCode = IsWindowRectAutoSave(key, enabled, persistentId);
1764     if (!reply.WriteBool(enabled)) {
1765         TLOGE(WmsLogTag::WMS_MAIN, "Write enabled failed.");
1766         return ERR_INVALID_DATA;
1767     }
1768     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1769         TLOGE(WmsLogTag::WMS_MAIN, "Write errCode failed.");
1770         return ERR_INVALID_DATA;
1771     }
1772     return ERR_NONE;
1773 }
1774 
HandleSetGlobalDragResizeType(MessageParcel & data,MessageParcel & reply)1775 int SceneSessionManagerStub::HandleSetGlobalDragResizeType(MessageParcel& data, MessageParcel& reply)
1776 {
1777     uint32_t dragResizeType;
1778     if (!data.ReadUint32(dragResizeType)) {
1779         TLOGE(WmsLogTag::WMS_LAYOUT, "Read dragResizeType failed.");
1780         return ERR_INVALID_DATA;
1781     }
1782     if (dragResizeType > static_cast<uint32_t>(DragResizeType::RESIZE_WHEN_DRAG_END)) {
1783         TLOGE(WmsLogTag::WMS_LAYOUT, "bad dragResizeType value");
1784         return ERR_INVALID_DATA;
1785     }
1786     WMError errCode = SetGlobalDragResizeType(static_cast<DragResizeType>(dragResizeType));
1787     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1788         TLOGE(WmsLogTag::WMS_LAYOUT, "Write errCode failed.");
1789         return ERR_INVALID_DATA;
1790     }
1791     return ERR_NONE;
1792 }
1793 
HandleGetGlobalDragResizeType(MessageParcel & data,MessageParcel & reply)1794 int SceneSessionManagerStub::HandleGetGlobalDragResizeType(MessageParcel& data, MessageParcel& reply)
1795 {
1796     DragResizeType dragResizeType = DragResizeType::RESIZE_TYPE_UNDEFINED;
1797     WMError errCode = GetGlobalDragResizeType(dragResizeType);
1798     if (!reply.WriteUint32(static_cast<uint32_t>(dragResizeType))) {
1799         TLOGE(WmsLogTag::WMS_LAYOUT, "Write dragResizeType failed.");
1800         return ERR_INVALID_DATA;
1801     }
1802     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1803         TLOGE(WmsLogTag::WMS_LAYOUT, "Write errCode failed.");
1804         return ERR_INVALID_DATA;
1805     }
1806     return ERR_NONE;
1807 }
1808 
HandleSetAppDragResizeType(MessageParcel & data,MessageParcel & reply)1809 int SceneSessionManagerStub::HandleSetAppDragResizeType(MessageParcel& data, MessageParcel& reply)
1810 {
1811     std::string bundleName;
1812     if (!data.ReadString(bundleName)) {
1813         TLOGE(WmsLogTag::WMS_LAYOUT, "Read bundleName failed.");
1814         return ERR_INVALID_DATA;
1815     }
1816     uint32_t dragResizeType;
1817     if (!data.ReadUint32(dragResizeType)) {
1818         TLOGE(WmsLogTag::WMS_LAYOUT, "Read dragResizeType failed.");
1819         return ERR_INVALID_DATA;
1820     }
1821     if (dragResizeType > static_cast<uint32_t>(DragResizeType::RESIZE_WHEN_DRAG_END)) {
1822         TLOGE(WmsLogTag::WMS_LAYOUT, "bad dragResizeType value");
1823         return ERR_INVALID_DATA;
1824     }
1825     WMError errCode = SetAppDragResizeType(bundleName, static_cast<DragResizeType>(dragResizeType));
1826     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1827         TLOGE(WmsLogTag::WMS_LAYOUT, "Write errCode failed.");
1828         return ERR_INVALID_DATA;
1829     }
1830     return ERR_NONE;
1831 }
1832 
HandleGetAppDragResizeType(MessageParcel & data,MessageParcel & reply)1833 int SceneSessionManagerStub::HandleGetAppDragResizeType(MessageParcel& data, MessageParcel& reply)
1834 {
1835     std::string bundleName;
1836     if (!data.ReadString(bundleName)) {
1837         TLOGE(WmsLogTag::WMS_LAYOUT, "Read bundleName failed.");
1838         return ERR_INVALID_DATA;
1839     }
1840     DragResizeType dragResizeType = DragResizeType::RESIZE_TYPE_UNDEFINED;
1841     WMError errCode = GetAppDragResizeType(bundleName, dragResizeType);
1842     if (!reply.WriteUint32(static_cast<uint32_t>(dragResizeType))) {
1843         TLOGE(WmsLogTag::WMS_LAYOUT, "Write dragResizeType failed.");
1844         return ERR_INVALID_DATA;
1845     }
1846     if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1847         TLOGE(WmsLogTag::WMS_LAYOUT, "Write errCode failed.");
1848         return ERR_INVALID_DATA;
1849     }
1850     return ERR_NONE;
1851 }
1852 
HandleShiftAppWindowPointerEvent(MessageParcel & data,MessageParcel & reply)1853 int SceneSessionManagerStub::HandleShiftAppWindowPointerEvent(MessageParcel& data, MessageParcel& reply)
1854 {
1855     int32_t sourcePersistentId = INVALID_WINDOW_ID;
1856     if (!data.ReadInt32(sourcePersistentId)) {
1857         TLOGE(WmsLogTag::WMS_PC, "read sourcePersistentId failed");
1858         return ERR_INVALID_DATA;
1859     }
1860     int32_t targetPersistentId = INVALID_WINDOW_ID;
1861     if (!data.ReadInt32(targetPersistentId)) {
1862         TLOGE(WmsLogTag::WMS_PC, "read targetPersistentId failed");
1863         return ERR_INVALID_DATA;
1864     }
1865     WMError errCode = ShiftAppWindowPointerEvent(sourcePersistentId, targetPersistentId);
1866     reply.WriteInt32(static_cast<int32_t>(errCode));
1867     return ERR_NONE;
1868 }
1869 
HandleMinimizeByWindowId(MessageParcel & data,MessageParcel & reply)1870 int SceneSessionManagerStub::HandleMinimizeByWindowId(MessageParcel& data, MessageParcel& reply)
1871 {
1872     std::vector<int32_t> windowIds;
1873     if (!data.ReadInt32Vector(&windowIds)) {
1874         TLOGE(WmsLogTag::WMS_LIFE, "read windowIds failed");
1875         return ERR_INVALID_DATA;
1876     }
1877     WMError errCode = MinimizeByWindowId(windowIds);
1878     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1879         TLOGE(WmsLogTag::WMS_LIFE, "Write errCode failed.");
1880         return ERR_INVALID_DATA;
1881     }
1882     return ERR_NONE;
1883 }
1884 } // namespace OHOS::Rosen