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/host/include/zidl/session_stub.h"
17 
18 #include "ability_start_setting.h"
19 #include <ipc_types.h>
20 #include <ui/rs_surface_node.h>
21 #include "want.h"
22 #include "pointer_event.h"
23 #include "key_event.h"
24 
25 #include "parcel/accessibility_event_info_parcel.h"
26 #include "process_options.h"
27 #include "start_window_option.h"
28 #include "session/host/include/zidl/session_ipc_interface_code.h"
29 #include "window_manager_hilog.h"
30 #include "wm_common.h"
31 
32 namespace OHOS::Accessibility {
33 class AccessibilityEventInfo;
34 }
35 namespace OHOS::Rosen {
36 namespace {
37 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStub" };
38 } // namespace
39 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int SessionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
41 {
42     WLOGFD("Scene session on remote request!, code: %{public}u", code);
43     if (data.ReadInterfaceToken() != GetDescriptor()) {
44         WLOGFE("Failed to check interface token!");
45         return ERR_TRANSACTION_FAILED;
46     }
47 
48     return ProcessRemoteRequest(code, data, reply, option);
49 }
50 
ProcessRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int SessionStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
52     MessageOption& option)
53 {
54     switch (code) {
55         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CONNECT):
56             return HandleConnect(data, reply);
57         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FOREGROUND):
58             return HandleForeground(data, reply);
59         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKGROUND):
60             return HandleBackground(data, reply);
61         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DISCONNECT):
62             return HandleDisconnect(data, reply);
63         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SHOW):
64             return HandleShow(data, reply);
65         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_HIDE):
66             return HandleHide(data, reply);
67         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DRAWING_COMPLETED):
68             return HandleDrawingCompleted(data, reply);
69         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_APP_REMOVE_STARTING_WINDOW):
70             return HandleRemoveStartingWindow(data, reply);
71         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED):
72             return HandleUpdateRectChangeListenerRegistered(data, reply);
73         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SESSION_EVENT):
74             return HandleSessionEvent(data, reply);
75         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SYNC_SESSION_EVENT):
76             return HandleSyncSessionEvent(data, reply);
77         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT):
78             return HandleUpdateSessionRect(data, reply);
79         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_GLOBAL_SCALED_RECT):
80             return HandleGetGlobalScaledRect(data, reply);
81         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP):
82             return HandleRaiseToAppTop(data, reply);
83         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKPRESSED):
84             return HandleBackPressed(data, reply);
85         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MARK_PROCESSED):
86             return HandleMarkProcessed(data, reply);
87         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_MAXIMIZE_MODE):
88             return HandleSetGlobalMaximizeMode(data, reply);
89         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_MAXIMIZE_MODE):
90             return HandleGetGlobalMaximizeMode(data, reply);
91         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NEED_AVOID):
92             return HandleNeedAvoid(data, reply);
93         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_AVOID_AREA):
94             return HandleGetAvoidAreaByType(data, reply);
95         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_ALL_AVOID_AREAS):
96             return HandleGetAllAvoidAreas(data, reply);
97         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_ASPECT_RATIO):
98             return HandleSetAspectRatio(data, reply);
99         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG):
100             return HandleSetWindowAnimationFlag(data, reply);
101         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION):
102             return HandleUpdateWindowSceneAfterCustomAnimation(data, reply);
103         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_LANDSCAPE_MULTI_WINDOW):
104             return HandleSetLandscapeMultiWindow(data, reply);
105         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_ABOVE_TARGET):
106             return HandleRaiseAboveTarget(data, reply);
107         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_APP_MAIN_WINDOW):
108             return HandleRaiseAppMainWindowToTop(data, reply);
109         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CHANGE_SESSION_VISIBILITY_WITH_STATUS_BAR):
110             return HandleChangeSessionVisibilityWithStatusBar(data, reply);
111         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ACTIVE_PENDING_SESSION):
112             return HandlePendingSessionActivation(data, reply);
113         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RESTORE_MAIN_WINDOW):
114             return HandleRestoreMainWindow(data, reply);
115         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TERMINATE):
116             return HandleTerminateSession(data, reply);
117         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_EXCEPTION):
118             return HandleSessionException(data, reply);
119         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_PROCESS_POINT_DOWN_SESSION):
120             return HandleProcessPointDownSession(data, reply);
121         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG):
122             return HandleSendPointerEvenForMoveDrag(data, reply);
123         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_IS_START_MOVING):
124             return HandleIsStartMoving(data, reply);
125         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SYSTEM_DRAG_ENABLE):
126             return HandleSetSystemEnableDrag(data, reply);
127         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CLIENT_RECT):
128             return HandleUpdateClientRect(data, reply);
129         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID):
130             return HandleSetCallingSessionId(data, reply);
131         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT):
132             return HandleSetCustomDecorHeight(data, reply);
133         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_PROPERTY):
134             return HandleUpdatePropertyByAction(data, reply);
135         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ADJUST_KEYBOARD_LAYOUT):
136             return HandleAdjustKeyboardLayout(data, reply);
137         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT):
138             return HandleTransferAbilityResult(data, reply);
139         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_EXTENSION_DATA):
140             return HandleTransferExtensionData(data, reply);
141         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_ASYNC_ON):
142             return HandleNotifyAsyncOn(data, reply);
143         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_SYNC_ON):
144             return HandleNotifySyncOn(data, reply);
145         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DIED):
146             return HandleNotifyExtensionDied(data, reply);
147         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_TIMEOUT):
148             return HandleNotifyExtensionTimeout(data, reply);
149         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRIGGER_BIND_MODAL_UI_EXTENSION):
150             return HandleTriggerBindModalUIExtension(data, reply);
151         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_REPORT_ACCESSIBILITY_EVENT):
152             return HandleTransferAccessibilityEvent(data, reply);
153         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE):
154             return HandleNotifyPiPWindowPrepareClose(data, reply);
155         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT):
156             return HandleUpdatePiPRect(data, reply);
157         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_CONTROL_STATUS):
158             return HandleUpdatePiPControlStatus(data, reply);
159         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_AUTOSTART_PIP):
160             return HandleSetAutoStartPiP(data, reply);
161         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE):
162             return HandleLayoutFullScreenChange(data, reply);
163         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DEFAULT_DENSITY_ENABLED):
164             return HandleDefaultDensityEnabled(data, reply);
165         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TITLE_AND_DOCK_HOVER_SHOW_CHANGE):
166             return HandleTitleAndDockHoverShowChange(data, reply);
167         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG):
168             return HandleGetAppForceLandscapeConfig(data, reply);
169         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_DIALOG_SESSION_BACKGESTURE_ENABLE):
170             return HandleSetDialogSessionBackGestureEnabled(data, reply);
171         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FRAME_LAYOUT_FINISH):
172             return HandleNotifyFrameLayoutFinish(data, reply);
173         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_EVENT_ASYNC):
174             return HandleNotifyExtensionEventAsync(data, reply);
175         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_REQUEST_FOCUS):
176             return HandleRequestFocus(data, reply);
177         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_GESTURE_BACK_ENABLE):
178             return HandleSetGestureBackEnabled(data, reply);
179         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SUB_MODAL_TYPE_CHANGE):
180             return HandleNotifySubModalTypeChange(data, reply);
181         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MAIN_MODAL_TYPE_CHANGE):
182             return HandleNotifyMainModalTypeChange(data, reply);
183         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_WINDOW_RECT_AUTO_SAVE):
184             return HandleSetWindowRectAutoSave(data, reply);
185         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DETACH_TO_DISPLAY):
186             return HandleNotifyExtensionDetachToDisplay(data, reply);
187         default:
188             WLOGFE("Failed to find function handler!");
189             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
190     }
191 }
192 
HandleSetWindowAnimationFlag(MessageParcel & data,MessageParcel & reply)193 int SessionStub::HandleSetWindowAnimationFlag(MessageParcel& data, MessageParcel& reply)
194 {
195     WLOGFD("HandleSetWindowAnimationFlag!");
196     bool isNeedWindowAnimationFlag = data.ReadBool();
197     WSError errCode = UpdateWindowAnimationFlag(isNeedWindowAnimationFlag);
198     reply.WriteUint32(static_cast<uint32_t>(errCode));
199     return ERR_NONE;
200 }
201 
HandleForeground(MessageParcel & data,MessageParcel & reply)202 int SessionStub::HandleForeground(MessageParcel& data, MessageParcel& reply)
203 {
204     WLOGFD("[WMSCom] Foreground!");
205     sptr<WindowSessionProperty> property = nullptr;
206     if (data.ReadBool()) {
207         property = data.ReadStrongParcelable<WindowSessionProperty>();
208         if (property == nullptr) {
209             return ERR_INVALID_DATA;
210         }
211     } else {
212         WLOGFW("[WMSCom] Property not exist!");
213         property = sptr<WindowSessionProperty>::MakeSptr();
214     }
215     bool isFromClient = data.ReadBool();
216     std::string identityToken;
217     if (!data.ReadString(identityToken)) {
218         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
219         return ERR_INVALID_DATA;
220     }
221     const WSError errCode = Foreground(property, isFromClient, identityToken);
222     reply.WriteUint32(static_cast<uint32_t>(errCode));
223     return ERR_NONE;
224 }
225 
HandleBackground(MessageParcel & data,MessageParcel & reply)226 int SessionStub::HandleBackground(MessageParcel& data, MessageParcel& reply)
227 {
228     WLOGFD("[WMSCom] Background!");
229     bool isFromClient = data.ReadBool();
230     std::string identityToken;
231     if (!data.ReadString(identityToken)) {
232         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
233         return ERR_INVALID_DATA;
234     }
235     const WSError errCode = Background(isFromClient, identityToken);
236     reply.WriteUint32(static_cast<uint32_t>(errCode));
237     return ERR_NONE;
238 }
239 
HandleDisconnect(MessageParcel & data,MessageParcel & reply)240 int SessionStub::HandleDisconnect(MessageParcel& data, MessageParcel& reply)
241 {
242     WLOGFD("Disconnect!");
243     bool isFromClient = data.ReadBool();
244     std::string identityToken;
245     if (!data.ReadString(identityToken)) {
246         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
247         return ERR_INVALID_DATA;
248     }
249     WSError errCode = Disconnect(isFromClient, identityToken);
250     reply.WriteUint32(static_cast<uint32_t>(errCode));
251     return ERR_NONE;
252 }
253 
HandleShow(MessageParcel & data,MessageParcel & reply)254 int SessionStub::HandleShow(MessageParcel& data, MessageParcel& reply)
255 {
256     WLOGFD("Show!");
257     sptr<WindowSessionProperty> property = nullptr;
258     if (data.ReadBool()) {
259         property = data.ReadStrongParcelable<WindowSessionProperty>();
260         if (property == nullptr) {
261             return ERR_INVALID_DATA;
262         }
263     } else {
264         WLOGFW("Property not exist!");
265         property = sptr<WindowSessionProperty>::MakeSptr();
266     }
267     WSError errCode = Show(property);
268     reply.WriteUint32(static_cast<uint32_t>(errCode));
269     return ERR_NONE;
270 }
271 
HandleHide(MessageParcel & data,MessageParcel & reply)272 int SessionStub::HandleHide(MessageParcel& data, MessageParcel& reply)
273 {
274     WLOGFD("Hide!");
275     WSError errCode = Hide();
276     reply.WriteUint32(static_cast<uint32_t>(errCode));
277     return ERR_NONE;
278 }
279 
HandleConnect(MessageParcel & data,MessageParcel & reply)280 int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply)
281 {
282     WLOGFD("Connect!");
283     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
284     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
285     sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
286     sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
287     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
288     if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
289         WLOGFE("Failed to read scene session stage object or event channel object!");
290         return ERR_INVALID_DATA;
291     }
292 
293     sptr<WindowSessionProperty> property = nullptr;
294     if (data.ReadBool()) {
295         property = data.ReadStrongParcelable<WindowSessionProperty>();
296         if (property == nullptr) {
297             return ERR_INVALID_DATA;
298         }
299     } else {
300         WLOGFW("Property not exist!");
301     }
302 
303     sptr<IRemoteObject> token = nullptr;
304     if (property && property->GetTokenState()) {
305         token = data.ReadRemoteObject();
306         if (token == nullptr) {
307             return ERR_INVALID_DATA;
308         }
309     } else {
310         WLOGI("accept token is nullptr");
311     }
312     std::string identityToken = data.ReadString();
313     SystemSessionConfig systemConfig;
314     WSError errCode = Connect(sessionStage, eventChannel, surfaceNode, systemConfig, property, token,
315         identityToken);
316     reply.WriteParcelable(&systemConfig);
317     if (property) {
318         reply.WriteInt32(property->GetPersistentId());
319         reply.WriteUint64(property->GetDisplayId());
320         bool needUpdate = property->GetIsNeedUpdateWindowMode();
321         reply.WriteBool(needUpdate);
322         if (needUpdate) {
323             reply.WriteUint32(static_cast<uint32_t>(property->GetWindowMode()));
324         }
325         property->SetIsNeedUpdateWindowMode(false);
326 
327         Rect winRect = property->GetWindowRect();
328         reply.WriteInt32(winRect.posX_);
329         reply.WriteInt32(winRect.posY_);
330         reply.WriteUint32(winRect.width_);
331         reply.WriteUint32(winRect.height_);
332         reply.WriteInt32(property->GetCollaboratorType());
333         reply.WriteBool(property->GetFullScreenStart());
334         std::vector<AppExecFwk::SupportWindowMode> supportWindowModes;
335         property->GetSupportWindowModes(supportWindowModes);
336         auto size = supportWindowModes.size();
337         if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
338             reply.WriteUint32(static_cast<uint32_t>(size));
339             for (decltype(size) i = 0; i < size; i++) {
340                 reply.WriteInt32(static_cast<int32_t>(supportWindowModes[i]));
341             }
342         } else {
343             reply.WriteUint32(0);
344         }
345         reply.WriteBool(property->GetCompatibleModeInPc());
346         reply.WriteInt32(property->GetCompatibleInPcPortraitWidth());
347         reply.WriteInt32(property->GetCompatibleInPcPortraitHeight());
348         reply.WriteInt32(property->GetCompatibleInPcLandscapeWidth());
349         reply.WriteInt32(property->GetCompatibleInPcLandscapeHeight());
350         reply.WriteBool(property->GetIsAppSupportPhoneInPc());
351         reply.WriteBool(property->GetIsSupportDragInPcCompatibleMode());
352         reply.WriteBool(property->GetIsPcAppInPad());
353         reply.WriteBool(property->GetCompatibleModeEnableInPad());
354         reply.WriteBool(property->GetDragEnabled());
355         reply.WriteUint32(static_cast<uint32_t>(property->GetRequestedOrientation()));
356     }
357     reply.WriteUint32(static_cast<uint32_t>(errCode));
358     return ERR_NONE;
359 }
360 
HandleNotifyFrameLayoutFinish(MessageParcel & data,MessageParcel & reply)361 int SessionStub::HandleNotifyFrameLayoutFinish(MessageParcel& data, MessageParcel& reply)
362 {
363     bool notifyListener = data.ReadBool();
364     WSRect rect = { data.ReadInt32(), data.ReadInt32(), data.ReadInt32(), data.ReadInt32() };
365     NotifyFrameLayoutFinishFromApp(notifyListener, rect);
366     return ERR_NONE;
367 }
368 
HandleDrawingCompleted(MessageParcel & data,MessageParcel & reply)369 int SessionStub::HandleDrawingCompleted(MessageParcel& data, MessageParcel& reply)
370 {
371     TLOGD(WmsLogTag::WMS_LIFE, "Called!");
372     const WSError errCode = DrawingCompleted();
373     reply.WriteInt32(static_cast<int32_t>(errCode));
374     return ERR_NONE;
375 }
376 
HandleRemoveStartingWindow(MessageParcel & data,MessageParcel & reply)377 int SessionStub::HandleRemoveStartingWindow(MessageParcel& data, MessageParcel& reply)
378 {
379     TLOGD(WmsLogTag::WMS_LIFE, "Called!");
380     WSError errCode = RemoveStartingWindow();
381     reply.WriteInt32(static_cast<int32_t>(errCode));
382     return ERR_NONE;
383 }
384 
HandleSessionEvent(MessageParcel & data,MessageParcel & reply)385 int SessionStub::HandleSessionEvent(MessageParcel& data, MessageParcel& reply)
386 {
387     uint32_t eventId = data.ReadUint32();
388     WLOGFD("HandleSessionEvent eventId: %{public}d", eventId);
389     WSError errCode = OnSessionEvent(static_cast<SessionEvent>(eventId));
390     reply.WriteUint32(static_cast<uint32_t>(errCode));
391     return ERR_NONE;
392 }
393 
HandleSyncSessionEvent(MessageParcel & data,MessageParcel & reply)394 int SessionStub::HandleSyncSessionEvent(MessageParcel& data, MessageParcel& reply)
395 {
396     uint32_t eventId = data.ReadUint32();
397     TLOGD(WmsLogTag::WMS_LAYOUT, "eventId: %{public}d", eventId);
398     WSError errCode = SyncSessionEvent(static_cast<SessionEvent>(eventId));
399     reply.WriteInt32(static_cast<int32_t>(errCode));
400     return ERR_NONE;
401 }
402 
HandleLayoutFullScreenChange(MessageParcel & data,MessageParcel & reply)403 int SessionStub::HandleLayoutFullScreenChange(MessageParcel& data, MessageParcel& reply)
404 {
405     bool isLayoutFullScreen = data.ReadBool();
406     TLOGD(WmsLogTag::WMS_LAYOUT, "isLayoutFullScreen: %{public}d", isLayoutFullScreen);
407     WSError errCode = OnLayoutFullScreenChange(isLayoutFullScreen);
408     reply.WriteUint32(static_cast<uint32_t>(errCode));
409     return ERR_NONE;
410 }
411 
HandleDefaultDensityEnabled(MessageParcel & data,MessageParcel & reply)412 int SessionStub::HandleDefaultDensityEnabled(MessageParcel& data, MessageParcel& reply)
413 {
414     bool isDefaultDensityEnabled = false;
415     if (!data.ReadBool(isDefaultDensityEnabled)) {
416         TLOGE(WmsLogTag::WMS_LAYOUT, "Read isDefaultDensityEnabled failed.");
417         return ERR_INVALID_DATA;
418     }
419     TLOGD(WmsLogTag::WMS_LAYOUT, "isDefaultDensityEnabled: %{public}d", isDefaultDensityEnabled);
420     WSError errCode = OnDefaultDensityEnabled(isDefaultDensityEnabled);
421     reply.WriteInt32(static_cast<int32_t>(errCode));
422     return ERR_NONE;
423 }
424 
HandleTitleAndDockHoverShowChange(MessageParcel & data,MessageParcel & reply)425 int SessionStub::HandleTitleAndDockHoverShowChange(MessageParcel& data, MessageParcel& reply)
426 {
427     bool isTitleHoverShown = true;
428     if (!data.ReadBool(isTitleHoverShown)) {
429         TLOGE(WmsLogTag::WMS_IMMS, "Read isTitleHoverShown failed.");
430         return ERR_INVALID_DATA;
431     }
432     bool isDockHoverShown = true;
433     if (!data.ReadBool(isDockHoverShown)) {
434         TLOGE(WmsLogTag::WMS_IMMS, "Read isDockHoverShown failed.");
435         return ERR_INVALID_DATA;
436     }
437     TLOGD(WmsLogTag::WMS_IMMS, "isTitleHoverShown: %{public}d, isDockHoverShown: %{public}d",
438         isTitleHoverShown, isDockHoverShown);
439     WSError errCode = OnTitleAndDockHoverShowChange(isTitleHoverShown, isDockHoverShown);
440     reply.WriteUint32(static_cast<uint32_t>(errCode));
441     return ERR_NONE;
442 }
443 
HandleRestoreMainWindow(MessageParcel & data,MessageParcel & reply)444 int SessionStub::HandleRestoreMainWindow(MessageParcel& data, MessageParcel& reply)
445 {
446     WSError errCode = OnRestoreMainWindow();
447     return ERR_NONE;
448 }
449 
HandleTerminateSession(MessageParcel & data,MessageParcel & reply)450 int SessionStub::HandleTerminateSession(MessageParcel& data, MessageParcel& reply)
451 {
452     WLOGFD("run HandleTerminateSession");
453     std::shared_ptr<AAFwk::Want> localWant(data.ReadParcelable<AAFwk::Want>());
454     if (localWant == nullptr) {
455         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
456         return ERR_INVALID_VALUE;
457     }
458     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
459     abilitySessionInfo->want = *localWant;
460     if (data.ReadBool()) {
461         abilitySessionInfo->callerToken = data.ReadRemoteObject();
462     }
463     abilitySessionInfo->resultCode = data.ReadInt32();
464     WSError errCode = TerminateSession(abilitySessionInfo);
465     reply.WriteUint32(static_cast<uint32_t>(errCode));
466     return ERR_NONE;
467 }
468 
HandleSessionException(MessageParcel & data,MessageParcel & reply)469 int SessionStub::HandleSessionException(MessageParcel& data, MessageParcel& reply)
470 {
471     WLOGFD("run HandleSessionException");
472     std::shared_ptr<AAFwk::Want> localWant(data.ReadParcelable<AAFwk::Want>());
473     if (localWant == nullptr) {
474         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
475         return ERR_INVALID_VALUE;
476     }
477     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
478     abilitySessionInfo->want = *localWant;
479     if (data.ReadBool()) {
480         abilitySessionInfo->callerToken = data.ReadRemoteObject();
481     }
482 
483     abilitySessionInfo->persistentId = data.ReadInt32();
484     abilitySessionInfo->errorCode = data.ReadInt32();
485     abilitySessionInfo->errorReason = data.ReadString();
486     abilitySessionInfo->identityToken = data.ReadString();
487     WSError errCode = NotifySessionException(abilitySessionInfo);
488     reply.WriteUint32(static_cast<uint32_t>(errCode));
489     return ERR_NONE;
490 }
491 
HandleChangeSessionVisibilityWithStatusBar(MessageParcel & data,MessageParcel & reply)492 int SessionStub::HandleChangeSessionVisibilityWithStatusBar(MessageParcel& data, MessageParcel& reply)
493 {
494     WLOGFD("HandleChangeSessionVisibilityWithStatusBar");
495     sptr<AAFwk::Want> localWant = data.ReadParcelable<AAFwk::Want>();
496     if (localWant == nullptr) {
497         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
498         return ERR_INVALID_VALUE;
499     }
500     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
501     abilitySessionInfo->want = *localWant;
502     abilitySessionInfo->requestCode = data.ReadInt32();
503     abilitySessionInfo->persistentId = data.ReadInt32();
504     abilitySessionInfo->state = static_cast<AAFwk::CallToState>(data.ReadInt32());
505     abilitySessionInfo->uiAbilityId = data.ReadInt64();
506     abilitySessionInfo->callingTokenId = data.ReadUint32();
507     abilitySessionInfo->reuse = data.ReadBool();
508     abilitySessionInfo->processOptions =
509         std::shared_ptr<AAFwk::ProcessOptions>(data.ReadParcelable<AAFwk::ProcessOptions>());
510     if (data.ReadBool()) {
511         abilitySessionInfo->callerToken = data.ReadRemoteObject();
512     }
513     if (data.ReadBool()) {
514         abilitySessionInfo->startSetting.reset(data.ReadParcelable<AAFwk::AbilityStartSetting>());
515     }
516     bool visible = data.ReadBool();
517     WSError errCode = ChangeSessionVisibilityWithStatusBar(abilitySessionInfo, visible);
518     reply.WriteUint32(static_cast<uint32_t>(errCode));
519     return ERR_NONE;
520 }
521 
HandlePendingSessionActivation(MessageParcel & data,MessageParcel & reply)522 int SessionStub::HandlePendingSessionActivation(MessageParcel& data, MessageParcel& reply)
523 {
524     WLOGFD("PendingSessionActivation!");
525     sptr<AAFwk::Want> localWant = data.ReadParcelable<AAFwk::Want>();
526     if (localWant == nullptr) {
527         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
528         return ERR_INVALID_VALUE;
529     }
530     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
531     abilitySessionInfo->want = *localWant;
532     abilitySessionInfo->requestCode = data.ReadInt32();
533     abilitySessionInfo->persistentId = data.ReadInt32();
534     abilitySessionInfo->state = static_cast<AAFwk::CallToState>(data.ReadInt32());
535     abilitySessionInfo->uiAbilityId = data.ReadInt64();
536     abilitySessionInfo->callingTokenId = data.ReadUint32();
537     abilitySessionInfo->reuse = data.ReadBool();
538     abilitySessionInfo->processOptions.reset(data.ReadParcelable<AAFwk::ProcessOptions>());
539     abilitySessionInfo->canStartAbilityFromBackground = data.ReadBool();
540     abilitySessionInfo->isAtomicService = data.ReadBool();
541     abilitySessionInfo->isBackTransition = data.ReadBool();
542     abilitySessionInfo->needClearInNotShowRecent = data.ReadBool();
543     if (data.ReadBool()) {
544         abilitySessionInfo->callerToken = data.ReadRemoteObject();
545     }
546     if (data.ReadBool()) {
547         abilitySessionInfo->startSetting.reset(data.ReadParcelable<AAFwk::AbilityStartSetting>());
548     }
549     if (!data.ReadBool(abilitySessionInfo->isFromIcon)) {
550         TLOGE(WmsLogTag::WMS_LIFE, "Read isFromIcon failed.");
551         return ERR_INVALID_DATA;
552     }
553     bool hasStartWindowOption = false;
554     if (!data.ReadBool(hasStartWindowOption)) {
555         TLOGE(WmsLogTag::WMS_LIFE, "Read hasStartWindowOption failed.");
556         return ERR_INVALID_DATA;
557     }
558     if (hasStartWindowOption) {
559         auto startWindowOption = data.ReadParcelable<AAFwk::StartWindowOption>();
560         abilitySessionInfo->startWindowOption.reset(startWindowOption);
561     }
562     uint32_t size = data.ReadUint32();
563     if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
564         abilitySessionInfo->supportWindowModes.reserve(size);
565         for (uint32_t i = 0; i < size; i++) {
566             abilitySessionInfo->supportWindowModes.push_back(
567                 static_cast<AppExecFwk::SupportWindowMode>(data.ReadInt32()));
568         }
569     }
570     WSError errCode = PendingSessionActivation(abilitySessionInfo);
571     reply.WriteUint32(static_cast<uint32_t>(errCode));
572     return ERR_NONE;
573 }
574 
HandleUpdateSessionRect(MessageParcel & data,MessageParcel & reply)575 int SessionStub::HandleUpdateSessionRect(MessageParcel& data, MessageParcel& reply)
576 {
577     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
578     auto posX = data.ReadInt32();
579     auto posY = data.ReadInt32();
580     auto width = data.ReadUint32();
581     auto height = data.ReadUint32();
582     WSRect rect = {posX, posY, width, height};
583     TLOGI(WmsLogTag::WMS_LAYOUT, "Rect [%{public}d, %{public}d, %{public}u, %{public}u]",
584         posX, posY, width, height);
585     const SizeChangeReason& reason = static_cast<SizeChangeReason>(data.ReadUint32());
586     auto isGlobal = data.ReadBool();
587     auto isFromMoveToGlobal = false;
588     if (!data.ReadBool(isFromMoveToGlobal)) {
589         TLOGE(WmsLogTag::WMS_LAYOUT, "read isFromMoveToGlobal failed");
590         return ERR_INVALID_DATA;
591     }
592     WSError errCode = UpdateSessionRect(rect, reason, isGlobal, isFromMoveToGlobal);
593     reply.WriteUint32(static_cast<uint32_t>(errCode));
594     return ERR_NONE;
595 }
596 
597 /** @note @window.layout */
HandleUpdateClientRect(MessageParcel & data,MessageParcel & reply)598 int SessionStub::HandleUpdateClientRect(MessageParcel& data, MessageParcel& reply)
599 {
600     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
601     int32_t posX = 0;
602     int32_t posY = 0;
603     int32_t width = 0;
604     int32_t height = 0;
605     if (!data.ReadInt32(posX) || !data.ReadInt32(posY) || !data.ReadInt32(width) || !data.ReadInt32(height)) {
606         TLOGE(WmsLogTag::WMS_LAYOUT, "read rect failed");
607         return ERR_INVALID_DATA;
608     }
609     WSRect rect = { posX, posY, width, height };
610     WSError errCode = UpdateClientRect(rect);
611     reply.WriteInt32(static_cast<int32_t>(errCode));
612     return ERR_NONE;
613 }
614 
615 /** @note @window.layout */
HandleGetGlobalScaledRect(MessageParcel & data,MessageParcel & reply)616 int SessionStub::HandleGetGlobalScaledRect(MessageParcel& data, MessageParcel& reply)
617 {
618     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
619     Rect globalScaledRect;
620     WMError errorCode = GetGlobalScaledRect(globalScaledRect);
621     if (!reply.WriteInt32(globalScaledRect.posX_) || !reply.WriteInt32(globalScaledRect.posY_) ||
622         !reply.WriteUint32(globalScaledRect.width_) || !reply.WriteUint32(globalScaledRect.height_) ||
623         !reply.WriteInt32(static_cast<int32_t>(errorCode))) {
624         TLOGE(WmsLogTag::WMS_LAYOUT, "Write failed");
625         return ERR_INVALID_DATA;
626     }
627     return ERR_NONE;
628 }
629 
HandleRaiseToAppTop(MessageParcel & data,MessageParcel & reply)630 int SessionStub::HandleRaiseToAppTop(MessageParcel& data, MessageParcel& reply)
631 {
632     WLOGFD("RaiseToAppTop!");
633     WSError errCode = RaiseToAppTop();
634     reply.WriteUint32(static_cast<uint32_t>(errCode));
635     return ERR_NONE;
636 }
637 
HandleRaiseAboveTarget(MessageParcel & data,MessageParcel & reply)638 int SessionStub::HandleRaiseAboveTarget(MessageParcel& data, MessageParcel& reply)
639 {
640     WLOGFD("RaiseAboveTarget!");
641     auto subWindowId = data.ReadInt32();
642     WSError errCode = RaiseAboveTarget(subWindowId);
643     reply.WriteUint32(static_cast<uint32_t>(errCode));
644     return ERR_NONE;
645 }
646 
HandleRaiseAppMainWindowToTop(MessageParcel & data,MessageParcel & reply)647 int SessionStub::HandleRaiseAppMainWindowToTop(MessageParcel& data, MessageParcel& reply)
648 {
649     WLOGFD("RaiseAppMainWindowToTop!");
650     WSError errCode = RaiseAppMainWindowToTop();
651     reply.WriteUint32(static_cast<uint32_t>(errCode));
652     return ERR_NONE;
653 }
654 
HandleBackPressed(MessageParcel & data,MessageParcel & reply)655 int SessionStub::HandleBackPressed(MessageParcel& data, MessageParcel& reply)
656 {
657     WLOGFD("HandleBackPressed!");
658     bool needMoveToBackground = false;
659     if (!data.ReadBool(needMoveToBackground)) {
660         WLOGFE("Read needMoveToBackground from parcel failed!");
661         return ERR_INVALID_DATA;
662     }
663     WSError errCode = RequestSessionBack(needMoveToBackground);
664     reply.WriteUint32(static_cast<uint32_t>(errCode));
665     return ERR_NONE;
666 }
667 
HandleMarkProcessed(MessageParcel & data,MessageParcel & reply)668 int SessionStub::HandleMarkProcessed(MessageParcel& data, MessageParcel& reply)
669 {
670     WLOGFD("HandleMarkProcessed!");
671     int32_t eventId = 0;
672     if (!data.ReadInt32(eventId)) {
673         WLOGFE("Read eventId from parcel failed!");
674         return ERR_INVALID_DATA;
675     }
676     WSError errCode = MarkProcessed(eventId);
677     reply.WriteUint32(static_cast<uint32_t>(errCode));
678     return ERR_NONE;
679 }
680 
HandleSetGlobalMaximizeMode(MessageParcel & data,MessageParcel & reply)681 int SessionStub::HandleSetGlobalMaximizeMode(MessageParcel& data, MessageParcel& reply)
682 {
683     WLOGFD("HandleSetGlobalMaximizeMode!");
684     auto mode = data.ReadUint32();
685     WSError errCode = SetGlobalMaximizeMode(static_cast<MaximizeMode>(mode));
686     reply.WriteUint32(static_cast<uint32_t>(errCode));
687     return ERR_NONE;
688 }
689 
HandleGetGlobalMaximizeMode(MessageParcel & data,MessageParcel & reply)690 int SessionStub::HandleGetGlobalMaximizeMode(MessageParcel& data, MessageParcel& reply)
691 {
692     WLOGFD("HandleGetGlobalMaximizeMode!");
693     MaximizeMode mode = MaximizeMode::MODE_FULL_FILL;
694     WSError errCode = GetGlobalMaximizeMode(mode);
695     reply.WriteUint32(static_cast<uint32_t>(mode));
696     reply.WriteUint32(static_cast<uint32_t>(errCode));
697     return ERR_NONE;
698 }
699 
HandleNeedAvoid(MessageParcel & data,MessageParcel & reply)700 int SessionStub::HandleNeedAvoid(MessageParcel& data, MessageParcel& reply)
701 {
702     bool status = static_cast<bool>(data.ReadUint32());
703     WLOGFD("HandleNeedAvoid status:%{public}d", static_cast<int32_t>(status));
704     WSError errCode = OnNeedAvoid(status);
705     reply.WriteUint32(static_cast<uint32_t>(errCode));
706     return ERR_NONE;
707 }
708 
HandleGetAvoidAreaByType(MessageParcel & data,MessageParcel & reply)709 int SessionStub::HandleGetAvoidAreaByType(MessageParcel& data, MessageParcel& reply)
710 {
711     AvoidAreaType type = static_cast<AvoidAreaType>(data.ReadUint32());
712     WLOGFD("HandleGetAvoidArea type:%{public}d", static_cast<int32_t>(type));
713     AvoidArea avoidArea = GetAvoidAreaByType(type);
714     reply.WriteParcelable(&avoidArea);
715     return ERR_NONE;
716 }
717 
HandleGetAllAvoidAreas(MessageParcel & data,MessageParcel & reply)718 int SessionStub::HandleGetAllAvoidAreas(MessageParcel& data, MessageParcel& reply)
719 {
720     TLOGD(WmsLogTag::WMS_IMMS, "in");
721     std::map<AvoidAreaType, AvoidArea> avoidAreas;
722     WSError errCode = GetAllAvoidAreas(avoidAreas);
723     reply.WriteUint32(avoidAreas.size());
724     for (const auto& [type, avoidArea] : avoidAreas) {
725         reply.WriteUint32(static_cast<uint32_t>(type));
726         reply.WriteParcelable(&avoidArea);
727     }
728     reply.WriteUint32(static_cast<uint32_t>(errCode));
729     return ERR_NONE;
730 }
731 
HandleSetAspectRatio(MessageParcel & data,MessageParcel & reply)732 int SessionStub::HandleSetAspectRatio(MessageParcel& data, MessageParcel& reply)
733 {
734     WLOGFD("HandleSetAspectRatio!");
735     float ratio = data.ReadFloat();
736     WSError errCode = SetAspectRatio(ratio);
737     reply.WriteUint32(static_cast<uint32_t>(errCode));
738     return ERR_NONE;
739 }
740 
HandleUpdateWindowSceneAfterCustomAnimation(MessageParcel & data,MessageParcel & reply)741 int SessionStub::HandleUpdateWindowSceneAfterCustomAnimation(MessageParcel& data, MessageParcel& reply)
742 {
743     WLOGD("HandleUpdateWindowSceneAfterCustomAnimation!");
744     bool isAdd = data.ReadBool();
745     WSError errCode = UpdateWindowSceneAfterCustomAnimation(isAdd);
746     reply.WriteUint32(static_cast<uint32_t>(errCode));
747     return ERR_NONE;
748 }
749 
HandleSetLandscapeMultiWindow(MessageParcel & data,MessageParcel & reply)750 int SessionStub::HandleSetLandscapeMultiWindow(MessageParcel& data, MessageParcel& reply)
751 {
752     TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "HandleSetLandscapeMultiWindow!");
753     bool isLandscapeMultiWindow = data.ReadBool();
754     const WSError errCode = SetLandscapeMultiWindow(isLandscapeMultiWindow);
755     reply.WriteUint32(static_cast<uint32_t>(errCode));
756     return ERR_NONE;
757 }
758 
HandleTransferAbilityResult(MessageParcel & data,MessageParcel & reply)759 int SessionStub::HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply)
760 {
761     WLOGFD("HandleTransferAbilityResult!");
762     uint32_t resultCode = data.ReadUint32();
763     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
764     if (want == nullptr) {
765         WLOGFE("want is nullptr");
766         return ERR_INVALID_VALUE;
767     }
768     WSError errCode = TransferAbilityResult(resultCode, *want);
769     reply.WriteUint32(static_cast<uint32_t>(errCode));
770     return ERR_NONE;
771 }
772 
HandleTransferExtensionData(MessageParcel & data,MessageParcel & reply)773 int SessionStub::HandleTransferExtensionData(MessageParcel& data, MessageParcel& reply)
774 {
775     WLOGFD("HandleTransferExtensionData!");
776     std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
777     if (wantParams == nullptr) {
778         WLOGFE("wantParams is nullptr");
779         return ERR_INVALID_VALUE;
780     }
781     WSError errCode = TransferExtensionData(*wantParams);
782     reply.WriteUint32(static_cast<uint32_t>(errCode));
783     return ERR_NONE;
784 }
785 
HandleNotifySyncOn(MessageParcel & data,MessageParcel & reply)786 int SessionStub::HandleNotifySyncOn(MessageParcel& data, MessageParcel& reply)
787 {
788     NotifySyncOn();
789     return ERR_NONE;
790 }
791 
HandleNotifyAsyncOn(MessageParcel & data,MessageParcel & reply)792 int SessionStub::HandleNotifyAsyncOn(MessageParcel& data, MessageParcel& reply)
793 {
794     NotifyAsyncOn();
795     return ERR_NONE;
796 }
797 
HandleNotifyExtensionDied(MessageParcel & data,MessageParcel & reply)798 int SessionStub::HandleNotifyExtensionDied(MessageParcel& data, MessageParcel& reply)
799 {
800     WLOGFD("called");
801     NotifyExtensionDied();
802     return ERR_NONE;
803 }
804 
HandleNotifyExtensionTimeout(MessageParcel & data,MessageParcel & reply)805 int SessionStub::HandleNotifyExtensionTimeout(MessageParcel& data, MessageParcel& reply)
806 {
807     int32_t errorCode = 0;
808     if (!data.ReadInt32(errorCode)) {
809         TLOGE(WmsLogTag::WMS_UIEXT, "Read eventId from parcel failed!");
810         return ERR_INVALID_DATA;
811     }
812     NotifyExtensionTimeout(errorCode);
813     return ERR_NONE;
814 }
815 
HandleTriggerBindModalUIExtension(MessageParcel & data,MessageParcel & reply)816 int SessionStub::HandleTriggerBindModalUIExtension(MessageParcel& data, MessageParcel& reply)
817 {
818     WLOGFD("called");
819     TriggerBindModalUIExtension();
820     return ERR_NONE;
821 }
822 
HandleTransferAccessibilityEvent(MessageParcel & data,MessageParcel & reply)823 int SessionStub::HandleTransferAccessibilityEvent(MessageParcel& data, MessageParcel& reply)
824 {
825     sptr<Accessibility::AccessibilityEventInfoParcel> infoPtr =
826         data.ReadStrongParcelable<Accessibility::AccessibilityEventInfoParcel>();
827     if (infoPtr == nullptr) {
828         return ERR_INVALID_DATA;
829     }
830     int64_t uiExtensionIdLevel = 0;
831     if (!data.ReadInt64(uiExtensionIdLevel)) {
832         WLOGFE("read uiExtensionIdLevel error");
833         return ERR_INVALID_DATA;
834     }
835     NotifyTransferAccessibilityEvent(*infoPtr, uiExtensionIdLevel);
836     return ERR_NONE;
837 }
838 
HandleNotifyPiPWindowPrepareClose(MessageParcel & data,MessageParcel & reply)839 int SessionStub::HandleNotifyPiPWindowPrepareClose(MessageParcel& data, MessageParcel& reply)
840 {
841     TLOGD(WmsLogTag::WMS_PIP, "HandleNotifyPiPWindowPrepareClose");
842     NotifyPiPWindowPrepareClose();
843     return ERR_NONE;
844 }
845 
HandleUpdatePiPRect(MessageParcel & data,MessageParcel & reply)846 int SessionStub::HandleUpdatePiPRect(MessageParcel& data, MessageParcel& reply)
847 {
848     TLOGD(WmsLogTag::WMS_PIP, "HandleUpdatePiPRect!");
849     Rect rect = {data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32()};
850     auto reason = static_cast<SizeChangeReason>(data.ReadInt32());
851     WSError errCode = UpdatePiPRect(rect, reason);
852     reply.WriteUint32(static_cast<uint32_t>(errCode));
853     return ERR_NONE;
854 }
855 
HandleUpdatePiPControlStatus(MessageParcel & data,MessageParcel & reply)856 int SessionStub::HandleUpdatePiPControlStatus(MessageParcel& data, MessageParcel& reply)
857 {
858     TLOGI(WmsLogTag::WMS_PIP, "called");
859     uint32_t controlType = 0;
860     int32_t status = 0;
861     if (data.ReadUint32(controlType) && data.ReadInt32(status)) {
862         WSError errCode = UpdatePiPControlStatus(static_cast<WsPiPControlType>(controlType),
863             static_cast<WsPiPControlStatus>(status));
864         reply.WriteInt32(static_cast<int32_t>(errCode));
865         return ERR_NONE;
866     } else {
867         return ERR_INVALID_DATA;
868     }
869 }
870 
HandleSetAutoStartPiP(MessageParcel & data,MessageParcel & reply)871 int SessionStub::HandleSetAutoStartPiP(MessageParcel& data, MessageParcel& reply)
872 {
873     TLOGD(WmsLogTag::WMS_PIP, "in");
874     bool isAutoStart = false;
875     if (!data.ReadBool(isAutoStart)) {
876         TLOGE(WmsLogTag::WMS_PIP, "read isAutoStart error");
877         return ERR_INVALID_DATA;
878     }
879     uint32_t priority = 0;
880     if (!data.ReadUint32(priority)) {
881         TLOGE(WmsLogTag::WMS_PIP, "read priority error");
882         return ERR_INVALID_DATA;
883     }
884     WSError errCode = SetAutoStartPiP(isAutoStart, priority);
885     reply.WriteInt32(static_cast<int32_t>(errCode));
886     return ERR_NONE;
887 }
888 
HandleSetSystemEnableDrag(MessageParcel & data,MessageParcel & reply)889 int SessionStub::HandleSetSystemEnableDrag(MessageParcel& data, MessageParcel& reply)
890 {
891     bool enableDrag = false;
892     if (!data.ReadBool(enableDrag)) {
893         TLOGE(WmsLogTag::WMS_LAYOUT, "read enableDrag failed");
894         return ERR_INVALID_DATA;
895     }
896     TLOGD(WmsLogTag::WMS_LAYOUT, "enableDrag: %{public}d", enableDrag);
897     WMError errcode = SetSystemWindowEnableDrag(enableDrag);
898     reply.WriteInt32(static_cast<int32_t>(errcode));
899     return ERR_NONE;
900 }
901 
HandleProcessPointDownSession(MessageParcel & data,MessageParcel & reply)902 int SessionStub::HandleProcessPointDownSession(MessageParcel& data, MessageParcel& reply)
903 {
904     WLOGFD("HandleProcessPointDownSession!");
905     int32_t posX = data.ReadInt32();
906     int32_t posY = data.ReadInt32();
907     WSError errCode = ProcessPointDownSession(posX, posY);
908     reply.WriteUint32(static_cast<uint32_t>(errCode));
909     return ERR_NONE;
910 }
911 
HandleSendPointerEvenForMoveDrag(MessageParcel & data,MessageParcel & reply)912 int SessionStub::HandleSendPointerEvenForMoveDrag(MessageParcel& data, MessageParcel& reply)
913 {
914     WLOGFD("HandleSendPointerEvenForMoveDrag!");
915     auto pointerEvent = MMI::PointerEvent::Create();
916     if (!pointerEvent) {
917         TLOGE(WmsLogTag::WMS_EVENT, "create pointer event failed");
918         return ERR_INVALID_DATA;
919     }
920     if (!pointerEvent->ReadFromParcel(data)) {
921         TLOGE(WmsLogTag::WMS_EVENT, "Read pointer event failed");
922         return ERR_INVALID_DATA;
923     }
924     WSError errCode = SendPointEventForMoveDrag(pointerEvent);
925     reply.WriteUint32(static_cast<uint32_t>(errCode));
926     return ERR_NONE;
927 }
928 
HandleIsStartMoving(MessageParcel & data,MessageParcel & reply)929 int SessionStub::HandleIsStartMoving(MessageParcel& data, MessageParcel& reply)
930 {
931     bool isMoving = IsStartMoving();
932     if (!reply.WriteBool(isMoving)) {
933         TLOGE(WmsLogTag::WMS_LAYOUT, "Write isMoving failed");
934         return ERR_INVALID_DATA;
935     }
936     return ERR_NONE;
937 }
938 
HandleUpdateRectChangeListenerRegistered(MessageParcel & data,MessageParcel & reply)939 int SessionStub::HandleUpdateRectChangeListenerRegistered(MessageParcel& data, MessageParcel& reply)
940 {
941     bool isRegister = data.ReadBool();
942     WSError errCode = UpdateRectChangeListenerRegistered(isRegister);
943     reply.WriteUint32(static_cast<uint32_t>(errCode));
944     return ERR_NONE;
945 }
946 
HandleSetCallingSessionId(MessageParcel & data,MessageParcel & reply)947 int SessionStub::HandleSetCallingSessionId(MessageParcel& data, MessageParcel& reply)
948 {
949     TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleSetCallingSessionId!");
950     uint32_t callingSessionId = data.ReadUint32();
951 
952     SetCallingSessionId(callingSessionId);
953     reply.WriteInt32(static_cast<int32_t>(WSError::WS_OK));
954     return ERR_NONE;
955 }
956 
HandleSetCustomDecorHeight(MessageParcel & data,MessageParcel & reply)957 int SessionStub::HandleSetCustomDecorHeight(MessageParcel& data, MessageParcel& reply)
958 {
959     TLOGD(WmsLogTag::WMS_LAYOUT, "run HandleSetCustomDecorHeight!");
960     int32_t height = data.ReadInt32();
961     SetCustomDecorHeight(height);
962     return ERR_NONE;
963 }
964 
HandleAdjustKeyboardLayout(MessageParcel & data,MessageParcel & reply)965 int SessionStub::HandleAdjustKeyboardLayout(MessageParcel& data, MessageParcel& reply)
966 {
967     TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleAdjustKeyboardLayout!");
968     sptr<KeyboardLayoutParams> keyboardLayoutParams = data.ReadParcelable<KeyboardLayoutParams>();
969     if (keyboardLayoutParams == nullptr) {
970         TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboardLayoutParams is nullptr.");
971         return ERR_INVALID_DATA;
972     }
973     WSError ret = AdjustKeyboardLayout(*keyboardLayoutParams);
974     reply.WriteInt32(static_cast<int32_t>(ret));
975     return ERR_NONE;
976 }
977 
HandleUpdatePropertyByAction(MessageParcel & data,MessageParcel & reply)978 int SessionStub::HandleUpdatePropertyByAction(MessageParcel& data, MessageParcel& reply)
979 {
980     auto action = static_cast<WSPropertyChangeAction>(data.ReadUint32());
981     TLOGD(WmsLogTag::DEFAULT, "action:%{public}u", action);
982     sptr<WindowSessionProperty> property = nullptr;
983     if (data.ReadBool()) {
984         property = sptr<WindowSessionProperty>::MakeSptr();
985         if (property != nullptr) {
986             property->Read(data, action);
987         }
988     } else {
989         TLOGW(WmsLogTag::DEFAULT, "Property not exist!");
990     }
991     const WMError ret = UpdateSessionPropertyByAction(property, action);
992     reply.WriteInt32(static_cast<int32_t>(ret));
993     return ERR_NONE;
994 }
995 
HandleGetAppForceLandscapeConfig(MessageParcel & data,MessageParcel & reply)996 int SessionStub::HandleGetAppForceLandscapeConfig(MessageParcel& data, MessageParcel& reply)
997 {
998     TLOGD(WmsLogTag::DEFAULT, "called");
999     AppForceLandscapeConfig config;
1000     WMError ret = GetAppForceLandscapeConfig(config);
1001     reply.WriteParcelable(&config);
1002     reply.WriteInt32(static_cast<int32_t>(ret));
1003     return ERR_NONE;
1004 }
1005 
HandleSetDialogSessionBackGestureEnabled(MessageParcel & data,MessageParcel & reply)1006 int SessionStub::HandleSetDialogSessionBackGestureEnabled(MessageParcel& data, MessageParcel& reply)
1007 {
1008     TLOGD(WmsLogTag::WMS_DIALOG, "called");
1009     bool isEnabled = data.ReadBool();
1010     WSError ret = SetDialogSessionBackGestureEnabled(isEnabled);
1011     reply.WriteInt32(static_cast<int32_t>(ret));
1012     return ERR_NONE;
1013 }
1014 
HandleNotifyExtensionEventAsync(MessageParcel & data,MessageParcel & reply)1015 int SessionStub::HandleNotifyExtensionEventAsync(MessageParcel& data, MessageParcel& reply)
1016 {
1017     uint32_t notifyEvent = 0;
1018     if (!data.ReadUint32(notifyEvent)) {
1019         return ERR_TRANSACTION_FAILED;
1020     }
1021     NotifyExtensionEventAsync(notifyEvent);
1022     return ERR_NONE;
1023 }
1024 
HandleNotifyExtensionDetachToDisplay(MessageParcel & data,MessageParcel & reply)1025 int SessionStub::HandleNotifyExtensionDetachToDisplay(MessageParcel& data, MessageParcel& reply)
1026 {
1027     TLOGD(WmsLogTag::WMS_UIEXT, "in");
1028     NotifyExtensionDetachToDisplay();
1029     return ERR_NONE;
1030 }
1031 
HandleRequestFocus(MessageParcel & data,MessageParcel & reply)1032 int SessionStub::HandleRequestFocus(MessageParcel& data, MessageParcel& reply)
1033 {
1034     TLOGD(WmsLogTag::WMS_FOCUS, "called");
1035     bool isFocused = false;
1036     if (!data.ReadBool(isFocused)) {
1037         TLOGE(WmsLogTag::WMS_FOCUS, "read isFocused failed");
1038         return ERR_INVALID_DATA;
1039     }
1040     WSError ret = RequestFocus(isFocused);
1041     reply.WriteInt32(static_cast<int32_t>(ret));
1042     return ERR_NONE;
1043 }
1044 
HandleSetGestureBackEnabled(MessageParcel & data,MessageParcel & reply)1045 int SessionStub::HandleSetGestureBackEnabled(MessageParcel& data, MessageParcel& reply)
1046 {
1047     TLOGD(WmsLogTag::WMS_IMMS, "in");
1048     bool isEnabled;
1049     if (!data.ReadBool(isEnabled)) {
1050         return ERR_INVALID_DATA;
1051     }
1052     WMError ret = SetGestureBackEnabled(isEnabled);
1053     reply.WriteInt32(static_cast<int32_t>(ret));
1054     return ERR_NONE;
1055 }
1056 
HandleNotifySubModalTypeChange(MessageParcel & data,MessageParcel & reply)1057 int SessionStub::HandleNotifySubModalTypeChange(MessageParcel& data, MessageParcel& reply)
1058 {
1059     uint32_t subWindowModalType = 0;
1060     if (!data.ReadUint32(subWindowModalType)) {
1061         return ERR_INVALID_DATA;
1062     }
1063     TLOGD(WmsLogTag::WMS_HIERARCHY, "subWindowModalType: %{public}u", subWindowModalType);
1064     if (subWindowModalType > static_cast<uint32_t>(SubWindowModalType::END)) {
1065         return ERR_INVALID_DATA;
1066     }
1067     NotifySubModalTypeChange(static_cast<SubWindowModalType>(subWindowModalType));
1068     return ERR_NONE;
1069 }
1070 
HandleNotifyMainModalTypeChange(MessageParcel & data,MessageParcel & reply)1071 int SessionStub::HandleNotifyMainModalTypeChange(MessageParcel& data, MessageParcel& reply)
1072 {
1073     bool isModal = false;
1074     if (!data.ReadBool(isModal)) {
1075         return ERR_INVALID_DATA;
1076     }
1077     TLOGD(WmsLogTag::WMS_MAIN, "isModal: %{public}d", isModal);
1078     NotifyMainModalTypeChange(isModal);
1079     return ERR_NONE;
1080 }
1081 
HandleSetWindowRectAutoSave(MessageParcel & data,MessageParcel & reply)1082 int SessionStub::HandleSetWindowRectAutoSave(MessageParcel& data, MessageParcel& reply)
1083 {
1084     bool enabled = true;
1085     if (!data.ReadBool(enabled)) {
1086         TLOGE(WmsLogTag::WMS_MAIN, "Read enable failed.");
1087         return ERR_INVALID_DATA;
1088     }
1089     TLOGD(WmsLogTag::WMS_MAIN, "enabled: %{public}d", enabled);
1090     WSError errCode = OnSetWindowRectAutoSave(enabled);
1091     return ERR_NONE;
1092 }
1093 } // namespace OHOS::Rosen
1094