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