• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "session/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 
ReadBasicAbilitySessionInfo(MessageParcel & data,sptr<AAFwk::SessionInfo> abilitySessionInfo)39 int ReadBasicAbilitySessionInfo(MessageParcel& data, sptr<AAFwk::SessionInfo> abilitySessionInfo)
40 {
41     sptr<AAFwk::Want> localWant = data.ReadParcelable<AAFwk::Want>();
42     if (localWant == nullptr) {
43         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
44         return ERR_INVALID_DATA;
45     }
46     abilitySessionInfo->want = *localWant;
47     if (!data.ReadInt32(abilitySessionInfo->requestCode)) {
48         TLOGE(WmsLogTag::WMS_LIFE, "Read requestCode failed.");
49         return ERR_INVALID_DATA;
50     }
51     if (!data.ReadInt32(abilitySessionInfo->persistentId)) {
52         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed.");
53         return ERR_INVALID_DATA;
54     }
55     int32_t state = 0;
56     if (!data.ReadInt32(state)) {
57         TLOGE(WmsLogTag::WMS_LIFE, "Read state failed.");
58         return ERR_INVALID_DATA;
59     }
60     abilitySessionInfo->state = static_cast<AAFwk::CallToState>(state);
61     if (!data.ReadInt64(abilitySessionInfo->uiAbilityId)) {
62         TLOGE(WmsLogTag::WMS_LIFE, "Read uiAbilityId failed.");
63         return ERR_INVALID_DATA;
64     }
65     if (!data.ReadUint32(abilitySessionInfo->callingTokenId)) {
66         TLOGE(WmsLogTag::WMS_LIFE, "Read callingTokenId failed.");
67         return ERR_INVALID_DATA;
68     }
69     if (!data.ReadInt32(abilitySessionInfo->requestId)) {
70         TLOGE(WmsLogTag::WMS_LIFE, "Read requestId failed.");
71         return ERR_INVALID_DATA;
72     }
73     if (!data.ReadBool(abilitySessionInfo->reuse)) {
74         TLOGE(WmsLogTag::WMS_LIFE, "Read reuse failed.");
75         return ERR_INVALID_DATA;
76     }
77     abilitySessionInfo->processOptions.reset(data.ReadParcelable<AAFwk::ProcessOptions>());
78     return ERR_NONE;
79 }
80 } // namespace
81 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)82 int SessionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
83 {
84     WLOGFD("Scene session on remote request!, code: %{public}u", code);
85     if (data.ReadInterfaceToken() != GetDescriptor()) {
86         WLOGFE("Failed to check interface token!");
87         return ERR_TRANSACTION_FAILED;
88     }
89 
90     return ProcessRemoteRequest(code, data, reply, option);
91 }
92 
ProcessRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)93 int SessionStub::ProcessRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
94     MessageOption& option)
95 {
96     switch (code) {
97         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CONNECT):
98             return HandleConnect(data, reply);
99         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FOREGROUND):
100             return HandleForeground(data, reply);
101         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKGROUND):
102             return HandleBackground(data, reply);
103         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DISCONNECT):
104             return HandleDisconnect(data, reply);
105         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SHOW):
106             return HandleShow(data, reply);
107         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_HIDE):
108             return HandleHide(data, reply);
109         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DRAWING_COMPLETED):
110             return HandleDrawingCompleted(data, reply);
111         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_APP_REMOVE_STARTING_WINDOW):
112             return HandleRemoveStartingWindow(data, reply);
113         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_RECTCHANGE_LISTENER_REGISTERED):
114             return HandleUpdateRectChangeListenerRegistered(data, reply);
115         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SESSION_EVENT):
116             return HandleSessionEvent(data, reply);
117         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SYNC_SESSION_EVENT):
118             return HandleSyncSessionEvent(data, reply);
119         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT):
120             return HandleUpdateSessionRect(data, reply);
121         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_GLOBAL_SCALED_RECT):
122             return HandleGetGlobalScaledRect(data, reply);
123         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP):
124             return HandleRaiseToAppTop(data, reply);
125         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_BACKPRESSED):
126             return HandleBackPressed(data, reply);
127         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MARK_PROCESSED):
128             return HandleMarkProcessed(data, reply);
129         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_MAXIMIZE_MODE):
130             return HandleSetGlobalMaximizeMode(data, reply);
131         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_MAXIMIZE_MODE):
132             return HandleGetGlobalMaximizeMode(data, reply);
133         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NEED_AVOID):
134             return HandleNeedAvoid(data, reply);
135         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_AVOID_AREA):
136             return HandleGetAvoidAreaByType(data, reply);
137         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_ALL_AVOID_AREAS):
138             return HandleGetAllAvoidAreas(data, reply);
139         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_ASPECT_RATIO):
140             return HandleSetAspectRatio(data, reply);
141         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_WINDOW_ANIMATION_FLAG):
142             return HandleSetWindowAnimationFlag(data, reply);
143         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CUSTOM_ANIMATION):
144             return HandleUpdateWindowSceneAfterCustomAnimation(data, reply);
145         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_LANDSCAPE_MULTI_WINDOW):
146             return HandleSetLandscapeMultiWindow(data, reply);
147         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_IS_MID_SCENE):
148             return HandleGetIsMidScene(data, reply);
149         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_ABOVE_TARGET):
150             return HandleRaiseAboveTarget(data, reply);
151         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RAISE_APP_MAIN_WINDOW):
152             return HandleRaiseAppMainWindowToTop(data, reply);
153         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CHANGE_SESSION_VISIBILITY_WITH_STATUS_BAR):
154             return HandleChangeSessionVisibilityWithStatusBar(data, reply);
155         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ACTIVE_PENDING_SESSION):
156             return HandlePendingSessionActivation(data, reply);
157         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_RESTORE_MAIN_WINDOW):
158             return HandleRestoreMainWindow(data, reply);
159         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TERMINATE):
160             return HandleTerminateSession(data, reply);
161         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_EXCEPTION):
162             return HandleSessionException(data, reply);
163         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_PROCESS_POINT_DOWN_SESSION):
164             return HandleProcessPointDownSession(data, reply);
165         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SEND_POINTEREVENT_FOR_MOVE_DRAG):
166             return HandleSendPointerEvenForMoveDrag(data, reply);
167         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_IS_START_MOVING):
168             return HandleIsStartMoving(data, reply);
169         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SYSTEM_DRAG_ENABLE):
170             return HandleSetSystemEnableDrag(data, reply);
171         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_CLIENT_RECT):
172             return HandleUpdateClientRect(data, reply);
173         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CALLING_SESSION_ID):
174             return HandleSetCallingSessionId(data, reply);
175         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_CUSTOM_DECOR_HEIGHT):
176             return HandleSetCustomDecorHeight(data, reply);
177         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_PROPERTY):
178             return HandleUpdatePropertyByAction(data, reply);
179         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_ADJUST_KEYBOARD_LAYOUT):
180             return HandleAdjustKeyboardLayout(data, reply);
181         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_ABILITY_RESULT):
182             return HandleTransferAbilityResult(data, reply);
183         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRANSFER_EXTENSION_DATA):
184             return HandleTransferExtensionData(data, reply);
185         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_ASYNC_ON):
186             return HandleNotifyAsyncOn(data, reply);
187         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_SYNC_ON):
188             return HandleNotifySyncOn(data, reply);
189         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DIED):
190             return HandleNotifyExtensionDied(data, reply);
191         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_TIMEOUT):
192             return HandleNotifyExtensionTimeout(data, reply);
193         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TRIGGER_BIND_MODAL_UI_EXTENSION):
194             return HandleTriggerBindModalUIExtension(data, reply);
195         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_REPORT_ACCESSIBILITY_EVENT):
196             return HandleTransferAccessibilityEvent(data, reply);
197         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_PIP_WINDOW_PREPARE_CLOSE):
198             return HandleNotifyPiPWindowPrepareClose(data, reply);
199         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_RECT):
200             return HandleUpdatePiPRect(data, reply);
201         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_PIP_CONTROL_STATUS):
202             return HandleUpdatePiPControlStatus(data, reply);
203         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_AUTOSTART_PIP):
204             return HandleSetAutoStartPiP(data, reply);
205         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_LAYOUT_FULL_SCREEN_CHANGE):
206             return HandleLayoutFullScreenChange(data, reply);
207         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_DEFAULT_DENSITY_ENABLED):
208             return HandleDefaultDensityEnabled(data, reply);
209         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_TITLE_AND_DOCK_HOVER_SHOW_CHANGE):
210             return HandleTitleAndDockHoverShowChange(data, reply);
211         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_FORCE_LANDSCAPE_CONFIG):
212             return HandleGetAppForceLandscapeConfig(data, reply);
213         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_DIALOG_SESSION_BACKGESTURE_ENABLE):
214             return HandleSetDialogSessionBackGestureEnabled(data, reply);
215         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_STATUSBAR_HEIGHT):
216             return HandleGetStatusBarHeight(data, reply);
217         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_FRAME_LAYOUT_FINISH):
218             return HandleNotifyFrameLayoutFinish(data, reply);
219         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_EVENT_ASYNC):
220             return HandleNotifyExtensionEventAsync(data, reply);
221         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_REQUEST_FOCUS):
222             return HandleRequestFocus(data, reply);
223         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_GESTURE_BACK_ENABLE):
224             return HandleSetGestureBackEnabled(data, reply);
225         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SUB_MODAL_TYPE_CHANGE):
226             return HandleNotifySubModalTypeChange(data, reply);
227         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_MAIN_MODAL_TYPE_CHANGE):
228             return HandleNotifyMainModalTypeChange(data, reply);
229         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_WINDOW_RECT_AUTO_SAVE):
230             return HandleSetWindowRectAutoSave(data, reply);
231         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_EXTENSION_DETACH_TO_DISPLAY):
232             return HandleNotifyExtensionDetachToDisplay(data, reply);
233         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SUPPORT_WINDOW_MODES):
234             return HandleSetSupportedWindowModes(data, reply);
235         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SEND_EXTENSION_DATA):
236             return HandleExtensionProviderData(data, reply, option);
237         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_SESSION_LABEL_AND_ICON):
238             return HandleSetSessionLabelAndIcon(data, reply);
239         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CHANGE_KEYBOARD_VIEW_MODE):
240             return HandleChangeKeyboardViewMode(data, reply);
241         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_WINDOW_CORNER_RADIUS):
242             return HandleSetWindowCornerRadius(data, reply);
243         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_START_MOVING_WITH_COORDINATE):
244             return HandleStartMovingWithCoordinate(data, reply);
245         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_CROSS_AXIS_STATE):
246             return HandleGetCrossAxisState(data, reply);
247         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_CONTAINER_MODAL_EVENT):
248             return HandleContainerModalEvent(data, reply);
249         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_NOTIFY_WINDOW_ATTACH_STATE_LISTENER_REGISTERED):
250             return HandleNotifyWindowAttachStateListenerRegistered(data, reply);
251         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_FOLLOW_PARENT_LAYOUT_ENABLED):
252             return HandleSetFollowParentWindowLayoutEnabled(data, reply);
253         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_KEYBOARD_DID_SHOW_REGISTERED):
254             return HandleNotifyKeyboardDidShowRegistered(data, reply);
255         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_KEYBOARD_DID_HIDE_REGISTERED):
256             return HandleNotifyKeyboardDidHideRegistered(data, reply);
257         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_UPDATE_FLAG):
258             return HandleUpdateFlag(data, reply);
259         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_GET_IS_HIGHLIGHTED):
260             return HandleGetIsHighlighted(data, reply);
261         case static_cast<uint32_t>(SessionInterfaceCode::TRANS_ID_SET_FOLLOW_PARENT_MULTI_SCREEN_POLICY):
262             return HandleNotifyFollowParentMultiScreenPolicy(data, reply);
263         default:
264             WLOGFE("Failed to find function handler!");
265             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
266     }
267 }
268 
HandleSetWindowAnimationFlag(MessageParcel & data,MessageParcel & reply)269 int SessionStub::HandleSetWindowAnimationFlag(MessageParcel& data, MessageParcel& reply)
270 {
271     WLOGFD("HandleSetWindowAnimationFlag!");
272     bool isNeedWindowAnimationFlag = data.ReadBool();
273     WSError errCode = UpdateWindowAnimationFlag(isNeedWindowAnimationFlag);
274     reply.WriteUint32(static_cast<uint32_t>(errCode));
275     return ERR_NONE;
276 }
277 
HandleForeground(MessageParcel & data,MessageParcel & reply)278 int SessionStub::HandleForeground(MessageParcel& data, MessageParcel& reply)
279 {
280     WLOGFD("[WMSCom] Foreground!");
281     sptr<WindowSessionProperty> property = nullptr;
282     if (data.ReadBool()) {
283         property = data.ReadStrongParcelable<WindowSessionProperty>();
284         if (property == nullptr) {
285             return ERR_INVALID_DATA;
286         }
287     } else {
288         WLOGFW("[WMSCom] Property not exist!");
289         property = sptr<WindowSessionProperty>::MakeSptr();
290     }
291     bool isFromClient = data.ReadBool();
292     std::string identityToken;
293     if (!data.ReadString(identityToken)) {
294         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
295         return ERR_INVALID_DATA;
296     }
297     const WSError errCode = Foreground(property, true, identityToken);
298     reply.WriteUint32(static_cast<uint32_t>(errCode));
299     return ERR_NONE;
300 }
301 
HandleBackground(MessageParcel & data,MessageParcel & reply)302 int SessionStub::HandleBackground(MessageParcel& data, MessageParcel& reply)
303 {
304     WLOGFD("[WMSCom] Background!");
305     bool isFromClient = data.ReadBool();
306     std::string identityToken;
307     if (!data.ReadString(identityToken)) {
308         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
309         return ERR_INVALID_DATA;
310     }
311     const WSError errCode = Background(true, identityToken);
312     reply.WriteUint32(static_cast<uint32_t>(errCode));
313     return ERR_NONE;
314 }
315 
HandleDisconnect(MessageParcel & data,MessageParcel & reply)316 int SessionStub::HandleDisconnect(MessageParcel& data, MessageParcel& reply)
317 {
318     WLOGFD("Disconnect!");
319     bool isFromClient = data.ReadBool();
320     std::string identityToken;
321     if (!data.ReadString(identityToken)) {
322         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
323         return ERR_INVALID_DATA;
324     }
325     WSError errCode = Disconnect(true, identityToken);
326     reply.WriteUint32(static_cast<uint32_t>(errCode));
327     return ERR_NONE;
328 }
329 
HandleShow(MessageParcel & data,MessageParcel & reply)330 int SessionStub::HandleShow(MessageParcel& data, MessageParcel& reply)
331 {
332     WLOGFD("Show!");
333     sptr<WindowSessionProperty> property = nullptr;
334     if (data.ReadBool()) {
335         property = data.ReadStrongParcelable<WindowSessionProperty>();
336         if (property == nullptr) {
337             return ERR_INVALID_DATA;
338         }
339     } else {
340         WLOGFW("Property not exist!");
341         property = sptr<WindowSessionProperty>::MakeSptr();
342     }
343     WSError errCode = Show(property);
344     reply.WriteUint32(static_cast<uint32_t>(errCode));
345     return ERR_NONE;
346 }
347 
HandleHide(MessageParcel & data,MessageParcel & reply)348 int SessionStub::HandleHide(MessageParcel& data, MessageParcel& reply)
349 {
350     WLOGFD("Hide!");
351     WSError errCode = Hide();
352     reply.WriteUint32(static_cast<uint32_t>(errCode));
353     return ERR_NONE;
354 }
355 
HandleConnect(MessageParcel & data,MessageParcel & reply)356 int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply)
357 {
358     TLOGD(WmsLogTag::WMS_LIFE, "In");
359     sptr<IRemoteObject> sessionStageObject = data.ReadRemoteObject();
360     sptr<ISessionStage> sessionStage = iface_cast<ISessionStage>(sessionStageObject);
361     sptr<IRemoteObject> eventChannelObject = data.ReadRemoteObject();
362     sptr<IWindowEventChannel> eventChannel = iface_cast<IWindowEventChannel>(eventChannelObject);
363     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
364     if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) {
365         TLOGE(WmsLogTag::WMS_LIFE, "Failed to read scene session stage object or event channel object!");
366         return ERR_INVALID_DATA;
367     }
368     bool hasWindowSessionProperty = false;
369     if (!data.ReadBool(hasWindowSessionProperty)) {
370         TLOGE(WmsLogTag::WMS_LIFE, "Read hasWindowSessionProperty failed.");
371         return ERR_INVALID_DATA;
372     }
373     sptr<WindowSessionProperty> property = nullptr;
374     if (hasWindowSessionProperty) {
375         property = data.ReadStrongParcelable<WindowSessionProperty>();
376         if (property == nullptr) {
377             TLOGE(WmsLogTag::WMS_LIFE, "Property is nullptr.");
378             return ERR_INVALID_DATA;
379         }
380     } else {
381         TLOGW(WmsLogTag::WMS_LIFE, "Property not exist!");
382     }
383     sptr<IRemoteObject> token = nullptr;
384     if (property && property->GetTokenState()) {
385         token = data.ReadRemoteObject();
386         if (token == nullptr) {
387             TLOGE(WmsLogTag::WMS_LIFE, "Token is nullptr.");
388             return ERR_INVALID_DATA;
389         }
390     }
391     std::string identityToken;
392     if (!data.ReadString(identityToken)) {
393         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
394         return ERR_INVALID_DATA;
395     }
396     SystemSessionConfig systemConfig;
397     WSError errCode = Connect(sessionStage, eventChannel, surfaceNode, systemConfig, property, token,
398         identityToken);
399     reply.WriteParcelable(&systemConfig);
400     if (property) {
401         reply.WriteInt32(property->GetPersistentId());
402         reply.WriteUint64(property->GetDisplayId());
403         bool needUpdate = property->GetIsNeedUpdateWindowMode();
404         reply.WriteBool(needUpdate);
405         if (needUpdate) {
406             reply.WriteUint32(static_cast<uint32_t>(property->GetWindowMode()));
407         }
408         property->SetIsNeedUpdateWindowMode(false);
409         Rect winRect = property->GetWindowRect();
410         reply.WriteInt32(winRect.posX_);
411         reply.WriteInt32(winRect.posY_);
412         reply.WriteUint32(winRect.width_);
413         reply.WriteUint32(winRect.height_);
414         reply.WriteInt32(property->GetCollaboratorType());
415         reply.WriteBool(property->GetFullScreenStart());
416         std::vector<AppExecFwk::SupportWindowMode> supportedWindowModes;
417         property->GetSupportedWindowModes(supportedWindowModes);
418         auto size = supportedWindowModes.size();
419         if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
420             reply.WriteUint32(static_cast<uint32_t>(size));
421             for (decltype(size) i = 0; i < size; i++) {
422                 reply.WriteInt32(static_cast<int32_t>(supportedWindowModes[i]));
423             }
424         } else {
425             reply.WriteUint32(0);
426         }
427         WindowSizeLimits windowSizeLimits = property->GetWindowSizeLimits();
428         reply.WriteUint32(windowSizeLimits.maxWindowWidth);
429         reply.WriteUint32(windowSizeLimits.minWindowWidth);
430         reply.WriteUint32(windowSizeLimits.maxWindowHeight);
431         reply.WriteUint32(windowSizeLimits.minWindowHeight);
432         reply.WriteBool(property->GetCompatibleModeInPc());
433         reply.WriteInt32(property->GetCompatibleInPcPortraitWidth());
434         reply.WriteInt32(property->GetCompatibleInPcPortraitHeight());
435         reply.WriteInt32(property->GetCompatibleInPcLandscapeWidth());
436         reply.WriteInt32(property->GetCompatibleInPcLandscapeHeight());
437         reply.WriteBool(property->GetIsAppSupportPhoneInPc());
438         reply.WriteBool(property->GetIsSupportDragInPcCompatibleMode());
439         reply.WriteBool(property->GetIsPcAppInPad());
440         reply.WriteBool(property->GetCompatibleModeEnableInPad());
441         reply.WriteUint32(static_cast<uint32_t>(property->GetRequestedOrientation()));
442         reply.WriteString(property->GetAppInstanceKey());
443         reply.WriteBool(property->GetDragEnabled());
444         reply.WriteBool(property->GetIsAtomicService());
445     }
446     reply.WriteUint32(static_cast<uint32_t>(errCode));
447     return ERR_NONE;
448 }
449 
HandleNotifyFrameLayoutFinish(MessageParcel & data,MessageParcel & reply)450 int SessionStub::HandleNotifyFrameLayoutFinish(MessageParcel& data, MessageParcel& reply)
451 {
452     bool notifyListener = data.ReadBool();
453     WSRect rect = { data.ReadInt32(), data.ReadInt32(), data.ReadInt32(), data.ReadInt32() };
454     NotifyFrameLayoutFinishFromApp(notifyListener, rect);
455     return ERR_NONE;
456 }
457 
HandleDrawingCompleted(MessageParcel & data,MessageParcel & reply)458 int SessionStub::HandleDrawingCompleted(MessageParcel& data, MessageParcel& reply)
459 {
460     TLOGD(WmsLogTag::WMS_LIFE, "Called!");
461     const WSError errCode = DrawingCompleted();
462     reply.WriteInt32(static_cast<int32_t>(errCode));
463     return ERR_NONE;
464 }
465 
HandleRemoveStartingWindow(MessageParcel & data,MessageParcel & reply)466 int SessionStub::HandleRemoveStartingWindow(MessageParcel& data, MessageParcel& reply)
467 {
468     TLOGD(WmsLogTag::WMS_STARTUP_PAGE, "Called!");
469     WSError errCode = RemoveStartingWindow();
470     reply.WriteInt32(static_cast<int32_t>(errCode));
471     return ERR_NONE;
472 }
473 
HandleSessionEvent(MessageParcel & data,MessageParcel & reply)474 int SessionStub::HandleSessionEvent(MessageParcel& data, MessageParcel& reply)
475 {
476     TLOGD(WmsLogTag::WMS_EVENT, "In!");
477     uint32_t eventId = 0;
478     if (!data.ReadUint32(eventId)) {
479         TLOGE(WmsLogTag::WMS_EVENT, "read eventId failed");
480         return ERR_INVALID_DATA;
481     }
482     TLOGD(WmsLogTag::WMS_EVENT, "eventId: %{public}d", eventId);
483     if (eventId < static_cast<uint32_t>(SessionEvent::EVENT_MAXIMIZE) ||
484         eventId >= static_cast<uint32_t>(SessionEvent::EVENT_END)) {
485         TLOGE(WmsLogTag::WMS_EVENT, "Invalid eventId: %{public}d", eventId);
486         return ERR_INVALID_DATA;
487     }
488     WSError errCode = OnSessionEvent(static_cast<SessionEvent>(eventId));
489     reply.WriteUint32(static_cast<uint32_t>(errCode));
490     return ERR_NONE;
491 }
492 
HandleSyncSessionEvent(MessageParcel & data,MessageParcel & reply)493 int SessionStub::HandleSyncSessionEvent(MessageParcel& data, MessageParcel& reply)
494 {
495     TLOGD(WmsLogTag::WMS_EVENT, "In!");
496     uint32_t eventId;
497     if (!data.ReadUint32(eventId)) {
498         TLOGE(WmsLogTag::WMS_EVENT, "read eventId failed");
499         return ERR_INVALID_DATA;
500     }
501     TLOGD(WmsLogTag::WMS_EVENT, "eventId: %{public}d", eventId);
502     WSError errCode = SyncSessionEvent(static_cast<SessionEvent>(eventId));
503     reply.WriteInt32(static_cast<int32_t>(errCode));
504     return ERR_NONE;
505 }
506 
HandleLayoutFullScreenChange(MessageParcel & data,MessageParcel & reply)507 int SessionStub::HandleLayoutFullScreenChange(MessageParcel& data, MessageParcel& reply)
508 {
509     bool isLayoutFullScreen = data.ReadBool();
510     TLOGD(WmsLogTag::WMS_LAYOUT_PC, "isLayoutFullScreen: %{public}d", isLayoutFullScreen);
511     WSError errCode = OnLayoutFullScreenChange(isLayoutFullScreen);
512     reply.WriteUint32(static_cast<uint32_t>(errCode));
513     return ERR_NONE;
514 }
515 
HandleDefaultDensityEnabled(MessageParcel & data,MessageParcel & reply)516 int SessionStub::HandleDefaultDensityEnabled(MessageParcel& data, MessageParcel& reply)
517 {
518     bool isDefaultDensityEnabled = false;
519     if (!data.ReadBool(isDefaultDensityEnabled)) {
520         TLOGE(WmsLogTag::WMS_LAYOUT, "Read isDefaultDensityEnabled failed.");
521         return ERR_INVALID_DATA;
522     }
523     TLOGD(WmsLogTag::WMS_LAYOUT, "isDefaultDensityEnabled: %{public}d", isDefaultDensityEnabled);
524     WSError errCode = OnDefaultDensityEnabled(isDefaultDensityEnabled);
525     reply.WriteInt32(static_cast<int32_t>(errCode));
526     return ERR_NONE;
527 }
528 
HandleTitleAndDockHoverShowChange(MessageParcel & data,MessageParcel & reply)529 int SessionStub::HandleTitleAndDockHoverShowChange(MessageParcel& data, MessageParcel& reply)
530 {
531     bool isTitleHoverShown = true;
532     if (!data.ReadBool(isTitleHoverShown)) {
533         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read isTitleHoverShown failed.");
534         return ERR_INVALID_DATA;
535     }
536     bool isDockHoverShown = true;
537     if (!data.ReadBool(isDockHoverShown)) {
538         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read isDockHoverShown failed.");
539         return ERR_INVALID_DATA;
540     }
541     TLOGD(WmsLogTag::WMS_LAYOUT_PC, "isTitleHoverShown: %{public}d, isDockHoverShown: %{public}d",
542         isTitleHoverShown, isDockHoverShown);
543     WSError errCode = OnTitleAndDockHoverShowChange(isTitleHoverShown, isDockHoverShown);
544     reply.WriteUint32(static_cast<uint32_t>(errCode));
545     return ERR_NONE;
546 }
547 
HandleRestoreMainWindow(MessageParcel & data,MessageParcel & reply)548 int SessionStub::HandleRestoreMainWindow(MessageParcel& data, MessageParcel& reply)
549 {
550     OnRestoreMainWindow();
551     return ERR_NONE;
552 }
553 
HandleTerminateSession(MessageParcel & data,MessageParcel & reply)554 int SessionStub::HandleTerminateSession(MessageParcel& data, MessageParcel& reply)
555 {
556     TLOGD(WmsLogTag::WMS_LIFE, "In");
557     std::shared_ptr<AAFwk::Want> localWant(data.ReadParcelable<AAFwk::Want>());
558     if (localWant == nullptr) {
559         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
560         return ERR_INVALID_VALUE;
561     }
562     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
563     abilitySessionInfo->want = *localWant;
564     bool hasCallerToken = false;
565     if (!data.ReadBool(hasCallerToken)) {
566         TLOGE(WmsLogTag::WMS_LIFE, "Read hasCallerToken failed.");
567         return ERR_INVALID_DATA;
568     }
569     if (hasCallerToken) {
570         abilitySessionInfo->callerToken = data.ReadRemoteObject();
571     }
572     if (!data.ReadInt32(abilitySessionInfo->resultCode)) {
573         TLOGE(WmsLogTag::WMS_LIFE, "Read resultCode failed.");
574         return ERR_INVALID_DATA;
575     }
576     WSError errCode = TerminateSession(abilitySessionInfo);
577     reply.WriteUint32(static_cast<uint32_t>(errCode));
578     return ERR_NONE;
579 }
580 
HandleSessionException(MessageParcel & data,MessageParcel & reply)581 int SessionStub::HandleSessionException(MessageParcel& data, MessageParcel& reply)
582 {
583     TLOGD(WmsLogTag::WMS_LIFE, "In");
584     std::shared_ptr<AAFwk::Want> localWant(data.ReadParcelable<AAFwk::Want>());
585     if (localWant == nullptr) {
586         TLOGE(WmsLogTag::WMS_LIFE, "localWant is nullptr");
587         return ERR_INVALID_VALUE;
588     }
589     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
590     abilitySessionInfo->want = *localWant;
591     bool hasCallerToken = false;
592     if (!data.ReadBool(hasCallerToken)) {
593         TLOGE(WmsLogTag::WMS_LIFE, "Read hasCallerToken failed.");
594         return ERR_INVALID_DATA;
595     }
596     if (hasCallerToken) {
597         abilitySessionInfo->callerToken = data.ReadRemoteObject();
598     }
599     if (!data.ReadInt32(abilitySessionInfo->persistentId)) {
600         TLOGE(WmsLogTag::WMS_LIFE, "Read persistentId failed.");
601         return ERR_INVALID_DATA;
602     }
603     if (!data.ReadInt32(abilitySessionInfo->errorCode)) {
604         TLOGE(WmsLogTag::WMS_LIFE, "Read errorCode failed.");
605         return ERR_INVALID_DATA;
606     }
607     if (!data.ReadString(abilitySessionInfo->errorReason)) {
608         TLOGE(WmsLogTag::WMS_LIFE, "Read errorReason failed.");
609         return ERR_INVALID_DATA;
610     }
611     if (!data.ReadString(abilitySessionInfo->identityToken)) {
612         TLOGE(WmsLogTag::WMS_LIFE, "Read identityToken failed.");
613         return ERR_INVALID_DATA;
614     }
615     ExceptionInfo exceptionInfo;
616     if (!data.ReadBool(exceptionInfo.needRemoveSession)) {
617         TLOGE(WmsLogTag::WMS_LIFE, "Read needRemoveSession failed.");
618         return ERR_INVALID_DATA;
619     }
620     if (!data.ReadBool(exceptionInfo.needClearCallerLink)) {
621         TLOGE(WmsLogTag::WMS_LIFE, "Read needClearCallerLink failed.");
622         return ERR_INVALID_DATA;
623     }
624     exceptionInfo.needClearCallerLink =
625         exceptionInfo.needRemoveSession ? true : exceptionInfo.needClearCallerLink;
626     WSError errCode = NotifySessionException(abilitySessionInfo, exceptionInfo);
627     reply.WriteUint32(static_cast<uint32_t>(errCode));
628     return ERR_NONE;
629 }
630 
HandleChangeSessionVisibilityWithStatusBar(MessageParcel & data,MessageParcel & reply)631 int SessionStub::HandleChangeSessionVisibilityWithStatusBar(MessageParcel& data, MessageParcel& reply)
632 {
633     TLOGD(WmsLogTag::WMS_LIFE, "In");
634     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
635     int32_t readResult = ReadBasicAbilitySessionInfo(data, abilitySessionInfo);
636     if (readResult == ERR_INVALID_DATA) {
637         return ERR_INVALID_DATA;
638     }
639     bool hasCallerToken = false;
640     if (!data.ReadBool(hasCallerToken)) {
641         TLOGE(WmsLogTag::WMS_LIFE, "Read hasCallerToken failed.");
642         return ERR_INVALID_DATA;
643     }
644     if (hasCallerToken) {
645         abilitySessionInfo->callerToken = data.ReadRemoteObject();
646     }
647     bool hasStartSetting = false;
648     if (!data.ReadBool(hasStartSetting)) {
649         TLOGE(WmsLogTag::WMS_LIFE, "Read hasStartSetting failed.");
650         return ERR_INVALID_DATA;
651     }
652     if (hasStartSetting) {
653         abilitySessionInfo->startSetting.reset(data.ReadParcelable<AAFwk::AbilityStartSetting>());
654     }
655     bool visible = false;
656     if (!data.ReadBool(visible)) {
657         TLOGE(WmsLogTag::WMS_LIFE, "Read visible failed.");
658         return ERR_INVALID_DATA;
659     }
660     WSError errCode = ChangeSessionVisibilityWithStatusBar(abilitySessionInfo, visible);
661     reply.WriteUint32(static_cast<uint32_t>(errCode));
662     return ERR_NONE;
663 }
664 
HandlePendingSessionActivation(MessageParcel & data,MessageParcel & reply)665 int SessionStub::HandlePendingSessionActivation(MessageParcel& data, MessageParcel& reply)
666 {
667     TLOGD(WmsLogTag::WMS_LIFE, "In!");
668     sptr<AAFwk::SessionInfo> abilitySessionInfo = sptr<AAFwk::SessionInfo>::MakeSptr();
669     int32_t readResult = ReadBasicAbilitySessionInfo(data, abilitySessionInfo);
670     if (readResult == ERR_INVALID_DATA) {
671         return ERR_INVALID_DATA;
672     }
673     if (!data.ReadBool(abilitySessionInfo->canStartAbilityFromBackground)) {
674         TLOGE(WmsLogTag::WMS_LIFE, "Read canStartAbilityFromBackground failed.");
675         return ERR_INVALID_DATA;
676     }
677     if (!data.ReadBool(abilitySessionInfo->isAtomicService)) {
678         TLOGE(WmsLogTag::WMS_LIFE, "Read isAtomicService failed.");
679         return ERR_INVALID_DATA;
680     }
681     if (!data.ReadBool(abilitySessionInfo->isBackTransition)) {
682         TLOGE(WmsLogTag::WMS_LIFE, "Read isBackTransition failed.");
683         return ERR_INVALID_DATA;
684     }
685     if (!data.ReadBool(abilitySessionInfo->needClearInNotShowRecent)) {
686         TLOGE(WmsLogTag::WMS_LIFE, "Read needClearInNotShowRecent failed.");
687         return ERR_INVALID_DATA;
688     }
689     bool hasCallerToken = false;
690     if (!data.ReadBool(hasCallerToken)) {
691         TLOGE(WmsLogTag::WMS_LIFE, "Read hasCallerToken failed.");
692         return ERR_INVALID_DATA;
693     }
694     if (hasCallerToken) {
695         abilitySessionInfo->callerToken = data.ReadRemoteObject();
696     }
697     bool hasStartSetting = false;
698     if (!data.ReadBool(hasStartSetting)) {
699         TLOGE(WmsLogTag::WMS_LIFE, "Read hasStartSetting failed.");
700         return ERR_INVALID_DATA;
701     }
702     if (hasStartSetting) {
703         abilitySessionInfo->startSetting.reset(data.ReadParcelable<AAFwk::AbilityStartSetting>());
704     }
705     if (!data.ReadString(abilitySessionInfo->instanceKey)) {
706         TLOGE(WmsLogTag::WMS_LIFE, "Read instanceKey failed.");
707         return ERR_INVALID_DATA;
708     }
709     if (!data.ReadBool(abilitySessionInfo->isFromIcon)) {
710         TLOGE(WmsLogTag::WMS_LIFE, "Read isFromIcon failed.");
711         return ERR_INVALID_DATA;
712     }
713     bool hasStartWindowOption = false;
714     if (!data.ReadBool(hasStartWindowOption)) {
715         TLOGE(WmsLogTag::WMS_STARTUP_PAGE, "Read hasStartWindowOption failed.");
716         return ERR_INVALID_DATA;
717     }
718     if (hasStartWindowOption) {
719         auto startWindowOption = data.ReadParcelable<AAFwk::StartWindowOption>();
720         abilitySessionInfo->startWindowOption.reset(startWindowOption);
721     }
722     uint32_t size = data.ReadUint32();
723     if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
724         abilitySessionInfo->supportWindowModes.reserve(size);
725         for (uint32_t i = 0; i < size; i++) {
726             abilitySessionInfo->supportWindowModes.push_back(
727                 static_cast<AppExecFwk::SupportWindowMode>(data.ReadInt32()));
728         }
729     }
730     if (!data.ReadString(abilitySessionInfo->specifiedFlag)) {
731         TLOGE(WmsLogTag::WMS_LIFE, "Read specifiedFlag failed.");
732         return ERR_INVALID_DATA;
733     }
734     WSError errCode = PendingSessionActivation(abilitySessionInfo);
735     reply.WriteUint32(static_cast<uint32_t>(errCode));
736     return ERR_NONE;
737 }
738 
739 /** @note @window.layout */
HandleUpdateSessionRect(MessageParcel & data,MessageParcel & reply)740 int SessionStub::HandleUpdateSessionRect(MessageParcel& data, MessageParcel& reply)
741 {
742     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
743     int32_t posX = 0;
744     int32_t posY = 0;
745     uint32_t width = 0;
746     uint32_t height = 0;
747     if (!data.ReadInt32(posX) || !data.ReadInt32(posY) || !data.ReadUint32(width) || !data.ReadUint32(height)) {
748         TLOGE(WmsLogTag::WMS_LAYOUT, "read rect failed");
749         return ERR_INVALID_DATA;
750     }
751     WSRect rect = {posX, posY, width, height};
752     TLOGD(WmsLogTag::WMS_LAYOUT, "rect:[%{public}d, %{public}d, %{public}u, %{public}u]", posX, posY,
753         width, height);
754     uint32_t changeReason = 0;
755     if (!data.ReadUint32(changeReason)) {
756         TLOGE(WmsLogTag::WMS_LAYOUT, "read changeReason failed");
757         return ERR_INVALID_DATA;
758     }
759     if (changeReason < static_cast<uint32_t>(SizeChangeReason::UNDEFINED) ||
760         changeReason > static_cast<uint32_t>(SizeChangeReason::END)) {
761         TLOGE(WmsLogTag::WMS_LAYOUT, "Unknown reason");
762         return ERR_INVALID_DATA;
763     }
764     SizeChangeReason reason = static_cast<SizeChangeReason>(changeReason);
765     bool isGlobal = false;
766     if (!data.ReadBool(isGlobal)) {
767         TLOGE(WmsLogTag::WMS_LAYOUT, "read isGlobal failed");
768         return ERR_INVALID_DATA;
769     }
770     auto isFromMoveToGlobal = false;
771     if (!data.ReadBool(isFromMoveToGlobal)) {
772         TLOGE(WmsLogTag::WMS_LAYOUT, "read isFromMoveToGlobal failed");
773         return ERR_INVALID_DATA;
774     }
775     uint64_t displayId = DISPLAY_ID_INVALID;
776     if (!data.ReadUint64(displayId)) {
777         TLOGE(WmsLogTag::WMS_LAYOUT, "read displayId failed");
778         return ERR_INVALID_DATA;
779     }
780     MoveConfiguration moveConfiguration;
781     moveConfiguration.displayId = static_cast<DisplayId>(displayId);
782     RectAnimationConfig rectAnimationConfig;
783     if (reason == SizeChangeReason::MOVE_WITH_ANIMATION || reason == SizeChangeReason::RESIZE_WITH_ANIMATION) {
784         if (!data.ReadUint32(rectAnimationConfig.duration) || !data.ReadFloat(rectAnimationConfig.x1) ||
785             !data.ReadFloat(rectAnimationConfig.y1) || !data.ReadFloat(rectAnimationConfig.x2) ||
786             !data.ReadFloat(rectAnimationConfig.y2)) {
787             TLOGE(WmsLogTag::WMS_LAYOUT, "read animation config failed");
788             return ERR_INVALID_DATA;
789         }
790         if (reason == SizeChangeReason::MOVE_WITH_ANIMATION) {
791             moveConfiguration.rectAnimationConfig = rectAnimationConfig;
792         }
793     }
794     TLOGD(WmsLogTag::WMS_LAYOUT, "rectAnimationConfig:[%{public}u, %{public}f, %{public}f, %{public}f, %{public}f]",
795         rectAnimationConfig.duration, rectAnimationConfig.x1, rectAnimationConfig.y1, rectAnimationConfig.x2,
796         rectAnimationConfig.y2);
797     WSError errCode = UpdateSessionRect(rect, reason, isGlobal, isFromMoveToGlobal, moveConfiguration,
798         rectAnimationConfig);
799     reply.WriteUint32(static_cast<uint32_t>(errCode));
800     return ERR_NONE;
801 }
802 
803 /** @note @window.layout */
HandleGetGlobalScaledRect(MessageParcel & data,MessageParcel & reply)804 int SessionStub::HandleGetGlobalScaledRect(MessageParcel& data, MessageParcel& reply)
805 {
806     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
807     Rect globalScaledRect;
808     WMError errorCode = GetGlobalScaledRect(globalScaledRect);
809     if (!reply.WriteInt32(globalScaledRect.posX_) || !reply.WriteInt32(globalScaledRect.posY_) ||
810         !reply.WriteUint32(globalScaledRect.width_) || !reply.WriteUint32(globalScaledRect.height_) ||
811         !reply.WriteInt32(static_cast<int32_t>(errorCode))) {
812         TLOGE(WmsLogTag::WMS_LAYOUT, "Write failed");
813         return ERR_INVALID_DATA;
814     }
815     return ERR_NONE;
816 }
817 
818 /** @note @window.layout */
HandleUpdateClientRect(MessageParcel & data,MessageParcel & reply)819 int SessionStub::HandleUpdateClientRect(MessageParcel& data, MessageParcel& reply)
820 {
821     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
822     int32_t posX = 0;
823     int32_t posY = 0;
824     int32_t width = 0;
825     int32_t height = 0;
826     if (!data.ReadInt32(posX) || !data.ReadInt32(posY) || !data.ReadInt32(width) || !data.ReadInt32(height)) {
827         TLOGE(WmsLogTag::WMS_LAYOUT, "read rect failed");
828         return ERR_INVALID_DATA;
829     }
830     WSRect rect = { posX, posY, width, height };
831     WSError errCode = UpdateClientRect(rect);
832     reply.WriteInt32(static_cast<int32_t>(errCode));
833     return ERR_NONE;
834 }
835 
HandleRaiseToAppTop(MessageParcel & data,MessageParcel & reply)836 int SessionStub::HandleRaiseToAppTop(MessageParcel& data, MessageParcel& reply)
837 {
838     WLOGFD("RaiseToAppTop!");
839     WSError errCode = RaiseToAppTop();
840     reply.WriteUint32(static_cast<uint32_t>(errCode));
841     return ERR_NONE;
842 }
843 
HandleRaiseAboveTarget(MessageParcel & data,MessageParcel & reply)844 int SessionStub::HandleRaiseAboveTarget(MessageParcel& data, MessageParcel& reply)
845 {
846     TLOGD(WmsLogTag::WMS_HIERARCHY, "In");
847     uint32_t subWindowId = 0;
848     if (!data.ReadUint32(subWindowId)) {
849         TLOGE(WmsLogTag::WMS_HIERARCHY, "read subWindowId failed");
850         return ERR_INVALID_DATA;
851     }
852     WSError errCode = RaiseAboveTarget(subWindowId);
853     reply.WriteUint32(static_cast<uint32_t>(errCode));
854     return ERR_NONE;
855 }
856 
HandleRaiseAppMainWindowToTop(MessageParcel & data,MessageParcel & reply)857 int SessionStub::HandleRaiseAppMainWindowToTop(MessageParcel& data, MessageParcel& reply)
858 {
859     WLOGFD("RaiseAppMainWindowToTop!");
860     WSError errCode = RaiseAppMainWindowToTop();
861     reply.WriteUint32(static_cast<uint32_t>(errCode));
862     return ERR_NONE;
863 }
864 
HandleBackPressed(MessageParcel & data,MessageParcel & reply)865 int SessionStub::HandleBackPressed(MessageParcel& data, MessageParcel& reply)
866 {
867     WLOGFD("HandleBackPressed!");
868     bool needMoveToBackground = false;
869     if (!data.ReadBool(needMoveToBackground)) {
870         WLOGFE("Read needMoveToBackground from parcel failed!");
871         return ERR_INVALID_DATA;
872     }
873     WSError errCode = RequestSessionBack(needMoveToBackground);
874     reply.WriteUint32(static_cast<uint32_t>(errCode));
875     return ERR_NONE;
876 }
877 
HandleMarkProcessed(MessageParcel & data,MessageParcel & reply)878 int SessionStub::HandleMarkProcessed(MessageParcel& data, MessageParcel& reply)
879 {
880     WLOGFD("HandleMarkProcessed!");
881     int32_t eventId = 0;
882     if (!data.ReadInt32(eventId)) {
883         WLOGFE("Read eventId from parcel failed!");
884         return ERR_INVALID_DATA;
885     }
886     WSError errCode = MarkProcessed(eventId);
887     reply.WriteUint32(static_cast<uint32_t>(errCode));
888     return ERR_NONE;
889 }
890 
HandleSetGlobalMaximizeMode(MessageParcel & data,MessageParcel & reply)891 int SessionStub::HandleSetGlobalMaximizeMode(MessageParcel& data, MessageParcel& reply)
892 {
893     WLOGFD("HandleSetGlobalMaximizeMode!");
894     uint32_t mode = 0;
895     if (!data.ReadUint32(mode) || mode >= static_cast<uint32_t>(MaximizeMode::MODE_END)) {
896         return ERR_INVALID_DATA;
897     }
898     WSError errCode = SetGlobalMaximizeMode(static_cast<MaximizeMode>(mode));
899     reply.WriteUint32(static_cast<uint32_t>(errCode));
900     return ERR_NONE;
901 }
902 
HandleGetGlobalMaximizeMode(MessageParcel & data,MessageParcel & reply)903 int SessionStub::HandleGetGlobalMaximizeMode(MessageParcel& data, MessageParcel& reply)
904 {
905     WLOGFD("HandleGetGlobalMaximizeMode!");
906     MaximizeMode mode = MaximizeMode::MODE_FULL_FILL;
907     WSError errCode = GetGlobalMaximizeMode(mode);
908     reply.WriteUint32(static_cast<uint32_t>(mode));
909     reply.WriteUint32(static_cast<uint32_t>(errCode));
910     return ERR_NONE;
911 }
912 
HandleNeedAvoid(MessageParcel & data,MessageParcel & reply)913 int SessionStub::HandleNeedAvoid(MessageParcel& data, MessageParcel& reply)
914 {
915     bool status = false;
916     if (!data.ReadBool(status)) {
917         return ERR_INVALID_DATA;
918     }
919     WLOGFD("HandleNeedAvoid status:%{public}d", static_cast<int32_t>(status));
920     WSError errCode = OnNeedAvoid(status);
921     reply.WriteUint32(static_cast<uint32_t>(errCode));
922     return ERR_NONE;
923 }
924 
HandleGetAvoidAreaByType(MessageParcel & data,MessageParcel & reply)925 int SessionStub::HandleGetAvoidAreaByType(MessageParcel& data, MessageParcel& reply)
926 {
927     uint32_t typeId = 0;
928     if (!data.ReadUint32(typeId) ||
929         typeId >= static_cast<uint32_t>(AvoidAreaType::TYPE_END)) {
930         TLOGE(WmsLogTag::WMS_IMMS, "read typeId error");
931         return ERR_INVALID_DATA;
932     }
933     WSRect rect {};
934     if (!data.ReadInt32(rect.posX_) || !data.ReadInt32(rect.posY_) ||
935         !data.ReadInt32(rect.width_) || !data.ReadInt32(rect.height_)) {
936         TLOGE(WmsLogTag::WMS_IMMS, "read rect error");
937         return ERR_INVALID_DATA;
938     }
939     int32_t apiVersion = API_VERSION_INVALID;
940     if (!data.ReadInt32(apiVersion)) {
941         TLOGE(WmsLogTag::WMS_IMMS, "read api version error");
942         return ERR_INVALID_DATA;
943     }
944     AvoidAreaType type = static_cast<AvoidAreaType>(typeId);
945     WLOGFD("HandleGetAvoidArea type:%{public}d", typeId);
946     AvoidArea avoidArea = GetAvoidAreaByType(type, rect, apiVersion);
947     reply.WriteParcelable(&avoidArea);
948     return ERR_NONE;
949 }
950 
HandleGetAllAvoidAreas(MessageParcel & data,MessageParcel & reply)951 int SessionStub::HandleGetAllAvoidAreas(MessageParcel& data, MessageParcel& reply)
952 {
953     TLOGD(WmsLogTag::WMS_IMMS, "in");
954     std::map<AvoidAreaType, AvoidArea> avoidAreas;
955     WSError errCode = GetAllAvoidAreas(avoidAreas);
956     reply.WriteUint32(avoidAreas.size());
957     for (const auto& [type, avoidArea] : avoidAreas) {
958         reply.WriteUint32(static_cast<uint32_t>(type));
959         reply.WriteParcelable(&avoidArea);
960     }
961     reply.WriteUint32(static_cast<uint32_t>(errCode));
962     return ERR_NONE;
963 }
964 
965 /** @note @window.layout */
HandleSetAspectRatio(MessageParcel & data,MessageParcel & reply)966 int SessionStub::HandleSetAspectRatio(MessageParcel& data, MessageParcel& reply)
967 {
968     TLOGD(WmsLogTag::WMS_LAYOUT, "In");
969     float ratio = 0.0f;
970     if (!data.ReadFloat(ratio)) {
971         TLOGE(WmsLogTag::WMS_LAYOUT, "read ratio failed");
972         return ERR_INVALID_DATA;
973     }
974     WSError errCode = SetAspectRatio(ratio);
975     reply.WriteUint32(static_cast<uint32_t>(errCode));
976     return ERR_NONE;
977 }
978 
HandleUpdateWindowSceneAfterCustomAnimation(MessageParcel & data,MessageParcel & reply)979 int SessionStub::HandleUpdateWindowSceneAfterCustomAnimation(MessageParcel& data, MessageParcel& reply)
980 {
981     WLOGD("HandleUpdateWindowSceneAfterCustomAnimation!");
982     bool isAdd = data.ReadBool();
983     WSError errCode = UpdateWindowSceneAfterCustomAnimation(isAdd);
984     reply.WriteUint32(static_cast<uint32_t>(errCode));
985     return ERR_NONE;
986 }
987 
HandleSetLandscapeMultiWindow(MessageParcel & data,MessageParcel & reply)988 int SessionStub::HandleSetLandscapeMultiWindow(MessageParcel& data, MessageParcel& reply)
989 {
990     TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "HandleSetLandscapeMultiWindow!");
991     bool isLandscapeMultiWindow = data.ReadBool();
992     const WSError errCode = SetLandscapeMultiWindow(isLandscapeMultiWindow);
993     reply.WriteUint32(static_cast<uint32_t>(errCode));
994     return ERR_NONE;
995 }
996 
HandleGetIsMidScene(MessageParcel & data,MessageParcel & reply)997 int SessionStub::HandleGetIsMidScene(MessageParcel& data, MessageParcel& reply)
998 {
999     TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "in");
1000     bool isMidScene = false;
1001     const WSError errCode = GetIsMidScene(isMidScene);
1002     if (!reply.WriteBool(isMidScene)) {
1003         TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Write isMidScene failed");
1004         return ERR_INVALID_DATA;
1005     }
1006     reply.WriteInt32(static_cast<int32_t>(errCode));
1007     return ERR_NONE;
1008 }
1009 
HandleTransferAbilityResult(MessageParcel & data,MessageParcel & reply)1010 int SessionStub::HandleTransferAbilityResult(MessageParcel& data, MessageParcel& reply)
1011 {
1012     WLOGFD("HandleTransferAbilityResult!");
1013     uint32_t resultCode = 0;
1014     if (!data.ReadUint32(resultCode)) {
1015         WLOGFE("Failed to read resultCode!");
1016         return ERR_TRANSACTION_FAILED;
1017     }
1018     std::shared_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1019     if (want == nullptr) {
1020         WLOGFE("want is nullptr");
1021         return ERR_INVALID_VALUE;
1022     }
1023     WSError errCode = TransferAbilityResult(resultCode, *want);
1024     reply.WriteUint32(static_cast<uint32_t>(errCode));
1025     return ERR_NONE;
1026 }
1027 
HandleTransferExtensionData(MessageParcel & data,MessageParcel & reply)1028 int SessionStub::HandleTransferExtensionData(MessageParcel& data, MessageParcel& reply)
1029 {
1030     WLOGFD("HandleTransferExtensionData!");
1031     std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
1032     if (wantParams == nullptr) {
1033         WLOGFE("wantParams is nullptr");
1034         return ERR_INVALID_VALUE;
1035     }
1036     WSError errCode = TransferExtensionData(*wantParams);
1037     reply.WriteUint32(static_cast<uint32_t>(errCode));
1038     return ERR_NONE;
1039 }
1040 
HandleNotifySyncOn(MessageParcel & data,MessageParcel & reply)1041 int SessionStub::HandleNotifySyncOn(MessageParcel& data, MessageParcel& reply)
1042 {
1043     NotifySyncOn();
1044     return ERR_NONE;
1045 }
1046 
HandleNotifyAsyncOn(MessageParcel & data,MessageParcel & reply)1047 int SessionStub::HandleNotifyAsyncOn(MessageParcel& data, MessageParcel& reply)
1048 {
1049     NotifyAsyncOn();
1050     return ERR_NONE;
1051 }
1052 
HandleNotifyExtensionDied(MessageParcel & data,MessageParcel & reply)1053 int SessionStub::HandleNotifyExtensionDied(MessageParcel& data, MessageParcel& reply)
1054 {
1055     WLOGFD("called");
1056     NotifyExtensionDied();
1057     return ERR_NONE;
1058 }
1059 
HandleNotifyExtensionTimeout(MessageParcel & data,MessageParcel & reply)1060 int SessionStub::HandleNotifyExtensionTimeout(MessageParcel& data, MessageParcel& reply)
1061 {
1062     int32_t errorCode = 0;
1063     if (!data.ReadInt32(errorCode)) {
1064         TLOGE(WmsLogTag::WMS_UIEXT, "Read eventId from parcel failed!");
1065         return ERR_INVALID_DATA;
1066     }
1067     NotifyExtensionTimeout(errorCode);
1068     return ERR_NONE;
1069 }
1070 
HandleTriggerBindModalUIExtension(MessageParcel & data,MessageParcel & reply)1071 int SessionStub::HandleTriggerBindModalUIExtension(MessageParcel& data, MessageParcel& reply)
1072 {
1073     WLOGFD("called");
1074     TriggerBindModalUIExtension();
1075     return ERR_NONE;
1076 }
1077 
HandleTransferAccessibilityEvent(MessageParcel & data,MessageParcel & reply)1078 int SessionStub::HandleTransferAccessibilityEvent(MessageParcel& data, MessageParcel& reply)
1079 {
1080     sptr<Accessibility::AccessibilityEventInfoParcel> infoPtr =
1081         data.ReadStrongParcelable<Accessibility::AccessibilityEventInfoParcel>();
1082     if (infoPtr == nullptr) {
1083         return ERR_INVALID_DATA;
1084     }
1085     int64_t uiExtensionIdLevel = 0;
1086     if (!data.ReadInt64(uiExtensionIdLevel)) {
1087         WLOGFE("read uiExtensionIdLevel error");
1088         return ERR_INVALID_DATA;
1089     }
1090     NotifyTransferAccessibilityEvent(*infoPtr, uiExtensionIdLevel);
1091     return ERR_NONE;
1092 }
1093 
HandleNotifyPiPWindowPrepareClose(MessageParcel & data,MessageParcel & reply)1094 int SessionStub::HandleNotifyPiPWindowPrepareClose(MessageParcel& data, MessageParcel& reply)
1095 {
1096     TLOGD(WmsLogTag::WMS_PIP, "HandleNotifyPiPWindowPrepareClose");
1097     NotifyPiPWindowPrepareClose();
1098     return ERR_NONE;
1099 }
1100 
HandleUpdatePiPRect(MessageParcel & data,MessageParcel & reply)1101 int SessionStub::HandleUpdatePiPRect(MessageParcel& data, MessageParcel& reply)
1102 {
1103     TLOGD(WmsLogTag::WMS_PIP, "HandleUpdatePiPRect!");
1104     int32_t posX = 0;
1105     int32_t posY = 0;
1106     uint32_t width = 0;
1107     uint32_t height = 0;
1108     uint32_t reason = 0;
1109     if (!data.ReadInt32(posX)) {
1110         TLOGE(WmsLogTag::WMS_PIP, "read posX error");
1111         return ERR_INVALID_DATA;
1112     }
1113     if (!data.ReadInt32(posY)) {
1114         TLOGE(WmsLogTag::WMS_PIP, "read posY error");
1115         return ERR_INVALID_DATA;
1116     }
1117     if (!data.ReadUint32(width)) {
1118         TLOGE(WmsLogTag::WMS_PIP, "read width error");
1119         return ERR_INVALID_DATA;
1120     }
1121     if (!data.ReadUint32(height)) {
1122         TLOGE(WmsLogTag::WMS_PIP, "read height error");
1123         return ERR_INVALID_DATA;
1124     }
1125     Rect rect = {posX, posY, width, height};
1126     if (!data.ReadUint32(reason)) {
1127         TLOGE(WmsLogTag::WMS_PIP, "read reason error");
1128         return ERR_INVALID_DATA;
1129     }
1130     if (reason > static_cast<uint32_t>(SizeChangeReason::END)) {
1131         TLOGE(WmsLogTag::WMS_PIP, "Unknown reason");
1132         return ERR_INVALID_DATA;
1133     }
1134     WSError errCode = UpdatePiPRect(rect, static_cast<SizeChangeReason>(reason));
1135     reply.WriteUint32(static_cast<uint32_t>(errCode));
1136     return ERR_NONE;
1137 }
1138 
HandleUpdatePiPControlStatus(MessageParcel & data,MessageParcel & reply)1139 int SessionStub::HandleUpdatePiPControlStatus(MessageParcel& data, MessageParcel& reply)
1140 {
1141     TLOGI(WmsLogTag::WMS_PIP, "called");
1142     uint32_t controlType = 0;
1143     int32_t status = 0;
1144     if (data.ReadUint32(controlType) && data.ReadInt32(status)) {
1145         if (controlType > static_cast<uint32_t>(WsPiPControlType::END)) {
1146             TLOGE(WmsLogTag::WMS_PIP, "Unknown controlType");
1147             return ERR_INVALID_DATA;
1148         }
1149         if (status > static_cast<int32_t>(WsPiPControlStatus::PLAY) ||
1150             status < static_cast<int32_t>(WsPiPControlStatus::DISABLED)) {
1151             TLOGE(WmsLogTag::WMS_PIP, "Unknown status");
1152             return ERR_INVALID_DATA;
1153         }
1154         WSError errCode = UpdatePiPControlStatus(static_cast<WsPiPControlType>(controlType),
1155             static_cast<WsPiPControlStatus>(status));
1156         reply.WriteInt32(static_cast<int32_t>(errCode));
1157         return ERR_NONE;
1158     } else {
1159         return ERR_INVALID_DATA;
1160     }
1161 }
1162 
HandleSetAutoStartPiP(MessageParcel & data,MessageParcel & reply)1163 int SessionStub::HandleSetAutoStartPiP(MessageParcel& data, MessageParcel& reply)
1164 {
1165     TLOGD(WmsLogTag::WMS_PIP, "in");
1166     bool isAutoStart = false;
1167     if (!data.ReadBool(isAutoStart)) {
1168         TLOGE(WmsLogTag::WMS_PIP, "read isAutoStart error");
1169         return ERR_INVALID_DATA;
1170     }
1171     uint32_t priority = 0;
1172     if (!data.ReadUint32(priority)) {
1173         TLOGE(WmsLogTag::WMS_PIP, "read priority error");
1174         return ERR_INVALID_DATA;
1175     }
1176     uint32_t width = 0;
1177     if (!data.ReadUint32(width)) {
1178         TLOGE(WmsLogTag::WMS_PIP, "read width error");
1179         return ERR_INVALID_DATA;
1180     }
1181     uint32_t height = 0;
1182     if (!data.ReadUint32(height)) {
1183         TLOGE(WmsLogTag::WMS_PIP, "read height error");
1184         return ERR_INVALID_DATA;
1185     }
1186     WSError errCode = SetAutoStartPiP(isAutoStart, priority, width, height);
1187     reply.WriteInt32(static_cast<int32_t>(errCode));
1188     return ERR_NONE;
1189 }
1190 
HandleSetSystemEnableDrag(MessageParcel & data,MessageParcel & reply)1191 int SessionStub::HandleSetSystemEnableDrag(MessageParcel& data, MessageParcel& reply)
1192 {
1193     bool enableDrag = false;
1194     if (!data.ReadBool(enableDrag)) {
1195         TLOGE(WmsLogTag::WMS_LAYOUT, "read enableDrag failed");
1196         return ERR_INVALID_DATA;
1197     }
1198     TLOGD(WmsLogTag::WMS_LAYOUT, "enableDrag: %{public}d", enableDrag);
1199     WMError errcode = SetSystemWindowEnableDrag(enableDrag);
1200     reply.WriteInt32(static_cast<int32_t>(errcode));
1201     return ERR_NONE;
1202 }
1203 
HandleProcessPointDownSession(MessageParcel & data,MessageParcel & reply)1204 int SessionStub::HandleProcessPointDownSession(MessageParcel& data, MessageParcel& reply)
1205 {
1206     TLOGD(WmsLogTag::WMS_EVENT, "called");
1207     int32_t posX = 0;
1208     int32_t posY = 0;
1209     if (!data.ReadInt32(posX) || !data.ReadInt32(posY)) {
1210         TLOGE(WmsLogTag::WMS_EVENT, "Read failed!");
1211         return ERR_INVALID_DATA;
1212     }
1213     WSError errCode = ProcessPointDownSession(posX, posY);
1214     reply.WriteUint32(static_cast<uint32_t>(errCode));
1215     return ERR_NONE;
1216 }
1217 
HandleSendPointerEvenForMoveDrag(MessageParcel & data,MessageParcel & reply)1218 int SessionStub::HandleSendPointerEvenForMoveDrag(MessageParcel& data, MessageParcel& reply)
1219 {
1220     WLOGFD("HandleSendPointerEvenForMoveDrag!");
1221     auto pointerEvent = MMI::PointerEvent::Create();
1222     if (!pointerEvent) {
1223         TLOGE(WmsLogTag::WMS_EVENT, "create pointer event failed");
1224         return ERR_INVALID_DATA;
1225     }
1226     if (!pointerEvent->ReadFromParcel(data)) {
1227         TLOGE(WmsLogTag::WMS_EVENT, "Read pointer event failed");
1228         return ERR_INVALID_DATA;
1229     }
1230     bool isExecuteDelayRaise = false;
1231     if (!data.ReadBool(isExecuteDelayRaise)) {
1232         TLOGE(WmsLogTag::WMS_FOCUS, "Read isExecuteDelayRaise failed");
1233         return ERR_INVALID_DATA;
1234     }
1235     WSError errCode = SendPointEventForMoveDrag(pointerEvent, isExecuteDelayRaise);
1236     reply.WriteUint32(static_cast<uint32_t>(errCode));
1237     return ERR_NONE;
1238 }
1239 
HandleIsStartMoving(MessageParcel & data,MessageParcel & reply)1240 int SessionStub::HandleIsStartMoving(MessageParcel& data, MessageParcel& reply)
1241 {
1242     bool isMoving = IsStartMoving();
1243     if (!reply.WriteBool(isMoving)) {
1244         TLOGE(WmsLogTag::WMS_LAYOUT, "Write isMoving failed");
1245         return ERR_INVALID_DATA;
1246     }
1247     return ERR_NONE;
1248 }
1249 
HandleUpdateRectChangeListenerRegistered(MessageParcel & data,MessageParcel & reply)1250 int SessionStub::HandleUpdateRectChangeListenerRegistered(MessageParcel& data, MessageParcel& reply)
1251 {
1252     bool isRegister = data.ReadBool();
1253     WSError errCode = UpdateRectChangeListenerRegistered(isRegister);
1254     reply.WriteUint32(static_cast<uint32_t>(errCode));
1255     return ERR_NONE;
1256 }
1257 
HandleSetCallingSessionId(MessageParcel & data,MessageParcel & reply)1258 int SessionStub::HandleSetCallingSessionId(MessageParcel& data, MessageParcel& reply)
1259 {
1260     TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleSetCallingSessionId!");
1261     uint32_t callingSessionId = INVALID_WINDOW_ID;
1262     if (!data.ReadUint32(callingSessionId)) {
1263         TLOGE(WmsLogTag::WMS_KEYBOARD, "callingSessionId read failed.");
1264         return ERR_INVALID_DATA;
1265     }
1266     SetCallingSessionId(callingSessionId);
1267     reply.WriteInt32(static_cast<int32_t>(WSError::WS_OK));
1268     return ERR_NONE;
1269 }
1270 
HandleSetCustomDecorHeight(MessageParcel & data,MessageParcel & reply)1271 int SessionStub::HandleSetCustomDecorHeight(MessageParcel& data, MessageParcel& reply)
1272 {
1273     TLOGD(WmsLogTag::WMS_DECOR, "In");
1274     int32_t height = 0;
1275     if (!data.ReadInt32(height)) {
1276         TLOGE(WmsLogTag::WMS_DECOR, "read height error");
1277         return ERR_INVALID_DATA;
1278     }
1279     SetCustomDecorHeight(height);
1280     return ERR_NONE;
1281 }
1282 
HandleAdjustKeyboardLayout(MessageParcel & data,MessageParcel & reply)1283 int SessionStub::HandleAdjustKeyboardLayout(MessageParcel& data, MessageParcel& reply)
1284 {
1285     TLOGD(WmsLogTag::WMS_KEYBOARD, "run HandleAdjustKeyboardLayout!");
1286     sptr<KeyboardLayoutParams> keyboardLayoutParams = data.ReadParcelable<KeyboardLayoutParams>();
1287     if (keyboardLayoutParams == nullptr) {
1288         TLOGE(WmsLogTag::WMS_KEYBOARD, "keyboardLayoutParams is nullptr.");
1289         return ERR_INVALID_DATA;
1290     }
1291     WSError ret = AdjustKeyboardLayout(*keyboardLayoutParams);
1292     reply.WriteInt32(static_cast<int32_t>(ret));
1293     return ERR_NONE;
1294 }
1295 
HandleUpdatePropertyByAction(MessageParcel & data,MessageParcel & reply)1296 int SessionStub::HandleUpdatePropertyByAction(MessageParcel& data, MessageParcel& reply)
1297 {
1298     uint64_t actionValue = 0;
1299     if (!data.ReadUint64(actionValue)) {
1300         TLOGE(WmsLogTag::DEFAULT, "read action error");
1301         return ERR_INVALID_DATA;
1302     }
1303     if (actionValue < static_cast<uint64_t>(WSPropertyChangeAction::ACTION_UPDATE_RECT) ||
1304         actionValue > static_cast<uint64_t>(WSPropertyChangeAction::ACTION_UPDATE_END)) {
1305         TLOGE(WmsLogTag::DEFAULT, "invalid action");
1306         return ERR_INVALID_DATA;
1307     }
1308     auto action = static_cast<WSPropertyChangeAction>(actionValue);
1309     TLOGD(WmsLogTag::DEFAULT, "action: %{public}" PRIu64, action);
1310     sptr<WindowSessionProperty> property = nullptr;
1311     if (data.ReadBool()) {
1312         property = sptr<WindowSessionProperty>::MakeSptr();
1313         if (property != nullptr) {
1314             property->Read(data, action);
1315         }
1316     } else {
1317         TLOGW(WmsLogTag::DEFAULT, "Property not exist!");
1318     }
1319     const WMError ret = UpdateSessionPropertyByAction(property, action);
1320     reply.WriteInt32(static_cast<int32_t>(ret));
1321     return ERR_NONE;
1322 }
1323 
HandleGetAppForceLandscapeConfig(MessageParcel & data,MessageParcel & reply)1324 int SessionStub::HandleGetAppForceLandscapeConfig(MessageParcel& data, MessageParcel& reply)
1325 {
1326     TLOGD(WmsLogTag::DEFAULT, "called");
1327     AppForceLandscapeConfig config;
1328     WMError ret = GetAppForceLandscapeConfig(config);
1329     reply.WriteParcelable(&config);
1330     reply.WriteInt32(static_cast<int32_t>(ret));
1331     return ERR_NONE;
1332 }
1333 
HandleSetDialogSessionBackGestureEnabled(MessageParcel & data,MessageParcel & reply)1334 int SessionStub::HandleSetDialogSessionBackGestureEnabled(MessageParcel& data, MessageParcel& reply)
1335 {
1336     TLOGD(WmsLogTag::WMS_DIALOG, "called");
1337     bool isEnabled = data.ReadBool();
1338     WSError ret = SetDialogSessionBackGestureEnabled(isEnabled);
1339     reply.WriteInt32(static_cast<int32_t>(ret));
1340     return ERR_NONE;
1341 }
1342 
HandleGetStatusBarHeight(MessageParcel & data,MessageParcel & reply)1343 int SessionStub::HandleGetStatusBarHeight(MessageParcel& data, MessageParcel& reply)
1344 {
1345     int32_t height = GetStatusBarHeight();
1346     TLOGD(WmsLogTag::WMS_IMMS, "StatusBarVectorHeight is %{public}d", height);
1347     reply.WriteInt32(height);
1348     return ERR_NONE;
1349 }
1350 
HandleNotifyExtensionEventAsync(MessageParcel & data,MessageParcel & reply)1351 int SessionStub::HandleNotifyExtensionEventAsync(MessageParcel& data, MessageParcel& reply)
1352 {
1353     uint32_t notifyEvent = 0;
1354     if (!data.ReadUint32(notifyEvent)) {
1355         return ERR_TRANSACTION_FAILED;
1356     }
1357     NotifyExtensionEventAsync(notifyEvent);
1358     return ERR_NONE;
1359 }
1360 
HandleNotifyExtensionDetachToDisplay(MessageParcel & data,MessageParcel & reply)1361 int SessionStub::HandleNotifyExtensionDetachToDisplay(MessageParcel& data, MessageParcel& reply)
1362 {
1363     TLOGD(WmsLogTag::WMS_UIEXT, "in");
1364     NotifyExtensionDetachToDisplay();
1365     return ERR_NONE;
1366 }
1367 
HandleExtensionProviderData(MessageParcel & data,MessageParcel & reply,MessageOption & option)1368 int SessionStub::HandleExtensionProviderData(MessageParcel& data, MessageParcel& reply, MessageOption& option)
1369 {
1370     TLOGD(WmsLogTag::WMS_UIEXT, "in");
1371     static_cast<void>(SendExtensionData(data, reply, option));
1372     return ERR_NONE;
1373 }
1374 
HandleRequestFocus(MessageParcel & data,MessageParcel & reply)1375 int SessionStub::HandleRequestFocus(MessageParcel& data, MessageParcel& reply)
1376 {
1377     TLOGD(WmsLogTag::WMS_FOCUS, "in");
1378     bool isFocused = false;
1379     if (!data.ReadBool(isFocused)) {
1380         TLOGE(WmsLogTag::WMS_FOCUS, "read isFocused failed");
1381         return ERR_INVALID_DATA;
1382     }
1383     WSError ret = RequestFocus(isFocused);
1384     reply.WriteInt32(static_cast<int32_t>(ret));
1385     return ERR_NONE;
1386 }
1387 
HandleSetGestureBackEnabled(MessageParcel & data,MessageParcel & reply)1388 int SessionStub::HandleSetGestureBackEnabled(MessageParcel& data, MessageParcel& reply)
1389 {
1390     TLOGD(WmsLogTag::WMS_IMMS, "in");
1391     bool isEnabled;
1392     if (!data.ReadBool(isEnabled)) {
1393         return ERR_INVALID_DATA;
1394     }
1395     WMError ret = SetGestureBackEnabled(isEnabled);
1396     reply.WriteInt32(static_cast<int32_t>(ret));
1397     return ERR_NONE;
1398 }
1399 
HandleNotifySubModalTypeChange(MessageParcel & data,MessageParcel & reply)1400 int SessionStub::HandleNotifySubModalTypeChange(MessageParcel& data, MessageParcel& reply)
1401 {
1402     uint32_t subWindowModalType = 0;
1403     if (!data.ReadUint32(subWindowModalType)) {
1404         return ERR_INVALID_DATA;
1405     }
1406     TLOGD(WmsLogTag::WMS_HIERARCHY, "subWindowModalType: %{public}u", subWindowModalType);
1407     if (subWindowModalType > static_cast<uint32_t>(SubWindowModalType::END)) {
1408         return ERR_INVALID_DATA;
1409     }
1410     NotifySubModalTypeChange(static_cast<SubWindowModalType>(subWindowModalType));
1411     return ERR_NONE;
1412 }
1413 
HandleNotifyMainModalTypeChange(MessageParcel & data,MessageParcel & reply)1414 int SessionStub::HandleNotifyMainModalTypeChange(MessageParcel& data, MessageParcel& reply)
1415 {
1416     bool isModal = false;
1417     if (!data.ReadBool(isModal)) {
1418         return ERR_INVALID_DATA;
1419     }
1420     TLOGD(WmsLogTag::WMS_MAIN, "isModal: %{public}d", isModal);
1421     NotifyMainModalTypeChange(isModal);
1422     return ERR_NONE;
1423 }
1424 
HandleSetWindowRectAutoSave(MessageParcel & data,MessageParcel & reply)1425 int SessionStub::HandleSetWindowRectAutoSave(MessageParcel& data, MessageParcel& reply)
1426 {
1427     bool enabled = true;
1428     if (!data.ReadBool(enabled)) {
1429         TLOGE(WmsLogTag::WMS_MAIN, "Read enable failed.");
1430         return ERR_INVALID_DATA;
1431     }
1432     bool isSaveBySpecifiedFlag = false;
1433     if (!data.ReadBool(isSaveBySpecifiedFlag)) {
1434         TLOGE(WmsLogTag::WMS_MAIN, "Read isSaveBySpecifiedFlag failed.");
1435         return ERR_INVALID_DATA;
1436     }
1437     TLOGD(WmsLogTag::WMS_MAIN, "enabled: %{public}d, isSaveBySpecifiedFlag: %{public}d",
1438         enabled, isSaveBySpecifiedFlag);
1439     OnSetWindowRectAutoSave(enabled, isSaveBySpecifiedFlag);
1440     return ERR_NONE;
1441 }
1442 
HandleSetSupportedWindowModes(MessageParcel & data,MessageParcel & reply)1443 int SessionStub::HandleSetSupportedWindowModes(MessageParcel& data, MessageParcel& reply)
1444 {
1445     uint32_t size = 0;
1446     if (!data.ReadUint32(size)) {
1447         return ERR_INVALID_DATA;
1448     }
1449     std::vector<AppExecFwk::SupportWindowMode> supportedWindowModes;
1450     if (size > 0 && size <= WINDOW_SUPPORT_MODE_MAX_SIZE) {
1451         supportedWindowModes.reserve(size);
1452         for (uint32_t i = 0; i < size; i++) {
1453             supportedWindowModes.push_back(
1454                 static_cast<AppExecFwk::SupportWindowMode>(data.ReadInt32()));
1455         }
1456     }
1457     TLOGD(WmsLogTag::WMS_LAYOUT_PC, "size: %{public}u", size);
1458     NotifySupportWindowModesChange(supportedWindowModes);
1459     return ERR_NONE;
1460 }
1461 
HandleSetSessionLabelAndIcon(MessageParcel & data,MessageParcel & reply)1462 int SessionStub::HandleSetSessionLabelAndIcon(MessageParcel& data, MessageParcel& reply)
1463 {
1464     std::string label;
1465     if (!data.ReadString(label)) {
1466         TLOGE(WmsLogTag::WMS_MAIN, "read label failed");
1467         return ERR_INVALID_DATA;
1468     }
1469     std::shared_ptr<Media::PixelMap> icon(data.ReadParcelable<Media::PixelMap>());
1470     if (icon == nullptr) {
1471         TLOGE(WmsLogTag::WMS_MAIN, "read icon failed");
1472         return ERR_INVALID_DATA;
1473     }
1474     WSError errCode = SetSessionLabelAndIcon(label, icon);
1475     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1476         TLOGE(WmsLogTag::WMS_MAIN, "write errCode fail.");
1477         return ERR_INVALID_DATA;
1478     }
1479     return ERR_NONE;
1480 }
1481 
HandleChangeKeyboardViewMode(MessageParcel & data,MessageParcel & reply)1482 int SessionStub::HandleChangeKeyboardViewMode(MessageParcel& data, MessageParcel& reply)
1483 {
1484     uint32_t mode = 0;
1485     if (!data.ReadUint32(mode)) {
1486         TLOGE(WmsLogTag::WMS_KEYBOARD, "Invalid data");
1487         return ERR_INVALID_DATA;
1488     }
1489     if (mode >= static_cast<uint32_t>(KeyboardViewMode::VIEW_MODE_END)) {
1490         TLOGE(WmsLogTag::WMS_KEYBOARD, "Invalid keyboard view mode");
1491         return ERR_INVALID_DATA;
1492     }
1493     WSError ret = ChangeKeyboardViewMode(static_cast<KeyboardViewMode>(mode));
1494     reply.WriteInt32(static_cast<int32_t>(ret));
1495     return ERR_NONE;
1496 }
1497 
HandleSetWindowCornerRadius(MessageParcel & data,MessageParcel & reply)1498 int SessionStub::HandleSetWindowCornerRadius(MessageParcel& data, MessageParcel& reply)
1499 {
1500     float cornerRadius = 0.0f;
1501     if (!data.ReadFloat(cornerRadius)) {
1502         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read cornerRadius failed.");
1503         return ERR_INVALID_DATA;
1504     }
1505     TLOGD(WmsLogTag::WMS_ATTRIBUTE, "cornerRadius: %{public}f", cornerRadius);
1506     SetWindowCornerRadius(cornerRadius);
1507     return ERR_NONE;
1508 }
1509 
HandleSetFollowParentWindowLayoutEnabled(MessageParcel & data,MessageParcel & reply)1510 int SessionStub::HandleSetFollowParentWindowLayoutEnabled(MessageParcel& data, MessageParcel& reply)
1511 {
1512     bool isFollow = false;
1513     if (!data.ReadBool(isFollow)) {
1514         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "Read cornerRadius failed.");
1515         return ERR_INVALID_DATA;
1516     }
1517     TLOGD(WmsLogTag::WMS_SUB, "isFollow: %{public}d", isFollow);
1518     WSError errCode = SetFollowParentWindowLayoutEnabled(isFollow);
1519     if (!reply.WriteInt32(static_cast<int32_t>(errCode))) {
1520         TLOGE(WmsLogTag::WMS_MAIN, "write errCode fail.");
1521         return ERR_INVALID_DATA;
1522     }
1523     return ERR_NONE;
1524 }
1525 
HandleStartMovingWithCoordinate(MessageParcel & data,MessageParcel & reply)1526 int SessionStub::HandleStartMovingWithCoordinate(MessageParcel& data, MessageParcel& reply)
1527 {
1528     int32_t offsetX;
1529     if (!data.ReadInt32(offsetX)) {
1530         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read offsetX failed!");
1531         return ERR_INVALID_DATA;
1532     }
1533     int32_t offsetY;
1534     if (!data.ReadInt32(offsetY)) {
1535         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read offsetY failed!");
1536         return ERR_INVALID_DATA;
1537     }
1538     int32_t pointerPosX;
1539     if (!data.ReadInt32(pointerPosX)) {
1540         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read pointerPosX failed!");
1541         return ERR_INVALID_DATA;
1542     }
1543     int32_t pointerPosY;
1544     if (!data.ReadInt32(pointerPosY)) {
1545         TLOGE(WmsLogTag::WMS_LAYOUT_PC, "Read pointerPosY failed!");
1546         return ERR_INVALID_DATA;
1547     }
1548     WSError errCode = StartMovingWithCoordinate(offsetX, offsetY, pointerPosX, pointerPosY);
1549     reply.WriteInt32(static_cast<int32_t>(errCode));
1550     return ERR_NONE;
1551 }
1552 
HandleGetCrossAxisState(MessageParcel & data,MessageParcel & reply)1553 int SessionStub::HandleGetCrossAxisState(MessageParcel& data, MessageParcel& reply)
1554 {
1555     CrossAxisState state = CrossAxisState::STATE_INVALID;
1556     GetCrossAxisState(state);
1557     if (!reply.WriteUint32(static_cast<uint32_t>(state))) {
1558         TLOGE(WmsLogTag::WMS_MAIN, "write errCode fail.");
1559         return ERR_INVALID_DATA;
1560     }
1561     return ERR_NONE;
1562 }
1563 
HandleContainerModalEvent(MessageParcel & data,MessageParcel & reply)1564 int SessionStub::HandleContainerModalEvent(MessageParcel& data, MessageParcel& reply)
1565 {
1566     TLOGD(WmsLogTag::WMS_EVENT, "In");
1567     std::string eventName;
1568     if (!data.ReadString(eventName)) {
1569         TLOGE(WmsLogTag::WMS_EVENT, "Read eventName failed.");
1570         return ERR_INVALID_DATA;
1571     }
1572     std::string eventValue;
1573     if (!data.ReadString(eventValue)) {
1574         TLOGE(WmsLogTag::WMS_EVENT, "Read eventValue failed.");
1575         return ERR_INVALID_DATA;
1576     }
1577     OnContainerModalEvent(eventName, eventValue);
1578     return ERR_NONE;
1579 }
1580 
HandleNotifyWindowAttachStateListenerRegistered(MessageParcel & data,MessageParcel & reply)1581 int SessionStub::HandleNotifyWindowAttachStateListenerRegistered(MessageParcel& data, MessageParcel& reply)
1582 {
1583     bool registered = false;
1584     if (!data.ReadBool(registered)) {
1585         TLOGE(WmsLogTag::WMS_PATTERN, "read registered failed");
1586         return ERR_INVALID_DATA;
1587     }
1588     TLOGD(WmsLogTag::WMS_PATTERN, "registered: %{public}d", registered);
1589     NotifyWindowAttachStateListenerRegistered(registered);
1590     return ERR_NONE;
1591 }
1592 
HandleNotifyKeyboardDidShowRegistered(MessageParcel & data,MessageParcel & reply)1593 int SessionStub::HandleNotifyKeyboardDidShowRegistered(MessageParcel& data, MessageParcel& reply)
1594 {
1595     bool registered = false;
1596     if (!data.ReadBool(registered)) {
1597         TLOGE(WmsLogTag::WMS_KEYBOARD, "read registered failed");
1598         return ERR_INVALID_DATA;
1599     }
1600     TLOGD(WmsLogTag::WMS_KEYBOARD, "registered: %{public}d", registered);
1601     NotifyKeyboardDidShowRegistered(registered);
1602     return ERR_NONE;
1603 }
1604 
HandleNotifyKeyboardDidHideRegistered(MessageParcel & data,MessageParcel & reply)1605 int SessionStub::HandleNotifyKeyboardDidHideRegistered(MessageParcel& data, MessageParcel& reply)
1606 {
1607     bool registered = false;
1608     if (!data.ReadBool(registered)) {
1609         TLOGE(WmsLogTag::WMS_KEYBOARD, "read registered failed");
1610         return ERR_INVALID_DATA;
1611     }
1612     TLOGD(WmsLogTag::WMS_KEYBOARD, "registered: %{public}d", registered);
1613     NotifyKeyboardDidHideRegistered(registered);
1614     return ERR_NONE;
1615 }
1616 
HandleUpdateFlag(MessageParcel & data,MessageParcel & reply)1617 int SessionStub::HandleUpdateFlag(MessageParcel& data, MessageParcel& reply)
1618 {
1619     std::string flag;
1620     if (!data.ReadString(flag)) {
1621         TLOGE(WmsLogTag::WMS_MAIN, "read flag failed");
1622         return ERR_INVALID_DATA;
1623     }
1624     TLOGD(WmsLogTag::WMS_MAIN, "specifiedFlag: %{public}s", flag.c_str());
1625     UpdateFlag(flag);
1626     return ERR_NONE;
1627 }
1628 
HandleGetIsHighlighted(MessageParcel & data,MessageParcel & reply)1629 int SessionStub::HandleGetIsHighlighted(MessageParcel& data, MessageParcel& reply)
1630 {
1631     bool isHighlighted = false;
1632     GetIsHighlighted(isHighlighted);
1633     if (!reply.WriteBool(isHighlighted)) {
1634         return ERR_INVALID_DATA;
1635     }
1636     return ERR_NONE;
1637 }
1638 
HandleNotifyFollowParentMultiScreenPolicy(MessageParcel & data,MessageParcel & reply)1639 int SessionStub::HandleNotifyFollowParentMultiScreenPolicy(MessageParcel& data, MessageParcel& reply)
1640 {
1641     bool enabled = false;
1642     if (!data.ReadBool(enabled)) {
1643         return ERR_INVALID_DATA;
1644     }
1645     TLOGD(WmsLogTag::WMS_SUB, "enabled: %{public}d", enabled);
1646     NotifyFollowParentMultiScreenPolicy(enabled);
1647     return ERR_NONE;
1648 }
1649 } // namespace OHOS::Rosen
1650