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 <ipc_types.h>
19 #include <ui/rs_surface_node.h>
20 #include "marshalling_helper.h"
21 #include "session/host/include/scene_session.h"
22 #include "window_manager.h"
23 #include "window_manager_agent_proxy.h"
24 #include "window_manager_hilog.h"
25
26 namespace OHOS::Rosen {
27 namespace {
28 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSessionManagerStub"};
29 constexpr uint32_t MAX_VECTOR_SIZE = 100;
30 }
31
32 const std::map<uint32_t, SceneSessionManagerStubFunc> SceneSessionManagerStub::stubFuncMap_{
33 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION),
34 &SceneSessionManagerStub::HandleCreateAndConnectSpecificSession),
35 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_CONNECT_SPECIFIC_SESSION),
36 &SceneSessionManagerStub::HandleRecoverAndConnectSpecificSession),
37 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RECOVER_AND_RECONNECT_SCENE_SESSION),
38 &SceneSessionManagerStub::HandleRecoverAndReconnectSceneSession),
39 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION),
40 &SceneSessionManagerStub::HandleDestroyAndDisconnectSpcificSession),
41 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_PROPERTY),
42 &SceneSessionManagerStub::HandleUpdateProperty),
43 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REQUEST_FOCUS),
44 &SceneSessionManagerStub::HandleRequestFocusStatus),
45 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
46 &SceneSessionManagerStub::HandleRegisterWindowManagerAgent),
47 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
48 &SceneSessionManagerStub::HandleUnregisterWindowManagerAgent),
49 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_INFO),
50 &SceneSessionManagerStub::HandleGetFocusSessionInfo),
51 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_LABEL),
52 &SceneSessionManagerStub::HandleSetSessionLabel),
53 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_ICON),
54 &SceneSessionManagerStub::HandleSetSessionIcon),
55 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_IS_VALID_SESSION_IDS),
56 &SceneSessionManagerStub::HandleIsValidSessionIds),
57 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_CHANGE_LISTENER),
58 &SceneSessionManagerStub::HandleRegisterSessionChangeListener),
59 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_CHANGE_LISTENER),
60 &SceneSessionManagerStub::HandleUnRegisterSessionChangeListener),
61 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_FOREGROUND),
62 &SceneSessionManagerStub::HandlePendingSessionToForeground),
63 std::make_pair(static_cast<uint32_t>(
64 SceneSessionManagerMessage::TRANS_ID_PENDING_SESSION_TO_BACKGROUND_FOR_DELEGATOR),
65 &SceneSessionManagerStub::HandlePendingSessionToBackgroundForDelegator),
66 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_FOCUS_SESSION_TOKEN),
67 &SceneSessionManagerStub::HandleGetFocusSessionToken),
68 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CHECK_WINDOW_ID),
69 &SceneSessionManagerStub::HandleCheckWindowId),
70 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_GESTURE_NAVIGATION_ENABLED),
71 &SceneSessionManagerStub::HandleSetGestureNavigationEnabled),
72 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_INFO),
73 &SceneSessionManagerStub::HandleGetAccessibilityWindowInfo),
74
75 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_LISTENER),
76 &SceneSessionManagerStub::HandleRegisterSessionListener),
77 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_SESSION_LISTENER),
78 &SceneSessionManagerStub::HandleUnRegisterSessionListener),
79 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFOS),
80 &SceneSessionManagerStub::HandleGetSessionInfos),
81 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_MISSION_INFO_BY_ID),
82 &SceneSessionManagerStub::HandleGetSessionInfo),
83
84 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_ALL),
85 &SceneSessionManagerStub::HandleDumpSessionAll),
86 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_DUMP_SESSION_WITH_ID),
87 &SceneSessionManagerStub::HandleDumpSessionWithId),
88 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_TERMINATE_SESSION_NEW),
89 &SceneSessionManagerStub::HandleTerminateSessionNew),
90 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_AVOIDAREA_LISTENER),
91 &SceneSessionManagerStub::HandleUpdateSessionAvoidAreaListener),
92 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_DUMP_INFO),
93 &SceneSessionManagerStub::HandleGetSessionDump),
94 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_SESSION_SNAPSHOT),
95 &SceneSessionManagerStub::HandleGetSessionSnapshot),
96 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_BIND_DIALOG_TARGET),
97 &SceneSessionManagerStub::HandleBindDialogTarget),
98 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_NOTIFY_DUMP_INFO_RESULT),
99 &SceneSessionManagerStub::HandleNotifyDumpInfoResult),
100 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_CONTINUE_STATE),
101 &SceneSessionManagerStub::HandleSetSessionContinueState),
102 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SET_SESSION_GRAVITY),
103 &SceneSessionManagerStub::HandleSetSessionGravity),
104 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_SESSION),
105 &SceneSessionManagerStub::HandleClearSession),
106 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_CLEAR_ALL_SESSIONS),
107 &SceneSessionManagerStub::HandleClearAllSessions),
108 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_LOCK_SESSION),
109 &SceneSessionManagerStub::HandleLockSession),
110 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNLOCK_SESSION),
111 &SceneSessionManagerStub::HandleUnlockSession),
112 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_FOREGROUND),
113 &SceneSessionManagerStub::HandleMoveSessionsToForeground),
114 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_MOVE_MISSIONS_TO_BACKGROUND),
115 &SceneSessionManagerStub::HandleMoveSessionsToBackground),
116 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_REGISTER_COLLABORATOR),
117 &SceneSessionManagerStub::HandleRegisterCollaborator),
118 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UNREGISTER_COLLABORATOR),
119 &SceneSessionManagerStub::HandleUnregisterCollaborator),
120 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_TOUCHOUTSIDE_LISTENER),
121 &SceneSessionManagerStub::HandleUpdateSessionTouchOutsideListener),
122 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_RAISE_WINDOW_TO_TOP),
123 &SceneSessionManagerStub::HandleRaiseWindowToTop),
124 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_TOP_WINDOW_ID),
125 &SceneSessionManagerStub::HandleGetTopWindowId),
126 std::make_pair(static_cast<uint32_t>(
127 SceneSessionManagerMessage::TRANS_ID_NOTIFY_WINDOW_EXTENSION_VISIBILITY_CHANGE),
128 &SceneSessionManagerStub::HandleNotifyWindowExtensionVisibilityChange),
129 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_UPDATE_WINDOW_VISIBILITY_LISTENER),
130 &SceneSessionManagerStub::HandleUpdateSessionWindowVisibilityListener),
131 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_SHIFT_APP_WINDOW_FOCUS),
132 &SceneSessionManagerStub::HandleShiftAppWindowFocus),
133 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID),
134 &SceneSessionManagerStub::HandleGetVisibilityWindowInfo),
135 std::make_pair(static_cast<uint32_t>(SceneSessionManagerMessage::TRANS_ID_HIDE_NON_SECURE_WINDOWS),
136 &SceneSessionManagerStub::HandleHideNonSecureWindows),
137 };
138
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)139 int SceneSessionManagerStub::OnRemoteRequest(uint32_t code,
140 MessageParcel &data, MessageParcel &reply, MessageOption &option)
141 {
142 WLOGFD("Scene session on remote request!, code: %{public}u", code);
143 if (data.ReadInterfaceToken() != GetDescriptor()) {
144 WLOGFE("Failed to check interface token!");
145 return ERR_INVALID_STATE;
146 }
147
148 const auto& func = stubFuncMap_.find(code);
149 if (func == stubFuncMap_.end()) {
150 WLOGFE("Failed to find function handler!");
151 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
152 }
153
154 return (this->*(func->second))(data, reply);
155 }
156
HandleCreateAndConnectSpecificSession(MessageParcel & data,MessageParcel & reply)157 int SceneSessionManagerStub::HandleCreateAndConnectSpecificSession(MessageParcel &data, MessageParcel &reply)
158 {
159 WLOGFI("run HandleCreateAndConnectSpecificSession!");
160 sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
161 sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
162 sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
163 sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
164 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
165 if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
166 WLOGFE("Failed to read scene session stage object or event channel object!");
167 return ERR_INVALID_DATA;
168 }
169
170 sptr<WindowSessionProperty> property = nullptr;
171 if (data.ReadBool()) {
172 property = data.ReadStrongParcelable<WindowSessionProperty>();
173 } else {
174 WLOGFW("Property not exist!");
175 }
176
177 sptr<IRemoteObject> token = nullptr;
178 if (property && property->GetTokenState()) {
179 token = data.ReadRemoteObject();
180 } else {
181 WLOGI("accept token is nullptr");
182 }
183
184 auto persistentId = INVALID_SESSION_ID;
185 sptr<ISession> sceneSession;
186 CreateAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode,
187 property, persistentId, sceneSession, token);
188 if (sceneSession== nullptr) {
189 return ERR_INVALID_STATE;
190 }
191 reply.WriteInt32(persistentId);
192 reply.WriteRemoteObject(sceneSession->AsObject());
193 reply.WriteUint32(static_cast<uint32_t>(WSError::WS_OK));
194 return ERR_NONE;
195 }
196
HandleRecoverAndConnectSpecificSession(MessageParcel & data,MessageParcel & reply)197 int SceneSessionManagerStub::HandleRecoverAndConnectSpecificSession(MessageParcel &data, MessageParcel &reply)
198 {
199 WLOGFI("[WMSRecover] run HandleCreateAndConnectSpecificSession!");
200 sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
201 sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
202 sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
203 sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
204 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
205 if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
206 WLOGFE("[WMSRecover] Failed to read scene session stage object or event channel object!");
207 return ERR_INVALID_DATA;
208 }
209
210 sptr<WindowSessionProperty> property = nullptr;
211 if (data.ReadBool()) {
212 property = data.ReadStrongParcelable<WindowSessionProperty>();
213 } else {
214 WLOGFW("Property not exist!");
215 }
216
217 sptr<IRemoteObject> token = nullptr;
218 if (property && property->GetTokenState()) {
219 token = data.ReadRemoteObject();
220 } else {
221 WLOGI("accept token is nullptr");
222 }
223
224 sptr<ISession> sceneSession;
225 auto ret = RecoverAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode, property, sceneSession, token);
226 if (sceneSession== nullptr) {
227 return ERR_INVALID_STATE;
228 }
229 reply.WriteRemoteObject(sceneSession->AsObject());
230 reply.WriteUint32(static_cast<uint32_t>(ret));
231 return ERR_NONE;
232 }
233
HandleRecoverAndReconnectSceneSession(MessageParcel & data,MessageParcel & reply)234 int SceneSessionManagerStub::HandleRecoverAndReconnectSceneSession(MessageParcel& data, MessageParcel& reply)
235 {
236 WLOGFI("run HandleRecoverAndReconnectSceneSession!");
237 sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
238 sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
239 sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
240 sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
241 std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
242 if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
243 WLOGFE("Failed to read scene session stage object or event channel object!");
244 return ERR_INVALID_DATA;
245 }
246
247 sptr<WindowSessionProperty> property = nullptr;
248 if (data.ReadBool()) {
249 property = data.ReadStrongParcelable<WindowSessionProperty>();
250 } else {
251 WLOGFW("Property not exist!");
252 }
253
254 sptr<IRemoteObject> token = nullptr;
255 if (property && property->GetTokenState()) {
256 token = data.ReadRemoteObject();
257 } else {
258 WLOGI("accept token is nullptr");
259 }
260
261 sptr<ISession> sceneSession;
262 RecoverAndReconnectSceneSession(sessionStage, eventChannel, surfaceNode, sceneSession, property, token);
263 if (sceneSession == nullptr) {
264 return ERR_INVALID_STATE;
265 }
266 reply.WriteRemoteObject(sceneSession->AsObject());
267 reply.WriteUint32(static_cast<uint32_t>(WSError::WS_OK));
268 return ERR_NONE;
269 }
270
HandleDestroyAndDisconnectSpcificSession(MessageParcel & data,MessageParcel & reply)271 int SceneSessionManagerStub::HandleDestroyAndDisconnectSpcificSession(MessageParcel &data, MessageParcel &reply)
272 {
273 WLOGFI("run HandleDestroyAndDisconnectSpcificSession!");
274 auto persistentId = data.ReadInt32();
275 const WSError& ret = DestroyAndDisconnectSpecificSession(persistentId);
276 reply.WriteUint32(static_cast<uint32_t>(ret));
277 return ERR_NONE;
278 }
279
HandleUpdateProperty(MessageParcel & data,MessageParcel & reply)280 int SceneSessionManagerStub::HandleUpdateProperty(MessageParcel &data, MessageParcel &reply)
281 {
282 WLOGFD("run HandleUpdateProperty!");
283 auto action = static_cast<WSPropertyChangeAction>(data.ReadUint32());
284 sptr<WindowSessionProperty> property = nullptr;
285 if (data.ReadBool()) {
286 property = data.ReadStrongParcelable<WindowSessionProperty>();
287 } else {
288 WLOGFW("Property not exist!");
289 }
290 const WMError& ret = UpdateSessionProperty(property, action);
291 reply.WriteInt32(static_cast<int32_t>(ret));
292 return ERR_NONE;
293 }
294
HandleRequestFocusStatus(MessageParcel & data,MessageParcel & reply)295 int SceneSessionManagerStub::HandleRequestFocusStatus(MessageParcel &data, MessageParcel &reply)
296 {
297 WLOGFI("run HandleRequestFocusStatus!");
298 int32_t persistentId = data.ReadInt32();
299 bool isFocused = data.ReadBool();
300 const WMError& ret = RequestFocusStatus(persistentId, isFocused, false);
301 reply.WriteInt32(static_cast<int32_t>(ret));
302 return ERR_NONE;
303 }
304
HandleRegisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)305 int SceneSessionManagerStub::HandleRegisterWindowManagerAgent(MessageParcel &data, MessageParcel &reply)
306 {
307 WLOGFI("run HandleRegisterWindowManagerAgent!");
308 auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
309 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
310 sptr<IWindowManagerAgent> windowManagerAgentProxy =
311 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
312 WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy);
313 reply.WriteInt32(static_cast<int32_t>(errCode));
314 return ERR_NONE;
315 }
316
HandleUnregisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)317 int SceneSessionManagerStub::HandleUnregisterWindowManagerAgent(MessageParcel &data, MessageParcel &reply)
318 {
319 WLOGFI("run HandleUnregisterWindowManagerAgent!");
320 auto type = static_cast<WindowManagerAgentType>(data.ReadUint32());
321 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
322 sptr<IWindowManagerAgent> windowManagerAgentProxy =
323 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
324 WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
325 reply.WriteInt32(static_cast<int32_t>(errCode));
326 return ERR_NONE;
327 }
328
HandleGetFocusSessionInfo(MessageParcel & data,MessageParcel & reply)329 int SceneSessionManagerStub::HandleGetFocusSessionInfo(MessageParcel &data, MessageParcel &reply)
330 {
331 WLOGFI("run HandleGetFocusSessionInfo!");
332 FocusChangeInfo focusInfo;
333 GetFocusWindowInfo(focusInfo);
334 reply.WriteParcelable(&focusInfo);
335 return ERR_NONE;
336 }
337
HandleSetSessionLabel(MessageParcel & data,MessageParcel & reply)338 int SceneSessionManagerStub::HandleSetSessionLabel(MessageParcel &data, MessageParcel &reply)
339 {
340 WLOGFI("run HandleSetSessionLabel!");
341 sptr<IRemoteObject> token = data.ReadRemoteObject();
342 std::string label = data.ReadString();
343 WSError errCode = SetSessionLabel(token, label);
344 reply.WriteInt32(static_cast<int32_t>(errCode));
345 return ERR_NONE;
346 }
347
HandleSetSessionIcon(MessageParcel & data,MessageParcel & reply)348 int SceneSessionManagerStub::HandleSetSessionIcon(MessageParcel &data, MessageParcel &reply)
349 {
350 WLOGFI("run HandleSetSessionIcon!");
351 sptr<IRemoteObject> token = data.ReadRemoteObject();
352 std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
353 WSError errCode = SetSessionIcon(token, icon);
354 reply.WriteInt32(static_cast<int32_t>(errCode));
355 return ERR_NONE;
356 }
357
HandleIsValidSessionIds(MessageParcel & data,MessageParcel & reply)358 int SceneSessionManagerStub::HandleIsValidSessionIds(MessageParcel &data, MessageParcel &reply)
359 {
360 WLOGFI("run HandleIsValidSessionIds!");
361 std::vector<int32_t> sessionIds;
362 data.ReadInt32Vector(&sessionIds);
363 std::vector<bool> results;
364 reply.WriteBoolVector(results);
365 return ERR_NONE;
366 }
367
HandleRegisterSessionChangeListener(MessageParcel & data,MessageParcel & reply)368 int SceneSessionManagerStub::HandleRegisterSessionChangeListener(MessageParcel &data, MessageParcel &reply)
369 {
370 WLOGFI("run HandleRegisterSessionChangeListener!");
371 sptr<ISessionChangeListener> listener = iface_cast<ISessionChangeListener>(data.ReadRemoteObject());
372 WSError errCode = RegisterSessionListener(listener);
373 reply.WriteInt32(static_cast<int32_t>(errCode));
374 return ERR_NONE;
375 }
376
HandleUnRegisterSessionChangeListener(MessageParcel & data,MessageParcel & reply)377 int SceneSessionManagerStub::HandleUnRegisterSessionChangeListener(MessageParcel &data, MessageParcel &reply)
378 {
379 WLOGFI("run HandleUnRegisterSessionChangeListener!");
380 UnregisterSessionListener();
381 return ERR_NONE;
382 }
383
HandlePendingSessionToForeground(MessageParcel & data,MessageParcel & reply)384 int SceneSessionManagerStub::HandlePendingSessionToForeground(MessageParcel &data, MessageParcel &reply)
385 {
386 WLOGFI("run HandlePendingSessionToForeground!");
387 sptr<IRemoteObject> token = data.ReadRemoteObject();
388 const WSError& errCode = PendingSessionToForeground(token);
389 reply.WriteUint32(static_cast<uint32_t>(errCode));
390 return ERR_NONE;
391 }
392
HandlePendingSessionToBackgroundForDelegator(MessageParcel & data,MessageParcel & reply)393 int SceneSessionManagerStub::HandlePendingSessionToBackgroundForDelegator(MessageParcel &data, MessageParcel &reply)
394 {
395 WLOGFI("run HandlePendingSessionToBackground!");
396 sptr<IRemoteObject> token = data.ReadRemoteObject();
397 const WSError& errCode = PendingSessionToBackgroundForDelegator(token);
398 reply.WriteInt32(static_cast<int32_t>(errCode));
399 return ERR_NONE;
400 }
401
HandleRegisterSessionListener(MessageParcel & data,MessageParcel & reply)402 int SceneSessionManagerStub::HandleRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
403 {
404 WLOGFI("run HandleRegisterSessionListener!");
405 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
406 WSError errCode = RegisterSessionListener(listener);
407 reply.WriteInt32(static_cast<int32_t>(errCode));
408 return ERR_NONE;
409 }
410
HandleUnRegisterSessionListener(MessageParcel & data,MessageParcel & reply)411 int SceneSessionManagerStub::HandleUnRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
412 {
413 WLOGFI("run HandleUnRegisterSessionListener!");
414 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
415 WSError errCode = UnRegisterSessionListener(listener);
416 reply.WriteInt32(static_cast<int32_t>(errCode));
417 return ERR_NONE;
418 }
419
HandleGetSessionInfos(MessageParcel & data,MessageParcel & reply)420 int SceneSessionManagerStub::HandleGetSessionInfos(MessageParcel& data, MessageParcel& reply)
421 {
422 WLOGFI("run HandleGetSessionInfos!");
423 std::string deviceId = Str16ToStr8(data.ReadString16());
424 int numMax = data.ReadInt32();
425 std::vector<SessionInfoBean> missionInfos;
426 WSError errCode = GetSessionInfos(deviceId, numMax, missionInfos);
427 reply.WriteInt32(missionInfos.size());
428 for (auto& it : missionInfos) {
429 if (!reply.WriteParcelable(&it)) {
430 WLOGFE("GetSessionInfos error");
431 return ERR_INVALID_DATA;
432 }
433 }
434 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
435 return ERR_INVALID_DATA;
436 }
437 return ERR_NONE;
438 }
439
HandleGetSessionInfo(MessageParcel & data,MessageParcel & reply)440 int SceneSessionManagerStub::HandleGetSessionInfo(MessageParcel& data, MessageParcel& reply)
441 {
442 WLOGFI("run HandleGetSessionInfo!");
443 SessionInfoBean info;
444 std::string deviceId = Str16ToStr8(data.ReadString16());
445 int32_t persistentId = data.ReadInt32();
446 WSError errCode = GetSessionInfo(deviceId, persistentId, info);
447 if (!reply.WriteParcelable(&info)) {
448 WLOGFE("GetSessionInfo error");
449 return ERR_INVALID_DATA;
450 }
451
452 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
453 WLOGFE("GetSessionInfo result error");
454 return ERR_INVALID_DATA;
455 }
456 return ERR_NONE;
457 }
458
HandleDumpSessionAll(MessageParcel & data,MessageParcel & reply)459 int SceneSessionManagerStub::HandleDumpSessionAll(MessageParcel& data, MessageParcel& reply)
460 {
461 WLOGFI("run HandleDumpSessionAll!");
462 std::vector<std::string> infos;
463 WSError errCode = DumpSessionAll(infos);
464 if (!reply.WriteStringVector(infos)) {
465 WLOGFE("HandleDumpSessionAll write info failed.");
466 return ERR_TRANSACTION_FAILED;
467 }
468
469 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
470 WLOGFE("HandleDumpSessionAll write errcode failed.");
471 return ERR_TRANSACTION_FAILED;
472 }
473 return ERR_NONE;
474 }
475
HandleDumpSessionWithId(MessageParcel & data,MessageParcel & reply)476 int SceneSessionManagerStub::HandleDumpSessionWithId(MessageParcel& data, MessageParcel& reply)
477 {
478 WLOGFI("run HandleDumpSessionWithId!");
479 int32_t persistentId = data.ReadInt32();
480 std::vector<std::string> infos;
481 WSError errCode = DumpSessionWithId(persistentId, infos);
482 if (!reply.WriteStringVector(infos)) {
483 WLOGFE("HandleDumpSessionWithId write info failed.");
484 return ERR_TRANSACTION_FAILED;
485 }
486
487 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
488 WLOGFE("HandleDumpSessionWithId write errcode failed.");
489 return ERR_TRANSACTION_FAILED;
490 }
491 return ERR_NONE;
492 }
493
HandleTerminateSessionNew(MessageParcel & data,MessageParcel & reply)494 int SceneSessionManagerStub::HandleTerminateSessionNew(MessageParcel& data, MessageParcel& reply)
495 {
496 WLOGFD("run HandleTerminateSessionNew");
497 sptr<AAFwk::SessionInfo> abilitySessionInfo = data.ReadParcelable<AAFwk::SessionInfo>();
498 bool needStartCaller = data.ReadBool();
499 const WSError& errCode = TerminateSessionNew(abilitySessionInfo, needStartCaller);
500 reply.WriteUint32(static_cast<uint32_t>(errCode));
501 return ERR_NONE;
502 }
503
HandleGetFocusSessionToken(MessageParcel & data,MessageParcel & reply)504 int SceneSessionManagerStub::HandleGetFocusSessionToken(MessageParcel &data, MessageParcel &reply)
505 {
506 WLOGFD("run HandleGetFocusSessionToken!");
507 sptr<IRemoteObject> token = nullptr;
508 const WSError& errCode = GetFocusSessionToken(token);
509 reply.WriteRemoteObject(token);
510 reply.WriteInt32(static_cast<int32_t>(errCode));
511 return ERR_NONE;
512 }
513
HandleCheckWindowId(MessageParcel & data,MessageParcel & reply)514 int SceneSessionManagerStub::HandleCheckWindowId(MessageParcel &data, MessageParcel &reply)
515 {
516 WLOGFI("run HandleCheckWindowId!");
517 int32_t windowId = INVALID_WINDOW_ID;
518 if (!data.ReadInt32(windowId)) {
519 WLOGE("Failed to readInt32 windowId");
520 return ERR_INVALID_DATA;
521 }
522 int32_t pid = INVALID_PID;
523 WMError errCode = CheckWindowId(windowId, pid);
524 if (errCode != WMError::WM_OK) {
525 WLOGE("Failed to checkWindowId(%{public}d)", pid);
526 return ERR_INVALID_DATA;
527 }
528 if (!reply.WriteInt32(pid)) {
529 WLOGE("Failed to WriteInt32 pid");
530 return ERR_INVALID_DATA;
531 }
532 return ERR_NONE;
533 }
534
HandleSetGestureNavigationEnabled(MessageParcel & data,MessageParcel & reply)535 int SceneSessionManagerStub::HandleSetGestureNavigationEnabled(MessageParcel &data, MessageParcel &reply)
536 {
537 WLOGFI("run HandleSetGestureNavigationEnabled!");
538 bool enable = data.ReadBool();
539 const WMError &ret = SetGestureNavigaionEnabled(enable);
540 reply.WriteInt32(static_cast<int32_t>(ret));
541 return ERR_NONE;
542 }
543
HandleGetAccessibilityWindowInfo(MessageParcel & data,MessageParcel & reply)544 int SceneSessionManagerStub::HandleGetAccessibilityWindowInfo(MessageParcel &data, MessageParcel &reply)
545 {
546 std::vector<sptr<AccessibilityWindowInfo>> infos;
547 WMError errCode = GetAccessibilityWindowInfo(infos);
548 if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
549 WLOGFE("Write window infos failed.");
550 return ERR_TRANSACTION_FAILED;
551 }
552 reply.WriteInt32(static_cast<int32_t>(errCode));
553 return ERR_NONE;
554 }
555
HandleSetSessionContinueState(MessageParcel & data,MessageParcel & reply)556 int SceneSessionManagerStub::HandleSetSessionContinueState(MessageParcel &data, MessageParcel &reply)
557 {
558 WLOGFI("HandleSetSessionContinueState");
559 sptr <IRemoteObject> token = data.ReadRemoteObject();
560 auto continueState = static_cast<ContinueState>(data.ReadInt32());
561 const WSError &ret = SetSessionContinueState(token, continueState);
562 reply.WriteUint32(static_cast<uint32_t>(ret));
563 return ERR_NONE;
564 }
565
HandleSetSessionGravity(MessageParcel & data,MessageParcel & reply)566 int SceneSessionManagerStub::HandleSetSessionGravity(MessageParcel &data, MessageParcel &reply)
567 {
568 WLOGFI("run HandleSetSessionGravity!");
569 auto persistentId = data.ReadInt32();
570 SessionGravity gravity = static_cast<SessionGravity>(data.ReadUint32());
571 uint32_t percent = data.ReadUint32();
572 WSError ret = SetSessionGravity(persistentId, gravity, percent);
573 reply.WriteInt32(static_cast<int32_t>(ret));
574 return ERR_NONE;
575 }
576
HandleGetSessionDump(MessageParcel & data,MessageParcel & reply)577 int SceneSessionManagerStub::HandleGetSessionDump(MessageParcel &data, MessageParcel &reply)
578 {
579 std::vector<std::string> params;
580 if (!data.ReadStringVector(¶ms)) {
581 WLOGFE("Fail to read params");
582 return -1;
583 }
584 std::string dumpInfo;
585 WSError errCode = GetSessionDumpInfo(params, dumpInfo);
586 const char* info = dumpInfo.c_str();
587 uint32_t infoSize = static_cast<uint32_t>(strlen(info));
588 WLOGFI("HandleGetSessionDump, infoSize: %{public}d", infoSize);
589 reply.WriteUint32(infoSize);
590 if (infoSize != 0) {
591 if (!reply.WriteRawData(info, infoSize)) {
592 WLOGFE("Fail to write dumpInfo");
593 return -1;
594 }
595 }
596 reply.WriteInt32(static_cast<int32_t>(errCode));
597 return ERR_NONE;
598 }
599
HandleUpdateSessionAvoidAreaListener(MessageParcel & data,MessageParcel & reply)600 int SceneSessionManagerStub::HandleUpdateSessionAvoidAreaListener(MessageParcel& data, MessageParcel& reply)
601 {
602 auto persistentId = data.ReadInt32();
603 bool haveAvoidAreaListener = data.ReadBool();
604 WSError errCode = UpdateSessionAvoidAreaListener(persistentId, haveAvoidAreaListener);
605 reply.WriteUint32(static_cast<uint32_t>(errCode));
606 return ERR_NONE;
607 }
608
HandleGetSessionSnapshot(MessageParcel & data,MessageParcel & reply)609 int SceneSessionManagerStub::HandleGetSessionSnapshot(MessageParcel &data, MessageParcel &reply)
610 {
611 WLOGFI("run HandleGetSessionSnapshot!");
612 std::string deviceId = Str16ToStr8(data.ReadString16());
613 int32_t persistentId = data.ReadInt32();
614 bool isLowResolution = data.ReadBool();
615 std::shared_ptr<SessionSnapshot> snapshot = std::make_shared<SessionSnapshot>();
616 const WSError& ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution);
617 reply.WriteParcelable(snapshot.get());
618 reply.WriteUint32(static_cast<uint32_t>(ret));
619 return ERR_NONE;
620 }
621
HandleBindDialogTarget(MessageParcel & data,MessageParcel & reply)622 int SceneSessionManagerStub::HandleBindDialogTarget(MessageParcel &data, MessageParcel &reply)
623 {
624 WLOGFI("run HandleBindDialogTarget!");
625 auto persistentId = data.ReadUint64();
626 sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
627 const WSError& ret = BindDialogSessionTarget(persistentId, remoteObject);
628 reply.WriteUint32(static_cast<uint32_t>(ret));
629 return ERR_NONE;
630 }
631
HandleNotifyDumpInfoResult(MessageParcel & data,MessageParcel & reply)632 int SceneSessionManagerStub::HandleNotifyDumpInfoResult(MessageParcel &data, MessageParcel &reply)
633 {
634 WLOGFI("HandleNotifyDumpInfoResult");
635 std::vector<std::string> info;
636 uint32_t vectorSize = data.ReadUint32();
637 if (vectorSize > MAX_VECTOR_SIZE) {
638 WLOGFI("Vector is too big!");
639 return -1;
640 }
641 for (uint32_t i = 0; i < vectorSize; i++) {
642 uint32_t curSize = data.ReadUint32();
643 std::string curInfo = "";
644 if (curSize != 0) {
645 const char* infoPtr = nullptr;
646 infoPtr = reinterpret_cast<const char*>(data.ReadRawData(curSize));
647 curInfo = (infoPtr) ? std::string(infoPtr, curSize) : "";
648 }
649 info.emplace_back(curInfo);
650 WLOGFD("HandleNotifyDumpInfoResult count: %{public}u, infoSize: %{public}u", i, curSize);
651 }
652 NotifyDumpInfoResult(info);
653 return ERR_NONE;
654 }
655
HandleClearSession(MessageParcel & data,MessageParcel & reply)656 int SceneSessionManagerStub::HandleClearSession(MessageParcel &data, MessageParcel &reply)
657 {
658 WLOGFI("run HandleClearSession!");
659 int32_t persistentId = data.ReadInt32();
660 const WSError& ret = ClearSession(persistentId);
661 reply.WriteUint32(static_cast<uint32_t>(ret));
662 return ERR_NONE;
663 }
664
HandleClearAllSessions(MessageParcel & data,MessageParcel & reply)665 int SceneSessionManagerStub::HandleClearAllSessions(MessageParcel &data, MessageParcel &reply)
666 {
667 WLOGFI("run HandleClearAllSessions!");
668 const WSError& ret = ClearAllSessions();
669 reply.WriteUint32(static_cast<uint32_t>(ret));
670 return ERR_NONE;
671 }
672
HandleLockSession(MessageParcel & data,MessageParcel & reply)673 int SceneSessionManagerStub::HandleLockSession(MessageParcel &data, MessageParcel &reply)
674 {
675 WLOGFI("run HandleLockSession!");
676 int32_t sessionId = data.ReadInt32();
677 const WSError& ret = LockSession(sessionId);
678 reply.WriteUint32(static_cast<uint32_t>(ret));
679 return ERR_NONE;
680 }
HandleUnlockSession(MessageParcel & data,MessageParcel & reply)681 int SceneSessionManagerStub::HandleUnlockSession(MessageParcel &data, MessageParcel &reply)
682 {
683 WLOGFI("run HandleUnlockSession!");
684 int32_t sessionId = data.ReadInt32();
685 const WSError& ret = UnlockSession(sessionId);
686 reply.WriteUint32(static_cast<uint32_t>(ret));
687 return ERR_NONE;
688 }
HandleMoveSessionsToForeground(MessageParcel & data,MessageParcel & reply)689 int SceneSessionManagerStub::HandleMoveSessionsToForeground(MessageParcel &data, MessageParcel &reply)
690 {
691 WLOGFI("run HandleMoveSessionsToForeground!");
692 std::vector<int32_t> sessionIds;
693 data.ReadInt32Vector(&sessionIds);
694 int32_t topSessionId = data.ReadInt32();
695 const WSError &ret = MoveSessionsToForeground(sessionIds, topSessionId);
696 reply.WriteUint32(static_cast<uint32_t>(ret));
697 return ERR_NONE;
698 }
HandleMoveSessionsToBackground(MessageParcel & data,MessageParcel & reply)699 int SceneSessionManagerStub::HandleMoveSessionsToBackground(MessageParcel &data, MessageParcel &reply)
700 {
701 WLOGFI("run HandleMoveSessionsToBackground!");
702 std::vector<int32_t> sessionIds;
703 data.ReadInt32Vector(&sessionIds);
704 std::vector<int32_t> result;
705 data.ReadInt32Vector(&result);
706 const WSError &ret = MoveSessionsToBackground(sessionIds, result);
707 reply.WriteInt32Vector(result);
708 reply.WriteUint32(static_cast<uint32_t>(ret));
709 return ERR_NONE;
710 }
711
HandleRegisterCollaborator(MessageParcel & data,MessageParcel & reply)712 int SceneSessionManagerStub::HandleRegisterCollaborator(MessageParcel &data, MessageParcel &reply)
713 {
714 WLOGFI("run HandleRegisterCollaborator!");
715 int32_t type = data.ReadInt32();
716 sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
717 iface_cast<AAFwk::IAbilityManagerCollaborator>(data.ReadRemoteObject());
718 const WSError& ret = RegisterIAbilityManagerCollaborator(type, collaborator);
719 reply.WriteUint32(static_cast<uint32_t>(ret));
720 return ERR_NONE;
721 }
722
HandleUnregisterCollaborator(MessageParcel & data,MessageParcel & reply)723 int SceneSessionManagerStub::HandleUnregisterCollaborator(MessageParcel &data, MessageParcel &reply)
724 {
725 WLOGFI("run HandleUnregisterCollaborator!");
726 int32_t type = data.ReadInt32();
727 const WSError& ret = UnregisterIAbilityManagerCollaborator(type);
728 reply.WriteUint32(static_cast<uint32_t>(ret));
729 return ERR_NONE;
730 }
731
HandleUpdateSessionTouchOutsideListener(MessageParcel & data,MessageParcel & reply)732 int SceneSessionManagerStub::HandleUpdateSessionTouchOutsideListener(MessageParcel& data, MessageParcel& reply)
733 {
734 auto persistentId = data.ReadInt32();
735 bool haveAvoidAreaListener = data.ReadBool();
736 WSError errCode = UpdateSessionTouchOutsideListener(persistentId, haveAvoidAreaListener);
737 reply.WriteUint32(static_cast<uint32_t>(errCode));
738 return ERR_NONE;
739 }
740
HandleRaiseWindowToTop(MessageParcel & data,MessageParcel & reply)741 int SceneSessionManagerStub::HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply)
742 {
743 auto persistentId = data.ReadInt32();
744 WSError errCode = RaiseWindowToTop(persistentId);
745 reply.WriteUint32(static_cast<uint32_t>(errCode));
746 return ERR_NONE;
747 }
748
HandleNotifyWindowExtensionVisibilityChange(MessageParcel & data,MessageParcel & reply)749 int SceneSessionManagerStub::HandleNotifyWindowExtensionVisibilityChange(MessageParcel& data, MessageParcel& reply)
750 {
751 auto pid = data.ReadInt32();
752 auto uid = data.ReadInt32();
753 bool visible = data.ReadBool();
754 const WSError& ret = NotifyWindowExtensionVisibilityChange(pid, uid, visible);
755 reply.WriteUint32(static_cast<uint32_t>(ret));
756 return ERR_NONE;
757 }
758
HandleGetTopWindowId(MessageParcel & data,MessageParcel & reply)759 int SceneSessionManagerStub::HandleGetTopWindowId(MessageParcel& data, MessageParcel& reply)
760 {
761 uint32_t mainWinId = data.ReadUint32();
762 uint32_t topWinId;
763 const WMError& ret = GetTopWindowId(mainWinId, topWinId);
764 reply.WriteUint32(topWinId);
765 reply.WriteUint32(static_cast<uint32_t>(ret));
766 return ERR_NONE;
767 }
768
HandleUpdateSessionWindowVisibilityListener(MessageParcel & data,MessageParcel & reply)769 int SceneSessionManagerStub::HandleUpdateSessionWindowVisibilityListener(MessageParcel& data, MessageParcel& reply)
770 {
771 int32_t persistendId = data.ReadInt32();
772 bool haveListener = data.ReadBool();
773 WSError ret = UpdateSessionWindowVisibilityListener(persistendId, haveListener);
774 reply.WriteUint32(static_cast<uint32_t>(ret));
775 return ERR_NONE;
776 }
777
HandleShiftAppWindowFocus(MessageParcel & data,MessageParcel & reply)778 int SceneSessionManagerStub::HandleShiftAppWindowFocus(MessageParcel& data, MessageParcel& reply)
779 {
780 int32_t sourcePersistentId = data.ReadInt32();
781 int32_t targetPersistentId = data.ReadInt32();
782 const WSError& ret = ShiftAppWindowFocus(sourcePersistentId, targetPersistentId);
783 reply.WriteUint32(static_cast<uint32_t>(ret));
784 return ERR_NONE;
785 }
786
HandleGetVisibilityWindowInfo(MessageParcel & data,MessageParcel & reply)787 int SceneSessionManagerStub::HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
788 {
789 std::vector<sptr<WindowVisibilityInfo>> infos;
790 WMError errCode = GetVisibilityWindowInfo(infos);
791 if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
792 WLOGFE("Write visibility window infos failed");
793 return -1;
794 }
795 reply.WriteInt32(static_cast<int32_t>(errCode));
796 return ERR_NONE;
797 }
798
HandleHideNonSecureWindows(MessageParcel & data,MessageParcel & reply)799 int SceneSessionManagerStub::HandleHideNonSecureWindows(MessageParcel &data, MessageParcel &reply)
800 {
801 WLOGFI("run HandleHideNonSecureWindows!");
802 bool shouldHide = data.ReadBool();
803 WSError ret = HideNonSecureWindows(shouldHide);
804 reply.WriteInt32(static_cast<int32_t>(ret));
805 return ERR_NONE;
806 }
807 } // namespace OHOS::Rosen
808