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 #ifndef OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H
18 
19 #include "session/host/include/session.h"
20 #include "session/host/include/move_drag_controller.h"
21 #include "wm_common.h"
22 
23 namespace OHOS::PowerMgr {
24 class RunningLock;
25 }
26 
27 namespace OHOS::Rosen {
28 namespace PARAM_KEY {
29 const std::string PARAM_MISSION_AFFINITY_KEY = "ohos.anco.param.missionAffinity";
30 const std::string PARAM_DMS_CONTINUE_SESSION_ID_KEY = "ohos.dms.continueSessionId";
31 const std::string PARAM_DMS_PERSISTENT_ID_KEY = "ohos.dms.persistentId";
32 }
33 
34 class SceneSession;
35 using SpecificSessionCreateCallback =
36   std::function<sptr<SceneSession>(const SessionInfo& info, sptr<WindowSessionProperty> property)>;
37 using SpecificSessionDestroyCallback = std::function<WSError(const int32_t& persistentId)>;
38 using CameraFloatSessionChangeCallback = std::function<void(uint32_t accessTokenId, bool isShowing)>;
39 using GetSceneSessionVectorByTypeCallback = std::function<std::vector<sptr<SceneSession>>(
40     WindowType type, DisplayId displayId)>;
41 using UpdateAvoidAreaCallback = std::function<void(int32_t persistentId)>;
42 using UpdateAvoidAreaByTypeCallback = std::function<void(int32_t persistentId, AvoidAreaType type)>;
43 using UpdateOccupiedAreaIfNeedCallback = std::function<void(const int32_t& persistentId)>;
44 using NotifyWindowInfoUpdateCallback = std::function<void(int32_t persistentId, WindowUpdateType type)>;
45 using NotifyWindowPidChangeCallback = std::function<void(int32_t windowId, bool startMoving)>;
46 using NotifySessionTouchOutsideCallback = std::function<void(int32_t persistentId)>;
47 using GetAINavigationBarArea = std::function<WSRect(uint64_t displayId)>;
48 using RecoveryCallback = std::function<void(int32_t persistentId, Rect rect)>;
49 using NotifyBindDialogSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
50 using NotifySessionPiPControlStatusChangeFunc = std::function<void(WsPiPControlType controlType,
51     WsPiPControlStatus status)>;
52 using NotifyAutoStartPiPStatusChangeFunc = std::function<void(bool isAutoStart)>;
53 using NotifySessionEventFunc = std::function<void(int32_t eventId, SessionEventParam param)>;
54 using NotifySessionTopmostChangeFunc = std::function<void(const bool topmost)>;
55 using NotifySessionModalTypeChangeFunc = std::function<void(const SubWindowModalType subWindowModalType)>;
56 using NotifyRaiseToTopFunc = std::function<void()>;
57 using SetWindowPatternOpacityFunc = std::function<void(float opacity)>;
58 using NotifyIsCustomAnimationPlayingCallback = std::function<void(bool isFinish)>;
59 using NotifyWindowAnimationFlagChangeFunc = std::function<void(const bool flag)>;
60 using NotifySystemBarPropertyChangeFunc = std::function<void(
61     const std::unordered_map<WindowType, SystemBarProperty>& propertyMap)>;
62 using NotifyNeedAvoidFunc = std::function<void(bool status)>;
63 using NotifyShowWhenLockedFunc = std::function<void(bool showWhenLocked)>;
64 using NotifyReqOrientationChangeFunc = std::function<void(uint32_t orientation)>;
65 using NotifyRaiseAboveTargetFunc = std::function<void(int32_t subWindowId)>;
66 using NotifyForceHideChangeFunc = std::function<void(bool hide)>;
67 using NotifyTouchOutsideFunc = std::function<void()>;
68 using ClearCallbackMapFunc = std::function<void(bool needRemove)>;
69 using NotifyPrepareClosePiPSessionFunc = std::function<void()>;
70 using OnOutsideDownEvent = std::function<void(int32_t x, int32_t y)>;
71 using HandleSecureSessionShouldHideCallback = std::function<WSError(const sptr<SceneSession>& sceneSession)>;
72 using ClearDisplayStatusBarTemporarilyFlags = std::function<void()>;
73 using CameraSessionChangeCallback = std::function<void(uint32_t accessTokenId, bool isShowing)>;
74 using NotifyLandscapeMultiWindowSessionFunc = std::function<void(bool isLandscapeMultiWindow)>;
75 using NotifyKeyboardGravityChangeFunc = std::function<void(SessionGravity gravity)>;
76 using NotifyKeyboardLayoutAdjustFunc = std::function<void(const KeyboardLayoutParams& params)>;
77 using SessionChangeByActionNotifyManagerFunc = std::function<void(const sptr<SceneSession>& sceneSession,
78     const sptr<WindowSessionProperty>& property, WSPropertyChangeAction action)>;
79 using NotifyLayoutFullScreenChangeFunc = std::function<void(bool isLayoutFullScreen)>;
80 using NotifyRestoreMainWindowFunc = std::function<void()>;
81 using NotifyTitleAndDockHoverShowChangeFunc = std::function<void(bool isTitleHoverShown,
82     bool isDockHoverShown)>;
83 using SetSkipSelfWhenShowOnVirtualScreenCallback = std::function<void(uint64_t surfaceNodeId, bool isSkip)>;
84 using NotifyForceSplitFunc = std::function<AppForceLandscapeConfig(const std::string& bundleName)>;
85 using UpdatePrivateStateAndNotifyFunc = std::function<void(int32_t persistentId)>;
86 using PiPStateChangeCallback = std::function<void(const std::string& bundleName, bool isForeground)>;
87 using NotifyMainWindowTopmostChangeFunc = std::function<void(bool isTopmost)>;
88 using NotifyPrivacyModeChangeFunc = std::function<void(uint32_t isPrivacyMode)>;
89 using UpdateGestureBackEnabledCallback = std::function<void(int32_t persistentId)>;
90 using NotifyVisibleChangeFunc = std::function<void(int32_t persistentId)>;
91 
92 class SceneSession : public Session {
93 public:
94     friend class HidumpController;
95     // callback for notify SceneSessionManager
96     struct SpecificSessionCallback : public RefBase {
97         SpecificSessionCreateCallback onCreate_;
98         SpecificSessionDestroyCallback onDestroy_;
99         ClearDisplayStatusBarTemporarilyFlags onClearDisplayStatusBarTemporarilyFlags_;
100         CameraFloatSessionChangeCallback onCameraFloatSessionChange_;
101         GetSceneSessionVectorByTypeCallback onGetSceneSessionVectorByType_;
102         UpdateAvoidAreaCallback onUpdateAvoidArea_;
103         UpdateAvoidAreaByTypeCallback onUpdateAvoidAreaByType_;
104         UpdateOccupiedAreaIfNeedCallback onUpdateOccupiedAreaIfNeed_;
105         NotifyWindowInfoUpdateCallback onWindowInfoUpdate_;
106         NotifyWindowPidChangeCallback onWindowInputPidChangeCallback_;
107         NotifySessionTouchOutsideCallback onSessionTouchOutside_;
108         GetAINavigationBarArea onGetAINavigationBarArea_;
109         OnOutsideDownEvent onOutsideDownEvent_;
110         HandleSecureSessionShouldHideCallback onHandleSecureSessionShouldHide_;
111         CameraSessionChangeCallback onCameraSessionChange_;
112         SetSkipSelfWhenShowOnVirtualScreenCallback onSetSkipSelfWhenShowOnVirtualScreen_;
113         PiPStateChangeCallback onPiPStateChange_;
114         UpdateGestureBackEnabledCallback onUpdateGestureBackEnabled_;
115     };
116 
117     // callback for notify SceneBoard
118     struct SessionChangeCallback : public RefBase {
119         NotifyBindDialogSessionFunc onBindDialogTarget_;
120         NotifySessionTopmostChangeFunc onSessionTopmostChange_;
121         NotifySessionModalTypeChangeFunc onSessionModalTypeChange_;
122         NotifyRaiseToTopFunc onRaiseToTop_;
123         NotifySessionEventFunc OnSessionEvent_;
124         NotifyNeedAvoidFunc OnNeedAvoid_;
125         NotifyIsCustomAnimationPlayingCallback onIsCustomAnimationPlaying_;
126         NotifyWindowAnimationFlagChangeFunc onWindowAnimationFlagChange_;
127         NotifyShowWhenLockedFunc OnShowWhenLocked_;
128         NotifyReqOrientationChangeFunc OnRequestedOrientationChange_;
129         NotifyRaiseAboveTargetFunc onRaiseAboveTarget_;
130         NotifyForceHideChangeFunc OnForceHideChange_;
131         NotifyTouchOutsideFunc OnTouchOutside_;
132         ClearCallbackMapFunc clearCallbackFunc_;
133         NotifyPrepareClosePiPSessionFunc onPrepareClosePiPSession_;
134         NotifyLandscapeMultiWindowSessionFunc onSetLandscapeMultiWindowFunc_;
135         NotifyLayoutFullScreenChangeFunc onLayoutFullScreenChangeFunc_;
136         NotifyRestoreMainWindowFunc onRestoreMainWindowFunc_;
137         NotifyTitleAndDockHoverShowChangeFunc onTitleAndDockHoverShowChangeFunc_;
138     };
139 
140     // func for change window scene pattern property
141     struct SetWindowScenePatternFunc : public RefBase {
142         SetWindowPatternOpacityFunc setOpacityFunc_;
143     };
144 
145     SceneSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback);
146     virtual ~SceneSession();
147 
148     WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
149         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
150         sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr,
151         const std::string& identityToken = "") override;
152     WSError ConnectInner(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
153         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
154         sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr,
155         int32_t pid = -1, int32_t uid = -1, const std::string& identityToken = "") override;
156     virtual WSError Reconnect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
157         const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowSessionProperty> property = nullptr,
158         sptr<IRemoteObject> token = nullptr, int32_t pid = -1, int32_t uid = -1);
159     WSError ReconnectInner(sptr<WindowSessionProperty> property);
160     WSError Foreground(sptr<WindowSessionProperty> property, bool isFromClient = false,
161         const std::string& identityToken = "") override;
162     WSError Background(bool isFromClient = false, const std::string& identityToken = "") override;
SyncScenePanelGlobalPosition(bool needSync)163     virtual void SyncScenePanelGlobalPosition(bool needSync) {}
164     WSError BackgroundTask(const bool isSaveSnapshot = true);
165     WSError Disconnect(bool isFromClient = false, const std::string& identityToken = "") override;
166     WSError DisconnectTask(bool isFromClient = false, bool isSaveSnapshot = true);
167     void SetClientIdentityToken(const std::string& clientIdentityToken);
BindKeyboardPanelSession(sptr<SceneSession> panelSession)168     virtual void BindKeyboardPanelSession(sptr<SceneSession> panelSession) {};
GetKeyboardPanelSession() const169     virtual sptr<SceneSession> GetKeyboardPanelSession() const { return nullptr; };
BindKeyboardSession(sptr<SceneSession> session)170     virtual void BindKeyboardSession(sptr<SceneSession> session) {};
GetKeyboardSession() const171     virtual sptr<SceneSession> GetKeyboardSession() const { return nullptr; };
GetKeyboardGravity() const172     virtual SessionGravity GetKeyboardGravity() const { return SessionGravity::SESSION_GRAVITY_DEFAULT; };
OnKeyboardPanelUpdated()173     virtual void OnKeyboardPanelUpdated() {};
OnCallingSessionUpdated()174     virtual void OnCallingSessionUpdated() {};
GetCallingSessionId()175     virtual uint32_t GetCallingSessionId() { return INVALID_SESSION_ID; };
176     bool GetScreenWidthAndHeightFromServer(const sptr<WindowSessionProperty>& sessionProperty,
177         uint32_t& screenWidth, uint32_t& screenHeight);
178     bool GetScreenWidthAndHeightFromClient(const sptr<WindowSessionProperty>& sessionProperty,
179         uint32_t& screenWidth, uint32_t& screenHeight);
180     void NotifyTargetScreenWidthAndHeight(bool isScreenAngleMismatch, uint32_t screenWidth,
181         uint32_t screenHeight);
182 
183     WSError UpdateActiveStatus(bool isActive) override;
184     WSError OnSessionEvent(SessionEvent event) override;
185     WSError OnSystemSessionEvent(SessionEvent event) override;
186     WSError OnLayoutFullScreenChange(bool isLayoutFullScreen) override;
187     WSError OnTitleAndDockHoverShowChange(bool isTitleHoverShown = true,
188         bool isDockHoverShown = true) override;
189     WSError RaiseToAppTop() override;
190     WSError UpdateSizeChangeReason(SizeChangeReason reason) override;
OpenKeyboardSyncTransaction()191     virtual void OpenKeyboardSyncTransaction() {};
CloseKeyboardSyncTransaction(const WSRect& keyboardPanelRect, bool isKeyboardShow, bool isRotating)192     virtual void CloseKeyboardSyncTransaction(const WSRect& keyboardPanelRect,
193         bool isKeyboardShow, bool isRotating) {};
194     WSError UpdateRect(const WSRect& rect, SizeChangeReason reason,
195         const std::string& updateReason, const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;
196     WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason reason, bool isGlobal = false) override;
197     WSError UpdateClientRect(const WSRect& rect) override;
198     WSError ChangeSessionVisibilityWithStatusBar(const sptr<AAFwk::SessionInfo> info, bool visible) override;
199     WSError PendingSessionActivation(const sptr<AAFwk::SessionInfo> info) override;
200     WSError TerminateSession(const sptr<AAFwk::SessionInfo> info) override;
201     WSError NotifySessionException(
202         const sptr<AAFwk::SessionInfo> info, bool needRemoveSession = false) override;
203     WSError NotifySessionExceptionInner(
204         const sptr<AAFwk::SessionInfo> info, bool needRemoveSession = false, bool isFromClient = false);
205     WSError NotifyClientToUpdateRect(const std::string& updateReason,
206         std::shared_ptr<RSTransaction> rsTransaction) override;
207 
208     WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
209         bool needNotifyClient = true) override;
210     WSError RequestSessionBack(bool needMoveToBackground) override;
211     WSError SetAspectRatio(float ratio) override;
212     WSError SetGlobalMaximizeMode(MaximizeMode mode) override;
213     WSError GetGlobalMaximizeMode(MaximizeMode& mode) override;
214     WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) override;
215     WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) override;
216     void SetZOrder(uint32_t zOrder) override;
217     std::vector<Rect> GetTouchHotAreas() const override;
218     void NotifyUILostFocus() override;
219     void SetScale(float scaleX, float scaleY, float pivotX, float pivotY) override;
220     void SetFloatingScale(float floatingScale) override;
221     WSError RaiseAboveTarget(int32_t subWindowId) override;
222 
223     /*
224      * PiP Window
225      */
226     PiPTemplateInfo GetPiPTemplateInfo() const;
227     void SetPiPTemplateInfo(const PiPTemplateInfo& pipTemplateInfo);
228     WSError UpdatePiPRect(const Rect& rect, SizeChangeReason reason) override;
229     WSError UpdatePiPControlStatus(WsPiPControlType controlType, WsPiPControlStatus status) override;
230     WSError SetAutoStartPiP(bool isAutoStart) override;
231     void NotifyPiPWindowPrepareClose() override;
232     void SetSessionPiPControlStatusChangeCallback(const NotifySessionPiPControlStatusChangeFunc& func);
233     void SetAutoStartPiPStatusChangeCallback(const NotifyAutoStartPiPStatusChangeFunc& func);
234     WSError SetPipActionEvent(const std::string& action, int32_t status);
235     WSError SetPiPControlEvent(WsPiPControlType controlType, WsPiPControlStatus status);
236 
237     void RequestHideKeyboard(bool isAppColdStart = false);
238     WSError ProcessPointDownSession(int32_t posX, int32_t posY) override;
239     WSError SendPointEventForMoveDrag(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
240     void NotifyOutsideDownEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
241     WSError NotifyFrameLayoutFinishFromApp(bool notifyListener, const WSRect& rect) override;
242     void SetForegroundInteractiveStatus(bool interactive) override;
243     WSError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) override;
244     WMError SetSystemWindowEnableDrag(bool enableDrag) override;
245 
246     WSError SetKeepScreenOn(bool keepScreenOn);
247     void SetParentPersistentId(int32_t parentId);
248     WSError SetTurnScreenOn(bool turnScreenOn);
249     void SetPrivacyMode(bool isPrivacy);
250     void SetSnapshotSkip(bool isSkip);
251     void SetSystemSceneOcclusionAlpha(double alpha);
252     void SetSystemSceneForceUIFirst(bool forceUIFirst);
253     void SetRequestedOrientation(Orientation orientation);
254     WSError SetDefaultRequestedOrientation(Orientation orientation);
255     void SetWindowAnimationFlag(bool needDefaultAnimationFlag);
256     void SetCollaboratorType(int32_t collaboratorType);
257     void SetLastSafeRect(WSRect rect);
258     void SetMovable(bool isMovable);
259     void SetOriPosYBeforeRaisedByKeyboard(int32_t posY);
260 
261     /*
262      * Window Hierarchy
263      */
SetTopmost(bool topmost)264     virtual WSError SetTopmost(bool topmost) { return WSError::WS_ERROR_INVALID_CALLING; }
IsTopmost() const265     virtual bool IsTopmost() const { return false; }
SetMainWindowTopmost(bool isTopmost)266     virtual WSError SetMainWindowTopmost(bool isTopmost) { return WSError::WS_ERROR_INVALID_CALLING; }
IsMainWindowTopmost() const267     virtual bool IsMainWindowTopmost() const { return false; }
268     void SetMainWindowTopmostChangeCallback(const NotifyMainWindowTopmostChangeFunc& func);
269 
IsModal() const270     virtual bool IsModal() const { return false; }
271     WSError OnSessionModalTypeChange(SubWindowModalType subWindowModalType) override;
272     void SetSessionModalTypeChangeCallback(const NotifySessionModalTypeChangeFunc& func);
273 
274     /**
275      * Window Immersive
276      */
277     WSError OnNeedAvoid(bool status) override;
278     AvoidArea GetAvoidAreaByTypeInner(AvoidAreaType type);
279     AvoidArea GetAvoidAreaByType(AvoidAreaType type) override;
280     WSError GetAllAvoidAreas(std::map<AvoidAreaType, AvoidArea>& avoidAreas) override;
281     WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty);
282     void SetIsStatusBarVisible(bool isVisible);
283     WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override;
284     void UpdateRotationAvoidArea();
285     bool CheckGetAvoidAreaAvailable(AvoidAreaType type) override;
286     bool GetIsDisplayStatusBarTemporarily() const;
287     void SetIsDisplayStatusBarTemporarily(bool isTemporary);
288 
289     void SetAbilitySessionInfo(std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo);
290     void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func);
291     void SetSessionEventParam(SessionEventParam param);
292     void SetSessionRectChangeCallback(const NotifySessionRectChangeFunc& func);
293     void SetKeyboardGravityChangeCallback(const NotifyKeyboardGravityChangeFunc& func);
294     void SetRestoreMainWindowCallback(const NotifyRestoreMainWindowFunc& func);
295     void SetAdjustKeyboardLayoutCallback(const NotifyKeyboardLayoutAdjustFunc& func);
296     void SetSkipDraw(bool skip);
297     virtual void SetSkipSelfWhenShowOnVirtualScreen(bool isSkip);
298     WMError SetUniqueDensityDpi(bool useUnique, float dpi);
299 
300     bool IsAnco() const override;
301     void SetBlankFlag(bool isAddBlank) override;
302     bool GetBlankFlag() const override;
303     void SetBufferAvailableCallbackEnable(bool enable);
304     bool GetBufferAvailableCallbackEnable() const override;
305     int32_t GetCollaboratorType() const;
306     WSRect GetLastSafeRect() const;
307     WSRect GetSessionTargetRect() const;
308     std::string GetUpdatedIconPath() const;
309     std::string GetSessionSnapshotFilePath() const;
310     int32_t GetParentPersistentId() const;
311     int32_t GetMainSessionId();
GetMissionId() const312     virtual int32_t GetMissionId() const { return persistentId_; };
313     Orientation GetRequestedOrientation() const;
314     std::vector<sptr<SceneSession>> GetSubSession() const;
315     std::vector<sptr<SceneSession>> GetToastSession() const;
316     std::shared_ptr<AppExecFwk::AbilityInfo> GetAbilityInfo() const;
317     std::string GetWindowNameAllType() const;
318     SubWindowModalType GetSubWindowModalType() const;
319     int32_t GetOriPosYBeforeRaisedByKeyboard() const;
320     std::string GetClientIdentityToken() const;
321 
322     /*
323      * Window Watermark
324      */
325     void SetWatermarkEnabled(const std::string& watermarkName, bool isEnabled);
326 
327     sptr<MoveDragController> moveDragController_ = nullptr;
328 
329     // Session recover
IsRecovered() const330     bool IsRecovered() const { return isRecovered_; }
SetRecovered(bool isRecovered)331     void SetRecovered(bool isRecovered) { isRecovered_ = isRecovered; }
332 
333     bool IsDecorEnable() const;
334     bool IsAppSession() const;
335     bool IsAppOrLowerSystemSession() const;
336     bool IsSystemSessionAboveApp() const;
337     bool IsTurnScreenOn() const;
338     bool IsKeepScreenOn() const;
339     bool IsShowWhenLocked() const;
340     bool GetShowWhenLockedFlagValue() const;
341     bool IsFloatingWindowAppType() const;
342     bool IsNeedDefaultAnimation() const;
343     bool IsDirtyWindow();
344     void SetSystemTouchable(bool touchable) override;
345     bool IsVisibleForAccessibility() const;
346     void SetStartingWindowExitAnimationFlag(bool enable);
347     bool NeedStartingWindowExitAnimation() const override;
348 
349     void NotifyWindowVisibility();
350     WSError OnShowWhenLocked(bool showWhenLocked);
351     void SaveUpdatedIcon(const std::shared_ptr<Media::PixelMap>& icon);
352     void NotifyTouchOutside();
353     bool CheckOutTouchOutsideRegister();
354     void UpdateNativeVisibility(bool visible);
355     void DumpSessionElementInfo(const std::vector<std::string>& params);
356     void NotifyForceHideChange(bool hide);
357     WSError BindDialogSessionTarget(const sptr<SceneSession>& sceneSession);
358     void DumpSessionInfo(std::vector<std::string>& info) const;
359     bool AddSubSession(const sptr<SceneSession>& subSession);
360     bool RemoveSubSession(int32_t persistentId);
361     bool AddToastSession(const sptr<SceneSession>& toastSession);
362     bool RemoveToastSession(int32_t persistentId);
363     void NotifySessionForeground(uint32_t reason, bool withAnimation);
364     void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits);
365     void RegisterSessionChangeCallback(const sptr<SceneSession::SessionChangeCallback>& sessionChangeCallback);
366     void RegisterDefaultAnimationFlagChangeCallback(NotifyWindowAnimationFlagChangeFunc&& callback);
367     void RegisterSystemBarPropertyChangeCallback(NotifySystemBarPropertyChangeFunc&& callback);
368     void RegisterForceSplitListener(const NotifyForceSplitFunc& func);
369     void SetUpdatePrivateStateAndNotifyFunc(const UpdatePrivateStateAndNotifyFunc& func);
370 
371     /*
372      * Window Visibility
373      */
374     void SetNotifyVisibleChangeFunc(const NotifyVisibleChangeFunc& func);
375 
376     /*
377      * Window Lifecycle
378      */
379     void ClearJsSceneSessionCbMap(bool needRemove); // ONLY Accessed on OS_sceneSession thread
380     void ClearSpecificSessionCbMap();
381 
382     void SendPointerEventToUI(std::shared_ptr<MMI::PointerEvent> pointerEvent);
383     bool SendKeyEventToUI(std::shared_ptr<MMI::KeyEvent> keyEvent, bool isPreImeEvent = false);
384     bool IsStartMoving() const;
385     void SetIsStartMoving(const bool startMoving);
386     WSError GetStartMoveFlag(bool& isMoving) override;
387     bool IsSystemSpecificSession() const;
388     void SetIsSystemSpecificSession(bool isSystemSpecificSession);
389     void SetShouldHideNonSecureWindows(bool shouldHide);
390     void UpdateExtWindowFlags(int32_t extPersistentId, const ExtensionWindowFlags& extWindowFlags,
391         const ExtensionWindowFlags& extWindowActions);
392     ExtensionWindowFlags GetCombinedExtWindowFlags();
393     void RemoveExtWindowFlags(int32_t extPersistentId);
394     void ClearExtWindowFlags();
395     void NotifyDisplayMove(DisplayId from, DisplayId to);
396     void NotifySessionFullScreen(bool fullScreen);
397     void SetDefaultDisplayIdIfNeed();
398 
399     void SetSessionState(SessionState state) override;
400     void UpdateSessionState(SessionState state) override;
401     void SetForceHideState(ForceHideState forceHideState);
402     ForceHideState GetForceHideState() const;
403     bool IsTemporarilyShowWhenLocked() const;
404     void SetTemporarilyShowWhenLocked(bool isTemporarilyShowWhenLocked);
405 
406     std::shared_ptr<PowerMgr::RunningLock> keepScreenLock_;
407 
408     static const wptr<SceneSession> GetEnterWindow();
409     static void ClearEnterWindow();
410     static MaximizeMode maximizeMode_;
411     static uint32_t GetWindowDragHotAreaType(DisplayId displayId, uint32_t type, int32_t pointerX, int32_t pointerY);
412     static void AddOrUpdateWindowDragHotArea(DisplayId displayId, uint32_t type, const WSRect& area);
413     WSError UpdateRectChangeListenerRegistered(bool isRegister) override;
414 
415     /*
416      * Window Decor
417      */
418     int32_t GetCustomDecorHeight() const;
419     void SetCustomDecorHeight(int32_t height) override;
420 
421     WMError UpdateSessionPropertyByAction(const sptr<WindowSessionProperty>& property,
422         WSPropertyChangeAction action) override;
423     void SetSessionChangeByActionNotifyManagerListener(const SessionChangeByActionNotifyManagerFunc& func);
424 
425     void AddModalUIExtension(const ExtensionWindowEventInfo& extensionInfo);
426     void RemoveModalUIExtension(int32_t persistentId);
427     bool HasModalUIExtension();
428     void UpdateModalUIExtension(const ExtensionWindowEventInfo& extensionInfo);
429     ExtensionWindowEventInfo GetLastModalUIExtensionEventInfo();
430     Vector2f GetSessionGlobalPosition(bool useUIExtension);
431     void AddUIExtSurfaceNodeId(uint64_t surfaceNodeId, int32_t persistentId);
432     void RemoveUIExtSurfaceNodeId(int32_t persistentId);
433     int32_t GetUIExtPersistentIdBySurfaceNodeId(uint64_t surfaceNodeId) const;
434     int32_t GetStatusBarHeight() override;
IsFreeMultiWindowMode() const435     bool IsFreeMultiWindowMode() const
436     {
437         return systemConfig_.IsFreeMultiWindowMode();
438     }
439     WMError GetAppForceLandscapeConfig(AppForceLandscapeConfig& config) override;
440 
441     // WMSPipeline-related: only accessed on SSM thread
442     uint32_t UpdateUIParam(const SessionUIParam& uiParam);   // update visible session, return dirty flags
443     uint32_t UpdateUIParam();   // update invisible session, return dirty flags
444     void SetPostProcessFocusState(PostProcessFocusState state);
445     PostProcessFocusState GetPostProcessFocusState() const;
446     void ResetPostProcessFocusState();
447     void SetPostProcessProperty(bool state);
448     bool GetPostProcessProperty() const;
449     void PostProcessNotifyAvoidArea();
450     bool IsImmersiveType() const;
451     bool IsPcOrPadEnableActivation() const;
452 
453     /*
454      * Multi User
455      */
456     void SetMinimizedFlagByUserSwitch(bool isMinimized);
457     bool IsMinimizedByUserSwitch() const;
458     void UnregisterSessionChangeListeners() override;
459     void SetVisibilityChangedDetectFunc(const VisibilityChangedDetectFunc& func);
460 
461     /*
462      * Window ZOrder: PC
463      */
SetPcScenePanel(bool isPcScenePanel)464     void SetPcScenePanel(bool isPcScenePanel) { isPcScenePanel_ = isPcScenePanel; }
465     void PcUpdateZOrderAndDirty(const uint32_t zOrder);
466 
467     void SetPrivacyModeChangeNotifyFunc(const NotifyPrivacyModeChangeFunc& func);
468 
469     /*
470      * Multi Window
471      */
472     WSError SetSplitButtonVisible(bool isVisible);
473 
474     /*
475      * Gesture Back
476      */
477     bool GetGestureBackEnabled();
478     bool GetEnableGestureBackHadSet();
479 
480 protected:
481     void NotifySessionRectChange(const WSRect& rect,
482         const SizeChangeReason reason = SizeChangeReason::UNDEFINED, const DisplayId displayId = DISPLAY_ID_INVALID);
483     void NotifyIsCustomAnimationPlaying(bool isPlaying);
484     void SetMoveDragCallback();
485     std::string GetRatioPreferenceKey();
486     WSError NotifyClientToUpdateRectTask(const std::string& updateReason, std::shared_ptr<RSTransaction> rsTransaction);
487     bool CheckPermissionWithPropertyAnimation(const sptr<WindowSessionProperty>& property) const;
488 
GetRectInfo(const WSRect& rect)489     std::string GetRectInfo(const WSRect& rect)
490     {
491         using std::to_string;
492         return "[" + to_string(rect.width_) + ", " + to_string(rect.height_) + "; "
493         + to_string(rect.posX_) + ", " + to_string(rect.posY_) + "]";
494     }
495 
496     bool UpdateVisibilityInner(bool visibility);
497     bool UpdateInteractiveInner(bool interactive);
NotifyClientToUpdateInteractive(bool interactive)498     virtual void NotifyClientToUpdateInteractive(bool interactive) {}
499     bool PipelineNeedNotifyClientToUpdateRect() const;
500     bool UpdateRectInner(const SessionUIParam& uiParam, SizeChangeReason reason);
501     bool NotifyServerToUpdateRect(const SessionUIParam& uiParam, SizeChangeReason reason);
502     bool UpdateScaleInner(float scaleX, float scaleY, float pivotX, float pivotY);
503     bool UpdateZOrderInner(uint32_t zOrder);
504     virtual void NotifyClientToUpdateAvoidArea();
505     bool PipelineNeedNotifyClientToUpdateAvoidArea(uint32_t dirty) const;
506 
507     /*
508      * Gesture Back
509      */
510     void UpdateGestureBackEnabled() override;
511 
512     sptr<SpecificSessionCallback> specificCallback_ = nullptr;
513     sptr<SessionChangeCallback> sessionChangeCallback_ = nullptr;
514     sptr<SceneSession> keyboardPanelSession_ = nullptr;
515     sptr<SceneSession> keyboardSession_ = nullptr;
516     NotifyKeyboardGravityChangeFunc keyboardGravityChangeFunc_;
517     NotifyKeyboardLayoutAdjustFunc adjustKeyboardLayoutFunc_;
518     NotifySystemBarPropertyChangeFunc onSystemBarPropertyChange_;
519 
520     /*
521      * Window Hierarchy
522      */
523     NotifyMainWindowTopmostChangeFunc mainWindowTopmostChangeFunc_;
524 
525 private:
526     void NotifyAccessibilityVisibilityChange();
527     void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const;
528     void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea);
529     void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea);
530     void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea);
531     void CalculateCombinedExtWindowFlags();
532     void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) const;
533     void HandleStyleEvent(MMI::WindowArea area) override;
534     WSError HandleEnterWinwdowArea(int32_t windowX, int32_t windowY);
535 
536     /*
537      * Window Lifecycle
538      */
539     bool CheckIdentityTokenIfMatched(const std::string& identityToken);
540     bool CheckPidIfMatched();
541 
542     // session lifecycle funcs
543     WSError ForegroundTask(const sptr<WindowSessionProperty>& property);
544 
545     /*
546      * Move Drag
547      */
548     void HandleMoveDragSurfaceNode(const SizeChangeReason reason);
549     void OnMoveDragCallback(const SizeChangeReason reason);
550     void InitializeCrossMoveDrag();
551     void HandleMoveDrag(WSRect& rect, WSRect& globalRect, const SizeChangeReason reason,
552         bool isGlobal, bool needFlush);
553     void HandleMoveDragEnd(WSRect& rect, const SizeChangeReason reason);
554 
555     /*
556      * Gesture Back
557      */
558     WMError SetGestureBackEnabled(bool isEnabled) override;
559 
560 #ifdef DEVICE_STATUS_ENABLE
561     void RotateDragWindow(std::shared_ptr<RSTransaction> rsTransaction);
562 #endif // DEVICE_STATUS_ENABLE
563     void HandleCompatibleModeMoveDrag(WSRect& rect, const SizeChangeReason reason,
564         bool isSupportDragInPcCompatibleMode, bool isGlobal = false, bool needFlush = true);
565     void HandleCompatibleModeDrag(WSRect& rect, const SizeChangeReason reason,
566         bool isSupportDragInPcCompatibleMode, bool isGlobal, bool needFlush);
567     void FixRectByLimits(WindowLimits limits, WSRect& rect, float ratio, bool isDecor, float vpr);
568     bool FixRectByAspectRatio(WSRect& rect);
569     bool SaveAspectRatio(float ratio);
570     void NotifyPropertyWhenConnect();
571     WSError RaiseAppMainWindowToTop() override;
572     void SetSurfaceBounds(const WSRect& rect, bool isGlobal = false, bool needFlush = true);
573     void UpdateWinRectForSystemBar(WSRect& rect);
574     bool UpdateInputMethodSessionRect(const WSRect& rect, WSRect& newWinRect, WSRect& newRequestRect);
575     bool IsMovableWindowType();
576     bool IsFullScreenMovable();
577     bool IsMovable();
578     void HandleCastScreenConnection(SessionInfo& info, sptr<SceneSession> session);
579     void UpdateSessionRectInner(const WSRect& rect, const SizeChangeReason reason);
580     WMError HandleUpdatePropertyByAction(const sptr<WindowSessionProperty>& property,
581         WSPropertyChangeAction action);
582     WMError HandleActionUpdateTurnScreenOn(const sptr<WindowSessionProperty>& property,
583         WSPropertyChangeAction action);
584     WMError HandleActionUpdateKeepScreenOn(const sptr<WindowSessionProperty>& property,
585         WSPropertyChangeAction action);
586     WMError HandleActionUpdateFocusable(const sptr<WindowSessionProperty>& property,
587         WSPropertyChangeAction action);
588     WMError HandleActionUpdateTouchable(const sptr<WindowSessionProperty>& property,
589         WSPropertyChangeAction action);
590     WMError HandleActionUpdateSetBrightness(const sptr<WindowSessionProperty>& property,
591         WSPropertyChangeAction action);
592     WMError HandleActionUpdateOrientation(const sptr<WindowSessionProperty>& property,
593         WSPropertyChangeAction action);
594     WMError HandleActionUpdatePrivacyMode(const sptr<WindowSessionProperty>& property,
595         WSPropertyChangeAction action);
596     WMError HandleActionUpdateSnapshotSkip(const sptr<WindowSessionProperty>& property,
597         WSPropertyChangeAction action);
598     WMError HandleActionUpdateMaximizeState(const sptr<WindowSessionProperty>& property,
599         WSPropertyChangeAction action);
600     WMError HandleActionUpdateOtherProps(const sptr<WindowSessionProperty>& property,
601         WSPropertyChangeAction action);
602     WMError HandleActionUpdateStatusProps(const sptr<WindowSessionProperty>& property,
603         WSPropertyChangeAction action);
604     WMError HandleActionUpdateNavigationProps(const sptr<WindowSessionProperty>& property,
605         WSPropertyChangeAction action);
606     WMError HandleActionUpdateNavigationIndicatorProps(const sptr<WindowSessionProperty>& property,
607         WSPropertyChangeAction action);
608     WMError HandleActionUpdateFlags(const sptr<WindowSessionProperty>& property,
609         WSPropertyChangeAction action);
610     WMError HandleActionUpdateMode(const sptr<WindowSessionProperty>& property,
611         WSPropertyChangeAction action);
612     WMError HandleActionUpdateAnimationFlag(const sptr<WindowSessionProperty>& property,
613         WSPropertyChangeAction action);
614     WMError HandleActionUpdateTouchHotArea(const sptr<WindowSessionProperty>& property,
615         WSPropertyChangeAction action);
616     WMError HandleActionUpdateDecorEnable(const sptr<WindowSessionProperty>& property,
617         WSPropertyChangeAction action);
618     WMError HandleActionUpdateWindowLimits(const sptr<WindowSessionProperty>& property,
619         WSPropertyChangeAction action);
620     WMError HandleActionUpdateDragenabled(const sptr<WindowSessionProperty>& property,
621         WSPropertyChangeAction action);
622     WMError HandleActionUpdateRaiseenabled(const sptr<WindowSessionProperty>& property,
623         WSPropertyChangeAction action);
624     WMError HandleActionUpdateHideNonSystemFloatingWindows(const sptr<WindowSessionProperty>& property,
625         WSPropertyChangeAction action);
626     WMError HandleActionUpdateTextfieldAvoidInfo(const sptr<WindowSessionProperty>& property,
627         WSPropertyChangeAction action);
628     WMError HandleActionUpdateWindowMask(const sptr<WindowSessionProperty>& property,
629         WSPropertyChangeAction action);
630     WMError HandleActionUpdateTopmost(const sptr<WindowSessionProperty>& property,
631         WSPropertyChangeAction action);
632     WMError HandleActionUpdateMainWindowTopmost(const sptr<WindowSessionProperty>& property,
633         WSPropertyChangeAction action);
634     WMError HandleActionUpdateModeSupportInfo(const sptr<WindowSessionProperty>& property,
635         WSPropertyChangeAction action);
636     WMError ProcessUpdatePropertyByAction(const sptr<WindowSessionProperty>& property,
637         WSPropertyChangeAction action);
638     void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property);
639     void SetWindowFlags(const sptr<WindowSessionProperty>& property);
640     void NotifySessionChangeByActionNotifyManager(const sptr<WindowSessionProperty>& property,
641         WSPropertyChangeAction action);
642     void NotifyPrivacyModeChange();
643 
644     /*
645      * PiP Window
646      */
647     NotifySessionPiPControlStatusChangeFunc sessionPiPControlStatusChangeFunc_;
648     NotifyAutoStartPiPStatusChangeFunc autoStartPiPStatusChangeFunc_;
649     PiPTemplateInfo pipTemplateInfo_ = {0, 0, {}};
650 
651     NotifyForceSplitFunc forceSplitFunc_;
652     UpdatePrivateStateAndNotifyFunc updatePrivateStateAndNotifyFunc_;
653     NotifyPrivacyModeChangeFunc privacyModeChangeNotifyFunc_;
654     static wptr<SceneSession> enterSession_;
655     static std::mutex enterSessionMutex_;
656     int32_t collaboratorType_ = CollaboratorType::DEFAULT_TYPE;
657     mutable std::mutex sessionChangeCbMutex_;
658     WSRect lastSafeRect = { 0, 0, 0, 0 };
659     std::vector<sptr<SceneSession>> subSession_;
660     std::vector<sptr<SceneSession>> toastSession_;
661     std::atomic_bool needStartingWindowExitAnimation_ { true };
662     bool needDefaultAnimationFlag_ = true;
663     SessionEventParam sessionEventParam_ = { 0, 0, 0, 0 };
664     std::atomic_bool isStartMoving_ { false };
665     std::atomic_bool isVisibleForAccessibility_ { true };
666     std::atomic_bool isDisplayStatusBarTemporarily_ { false };
667     bool isSystemSpecificSession_ { false };
668     std::atomic_bool shouldHideNonSecureWindows_ { false };
669     std::shared_mutex combinedExtWindowFlagsMutex_;
670     ExtensionWindowFlags combinedExtWindowFlags_ { 0 };
671     std::map<int32_t, ExtensionWindowFlags> extWindowFlagsMap_;
672 
673     /*
674      * Window Decor
675      */
676     mutable std::mutex customDecorHeightMutex_;
677     int32_t customDecorHeight_ = 0;
678 
679     ForceHideState forceHideState_ { ForceHideState::NOT_HIDDEN };
680     std::string clientIdentityToken_ = { "" };
681     SessionChangeByActionNotifyManagerFunc sessionChangeByActionNotifyManagerFunc_;
682     int32_t oriPosYBeforeRaisedByKeyboard_ = 0;
683     std::atomic_bool isTemporarilyShowWhenLocked_ { false };
684     std::shared_mutex modalUIExtensionInfoListMutex_;
685     std::vector<ExtensionWindowEventInfo> modalUIExtensionInfoList_;
686     mutable std::shared_mutex uiExtNodeIdToPersistentIdMapMutex_;
687     std::map<uint64_t, int32_t> uiExtNodeIdToPersistentIdMap_;
688 
689     bool isAddBlank_ = false;
690     bool bufferAvailableCallbackEnable_ = false;
691     bool isScreenAngleMismatch_ = false;
692     uint32_t targetScreenWidth_ = 0;
693     uint32_t targetScreenHeight_ = 0;
694     bool isStatusBarVisible_ = true;
695 
696     // WMSPipeline-related: only accessed on SSM thread
697     PostProcessFocusState postProcessFocusState_;
698     bool postProcessProperty_ { false };
699 
700     // Session recover
701     bool isRecovered_ = false;
702 
703     // Multi User
704     bool isMinimizedByUserSwitch_ { false };
705 
706     /*
707      * Window ZOrder: PC
708      */
709     bool isPcScenePanel_ { false };
710 
711     /*
712      * Move Drag
713      */
714     static std::shared_mutex windowDragHotAreaMutex_;
715     static std::map<uint64_t, std::map<uint32_t, WSRect>> windowDragHotAreaMap_;
716 
717     // Set true if either sessionProperty privacyMode or combinedExtWindowFlags_ privacyModeFlag is true.
718     bool isPrivacyMode_ { false };
719 
720     /*
721      * Gesture Back
722      */
723     bool isEnableGestureBack_ { true };
724     bool isEnableGestureBackHadSet_ { false };
725 
726     /*
727      * Window Visibility
728      */
729     NotifyVisibleChangeFunc notifyVisibleChangeFunc_;
730 };
731 } // namespace OHOS::Rosen
732 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H
733