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