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_LIST_WINDOW_INFO):
101 return HandleListWindowInfo(data, reply);
102 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_VISIBILITY_WINDOW_INFO_ID):
103 return HandleGetVisibilityWindowInfo(data, reply);
104 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_MODE_TYPE):
105 return HandleGetWindowModeType(data, reply);
106 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_RAISE_WINDOW_TO_TOP):
107 return HandleRaiseWindowToTop(data, reply);
108 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_TOPN_MAIN_WINDOW_INFO):
109 return HandleGetMainWinodowInfo(data, reply);
110 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_COLLABORATOR):
111 return HandleRegisterCollaborator(data, reply);
112 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_COLLABORATOR):
113 return HandleUnregisterCollaborator(data, reply);
114 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_ALL_MAIN_WINDOW_INFO):
115 return HandleGetAllMainWindowInfos(data, reply);
116 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_CLEAR_MAIN_SESSIONS):
117 return HandleClearMainSessions(data, reply);
118 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_STYLE_TYPE):
119 return HandleGetWindowStyleType(data, reply);
120 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_TERMINATE_SESSION_BY_PERSISTENT_ID):
121 return HandleTerminateSessionByPersistentId(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_GET_ROOT_MAIN_WINDOW_ID):
129 return HandleGetRootMainWindowId(data, reply);
130 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_WINDOW_INFO):
131 return HandleGetAccessibilityWindowInfo(data, reply);
132 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_NOTIFY_APP_USE_CONTROL_LIST):
133 return HandleNotifyAppUseControlList(data, reply);
134 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_MINIMIZE_MAIN_SESSION):
135 return HandleMinimizeMainSession(data, reply);
136 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_HAS_FLOAT_FOREGROUND):
137 return HandleHasFloatingWindowForeground(data, reply);
138 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_LOCK_SESSION_BY_ABILITY_INFO):
139 return HandleLockSessionByAbilityInfo(data, reply);
140 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_GET_CALLING_WINDOW_INFO):
141 return HandleGetCallingWindowInfo(data, reply);
142 case static_cast<uint32_t>(
143 SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_IDS):
144 return HandleRegisterSessionLifecycleListenerByIds(data, reply);
145 case static_cast<uint32_t>(
146 SceneSessionManagerLiteMessage::TRANS_ID_REGISTER_SESSION_LIFECYCLE_LISTENER_BY_BUNDLES):
147 return HandleRegisterSessionLifecycleListenerByBundles(data, reply);
148 case static_cast<uint32_t>(SceneSessionManagerLiteMessage::TRANS_ID_UNREGISTER_SESSION_LIFECYCLE_LISTENER):
149 return HandleUnregisterSessionLifecycleListener(data, reply);
150 default:
151 WLOGFE("Failed to find function handler!");
152 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
153 }
154 }
155
HandleSetSessionLabel(MessageParcel & data,MessageParcel & reply)156 int SceneSessionManagerLiteStub::HandleSetSessionLabel(MessageParcel& data, MessageParcel& reply)
157 {
158 TLOGD(WmsLogTag::WMS_LIFE, "In");
159 sptr<IRemoteObject> token = data.ReadRemoteObject();
160 std::string label;
161 if (!data.ReadString(label)) {
162 TLOGD(WmsLogTag::WMS_LIFE, "Read label failed.");
163 return ERR_INVALID_DATA;
164 }
165 WSError errCode = SetSessionLabel(token, label);
166 reply.WriteInt32(static_cast<int32_t>(errCode));
167 return ERR_NONE;
168 }
169
HandleSetSessionIcon(MessageParcel & data,MessageParcel & reply)170 int SceneSessionManagerLiteStub::HandleSetSessionIcon(MessageParcel& data, MessageParcel& reply)
171 {
172 WLOGFD("run HandleSetSessionIcon!");
173 sptr<IRemoteObject> token = data.ReadRemoteObject();
174 std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
175 if (icon == nullptr) {
176 WLOGFE("icon is null");
177 return ERR_INVALID_DATA;
178 }
179 WSError errCode = SetSessionIcon(token, icon);
180 reply.WriteInt32(static_cast<int32_t>(errCode));
181 return ERR_NONE;
182 }
183
HandleIsValidSessionIds(MessageParcel & data,MessageParcel & reply)184 int SceneSessionManagerLiteStub::HandleIsValidSessionIds(MessageParcel& data, MessageParcel& reply)
185 {
186 WLOGFD("run HandleIsValidSessionIds!");
187 std::vector<int32_t> sessionIds;
188 data.ReadInt32Vector(&sessionIds);
189 std::vector<bool> results;
190 WSError errCode = IsValidSessionIds(sessionIds, results);
191 reply.WriteBoolVector(results);
192 reply.WriteUint32(static_cast<uint32_t>(errCode));
193 return ERR_NONE;
194 }
195
HandlePendingSessionToForeground(MessageParcel & data,MessageParcel & reply)196 int SceneSessionManagerLiteStub::HandlePendingSessionToForeground(MessageParcel& data, MessageParcel& reply)
197 {
198 WLOGFD("run HandlePendingSessionToForeground!");
199 sptr<IRemoteObject> token = data.ReadRemoteObject();
200 if (token == nullptr) {
201 WLOGFE("token is nullptr");
202 return ERR_INVALID_DATA;
203 }
204 WSError errCode = PendingSessionToForeground(token);
205 reply.WriteUint32(static_cast<uint32_t>(errCode));
206 return ERR_NONE;
207 }
208
HandlePendingSessionToBackgroundForDelegator(MessageParcel & data,MessageParcel & reply)209 int SceneSessionManagerLiteStub::HandlePendingSessionToBackgroundForDelegator(MessageParcel& data, MessageParcel& reply)
210 {
211 TLOGD(WmsLogTag::WMS_LIFE, "run");
212 sptr<IRemoteObject> token = data.ReadRemoteObject();
213 if (token == nullptr) {
214 TLOGE(WmsLogTag::WMS_LIFE, "token is nullptr");
215 return ERR_INVALID_DATA;
216 }
217 bool shouldBackToCaller = true;
218 if (!data.ReadBool(shouldBackToCaller)) {
219 TLOGE(WmsLogTag::WMS_LIFE, "Read shouldBackToCaller failed");
220 return ERR_INVALID_DATA;
221 }
222 WSError errCode = PendingSessionToBackgroundForDelegator(token, shouldBackToCaller);
223 reply.WriteInt32(static_cast<int32_t>(errCode));
224 return ERR_NONE;
225 }
226
HandleRegisterSessionListener(MessageParcel & data,MessageParcel & reply)227 int SceneSessionManagerLiteStub::HandleRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
228 {
229 WLOGFD("run HandleRegisterSessionListener!");
230 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
231 if (listener == nullptr) {
232 TLOGE(WmsLogTag::WMS_MAIN, "listener is nullptr!");
233 reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
234 return ERR_NONE;
235 }
236 WSError errCode = RegisterSessionListener(listener);
237 reply.WriteInt32(static_cast<int32_t>(errCode));
238 return ERR_NONE;
239 }
240
HandleUnRegisterSessionListener(MessageParcel & data,MessageParcel & reply)241 int SceneSessionManagerLiteStub::HandleUnRegisterSessionListener(MessageParcel& data, MessageParcel& reply)
242 {
243 WLOGFD("run HandleUnRegisterSessionListener!");
244 sptr<ISessionListener> listener = iface_cast<ISessionListener>(data.ReadRemoteObject());
245 if (listener == nullptr) {
246 reply.WriteInt32(static_cast<int32_t>(WSError::WS_ERROR_INVALID_PARAM));
247 return ERR_NONE;
248 }
249 WSError errCode = UnRegisterSessionListener(listener);
250 reply.WriteInt32(static_cast<int32_t>(errCode));
251 return ERR_NONE;
252 }
253
HandleGetSessionInfos(MessageParcel & data,MessageParcel & reply)254 int SceneSessionManagerLiteStub::HandleGetSessionInfos(MessageParcel& data, MessageParcel& reply)
255 {
256 WLOGFD("run HandleGetSessionInfos!");
257 std::u16string deviceIdU16;
258 if (!data.ReadString16(deviceIdU16)) {
259 TLOGE(WmsLogTag::WMS_LIFE, "Read deviceId fail");
260 return ERR_TRANSACTION_FAILED;
261 }
262 std::string deviceId = Str16ToStr8(deviceIdU16);
263 int32_t numMax = 0;
264 if (!data.ReadInt32(numMax)) {
265 TLOGE(WmsLogTag::WMS_LIFE, "Read numMax fail");
266 return ERR_TRANSACTION_FAILED;
267 }
268 std::vector<SessionInfoBean> missionInfos;
269 WSError errCode = GetSessionInfos(deviceId, numMax, missionInfos);
270 reply.WriteInt32(missionInfos.size());
271 for (auto& it : missionInfos) {
272 if (!reply.WriteParcelable(&it)) {
273 WLOGFE("GetSessionInfos error");
274 return ERR_INVALID_DATA;
275 }
276 }
277 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
278 return ERR_INVALID_DATA;
279 }
280 return ERR_NONE;
281 }
282
HandleGetMainWindowStatesByPid(MessageParcel & data,MessageParcel & reply)283 int SceneSessionManagerLiteStub::HandleGetMainWindowStatesByPid(MessageParcel& data, MessageParcel& reply)
284 {
285 int32_t pid = 0;
286 if (!data.ReadInt32(pid)) {
287 TLOGE(WmsLogTag::WMS_LIFE, "read pid fail");
288 return ERR_INVALID_DATA;
289 }
290 std::vector<MainWindowState> windowStates;
291 WSError errCode = GetMainWindowStatesByPid(pid, windowStates);
292 if (!reply.WriteInt32(windowStates.size())) {
293 TLOGE(WmsLogTag::WMS_LIFE, "write windowStates size fail");
294 return ERR_INVALID_DATA;
295 }
296 for (auto& state : windowStates) {
297 if (!reply.WriteParcelable(&state)) {
298 TLOGE(WmsLogTag::WMS_LIFE, "write windowState fail");
299 return ERR_INVALID_DATA;
300 }
301 }
302 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
303 return ERR_INVALID_DATA;
304 }
305 return ERR_NONE;
306 }
307
HandleGetSessionInfo(MessageParcel & data,MessageParcel & reply)308 int SceneSessionManagerLiteStub::HandleGetSessionInfo(MessageParcel& data, MessageParcel& reply)
309 {
310 TLOGD(WmsLogTag::WMS_LIFE, "In!");
311 SessionInfoBean info;
312 std::u16string deviceIdU16;
313 if (!data.ReadString16(deviceIdU16)) {
314 TLOGE(WmsLogTag::WMS_LIFE, "Read deviceId fail");
315 return ERR_TRANSACTION_FAILED;
316 }
317 std::string deviceId = Str16ToStr8(deviceIdU16);
318 int32_t persistentId = 0;
319 if (!data.ReadInt32(persistentId)) {
320 TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId fail");
321 return ERR_TRANSACTION_FAILED;
322 }
323 WSError errCode = GetSessionInfo(deviceId, persistentId, info);
324 if (!reply.WriteParcelable(&info)) {
325 TLOGE(WmsLogTag::WMS_LIFE, "Write sessionInfo fail");
326 return ERR_INVALID_DATA;
327 }
328
329 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
330 TLOGE(WmsLogTag::WMS_LIFE, "Write sessionInfo result fail");
331 return ERR_INVALID_DATA;
332 }
333 return ERR_NONE;
334 }
335
HandleGetSessionInfoByContinueSessionId(MessageParcel & data,MessageParcel & reply)336 int SceneSessionManagerLiteStub::HandleGetSessionInfoByContinueSessionId(MessageParcel& data, MessageParcel& reply)
337 {
338 TLOGD(WmsLogTag::WMS_LIFE, "In!");
339 std::string continueSessionId;
340 if (!data.ReadString(continueSessionId)) {
341 TLOGE(WmsLogTag::WMS_LIFE, "read continueSessionId fail");
342 return ERR_INVALID_DATA;
343 }
344 TLOGI(WmsLogTag::WMS_LIFE, "continueSessionId: %{public}s", continueSessionId.c_str());
345 SessionInfoBean info;
346 WSError errCode = GetSessionInfoByContinueSessionId(continueSessionId, info);
347 if (!reply.WriteParcelable(&info)) {
348 TLOGE(WmsLogTag::WMS_LIFE, "Get sessionInfo by continueSessionId error");
349 return ERR_INVALID_DATA;
350 }
351
352 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
353 TLOGE(WmsLogTag::WMS_LIFE, "Get sessionInfo by continueSessionId result error");
354 return ERR_INVALID_DATA;
355 }
356 return ERR_NONE;
357 }
358
HandleTerminateSessionNew(MessageParcel & data,MessageParcel & reply)359 int SceneSessionManagerLiteStub::HandleTerminateSessionNew(MessageParcel& data, MessageParcel& reply)
360 {
361 TLOGD(WmsLogTag::WMS_LIFE, "in");
362 sptr<AAFwk::SessionInfo> abilitySessionInfo = data.ReadParcelable<AAFwk::SessionInfo>();
363 if (abilitySessionInfo == nullptr) {
364 TLOGE(WmsLogTag::WMS_LIFE, "abilitySessionInfo is null");
365 return ERR_INVALID_DATA;
366 }
367 bool needStartCaller = false;
368 if (!data.ReadBool(needStartCaller)) {
369 TLOGE(WmsLogTag::WMS_LIFE, "Read needStartCaller failed.");
370 return ERR_INVALID_DATA;
371 }
372 bool isFromBroker = false;
373 if (!data.ReadBool(isFromBroker)) {
374 TLOGE(WmsLogTag::WMS_LIFE, "Read isFromBroker failed.");
375 return ERR_INVALID_DATA;
376 }
377 WSError errCode = TerminateSessionNew(abilitySessionInfo, needStartCaller, isFromBroker);
378 reply.WriteUint32(static_cast<uint32_t>(errCode));
379 return ERR_NONE;
380 }
381
HandleGetFocusSessionToken(MessageParcel & data,MessageParcel & reply)382 int SceneSessionManagerLiteStub::HandleGetFocusSessionToken(MessageParcel& data, MessageParcel& reply)
383 {
384 TLOGD(WmsLogTag::WMS_FOCUS, "run");
385 uint64_t displayId = 0;
386 if (!data.ReadUint64(displayId)) {
387 TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
388 return ERR_INVALID_DATA;
389 }
390 sptr<IRemoteObject> token = nullptr;
391 WSError errCode = GetFocusSessionToken(token, displayId);
392 reply.WriteRemoteObject(token);
393 reply.WriteInt32(static_cast<int32_t>(errCode));
394 return ERR_NONE;
395 }
396
HandleGetFocusSessionElement(MessageParcel & data,MessageParcel & reply)397 int SceneSessionManagerLiteStub::HandleGetFocusSessionElement(MessageParcel& data, MessageParcel& reply)
398 {
399 TLOGD(WmsLogTag::WMS_FOCUS, "run");
400 uint64_t displayId = 0;
401 if (!data.ReadUint64(displayId)) {
402 TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
403 return ERR_INVALID_DATA;
404 }
405 AppExecFwk::ElementName element;
406 WSError errCode = GetFocusSessionElement(element, displayId);
407 reply.WriteParcelable(&element);
408 reply.WriteInt32(static_cast<int32_t>(errCode));
409 return ERR_NONE;
410 }
411
HandleSetSessionContinueState(MessageParcel & data,MessageParcel & reply)412 int SceneSessionManagerLiteStub::HandleSetSessionContinueState(MessageParcel& data, MessageParcel& reply)
413 {
414 WLOGFD("HandleSetSessionContinueState");
415 sptr <IRemoteObject> token = data.ReadRemoteObject();
416 int32_t continueStateValue = 0;
417 if (!data.ReadInt32(continueStateValue)) {
418 TLOGE(WmsLogTag::WMS_LIFE, "Read continueState fail");
419 return ERR_TRANSACTION_FAILED;
420 }
421 if (continueStateValue < static_cast<int32_t>(ContinueState::CONTINUESTATE_UNKNOWN) ||
422 continueStateValue > static_cast<int32_t>(ContinueState::CONTINUESTATE_MAX)) {
423 TLOGE(WmsLogTag::WMS_LIFE, "Invalid continueState");
424 return ERR_INVALID_DATA;
425 }
426 auto continueState = static_cast<ContinueState>(continueStateValue);
427 const WSError &ret = SetSessionContinueState(token, continueState);
428 reply.WriteUint32(static_cast<uint32_t>(ret));
429 return ERR_NONE;
430 }
431
HandleGetSessionSnapshot(MessageParcel & data,MessageParcel & reply)432 int SceneSessionManagerLiteStub::HandleGetSessionSnapshot(MessageParcel& data, MessageParcel& reply)
433 {
434 TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!");
435 std::u16string deviceIdData;
436 if (!data.ReadString16(deviceIdData)) {
437 TLOGE(WmsLogTag::WMS_SYSTEM, "read deviceId fail");
438 return ERR_INVALID_DATA;
439 }
440 std::string deviceId = Str16ToStr8(deviceIdData);
441 int32_t persistentId = 0;
442 if (!data.ReadInt32(persistentId)) {
443 TLOGE(WmsLogTag::WMS_SYSTEM, "read persistentId fail");
444 return ERR_INVALID_DATA;
445 }
446 bool isLowResolution = false;
447 if (!data.ReadBool(isLowResolution)) {
448 TLOGE(WmsLogTag::WMS_SYSTEM, "read isLowResolution fail");
449 return ERR_INVALID_DATA;
450 }
451 std::shared_ptr<SessionSnapshot> snapshot = std::make_shared<SessionSnapshot>();
452 WSError ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution);
453 reply.WriteParcelable(snapshot.get());
454 reply.WriteUint32(static_cast<uint32_t>(ret));
455 return ERR_NONE;
456 }
457
HandleClearSession(MessageParcel & data,MessageParcel & reply)458 int SceneSessionManagerLiteStub::HandleClearSession(MessageParcel& data, MessageParcel& reply)
459 {
460 WLOGFD("run HandleClearSession!");
461 int32_t persistentId = 0;
462 if (!data.ReadInt32(persistentId)) {
463 TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId fail");
464 return ERR_TRANSACTION_FAILED;
465 }
466 WSError ret = ClearSession(persistentId);
467 reply.WriteUint32(static_cast<uint32_t>(ret));
468 return ERR_NONE;
469 }
470
HandleClearAllSessions(MessageParcel & data,MessageParcel & reply)471 int SceneSessionManagerLiteStub::HandleClearAllSessions(MessageParcel& data, MessageParcel& reply)
472 {
473 WLOGFD("run HandleClearAllSessions!");
474 WSError ret = ClearAllSessions();
475 reply.WriteUint32(static_cast<uint32_t>(ret));
476 return ERR_NONE;
477 }
478
HandleLockSession(MessageParcel & data,MessageParcel & reply)479 int SceneSessionManagerLiteStub::HandleLockSession(MessageParcel& data, MessageParcel& reply)
480 {
481 WLOGFD("run HandleLockSession!");
482 int32_t sessionId = 0;
483 if (!data.ReadInt32(sessionId)) {
484 TLOGE(WmsLogTag::WMS_LIFE, "Read sessionId fail");
485 return ERR_TRANSACTION_FAILED;
486 }
487 WSError ret = LockSession(sessionId);
488 reply.WriteUint32(static_cast<uint32_t>(ret));
489 return ERR_NONE;
490 }
491
HandleUnlockSession(MessageParcel & data,MessageParcel & reply)492 int SceneSessionManagerLiteStub::HandleUnlockSession(MessageParcel& data, MessageParcel& reply)
493 {
494 WLOGFD("run HandleUnlockSession!");
495 int32_t sessionId = 0;
496 if (!data.ReadInt32(sessionId)) {
497 TLOGE(WmsLogTag::WMS_LIFE, "Read sessionId fail");
498 return ERR_TRANSACTION_FAILED;
499 }
500 WSError ret = UnlockSession(sessionId);
501 reply.WriteUint32(static_cast<uint32_t>(ret));
502 return ERR_NONE;
503 }
504
HandleMoveSessionsToForeground(MessageParcel & data,MessageParcel & reply)505 int SceneSessionManagerLiteStub::HandleMoveSessionsToForeground(MessageParcel& data, MessageParcel& reply)
506 {
507 WLOGFD("run HandleMoveSessionsToForeground!");
508 std::vector<int32_t> sessionIds;
509 data.ReadInt32Vector(&sessionIds);
510 int32_t topSessionId = 0;
511 if (!data.ReadInt32(topSessionId)) {
512 TLOGE(WmsLogTag::WMS_LIFE, "Read topSessionId fail");
513 return ERR_TRANSACTION_FAILED;
514 }
515 const WSError &ret = MoveSessionsToForeground(sessionIds, topSessionId);
516 reply.WriteUint32(static_cast<uint32_t>(ret));
517 return ERR_NONE;
518 }
519
HandleMoveSessionsToBackground(MessageParcel & data,MessageParcel & reply)520 int SceneSessionManagerLiteStub::HandleMoveSessionsToBackground(MessageParcel& data, MessageParcel& reply)
521 {
522 WLOGFD("run HandleMoveSessionsToBackground!");
523 std::vector<int32_t> sessionIds;
524 data.ReadInt32Vector(&sessionIds);
525 std::vector<int32_t> result;
526 data.ReadInt32Vector(&result);
527 const WSError &ret = MoveSessionsToBackground(sessionIds, result);
528 reply.WriteInt32Vector(result);
529 reply.WriteUint32(static_cast<uint32_t>(ret));
530 return ERR_NONE;
531 }
532
HandleGetFocusSessionInfo(MessageParcel & data,MessageParcel & reply)533 int SceneSessionManagerLiteStub::HandleGetFocusSessionInfo(MessageParcel& data, MessageParcel& reply)
534 {
535 TLOGI(WmsLogTag::WMS_FOCUS, "run");
536 uint64_t displayId = 0;
537 if (!data.ReadUint64(displayId)) {
538 TLOGE(WmsLogTag::WMS_FOCUS, "Failed to read displayId");
539 return ERR_INVALID_DATA;
540 }
541 FocusChangeInfo focusInfo;
542 GetFocusWindowInfo(focusInfo, displayId);
543 TLOGI(WmsLogTag::WMS_FOCUS, "start reply");
544 reply.WriteParcelable(&focusInfo);
545 return ERR_NONE;
546 }
547
HandleCheckWindowId(MessageParcel & data,MessageParcel & reply)548 int SceneSessionManagerLiteStub::HandleCheckWindowId(MessageParcel& data, MessageParcel& reply)
549 {
550 WLOGFI("run HandleCheckWindowId!");
551 int32_t windowId = INVALID_WINDOW_ID;
552 if (!data.ReadInt32(windowId)) {
553 WLOGE("Failed to readInt32 windowId");
554 return ERR_INVALID_DATA;
555 }
556 int32_t pid = INVALID_PID;
557 WMError errCode = CheckWindowId(windowId, pid);
558 if (errCode != WMError::WM_OK) {
559 WLOGE("Failed to checkWindowId(%{public}d)", pid);
560 return ERR_INVALID_DATA;
561 }
562 if (!reply.WriteInt32(pid)) {
563 WLOGE("Failed to WriteInt32 pid");
564 return ERR_INVALID_DATA;
565 }
566 return ERR_NONE;
567 }
568
HandleCheckUIExtensionCreation(MessageParcel & data,MessageParcel & reply)569 int SceneSessionManagerLiteStub::HandleCheckUIExtensionCreation(MessageParcel& data, MessageParcel& reply)
570 {
571 TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: called");
572
573 int32_t windowId = INVALID_WINDOW_ID;
574 if (!data.ReadInt32(windowId)) {
575 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to get windowId");
576 return ERR_INVALID_DATA;
577 }
578
579 uint32_t token = -1;
580 if (!data.ReadUint32(token)) {
581 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to get token");
582 return ERR_INVALID_DATA;
583 }
584
585 int32_t extAbilityTypeValue = -1;
586 if (!data.ReadInt32(extAbilityTypeValue)) {
587 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to get extensionAbilityType");
588 return ERR_INVALID_DATA;
589 }
590 if (extAbilityTypeValue < 0) {
591 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to get extensionAbilityType(out of range)");
592 return ERR_INVALID_DATA;
593 }
594 auto extAbilityType = static_cast<AppExecFwk::ExtensionAbilityType>(extAbilityTypeValue);
595
596 sptr<AppExecFwk::ElementName> element = data.ReadParcelable<AppExecFwk::ElementName>();
597 if (!element) {
598 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to get element");
599 return ERR_INVALID_DATA;
600 }
601
602 int32_t pid = INVALID_PID;
603 WMError errCode = CheckUIExtensionCreation(windowId, token, *element, extAbilityType, pid);
604 TLOGD(WmsLogTag::WMS_UIEXT, "UIExtOnLock: ret %{public}u", errCode);
605
606 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
607 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write errcode");
608 return ERR_INVALID_DATA;
609 }
610
611 if (!reply.WriteInt32(pid)) {
612 TLOGE(WmsLogTag::WMS_UIEXT, "UIExtOnLock: Failed to write pid");
613 return ERR_INVALID_DATA;
614 }
615
616 return ERR_NONE;
617 }
618
HandleRegisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)619 int SceneSessionManagerLiteStub::HandleRegisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
620 {
621 uint32_t typeId = 0;
622 if (!data.ReadUint32(typeId) ||
623 typeId < static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS) ||
624 typeId >= static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) {
625 return ERR_INVALID_DATA;
626 }
627 WindowManagerAgentType type = static_cast<WindowManagerAgentType>(typeId);
628 TLOGI(WmsLogTag::DEFAULT, "type=%{public}u", typeId);
629 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
630 sptr<IWindowManagerAgent> windowManagerAgentProxy =
631 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
632 WMError errCode = RegisterWindowManagerAgent(type, windowManagerAgentProxy);
633 reply.WriteInt32(static_cast<int32_t>(errCode));
634 return ERR_NONE;
635 }
636
HandleUnregisterWindowManagerAgent(MessageParcel & data,MessageParcel & reply)637 int SceneSessionManagerLiteStub::HandleUnregisterWindowManagerAgent(MessageParcel& data, MessageParcel& reply)
638 {
639 uint32_t typeId = 0;
640 if (!data.ReadUint32(typeId) ||
641 typeId < static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS) ||
642 typeId >= static_cast<uint32_t>(WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_END)) {
643 return ERR_INVALID_DATA;
644 }
645 WindowManagerAgentType type = static_cast<WindowManagerAgentType>(typeId);
646 TLOGI(WmsLogTag::DEFAULT, "type=%{public}u", typeId);
647 sptr<IRemoteObject> windowManagerAgentObject = data.ReadRemoteObject();
648 sptr<IWindowManagerAgent> windowManagerAgentProxy =
649 iface_cast<IWindowManagerAgent>(windowManagerAgentObject);
650 WMError errCode = UnregisterWindowManagerAgent(type, windowManagerAgentProxy);
651 reply.WriteInt32(static_cast<int32_t>(errCode));
652 return ERR_NONE;
653 }
654
HandleListWindowInfo(MessageParcel & data,MessageParcel & reply)655 int SceneSessionManagerLiteStub::HandleListWindowInfo(MessageParcel& data, MessageParcel& reply)
656 {
657 WindowInfoOption windowInfoOption;
658 uint8_t windowInfoFilterOptionValue = static_cast<WindowInfoFilterOptionDataType>(WindowInfoFilterOption::ALL);
659 if (!data.ReadUint8(windowInfoFilterOptionValue)) {
660 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowInfoFilterOption");
661 return ERR_INVALID_DATA;
662 }
663 windowInfoOption.windowInfoFilterOption = static_cast<WindowInfoFilterOption>(windowInfoFilterOptionValue);
664 uint8_t windowInfoTypeOptionValue = static_cast<WindowInfoTypeOptionDataType>(WindowInfoTypeOption::ALL);
665 if (!data.ReadUint8(windowInfoTypeOptionValue)) {
666 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowInfoTypeOption");
667 return ERR_INVALID_DATA;
668 }
669 windowInfoOption.windowInfoTypeOption = static_cast<WindowInfoTypeOption>(windowInfoTypeOptionValue);
670 if (!data.ReadUint64(windowInfoOption.displayId)) {
671 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read displayId");
672 return ERR_INVALID_DATA;
673 }
674 if (!data.ReadInt32(windowInfoOption.windowId)) {
675 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to read windowId");
676 return ERR_INVALID_DATA;
677 }
678 std::vector<sptr<WindowInfo>> infos;
679 WMError errCode = ListWindowInfo(windowInfoOption, infos);
680 if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowInfo>(reply, infos)) {
681 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Failed to write window info");
682 return ERR_INVALID_DATA;
683 }
684 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
685 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Write errCode fail");
686 return ERR_INVALID_DATA;
687 }
688 return ERR_NONE;
689 }
690
HandleGetVisibilityWindowInfo(MessageParcel & data,MessageParcel & reply)691 int SceneSessionManagerLiteStub::HandleGetVisibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
692 {
693 std::vector<sptr<WindowVisibilityInfo>> infos;
694 WMError errCode = GetVisibilityWindowInfo(infos);
695 if (!MarshallingHelper::MarshallingVectorParcelableObj<WindowVisibilityInfo>(reply, infos)) {
696 WLOGFE("Write visibility window infos failed");
697 return -1;
698 }
699 reply.WriteInt32(static_cast<int32_t>(errCode));
700 return ERR_NONE;
701 }
702
HandleGetWindowModeType(MessageParcel & data,MessageParcel & reply)703 int SceneSessionManagerLiteStub::HandleGetWindowModeType(MessageParcel& data, MessageParcel& reply)
704 {
705 WindowModeType windowModeType = Rosen::WindowModeType::WINDOW_MODE_OTHER;
706 WMError errCode = GetWindowModeType(windowModeType);
707 WLOGFI("run HandleGetWindowModeType, windowModeType:%{public}d!", static_cast<int32_t>(windowModeType));
708 if (!reply.WriteUint32(static_cast<int32_t>(windowModeType))) {
709 WLOGE("Failed to WriteBool");
710 return ERR_INVALID_DATA;
711 }
712 reply.WriteInt32(static_cast<int32_t>(errCode));
713 return ERR_NONE;
714 }
715
HandleGetMainWinodowInfo(MessageParcel & data,MessageParcel & reply)716 int SceneSessionManagerLiteStub::HandleGetMainWinodowInfo(MessageParcel& data, MessageParcel& reply)
717 {
718 TLOGI(WmsLogTag::WMS_MAIN, "run HandleGetMainWinodowInfo lite");
719 int32_t topN = 0;
720 if (!data.ReadInt32(topN)) {
721 TLOGE(WmsLogTag::WMS_MAIN, "failed to read topN");
722 return ERR_INVALID_DATA;
723 }
724 TLOGD(WmsLogTag::WMS_MAIN, "topN :%{public}d", topN);
725 std::vector<MainWindowInfo> topNInfos;
726 WMError errCode = GetMainWindowInfos(topN, topNInfos);
727 if ((topNInfos.size() <= 0) || (topNInfos.size() >= MAX_TOPN_INFO_SIZE)) {
728 return ERR_INVALID_DATA;
729 }
730 reply.WriteInt32(topNInfos.size());
731 for (auto& it : topNInfos) {
732 if (!reply.WriteParcelable(&it)) {
733 TLOGE(WmsLogTag::WMS_MAIN, "write topNinfo fail");
734 return ERR_INVALID_DATA;
735 }
736
737 TLOGI(WmsLogTag::WMS_MAIN, "pid %{public}d, name %{public}s",
738 it.pid_, it.bundleName_.c_str());
739 }
740
741 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
742 return ERR_INVALID_DATA;
743 }
744
745 return ERR_NONE;
746 }
747
HandleGetCallingWindowInfo(MessageParcel & data,MessageParcel & reply)748 int SceneSessionManagerLiteStub::HandleGetCallingWindowInfo(MessageParcel& data, MessageParcel& reply)
749 {
750 TLOGD(WmsLogTag::WMS_KEYBOARD, "In");
751 sptr<CallingWindowInfo> callingWindowInfo = data.ReadParcelable<CallingWindowInfo>();
752 if (callingWindowInfo == nullptr) {
753 TLOGE(WmsLogTag::WMS_KEYBOARD, "Read callingWindowInfo failed");
754 return ERR_INVALID_DATA;
755 }
756 WMError ret = GetCallingWindowInfo(*callingWindowInfo);
757 if (ret != WMError::WM_OK) {
758 TLOGE(WmsLogTag::WMS_KEYBOARD, "Get callingWindowInfo failed, id: %{public}d, userId: %{public}d",
759 callingWindowInfo->windowId_, callingWindowInfo->userId_);
760 return ERR_INVALID_DATA;
761 }
762 if (!reply.WriteInt32(static_cast<int32_t>(ret)) || !reply.WriteParcelable(callingWindowInfo)) {
763 TLOGE(WmsLogTag::WMS_KEYBOARD, "Write callingWindowInfo failed, id: %{public}d, userId: %{public}d",
764 callingWindowInfo->windowId_, callingWindowInfo->userId_);
765 return ERR_INVALID_DATA;
766 }
767 return ERR_NONE;
768 }
769
HandleGetAllMainWindowInfos(MessageParcel & data,MessageParcel & reply)770 int SceneSessionManagerLiteStub::HandleGetAllMainWindowInfos(MessageParcel& data, MessageParcel& reply)
771 {
772 std::vector<MainWindowInfo> infos;
773 WMError errCode = GetAllMainWindowInfos(infos);
774 reply.WriteInt32(infos.size());
775 for (auto& info : infos) {
776 if (!reply.WriteParcelable(&info)) {
777 TLOGE(WmsLogTag::WMS_MAIN, "write main window info fail");
778 return ERR_INVALID_DATA;
779 }
780 }
781 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
782 return ERR_INVALID_DATA;
783 }
784 return ERR_NONE;
785 }
786
HandleClearMainSessions(MessageParcel & data,MessageParcel & reply)787 int SceneSessionManagerLiteStub::HandleClearMainSessions(MessageParcel& data, MessageParcel& reply)
788 {
789 std::vector<int32_t> persistentIds;
790 std::vector<int32_t> clearFailedIds;
791 if (!data.ReadInt32Vector(&persistentIds)) {
792 TLOGE(WmsLogTag::WMS_MAIN, "failed to read persistentIds.");
793 return ERR_INVALID_DATA;
794 }
795 WMError errCode = ClearMainSessions(persistentIds, clearFailedIds);
796 if (!reply.WriteInt32Vector(clearFailedIds)) {
797 TLOGE(WmsLogTag::WMS_MAIN, "write clearFailedIds fail.");
798 return ERR_INVALID_DATA;
799 }
800 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
801 return ERR_INVALID_DATA;
802 }
803 return ERR_NONE;
804 }
805
HandleRaiseWindowToTop(MessageParcel & data,MessageParcel & reply)806 int SceneSessionManagerLiteStub::HandleRaiseWindowToTop(MessageParcel& data, MessageParcel& reply)
807 {
808 auto persistentId = 0;
809 if (!data.ReadInt32(persistentId)) {
810 TLOGE(WmsLogTag::WMS_HIERARCHY, "read persistentId failed");
811 return ERR_INVALID_DATA;
812 }
813 WSError errCode = RaiseWindowToTop(persistentId);
814 reply.WriteUint32(static_cast<uint32_t>(errCode));
815 return ERR_NONE;
816 }
817
HandleRegisterCollaborator(MessageParcel & data,MessageParcel & reply)818 int SceneSessionManagerLiteStub::HandleRegisterCollaborator(MessageParcel& data, MessageParcel& reply)
819 {
820 TLOGD(WmsLogTag::WMS_MAIN, "called.");
821 int32_t type = 0;
822 if (!data.ReadInt32(type)) {
823 TLOGE(WmsLogTag::WMS_LIFE, "Read type fail");
824 return ERR_TRANSACTION_FAILED;
825 }
826 sptr<IRemoteObject> collaboratorObject = data.ReadRemoteObject();
827 if (collaboratorObject == nullptr) {
828 TLOGE(WmsLogTag::WMS_MAIN, "collaboratorObject is null.");
829 return ERR_NULL_OBJECT;
830 }
831 sptr<AAFwk::IAbilityManagerCollaborator> collaborator =
832 iface_cast<AAFwk::IAbilityManagerCollaborator>(collaboratorObject);
833 WSError ret = RegisterIAbilityManagerCollaborator(type, collaborator);
834 reply.WriteInt32(static_cast<int32_t>(ret));
835 return ERR_NONE;
836 }
837
HandleUnregisterCollaborator(MessageParcel & data,MessageParcel & reply)838 int SceneSessionManagerLiteStub::HandleUnregisterCollaborator(MessageParcel& data, MessageParcel& reply)
839 {
840 TLOGD(WmsLogTag::WMS_MAIN, "called.");
841 int32_t type = 0;
842 if (!data.ReadInt32(type)) {
843 TLOGE(WmsLogTag::WMS_LIFE, "Read type fail");
844 return ERR_TRANSACTION_FAILED;
845 }
846 WSError ret = UnregisterIAbilityManagerCollaborator(type);
847 reply.WriteInt32(static_cast<int32_t>(ret));
848 return ERR_NONE;
849 }
850
HandleGetWindowStyleType(MessageParcel & data,MessageParcel & reply)851 int SceneSessionManagerLiteStub::HandleGetWindowStyleType(MessageParcel& data, MessageParcel& reply)
852 {
853 WindowStyleType windowStyleType = Rosen::WindowStyleType::WINDOW_STYLE_DEFAULT;
854 WMError errCode = GetWindowStyleType(windowStyleType);
855 TLOGI(WmsLogTag::WMS_MAIN, "windowStyleType:%{public}d!", static_cast<int32_t>(windowStyleType));
856 if (!reply.WriteUint32(static_cast<int32_t>(windowStyleType))) {
857 TLOGE(WmsLogTag::WMS_MAIN, "Failed to WriteBool");
858 return ERR_INVALID_DATA;
859 }
860 reply.WriteInt32(static_cast<int32_t>(errCode));
861 return ERR_NONE;
862 }
863
HandleTerminateSessionByPersistentId(MessageParcel & data,MessageParcel & reply)864 int SceneSessionManagerLiteStub::HandleTerminateSessionByPersistentId(MessageParcel& data, MessageParcel& reply)
865 {
866 TLOGD(WmsLogTag::WMS_LIFE, "In!");
867 int32_t persistentId;
868 if (!data.ReadInt32(persistentId)) {
869 TLOGE(WmsLogTag::WMS_LIFE, "read persistentId failed");
870 return ERR_INVALID_DATA;
871 }
872 WMError errCode = TerminateSessionByPersistentId(persistentId);
873 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
874 return ERR_INVALID_DATA;
875 }
876 return ERR_NONE;
877 }
878
HandleCloseTargetFloatWindow(MessageParcel & data,MessageParcel & reply)879 int SceneSessionManagerLiteStub::HandleCloseTargetFloatWindow(MessageParcel& data, MessageParcel& reply)
880 {
881 std::string bundleName = data.ReadString();
882 CloseTargetFloatWindow(bundleName);
883 return ERR_NONE;
884 }
885
HandleCloseTargetPiPWindow(MessageParcel & data,MessageParcel & reply)886 int SceneSessionManagerLiteStub::HandleCloseTargetPiPWindow(MessageParcel& data, MessageParcel& reply)
887 {
888 std::string bundleName = data.ReadString();
889 WMError errCode = CloseTargetPiPWindow(bundleName);
890 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
891 return ERR_INVALID_DATA;
892 }
893 return ERR_NONE;
894 }
895
HandleGetCurrentPiPWindowInfo(MessageParcel & data,MessageParcel & reply)896 int SceneSessionManagerLiteStub::HandleGetCurrentPiPWindowInfo(MessageParcel& data, MessageParcel& reply)
897 {
898 std::string bundleName;
899 WMError errCode = GetCurrentPiPWindowInfo(bundleName);
900 if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
901 return ERR_INVALID_DATA;
902 }
903 if (!reply.WriteString(bundleName)) {
904 return ERR_INVALID_DATA;
905 }
906 return ERR_NONE;
907 }
908
HandleGetRootMainWindowId(MessageParcel & data,MessageParcel & reply)909 int SceneSessionManagerLiteStub::HandleGetRootMainWindowId(MessageParcel &data, MessageParcel &reply)
910 {
911 TLOGI(WmsLogTag::WMS_MAIN, "call");
912 int32_t persistentId = INVALID_WINDOW_ID;
913 if (!data.ReadInt32(persistentId)) {
914 TLOGE(WmsLogTag::WMS_MAIN, "Failed to readInt32 windowId");
915 return ERR_INVALID_DATA;
916 }
917 int32_t hostWindowId = INVALID_WINDOW_ID;
918 WMError errCode = GetRootMainWindowId(persistentId, hostWindowId);
919 if (errCode != WMError::WM_OK) {
920 TLOGE(WmsLogTag::WMS_MAIN, "Failed to GetRootMainWindowId(%{public}d)", hostWindowId);
921 return ERR_INVALID_DATA;
922 }
923 if (!reply.WriteInt32(hostWindowId)) {
924 TLOGE(WmsLogTag::WMS_MAIN, "Failed to WriteInt32 hostWindowId");
925 return ERR_INVALID_DATA;
926 }
927 return ERR_NONE;
928 }
929
HandleGetAccessibilityWindowInfo(MessageParcel & data,MessageParcel & reply)930 int SceneSessionManagerLiteStub::HandleGetAccessibilityWindowInfo(MessageParcel& data, MessageParcel& reply)
931 {
932 std::vector<sptr<AccessibilityWindowInfo>> infos;
933 WMError errCode = GetAccessibilityWindowInfo(infos);
934 if (!MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(reply, infos)) {
935 WLOGFE("Write window infos failed.");
936 return ERR_TRANSACTION_FAILED;
937 }
938 reply.WriteInt32(static_cast<int32_t>(errCode));
939 return ERR_NONE;
940 }
941
HandleNotifyAppUseControlList(MessageParcel & data,MessageParcel & reply)942 int SceneSessionManagerLiteStub::HandleNotifyAppUseControlList(MessageParcel& data, MessageParcel& reply)
943 {
944 TLOGD(WmsLogTag::WMS_LIFE, "In!");
945 uint8_t controlType = 0;
946 if (!data.ReadUint8(controlType) || controlType <= static_cast<uint8_t>(ControlAppType::CONTROL_APP_TYPE_BEGIN) ||
947 controlType >= static_cast<uint8_t>(ControlAppType::CONTROL_APP_TYPE_END)) {
948 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read controlType");
949 return ERR_INVALID_DATA;
950 }
951 ControlAppType type = static_cast<ControlAppType>(controlType);
952
953 int32_t userId;
954 if (!data.ReadInt32(userId)) {
955 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read userId");
956 return ERR_INVALID_DATA;
957 }
958
959 int32_t size = 0;
960 if (!data.ReadInt32(size) || size < 0 || size > MAX_CONTROL_APP_INFO) {
961 TLOGE(WmsLogTag::WMS_LIFE, "Read controlList size failed");
962 return ERR_INVALID_DATA;
963 }
964 TLOGD(WmsLogTag::WMS_LIFE, "app control list size: %{public}d", size);
965 std::vector<AppUseControlInfo> controlList;
966 controlList.resize(size);
967 for (int32_t i = 0; i < size; i++) {
968 if (!data.ReadString(controlList[i].bundleName_) ||
969 !data.ReadInt32(controlList[i].appIndex_) ||
970 !data.ReadBool(controlList[i].isNeedControl_) ||
971 !data.ReadBool(controlList[i].isControlRecentOnly_)) {
972 TLOGE(WmsLogTag::WMS_LIFE, "Read controlList failed");
973 return ERR_INVALID_DATA;
974 }
975 }
976
977 WSError ret = NotifyAppUseControlList(type, userId, controlList);
978 reply.WriteInt32(static_cast<int32_t>(ret));
979 return ERR_NONE;
980 }
981
HandleMinimizeMainSession(MessageParcel & data,MessageParcel & reply)982 int SceneSessionManagerLiteStub::HandleMinimizeMainSession(MessageParcel& data, MessageParcel& reply)
983 {
984 TLOGD(WmsLogTag::WMS_LIFE, "in");
985 std::string bundleName;
986 if (!data.ReadString(bundleName)) {
987 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read bundleName");
988 return ERR_INVALID_DATA;
989 }
990 int32_t appIndex = 0;
991 if (!data.ReadInt32(appIndex)) {
992 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read appIndex");
993 return ERR_INVALID_DATA;
994 }
995 int32_t userId = 0;
996 if (!data.ReadInt32(userId)) {
997 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read userId");
998 return ERR_INVALID_DATA;
999 }
1000 WMError ret = MinimizeMainSession(bundleName, appIndex, userId);
1001 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1002 TLOGE(WmsLogTag::WMS_LIFE, "Write ret failed.");
1003 return ERR_INVALID_DATA;
1004 }
1005 return ERR_NONE;
1006 }
1007
HandleLockSessionByAbilityInfo(MessageParcel & data,MessageParcel & reply)1008 int SceneSessionManagerLiteStub::HandleLockSessionByAbilityInfo(MessageParcel& data, MessageParcel& reply)
1009 {
1010 TLOGD(WmsLogTag::WMS_LIFE, "in");
1011 AbilityInfoBase abilityInfo;
1012 if (!data.ReadString(abilityInfo.bundleName)) {
1013 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read bundleName");
1014 return ERR_INVALID_DATA;
1015 }
1016 if (!data.ReadString(abilityInfo.moduleName)) {
1017 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read moduleName");
1018 return ERR_INVALID_DATA;
1019 }
1020 if (!data.ReadString(abilityInfo.abilityName)) {
1021 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read abilityName");
1022 return ERR_INVALID_DATA;
1023 }
1024 if (!data.ReadInt32(abilityInfo.appIndex)) {
1025 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read appIndex");
1026 return ERR_INVALID_DATA;
1027 }
1028 bool isLock = false;
1029 if (!data.ReadBool(isLock)) {
1030 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read isLock");
1031 return ERR_INVALID_DATA;
1032 }
1033 WMError ret = LockSessionByAbilityInfo(abilityInfo, isLock);
1034 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1035 return ERR_INVALID_DATA;
1036 }
1037 return ERR_NONE;
1038 }
1039
HandleHasFloatingWindowForeground(MessageParcel & data,MessageParcel & reply)1040 int SceneSessionManagerLiteStub::HandleHasFloatingWindowForeground(MessageParcel& data, MessageParcel& reply)
1041 {
1042 TLOGD(WmsLogTag::WMS_SYSTEM, "in");
1043 sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
1044 if (!abilityToken) {
1045 TLOGE(WmsLogTag::WMS_SYSTEM, "AbilityToken is null.");
1046 return ERR_INVALID_DATA;
1047 }
1048 bool hasOrNot = false;
1049 WMError errCode = HasFloatingWindowForeground(abilityToken, hasOrNot);
1050 if (!reply.WriteBool(hasOrNot)) {
1051 TLOGE(WmsLogTag::WMS_SYSTEM, "Write hasOrNot failed.");
1052 return ERR_INVALID_DATA;
1053 }
1054 if (!reply.WriteUint32(static_cast<uint32_t>(errCode))) {
1055 TLOGE(WmsLogTag::WMS_SYSTEM, "Write errCode failed.");
1056 return ERR_INVALID_DATA;
1057 }
1058 return ERR_NONE;
1059 }
1060
HandleRegisterSessionLifecycleListenerByIds(MessageParcel & data,MessageParcel & reply)1061 int SceneSessionManagerLiteStub::HandleRegisterSessionLifecycleListenerByIds(MessageParcel& data, MessageParcel& reply)
1062 {
1063 TLOGD(WmsLogTag::WMS_LIFE, "in");
1064 sptr<IRemoteObject> listenerObject = data.ReadRemoteObject();
1065 if (listenerObject == nullptr) {
1066 TLOGE(WmsLogTag::WMS_LIFE, "remote object is nullptr!");
1067 return ERR_INVALID_DATA;
1068 }
1069 sptr<ISessionLifecycleListener> listener = iface_cast<ISessionLifecycleListener>(listenerObject);
1070 if (listener == nullptr) {
1071 TLOGE(WmsLogTag::WMS_LIFE, "listener is nullptr!");
1072 return ERR_INVALID_DATA;
1073 }
1074 std::vector<int32_t> persistentIdList;
1075 if (!data.ReadInt32Vector(&persistentIdList)) {
1076 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read persistentIdList");
1077 return ERR_INVALID_DATA;
1078 }
1079 WMError ret = RegisterSessionLifecycleListenerByIds(listener, persistentIdList);
1080 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1081 return ERR_INVALID_DATA;
1082 }
1083 return ERR_NONE;
1084 }
1085
HandleRegisterSessionLifecycleListenerByBundles(MessageParcel & data,MessageParcel & reply)1086 int SceneSessionManagerLiteStub::HandleRegisterSessionLifecycleListenerByBundles(
1087 MessageParcel& data, MessageParcel& reply)
1088 {
1089 TLOGD(WmsLogTag::WMS_LIFE, "in");
1090 sptr<IRemoteObject> listenerObject = data.ReadRemoteObject();
1091 if (listenerObject == nullptr) {
1092 TLOGE(WmsLogTag::WMS_LIFE, "remote object is nullptr!");
1093 return ERR_INVALID_DATA;
1094 }
1095 sptr<ISessionLifecycleListener> listener = iface_cast<ISessionLifecycleListener>(listenerObject);
1096 if (listener == nullptr) {
1097 TLOGE(WmsLogTag::WMS_LIFE, "listener is nullptr!");
1098 return ERR_INVALID_DATA;
1099 }
1100 std::vector<std::string> bundleNameList;
1101 if (!data.ReadStringVector(&bundleNameList)) {
1102 TLOGE(WmsLogTag::WMS_LIFE, "Failed to read bundleNameList");
1103 return ERR_INVALID_DATA;
1104 }
1105 WMError ret = RegisterSessionLifecycleListenerByBundles(listener, bundleNameList);
1106 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1107 return ERR_INVALID_DATA;
1108 }
1109 return ERR_NONE;
1110 }
1111
HandleUnregisterSessionLifecycleListener(MessageParcel & data,MessageParcel & reply)1112 int SceneSessionManagerLiteStub::HandleUnregisterSessionLifecycleListener(MessageParcel& data, MessageParcel& reply)
1113 {
1114 TLOGD(WmsLogTag::WMS_LIFE, "in");
1115 sptr<IRemoteObject> listenerObject = data.ReadRemoteObject();
1116 if (listenerObject == nullptr) {
1117 TLOGE(WmsLogTag::WMS_LIFE, "remote object is nullptr!");
1118 return ERR_INVALID_DATA;
1119 }
1120 sptr<ISessionLifecycleListener> listener = iface_cast<ISessionLifecycleListener>(listenerObject);
1121 if (listener == nullptr) {
1122 TLOGE(WmsLogTag::WMS_LIFE, "listener is nullptr!");
1123 return ERR_INVALID_DATA;
1124 }
1125 WMError ret = UnregisterSessionLifecycleListener(listener);
1126 if (!reply.WriteInt32(static_cast<int32_t>(ret))) {
1127 return ERR_INVALID_DATA;
1128 }
1129 return ERR_NONE;
1130 }
1131 } // namespace OHOS::Rosen
1132