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