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