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_SESSION_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_H 18 19 #include <list> 20 #include <mutex> 21 #include <shared_mutex> 22 #include <vector> 23 24 #include <event_handler.h> 25 26 #include "dm_common.h" 27 #include "interfaces/include/ws_common.h" 28 #include "layout_controller.h" 29 #include "occupied_area_change_info.h" 30 #include "pattern_detach_callback_interface.h" 31 #include "session/container/include/zidl/session_stage_interface.h" 32 #include "session/host/include/zidl/session_stub.h" 33 #include "session/host/include/scene_persistence.h" 34 #include "thread_safety_annotations.h" 35 #include "vsync_station.h" 36 #include "window_visibility_info.h" 37 #include "wm_common.h" 38 #include "floating_ball_template_info.h" 39 40 namespace OHOS::MMI { 41 class PointerEvent; 42 class KeyEvent; 43 class AxisEvent; 44 enum class WindowArea; 45 } // namespace OHOS::MMI 46 47 namespace OHOS::Media { 48 class PixelMap; 49 } // namespace OHOS::Media 50 51 namespace OHOS::Rosen { 52 class RSSurfaceNode; 53 class RSUIContext; 54 class RSTransaction; 55 class Session; 56 using NotifySessionRectChangeFunc = std::function<void(const WSRect& rect, 57 SizeChangeReason reason, DisplayId displayId, const RectAnimationConfig& rectAnimationConfig)>; 58 using NotifyUpdateFloatingBallFunc = std::function<void(const FloatingBallTemplateInfo& fbTemplateInfo)>; 59 using NotifyStopFloatingBallFunc = std::function<void()>; 60 using NotifyRestoreFloatingBallMainWindowFunc = std::function<void(const std::shared_ptr<AAFwk::Want>& want)>; 61 using NotifySessionDisplayIdChangeFunc = std::function<void(uint64_t displayId)>; 62 using NotifyPendingSessionActivationFunc = std::function<void(SessionInfo& info)>; 63 using NotifyBatchPendingSessionsActivationFunc = std::function<void(std::vector<std::shared_ptr<SessionInfo>>& info)>; 64 using NotifyChangeSessionVisibilityWithStatusBarFunc = std::function<void(const SessionInfo& info, bool visible)>; 65 using NotifySessionStateChangeFunc = std::function<void(const SessionState& state)>; 66 using NotifyBufferAvailableChangeFunc = std::function<void(const bool isAvailable, bool startWindowInvisible)>; 67 using NotifySessionStateChangeNotifyManagerFunc = std::function<void(int32_t persistentId, const SessionState& state)>; 68 using NotifyRequestFocusStatusNotifyManagerFunc = 69 std::function<void(int32_t persistentId, const bool isFocused, const bool byForeground, FocusChangeReason reason)>; 70 using NotifyBackPressedFunc = std::function<void(const bool needMoveToBackground)>; 71 using NotifySessionFocusableChangeFunc = std::function<void(const bool isFocusable)>; 72 using NotifySessionTouchableChangeFunc = std::function<void(const bool touchable)>; 73 using NotifyClickFunc = std::function<void(bool requestFocus, bool isClick)>; 74 using NotifyTerminateSessionFunc = std::function<void(const SessionInfo& info)>; 75 using NotifyTerminateSessionFuncNew = 76 std::function<void(const SessionInfo& info, bool needStartCaller, bool isFromBroker, bool isForceClean)>; 77 using NotifyTerminateSessionFuncTotal = std::function<void(const SessionInfo& info, TerminateType terminateType)>; 78 using NofitySessionLabelUpdatedFunc = std::function<void(const std::string& label)>; 79 using NofitySessionIconUpdatedFunc = std::function<void(const std::string& iconPath)>; 80 using NotifySessionExceptionFunc = 81 std::function<void(const SessionInfo& info, const ExceptionInfo& exceptionInfo, bool startFail)>; 82 using NotifySessionSnapshotFunc = std::function<void(const int32_t& persistentId)>; 83 using NotifyPendingSessionToForegroundFunc = std::function<void(const SessionInfo& info)>; 84 using NotifyPendingSessionToBackgroundFunc = std::function<void(const SessionInfo& info, 85 const BackgroundParams& params)>; 86 using NotifyPendingSessionToBackgroundForDelegatorFunc = std::function<void(const SessionInfo& info, 87 bool shouldBackToCaller)>; 88 using NotifyClickModalWindowOutsideFunc = std::function<void()>; 89 using NotifyRaiseMainWindowAboveTargetFunc = std::function<void(int32_t targetId)>; 90 using NotifyRaiseToTopForPointDownFunc = std::function<void()>; 91 using NotifyUIRequestFocusFunc = std::function<void()>; 92 using NotifyUILostFocusFunc = std::function<void()>; 93 using NotifySessionInfoLockedStateChangeFunc = std::function<void(const bool lockedState)>; 94 using NotifyDisplayIdChangedNotifyManagerFunc = std::function<void(int32_t persistentId, uint64_t displayId)>; 95 using GetStateFromManagerFunc = std::function<bool(const ManagerState key)>; 96 using NotifySystemSessionPointerEventFunc = std::function<void(std::shared_ptr<MMI::PointerEvent> pointerEvent)>; 97 using NotifySessionInfoChangeNotifyManagerFunc = std::function<void(int32_t persistentid)>; 98 using NotifySessionPropertyChangeNotifyManagerFunc = 99 std::function<void(int32_t persistentid, WindowInfoKey windowInfoKey)>; 100 using NotifySystemSessionKeyEventFunc = std::function<bool(std::shared_ptr<MMI::KeyEvent> keyEvent, 101 bool isPreImeEvent)>; 102 using NotifyContextTransparentFunc = std::function<void()>; 103 using NotifyFrameLayoutFinishFunc = std::function<void()>; 104 using VisibilityChangedDetectFunc = std::function<void(int32_t pid, bool isVisible, bool newIsVisible)>; 105 using AcquireRotateAnimationConfigFunc = std::function<void(RotateAnimationConfig& config)>; 106 using RequestVsyncFunc = std::function<void(const std::shared_ptr<VsyncCallback>& callback)>; 107 using NotifyWindowMovingFunc = std::function<void(DisplayId displayId, int32_t pointerX, int32_t pointerY)>; 108 using UpdateTransitionAnimationFunc = std::function<void(WindowTransitionType type, TransitionAnimation animation)>; 109 using NofitySessionLabelAndIconUpdatedFunc = 110 std::function<void(const std::string& label, const std::shared_ptr<Media::PixelMap>& icon)>; 111 using NotifySessionGetTargetOrientationConfigInfoFunc = std::function<void(uint32_t targetOrientation)>; 112 using NotifyKeyboardStateChangeFunc = std::function<void(SessionState state, const KeyboardEffectOption& effectOption)>; 113 using NotifyHighlightChangeFunc = std::function<void(bool isHighlight)>; 114 using NotifySurfaceBoundsChangeFunc = std::function<void(const WSRect& rect, bool isGlobal, bool needFlush)>; 115 using HasRequestedVsyncFunc = std::function<WSError(bool& hasRequestedVsync)>; 116 using RequestNextVsyncWhenModeChangeFunc = std::function<WSError(const std::shared_ptr<VsyncCallback>& vsyncCallback)>; 117 using NotifyClearSubSessionFunc = std::function<void(const int32_t subPersistentId)>; 118 class ILifecycleListener { 119 public: OnActivation()120 virtual void OnActivation() {} OnConnect()121 virtual void OnConnect() {} OnForeground()122 virtual void OnForeground() {} OnBackground()123 virtual void OnBackground() {} OnDisconnect()124 virtual void OnDisconnect() {} OnLayoutFinished()125 virtual void OnLayoutFinished() {} OnRemoveBlank()126 virtual void OnRemoveBlank() {} OnAddSnapshot()127 virtual void OnAddSnapshot() {} OnRemoveSnapshot()128 virtual void OnRemoveSnapshot() {} OnDrawingCompleted()129 virtual void OnDrawingCompleted() {} OnExtensionDied()130 virtual void OnExtensionDied() {} OnExtensionDetachToDisplay()131 virtual void OnExtensionDetachToDisplay() {} OnExtensionTimeout(int32_t errorCode)132 virtual void OnExtensionTimeout(int32_t errorCode) {} OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo & info,int64_t uiExtensionIdLevel)133 virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, 134 int64_t uiExtensionIdLevel) {} OnAppRemoveStartingWindow()135 virtual void OnAppRemoveStartingWindow() {} OnUpdateSnapshotWindow()136 virtual void OnUpdateSnapshotWindow() {} OnPreLoadStartingWindowFinished()137 virtual void OnPreLoadStartingWindowFinished() {} 138 }; 139 140 enum class LifeCycleTaskType : uint32_t { 141 START, 142 STOP 143 }; 144 145 enum class DetectTaskState : uint32_t { 146 NO_TASK, 147 ATTACH_TASK, 148 DETACH_TASK 149 }; 150 151 struct DetectTaskInfo { 152 WindowMode taskWindowMode = WindowMode::WINDOW_MODE_UNDEFINED; 153 DetectTaskState taskState = DetectTaskState::NO_TASK; 154 }; 155 156 struct ControlInfo { 157 bool isNeedControl; 158 bool isControlRecentOnly; 159 }; 160 161 const std::string ATTACH_EVENT_NAME { "wms::ReportWindowTimeout_Attach" }; 162 const std::string DETACH_EVENT_NAME { "wms::ReportWindowTimeout_Detach" }; 163 164 class Session : public SessionStub { 165 public: 166 friend class HidumpController; 167 using Task = std::function<void()>; 168 explicit Session(const SessionInfo& info); 169 virtual ~Session(); 170 bool isKeyboardPanelEnabled_ = false; 171 virtual void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler>& handler, 172 const std::shared_ptr<AppExecFwk::EventHandler>& exportHandler = nullptr); 173 174 /* 175 * Window LifeCycle 176 */ 177 virtual WSError ConnectInner(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 178 const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig, 179 sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr, 180 int32_t pid = -1, int32_t uid = -1, const std::string& identityToken = "") REQUIRES(SCENE_GUARD); 181 WSError Foreground(sptr<WindowSessionProperty> property, bool isFromClient = false, 182 const std::string& identityToken = "") override; 183 WSError Background(bool isFromClient = false, const std::string& identityToken = "") override; 184 WSError Disconnect(bool isFromClient = false, const std::string& identityToken = "") override REQUIRES(SCENE_GUARD); 185 WSError Show(sptr<WindowSessionProperty> property) override; 186 WSError Hide() override; 187 WSError DrawingCompleted() override; 188 void ResetSessionConnectState() REQUIRES(SCENE_GUARD); 189 void ResetIsActive(); 190 WSError PendingSessionToForeground(); 191 WSError PendingSessionToBackground(const BackgroundParams& params); 192 WSError PendingSessionToBackgroundForDelegator(bool shouldBackToCaller); 193 bool RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener); 194 bool UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener); 195 void SetPendingSessionActivationEventListener(NotifyPendingSessionActivationFunc&& func); 196 void SetBatchPendingSessionsActivationEventListener(NotifyBatchPendingSessionsActivationFunc&& func); 197 void SetTerminateSessionListener(NotifyTerminateSessionFunc&& func); 198 void SetTerminateSessionListenerNew(NotifyTerminateSessionFuncNew&& func); 199 void SetSessionExceptionListener(NotifySessionExceptionFunc&& func, bool fromJsScene); 200 void SetTerminateSessionListenerTotal(NotifyTerminateSessionFuncTotal&& func); 201 void SetBackPressedListenser(NotifyBackPressedFunc&& func); 202 void SetPendingSessionToForegroundListener(NotifyPendingSessionToForegroundFunc&& func); 203 void SetPendingSessionToBackgroundListener(NotifyPendingSessionToBackgroundFunc&& func); 204 void SetPendingSessionToBackgroundForDelegatorListener(NotifyPendingSessionToBackgroundForDelegatorFunc&& func); 205 void SetSessionSnapshotListener(const NotifySessionSnapshotFunc& func); 206 WSError TerminateSessionNew(const sptr<AAFwk::SessionInfo> info, bool needStartCaller, bool isFromBroker); 207 WSError TerminateSessionTotal(const sptr<AAFwk::SessionInfo> info, TerminateType terminateType); 208 209 /* 210 * App Use Control 211 */ GetIsUseControlSession()212 virtual bool GetIsUseControlSession() const { return false; } SetIsUseControlSession(bool isUseControlSession)213 virtual void SetIsUseControlSession(bool isUseControlSession) {} NotifyUpdateAppUseControl(ControlAppType type,const ControlInfo & controlInfo)214 virtual void NotifyUpdateAppUseControl(ControlAppType type, const ControlInfo& controlInfo) {} 215 216 /* 217 * Window Recover 218 */ 219 WSError Reconnect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel, 220 const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowSessionProperty> property = nullptr, 221 sptr<IRemoteObject> token = nullptr, int32_t pid = -1, int32_t uid = -1) REQUIRES(SCENE_GUARD); 222 223 /* 224 * Callbacks for ILifecycleListener 225 */ 226 void NotifyActivation(); 227 void NotifyConnect(); 228 void NotifyForeground(); 229 void NotifyBackground(); 230 void NotifyDisconnect(); 231 void NotifyLayoutFinished(); 232 void NotifyRemoveBlank(); 233 void NotifyAddSnapshot(bool useFfrt = false, bool needPersist = false, bool needSaveSnapshot = true); 234 void NotifyRemoveSnapshot(); 235 void NotifyUpdateSnapshotWindow(); 236 void NotifyPreLoadStartingWindowFinished(); 237 void NotifyExtensionDied() override; 238 void NotifyExtensionTimeout(int32_t errorCode) override; 239 void NotifyTransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, 240 int64_t uiExtensionIdLevel) override; 241 void NotifyExtensionDetachToDisplay() override; 242 243 /* 244 * Cross Display Move Drag 245 */ 246 std::shared_ptr<RSSurfaceNode> GetSurfaceNodeForMoveDrag() const; 247 248 virtual WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 249 bool needNotifyClient = true, bool isExecuteDelayRaise = false); 250 virtual WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 251 NotifyClientToUpdateRect(const std::string & updateReason,std::shared_ptr<RSTransaction> rsTransaction)252 virtual WSError NotifyClientToUpdateRect(const std::string& updateReason, 253 std::shared_ptr<RSTransaction> rsTransaction) { return WSError::WS_OK; } 254 WSError TransferBackPressedEventForConsumed(bool& isConsumed); 255 WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed, 256 bool isPreImeEvent = false); 257 WSError TransferFocusActiveEvent(bool isFocusActive); 258 WSError TransferFocusStateEvent(bool focusState); UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)259 virtual WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) { return WSError::WS_OK; } 260 261 int32_t GetPersistentId() const; 262 void SetSurfaceNode(const std::shared_ptr<RSSurfaceNode>& surfaceNode); 263 std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const; 264 std::optional<NodeId> GetSurfaceNodeId() const; 265 void SetLeashWinSurfaceNode(std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode); 266 std::shared_ptr<RSSurfaceNode> GetLeashWinSurfaceNode() const; 267 268 /* 269 * Window Scene Snapshot 270 */ 271 std::shared_ptr<Media::PixelMap> GetSnapshot() const; 272 std::shared_ptr<Media::PixelMap> Snapshot( 273 bool runInFfrt = false, float scaleParam = 0.0f, bool useCurWindow = false) const; 274 void ResetSnapshot(); 275 void SaveSnapshot(bool useFfrt, bool needPersist = true, 276 std::shared_ptr<Media::PixelMap> persistentPixelMap = nullptr, bool updateSnapshot = false, 277 ScreenLockReason reason = ScreenLockReason::DEFAULT); SetSaveSnapshotCallback(Task && task)278 void SetSaveSnapshotCallback(Task&& task) 279 { 280 if (task) { 281 std::lock_guard lock(saveSnapshotCallbackMutex_); 282 saveSnapshotCallback_ = std::move(task); 283 } 284 } SetRemoveSnapshotCallback(Task && task)285 void SetRemoveSnapshotCallback(Task&& task) 286 { 287 if (task) { 288 std::lock_guard lock(removeSnapshotCallbackMutex_); 289 removeSnapshotCallback_ = std::move(task); 290 } 291 } SetAddSnapshotCallback(Task && task)292 void SetAddSnapshotCallback(Task&& task) 293 { 294 if (task) { 295 std::lock_guard lock(addSnapshotCallbackMutex_); 296 addSnapshotCallback_ = std::move(task); 297 } 298 } 299 void SetEnableAddSnapshot(bool enableAddSnapshot = true); 300 bool GetEnableAddSnapshot() const; 301 302 SessionState GetSessionState() const; 303 virtual void SetSessionState(SessionState state); 304 void SetSessionInfoSupportedWindowModes( 305 const std::vector<AppExecFwk::SupportWindowMode>& updatedWindowModes); 306 void SetSessionInfoAncoSceneState(int32_t ancoSceneState); 307 void SetSessionInfoTime(const std::string& time); 308 void SetSessionInfoAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo); 309 void SetSessionInfoWant(const std::shared_ptr<AAFwk::Want>& want); 310 void ResetSessionInfoResultCode(); 311 void SetSessionInfoPersistentId(int32_t persistentId); 312 void SetSessionInfoCallerPersistentId(int32_t callerPersistentId); 313 void SetSessionInfoContinueState(ContinueState state); 314 void SetSessionInfoLockedState(bool lockedState); 315 void SetSessionInfoIsClearSession(bool isClearSession); 316 void SetSessionInfoAffinity(std::string affinity); 317 void GetCloseAbilityWantAndClean(AAFwk::Want& outWant); 318 void SetSessionInfo(const SessionInfo& info); 319 void SetSessionInfoWindowInputType(uint32_t windowInputType); 320 const SessionInfo& GetSessionInfo() const; 321 SessionInfo& EditSessionInfo(); 322 DisplayId GetScreenId() const; 323 virtual void SetScreenId(uint64_t screenId); 324 WindowType GetWindowType() const; 325 float GetAspectRatio() const; 326 WSError SetAspectRatio(float ratio) override; 327 WSError SetSessionProperty(const sptr<WindowSessionProperty>& property); 328 WSError SetSessionPropertyForReconnect(const sptr<WindowSessionProperty>& property); GetSessionProperty()329 const sptr<WindowSessionProperty>& GetSessionProperty() const { return property_; } 330 void SetSessionRect(const WSRect& rect); 331 WSRect GetSessionRect() const; 332 WSRect GetSessionGlobalRect() const; 333 WSRect GetSessionScreenRelativeRect() const; 334 WSRect GetSessionGlobalRectInMultiScreen() const; 335 WMError GetGlobalScaledRect(Rect& globalScaledRect) override; 336 void SetSessionGlobalRect(const WSRect& rect); 337 void SetSessionRequestRect(const WSRect& rect); 338 WSRect GetSessionRequestRect() const; 339 void SetRequestRectAnimationConfig(const RectAnimationConfig& rectAnimationConfig); 340 RectAnimationConfig GetRequestRectAnimationConfig() const; 341 std::string GetWindowName() const; 342 WSRect GetLastLayoutRect() const; 343 WSRect GetLayoutRect() const; 344 bool GetSkipSelfWhenShowOnVirtualScreen() const; GetDisplayId()345 DisplayId GetDisplayId() const { return GetSessionProperty()->GetDisplayId(); } 346 347 virtual WSError SetActive(bool active); 348 virtual WSError UpdateSizeChangeReason(SizeChangeReason reason); GetSizeChangeReason()349 SizeChangeReason GetSizeChangeReason() const { return layoutController_->GetSizeChangeReason(); } 350 bool IsDraggingReason(SizeChangeReason reason) const; 351 virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, 352 const std::string& updateReason, const std::shared_ptr<RSTransaction>& rsTransaction = nullptr); 353 virtual WSError UpdateRectWithLayoutInfo(const WSRect& rect, SizeChangeReason reason, 354 const std::string& updateReason, const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 355 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 356 WSError UpdateDensity(); 357 WSError UpdateOrientation(); IsDragMoving()358 virtual bool IsDragMoving() const { return false; } IsDragZooming()359 virtual bool IsDragZooming() const { return false; } 360 361 void SetShowRecent(bool showRecent); 362 void SetSystemActive(bool systemActive); 363 bool GetShowRecent() const; 364 void SetOffset(float x, float y); 365 float GetOffsetX() const; 366 float GetOffsetY() const; 367 void SetBounds(const WSRectF& bounds); 368 WSRectF GetBounds(); 369 void SetRotation(Rotation rotation); 370 Rotation GetRotation() const; 371 void SetBufferAvailable(bool bufferAvailable, bool startWindowInvisible = false); 372 bool GetBufferAvailable() const; 373 void SetNeedSnapshot(bool needSnapshot); 374 virtual void SetExitSplitOnBackground(bool isExitSplitOnBackground); 375 virtual bool IsExitSplitOnBackground() const; NeedStartingWindowExitAnimation()376 virtual bool NeedStartingWindowExitAnimation() const { return true; } 377 378 void SetChangeSessionVisibilityWithStatusBarEventListener( 379 NotifyChangeSessionVisibilityWithStatusBarFunc&& func); 380 // Just terminate, not clear session 381 WSError Clear(bool needStartCaller = false, bool isForceClean = false); 382 WSError SetSessionLabel(const std::string& label); 383 void SetUpdateSessionLabelListener(const NofitySessionLabelUpdatedFunc& func); 384 WSError SetSessionIcon(const std::shared_ptr<Media::PixelMap>& icon); 385 void SetUpdateSessionIconListener(const NofitySessionIconUpdatedFunc& func); 386 void SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& func); 387 void SetBufferAvailableChangeListener(const NotifyBufferAvailableChangeFunc& func); 388 virtual void UnregisterSessionChangeListeners(); 389 void SetSessionStateChangeNotifyManagerListener(const NotifySessionStateChangeNotifyManagerFunc& func); 390 void SetSessionInfoChangeNotifyManagerListener(const NotifySessionInfoChangeNotifyManagerFunc& func); 391 void SetSessionPropertyChangeNotifyManagerListener(const NotifySessionPropertyChangeNotifyManagerFunc& func); 392 void SetDisplayIdChangedNotifyManagerListener(const NotifyDisplayIdChangedNotifyManagerFunc& func); 393 void SetRequestFocusStatusNotifyManagerListener(const NotifyRequestFocusStatusNotifyManagerFunc& func); 394 void SetNotifyUIRequestFocusFunc(const NotifyUIRequestFocusFunc& func); 395 void SetNotifyUILostFocusFunc(const NotifyUILostFocusFunc& func); 396 void SetGetStateFromManagerListener(const GetStateFromManagerFunc& func); 397 void SetClearSubSessionCallback(const NotifyClearSubSessionFunc& func); 398 399 void SetSystemConfig(const SystemSessionConfig& systemConfig); 400 void SetSnapshotScale(const float snapshotScale); 401 virtual WSError ProcessBackEvent(); // send back event to session_stage 402 403 sptr<ScenePersistence> GetScenePersistence() const; 404 void SetParentSession(const sptr<Session>& session); 405 sptr<Session> GetParentSession() const; 406 void BindDialogToParentSession(const sptr<Session>& session); 407 void RemoveDialogToParentSession(const sptr<Session>& session); 408 std::vector<sptr<Session>> GetDialogVector() const; 409 void ClearDialogVector(); 410 WSError NotifyDestroy(); 411 WSError NotifyAppForceLandscapeConfigUpdated(); 412 WSError NotifyCloseExistPipWindow(); 413 414 void SetSessionFocusableChangeListener(const NotifySessionFocusableChangeFunc& func); 415 void SetSessionTouchableChangeListener(const NotifySessionTouchableChangeFunc& func); 416 void SetClickListener(const NotifyClickFunc& func); 417 void NotifySessionFocusableChange(bool isFocusable); 418 void NotifySessionTouchableChange(bool touchable); 419 void NotifyClick(bool requestFocus = true, bool isClick = true); 420 bool GetStateFromManager(const ManagerState key); 421 virtual void PresentFocusIfNeed(int32_t pointerAcrion, int32_t sourceType = 0); 422 virtual WSError UpdateWindowMode(WindowMode mode); 423 WSError SetAppSupportPhoneInPc(bool isSupportPhone); 424 WSError SetCompatibleModeProperty(const sptr<CompatibleModeProperty> compatibleModeProperty); 425 WSError PcAppInPadNormalClose(); 426 WSError SetIsPcAppInPad(bool enable); 427 WSError SetPcAppInpadCompatibleMode(bool enabled); 428 WSError SetPcAppInpadSpecificSystemBarInvisible(bool isPcAppInpadSpecificSystemBarInvisible); 429 WSError SetPcAppInpadOrientationLandscape(bool isPcAppInpadOrientationLandscape); 430 bool NeedNotify() const; 431 void SetNeedNotify(bool needNotify); 432 WSError SetTouchable(bool touchable); 433 bool GetTouchable() const; 434 void SetForceTouchable(bool touchable); 435 virtual void SetSystemTouchable(bool touchable); 436 bool GetSystemTouchable() const; 437 virtual WSError SetRSVisible(bool isVisible); 438 bool GetRSVisible() const; 439 WSError SetVisibilityState(WindowVisibilityState state); 440 WindowVisibilityState GetVisibilityState() const; 441 WSError SetDrawingContentState(bool isRSDrawing); 442 bool GetDrawingContentState() const; 443 WSError SetBrightness(float brightness); 444 float GetBrightness() const; 445 void NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info, 446 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 447 const Rect& callingSessionRect = {}, const std::map<AvoidAreaType, AvoidArea>& = {}); 448 void SetSessionInfoLockedStateChangeListener(const NotifySessionInfoLockedStateChangeFunc& func); 449 void NotifySessionInfoLockedStateChange(bool lockedState); 450 void SetContextTransparentFunc(const NotifyContextTransparentFunc& func); 451 void NotifyContextTransparent(); 452 bool NeedCheckContextTransparent() const; 453 454 /* 455 * Window Layout 456 */ 457 bool UpdateWindowModeSupportType(const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo); 458 459 /* 460 * Window Rotate Animation 461 */ 462 void SetAcquireRotateAnimationConfigFunc(const AcquireRotateAnimationConfigFunc& func); 463 464 /* 465 * Window Focus 466 */ 467 virtual WSError SetSystemSceneBlockingFocus(bool blocking); 468 bool GetBlockingFocus() const; 469 WSError SetFocusable(bool isFocusable); 470 bool GetFocusable() const; 471 void SetFocusedOnShow(bool focusedOnShow); // Used when creating ability 472 bool IsFocusedOnShow() const; 473 WSError SetFocusableOnShow(bool isFocusableOnShow); // Used when showing window 474 bool IsFocusableOnShow() const; 475 virtual void SetSystemFocusable(bool systemFocusable); // Used by SCB 476 bool GetSystemFocusable() const; 477 bool CheckFocusable() const; 478 void SetStartingBeforeVisible(bool isStartingBeforeVisible); 479 bool GetStartingBeforeVisible() const; 480 bool IsFocused() const; 481 bool GetFocused() const; 482 virtual WSError UpdateFocus(bool isFocused); 483 virtual void PresentFocusIfPointDown(); 484 WSError RequestFocus(bool isFocused) override; 485 void NotifyRequestFocusStatusNotifyManager(bool isFocused, bool byForeground = true, 486 FocusChangeReason reason = FocusChangeReason::DEFAULT); 487 void NotifyUIRequestFocus(); 488 virtual void NotifyUILostFocus(); 489 WSError NotifyFocusStatus(bool isFocused); 490 void SetExclusivelyHighlighted(bool isExclusivelyHighlighted); 491 virtual WSError UpdateHighlightStatus(bool isHighlight, bool needBlockHighlightNotify); 492 WSError NotifyHighlightChange(bool isHighlight); 493 WSError GetIsHighlighted(bool& isHighlighted) override; 494 WSError HandlePointerEventForFocus(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 495 bool isExecuteDelayRaise = false); 496 bool HasParentSessionWithToken(const sptr<IRemoteObject>& token); 497 498 /* 499 * Multi Window 500 */ 501 void SetIsMidScene(bool isMidScene); 502 bool GetIsMidScene() const; 503 WSError GetIsMidScene(bool& isMidScene) override; 504 505 /* 506 * Keyboard Window 507 */ 508 bool CheckEmptyKeyboardAvoidAreaIfNeeded() const; 509 void SetKeyboardStateChangeListener(const NotifyKeyboardStateChangeFunc& func); GetDirtyFlags()510 uint32_t GetDirtyFlags() const { return dirtyFlags_; } 511 512 bool IsSessionValid() const; 513 bool IsActive() const; 514 bool IsSystemActive() const; 515 bool IsSystemSession() const; 516 bool IsTerminated() const; 517 bool IsSessionForeground() const; 518 bool IsSessionNotBackground() const; IsAnco()519 virtual bool IsAnco() const { return false; } SetBlank(bool isAddBlank)520 virtual void SetBlank(bool isAddBlank) {}; GetBlank()521 virtual bool GetBlank() const { return false; } GetBufferAvailableCallbackEnable()522 virtual bool GetBufferAvailableCallbackEnable() const { return false; } 523 524 sptr<IRemoteObject> dialogTargetToken_ = nullptr; 525 int32_t GetWindowId() const; 526 void SetAppIndex(const int32_t appIndex); 527 int32_t GetAppIndex() const; 528 void SetCallingPid(int32_t id) REQUIRES(SCENE_GUARD); 529 void SetCallingUid(int32_t id); 530 int32_t GetCallingPid() const; 531 int32_t GetCallingUid() const; 532 void SetAbilityToken(sptr<IRemoteObject> token); 533 sptr<IRemoteObject> GetAbilityToken() const; 534 WindowMode GetWindowMode() const; 535 536 /* 537 * Window ZOrder 538 */ 539 virtual void SetZOrder(uint32_t zOrder); 540 uint32_t GetZOrder() const; 541 uint32_t GetLastZOrder() const; 542 543 void SetUINodeId(uint32_t uiNodeId); 544 uint32_t GetUINodeId() const; 545 virtual void SetFloatingScale(float floatingScale); 546 float GetFloatingScale() const; 547 virtual void SetScale(float scaleX, float scaleY, float pivotX, float pivotY); 548 float GetScaleX() const; 549 float GetScaleY() const; 550 float GetPivotX() const; 551 float GetPivotY() const; 552 void SetSCBKeepKeyboard(bool scbKeepKeyboardFlag); 553 bool GetSCBKeepKeyboardFlag() const; 554 555 void SetRaiseToAppTopForPointDownFunc(const NotifyRaiseToTopForPointDownFunc& func); 556 void SetFrameLayoutFinishListener(const NotifyFrameLayoutFinishFunc& func); 557 void NotifyScreenshot(); 558 void RemoveLifeCycleTask(const LifeCycleTaskType& taskType); 559 void PostLifeCycleTask(Task &&task, const std::string& name, const LifeCycleTaskType& taskType); 560 WSError UpdateMaximizeMode(bool isMaximize); 561 void NotifySessionForeground(uint32_t reason, bool withAnimation); 562 void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits); 563 void HandlePointDownDialog(); 564 bool CheckDialogOnForeground(); 565 std::shared_ptr<Media::PixelMap> GetSnapshotPixelMap(const float oriScale = 1.0f, const float newScale = 1.0f); GetTouchHotAreas()566 virtual std::vector<Rect> GetTouchHotAreas() const 567 { 568 return std::vector<Rect>(); 569 } 570 571 virtual void SetTouchHotAreas(const std::vector<Rect>& touchHotAreas); 572 SetVpr(float vpr)573 void SetVpr(float vpr) 574 { 575 vpr_ = vpr; 576 } 577 578 bool operator==(const Session* session) const 579 { 580 if (session == nullptr) { 581 return false; 582 } 583 return (persistentId_ == session->persistentId_ && callingPid_ == session->callingPid_); 584 } 585 586 bool operator!=(const Session* session) const 587 { 588 return !this->operator==(session); 589 } 590 591 const char* DumpPointerWindowArea(MMI::WindowArea area) const; 592 WSRectF UpdateHotRect(const WSRect& rect); 593 WSError RaiseToAppTopForPointDown(); 594 595 virtual void NotifyForegroundInteractiveStatus(bool interactive); 596 WSError UpdateTitleInTargetPos(bool isShow, int32_t height); 597 void SetNotifySystemSessionPointerEventFunc(const NotifySystemSessionPointerEventFunc& func); 598 void SetNotifySystemSessionKeyEventFunc(const NotifySystemSessionKeyEventFunc& func); 599 bool IsSystemInput(); 600 // ForegroundInteractiveStatus interface only for event use 601 bool GetForegroundInteractiveStatus() const; 602 virtual void SetForegroundInteractiveStatus(bool interactive); 603 604 /* 605 * Window Lifecycle 606 */ 607 bool GetIsPendingToBackgroundState() const; 608 void SetIsPendingToBackgroundState(bool isPendingToBackgroundState); 609 bool IsActivatedAfterScreenLocked() const; 610 void SetIsActivatedAfterScreenLocked(bool isActivatedAfterScreenLocked); 611 void SetAttachState(bool isAttach, WindowMode windowMode = WindowMode::WINDOW_MODE_UNDEFINED); 612 bool GetAttachState() const; 613 void RegisterDetachCallback(const sptr<IPatternDetachCallback>& callback); 614 615 SystemSessionConfig GetSystemConfig() const; 616 void RectCheckProcess(); RectCheck(uint32_t curWidth,uint32_t curHeight)617 virtual void RectCheck(uint32_t curWidth, uint32_t curHeight) {}; 618 void RectSizeCheckProcess(uint32_t curWidth, uint32_t curHeight, uint32_t minWidth, 619 uint32_t minHeight, uint32_t maxFloatingWindowSize); 620 DetectTaskInfo GetDetectTaskInfo() const; 621 void SetDetectTaskInfo(const DetectTaskInfo& detectTaskInfo); 622 WSError GetUIContentRemoteObj(sptr<IRemoteObject>& uiContentRemoteObj); 623 void CreateWindowStateDetectTask(bool isAttach, WindowMode windowMode); 624 void RegisterIsScreenLockedCallback(const std::function<bool()>& callback); 625 std::string GetWindowDetectTaskName() const; 626 void RemoveWindowDetectTask(); 627 WSError SwitchFreeMultiWindow(const SystemSessionConfig& config); 628 CheckGetAvoidAreaAvailable(AvoidAreaType type)629 virtual bool CheckGetAvoidAreaAvailable(AvoidAreaType type) { return true; } 630 631 virtual bool IsVisibleForeground() const; 632 virtual bool IsVisibleNotBackground() const; 633 void SetIsStarting(bool isStarting); 634 void SetUIStateDirty(bool dirty); 635 void SetMainSessionUIStateDirty(bool dirty); 636 bool GetUIStateDirty() const; 637 static bool IsScbCoreEnabled(); 638 static void SetScbCoreEnabled(bool enabled); 639 bool IsVisible() const; IsNeedSyncScenePanelGlobalPosition()640 virtual bool IsNeedSyncScenePanelGlobalPosition() { return true; } 641 void SetAppInstanceKey(const std::string& appInstanceKey); 642 std::string GetAppInstanceKey() const; 643 644 /* 645 * Starting Window 646 */ 647 WSError RemoveStartingWindow() override; 648 void SetEnableRemoveStartingWindow(bool enableRemoveStartingWindow); 649 bool GetEnableRemoveStartingWindow() const; 650 void SetAppBufferReady(bool appBufferReady); 651 bool GetAppBufferReady() const; 652 void SetUseStartingWindowAboveLocked(bool useStartingWindowAboveLocked); 653 bool UseStartingWindowAboveLocked() const; 654 WSError SetHidingStartingWindow(bool hidingStartWindow); 655 bool GetHidingStartingWindow() const; 656 657 /* 658 * Window Hierarchy 659 */ 660 void ProcessClickModalWindowOutside(int32_t posX, int32_t posY); 661 void SetClickModalWindowOutsideListener(NotifyClickModalWindowOutsideFunc&& func); 662 663 /* 664 * Window Layout 665 */ 666 static bool IsBackgroundUpdateRectNotifyEnabled(); 667 static void SetBackgroundUpdateRectNotifyEnabled(const bool enabled); 668 void SetClientRect(const WSRect& rect); 669 WSRect GetClientRect() const; 670 void ResetDirtyFlags(); 671 void SetDragActivated(bool dragActivated); 672 void SetClientDragEnable(bool dragEnable); 673 std::optional<bool> GetClientDragEnable() const; 674 std::shared_ptr<AppExecFwk::EventHandler> GetEventHandler() const; 675 WSError UpdateClientDisplayId(DisplayId displayId); 676 DisplayId TransformGlobalRectToRelativeRect(WSRect& rect) const; 677 void TransformRelativeRectToGlobalRect(WSRect& rect) const; 678 void UpdateClientRectPosYAndDisplayId(WSRect& rect); 679 bool IsDragAccessible() const; 680 void SetSingleHandTransform(const SingleHandTransform& transform); 681 SingleHandTransform GetSingleHandTransform() const; 682 void SetSingleHandModeFlag(bool flag); 683 bool SessionIsSingleHandMode(); 684 void SetClientDisplayId(DisplayId displayId); 685 DisplayId GetClientDisplayId() const; RegisterNotifySurfaceBoundsChangeFunc(int32_t sessionId,NotifySurfaceBoundsChangeFunc && func)686 virtual void RegisterNotifySurfaceBoundsChangeFunc(int32_t sessionId, NotifySurfaceBoundsChangeFunc&& func) {}; UnregisterNotifySurfaceBoundsChangeFunc(int32_t sessionId)687 virtual void UnregisterNotifySurfaceBoundsChangeFunc(int32_t sessionId) {}; IsAnyParentSessionDragMoving()688 virtual bool IsAnyParentSessionDragMoving() const { return false; } IsAnyParentSessionDragZooming()689 virtual bool IsAnyParentSessionDragZooming() const { return false; } 690 void SetHasRequestedVsyncFunc(HasRequestedVsyncFunc&& func); 691 void SetRequestNextVsyncWhenModeChangeFunc(RequestNextVsyncWhenModeChangeFunc&& func); 692 void SetGlobalDisplayRect(const WSRect& rect); 693 WSRect GetGlobalDisplayRect() const; 694 virtual WSError UpdateGlobalDisplayRect(const WSRect& rect, SizeChangeReason reason); 695 WSError NotifyClientToUpdateGlobalDisplayRect(const WSRect& rect, SizeChangeReason reason); GetLayoutController()696 const sptr<LayoutController>& GetLayoutController() const { return layoutController_; } 697 WSError NotifyAppHookWindowInfoUpdated(); 698 699 /* 700 * Screen Lock 701 */ 702 bool IsScreenLockWindow() const; 703 704 /* 705 * Free Multi Window 706 */ 707 std::shared_ptr<Media::PixelMap> SetFreezeImmediately(float scale, bool isFreeze, float blur) const; 708 709 /* 710 * PC Window 711 */ 712 sptr<Session> GetMainSession() const; 713 sptr<Session> GetMainOrFloatSession() const; 714 bool IsPcWindow() const; 715 bool IsAncestorsSession(int32_t ancestorsId) const; 716 717 /** 718 * Window Property 719 */ 720 WindowUIInfo GetWindowUIInfoForWindowInfo() const; 721 WindowDisplayInfo GetWindowDisplayInfoForWindowInfo() const; 722 WindowLayoutInfo GetWindowLayoutInfoForWindowInfo() const; 723 WindowMetaInfo GetWindowMetaInfoForWindowInfo() const; GetPropertyDirtyFlags()724 uint32_t GetPropertyDirtyFlags() const { return propertyDirtyFlags_; }; SetPropertyDirtyFlags(uint32_t dirtyFlags)725 void SetPropertyDirtyFlags(uint32_t dirtyFlags) { propertyDirtyFlags_ = dirtyFlags; } AddPropertyDirtyFlags(uint32_t dirtyFlags)726 void AddPropertyDirtyFlags(uint32_t dirtyFlags) { propertyDirtyFlags_ |= dirtyFlags; } 727 WSError NotifyScreenshotAppEvent(ScreenshotEventType type); 728 729 /* 730 * Window Pattern 731 */ 732 void SetBorderUnoccupied(bool borderUnoccupied = false); 733 bool GetBorderUnoccupied() const; 734 bool IsPersistentImageFit() const; 735 bool SupportSnapshotAllSessionStatus() const; 736 void InitSnapshotCapacity(); 737 SnapshotStatus GetWindowStatus() const; 738 SnapshotStatus GetSessionStatus(ScreenLockReason reason = ScreenLockReason::DEFAULT) const; 739 DisplayOrientation GetWindowOrientation() const; 740 uint32_t GetLastOrientation() const; 741 bool HasSnapshotFreeMultiWindow(); 742 bool HasSnapshot(SnapshotStatus key); 743 bool HasSnapshot(); 744 void DeleteHasSnapshot(); 745 void DeleteHasSnapshot(SnapshotStatus key); 746 void DeleteHasSnapshotFreeMultiWindow(); 747 void SetFreeMultiWindow(); 748 std::atomic<bool> freeMultiWindow_ { false }; 749 750 /* 751 * Specific Window 752 */ 753 void SetWindowAnimationDuration(int32_t duration); 754 755 /* 756 * RS Client Multi Instance 757 */ 758 std::shared_ptr<RSUIContext> GetRSUIContext(const char* caller = ""); 759 760 protected: 761 class SessionLifeCycleTask : public virtual RefBase { 762 public: SessionLifeCycleTask(const Task & task,const std::string & name,const LifeCycleTaskType & type)763 SessionLifeCycleTask(const Task& task, const std::string& name, const LifeCycleTaskType& type) 764 : task(task), name(name), type(type) {} 765 Task task; 766 const std::string name; 767 LifeCycleTaskType type; 768 std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now(); 769 bool running = false; 770 }; 771 void GeneratePersistentId(bool isExtension, int32_t persistentId); 772 virtual void UpdateSessionState(SessionState state); 773 void NotifySessionStateChange(const SessionState& state); 774 void UpdateSessionTouchable(bool touchable); UpdateActiveStatus(bool isActive)775 virtual WSError UpdateActiveStatus(bool isActive) { return WSError::WS_OK; } 776 777 /* 778 * Gesture Back 779 */ UpdateGestureBackEnabled()780 virtual void UpdateGestureBackEnabled() {} 781 782 WSRectF UpdateTopBottomArea(const WSRectF& rect, MMI::WindowArea area); 783 WSRectF UpdateLeftRightArea(const WSRectF& rect, MMI::WindowArea area); 784 WSRectF UpdateInnerAngleArea(const WSRectF& rect, MMI::WindowArea area); 785 virtual void UpdatePointerArea(const WSRect& rect); 786 virtual bool CheckPointerEventDispatch(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const; 787 bool IsTopDialog() const; 788 void HandlePointDownDialog(int32_t pointAction); 789 void NotifySessionInfoChange(); 790 void NotifySessionPropertyChange(WindowInfoKey windowInfoKey); 791 void NotifyDisplayIdChanged(int32_t persistentId, uint64_t screenId); 792 793 void PostTask(Task&& task, const std::string& name = "sessionTask", int64_t delayTime = 0); 794 void PostExportTask(Task&& task, const std::string& name = "sessionExportTask", int64_t delayTime = 0); 795 template<typename SyncTask, typename Return = std::invoke_result_t<SyncTask>> 796 Return PostSyncTask(SyncTask&& task, const std::string& name = "sessionTask") 797 { 798 Return ret; 799 if (!handler_ || handler_->GetEventRunner()->IsCurrentRunnerThread()) { 800 StartTraceForSyncTask(name); 801 ret = task(); 802 FinishTraceForSyncTask(); 803 return ret; 804 } 805 auto syncTask = [&ret, &task, &name] { 806 StartTraceForSyncTask(name); 807 ret = task(); 808 FinishTraceForSyncTask(); 809 }; 810 handler_->PostSyncTask(std::move(syncTask), name, AppExecFwk::EventQueue::Priority::IMMEDIATE); 811 return ret; 812 } 813 814 static std::shared_ptr<AppExecFwk::EventHandler> mainHandler_; 815 int32_t persistentId_ = INVALID_SESSION_ID; 816 std::atomic<SessionState> state_ = SessionState::STATE_DISCONNECT; 817 SessionInfo sessionInfo_; 818 std::recursive_mutex sessionInfoMutex_; 819 mutable std::mutex surfaceNodeMutex_; 820 std::shared_ptr<RSSurfaceNode> surfaceNode_; 821 mutable std::mutex snapshotMutex_; 822 std::shared_ptr<Media::PixelMap> snapshot_; 823 sptr<ISessionStage> sessionStage_; 824 std::mutex lifeCycleTaskQueueMutex_; 825 std::list<sptr<SessionLifeCycleTask>> lifeCycleTaskQueue_; 826 bool isActive_ = false; 827 bool isSystemActive_ = false; 828 WSRectF bounds_; 829 Rotation rotation_; 830 float offsetX_ = 0.0f; 831 float offsetY_ = 0.0f; 832 std::atomic_bool isExitSplitOnBackground_ = false; 833 bool isVisible_ = false; 834 int32_t currentRotation_ = 0; 835 836 NotifyChangeSessionVisibilityWithStatusBarFunc changeSessionVisibilityWithStatusBarFunc_; 837 NotifySessionStateChangeFunc sessionStateChangeFunc_; 838 NotifyBufferAvailableChangeFunc bufferAvailableChangeFunc_; 839 NotifySessionInfoChangeNotifyManagerFunc sessionInfoChangeNotifyManagerFunc_; 840 NotifySessionPropertyChangeNotifyManagerFunc sessionPropertyChangeNotifyManagerFunc_; 841 NotifyDisplayIdChangedNotifyManagerFunc displayIdChangedNotifyManagerFunc_; 842 NotifySessionStateChangeNotifyManagerFunc sessionStateChangeNotifyManagerFunc_; 843 NotifyRequestFocusStatusNotifyManagerFunc requestFocusStatusNotifyManagerFunc_; 844 NotifyUIRequestFocusFunc requestFocusFunc_; 845 NotifyUILostFocusFunc lostFocusFunc_; 846 GetStateFromManagerFunc getStateFromManagerFunc_; 847 NotifySessionFocusableChangeFunc sessionFocusableChangeFunc_; 848 NotifySessionTouchableChangeFunc sessionTouchableChangeFunc_; 849 NotifyClickFunc clickFunc_; 850 NofitySessionLabelUpdatedFunc updateSessionLabelFunc_; 851 NofitySessionIconUpdatedFunc updateSessionIconFunc_; 852 NotifySessionSnapshotFunc notifySessionSnapshotFunc_; 853 NotifyRaiseToTopForPointDownFunc raiseToTopForPointDownFunc_; 854 NotifySessionInfoLockedStateChangeFunc sessionInfoLockedStateChangeFunc_; 855 NotifySystemSessionPointerEventFunc systemSessionPointerEventFunc_; 856 NotifySystemSessionKeyEventFunc systemSessionKeyEventFunc_; 857 NotifyContextTransparentFunc contextTransparentFunc_; 858 NotifyFrameLayoutFinishFunc frameLayoutFinishFunc_; 859 std::mutex highlightChangeFuncMutex_; 860 NotifyHighlightChangeFunc highlightChangeFunc_; 861 862 /* 863 * Window LifeCycle 864 */ 865 NotifyPendingSessionActivationFunc pendingSessionActivationFunc_; 866 NotifyBatchPendingSessionsActivationFunc batchPendingSessionsActivationFunc_; 867 NotifyPendingSessionToForegroundFunc pendingSessionToForegroundFunc_; 868 NotifyPendingSessionToBackgroundFunc pendingSessionToBackgroundFunc_; 869 NotifyPendingSessionToBackgroundForDelegatorFunc pendingSessionToBackgroundForDelegatorFunc_; 870 NotifyBackPressedFunc backPressedFunc_; 871 NotifyTerminateSessionFunc terminateSessionFunc_; 872 NotifyTerminateSessionFuncNew terminateSessionFuncNew_; 873 NotifyTerminateSessionFuncTotal terminateSessionFuncTotal_; 874 NotifySessionExceptionFunc sessionExceptionFunc_; 875 NotifySessionExceptionFunc jsSceneSessionExceptionFunc_; 876 VisibilityChangedDetectFunc visibilityChangedDetectFunc_ GUARDED_BY(SCENE_GUARD); 877 NofitySessionLabelAndIconUpdatedFunc updateSessionLabelAndIconFunc_; 878 NotifySessionGetTargetOrientationConfigInfoFunc sessionGetTargetOrientationConfigInfoFunc_; 879 NotifyClearSubSessionFunc clearSubSessionFunc_; 880 881 /* 882 * Window Rotate Animation 883 */ 884 AcquireRotateAnimationConfigFunc acquireRotateAnimationConfigFunc_; 885 886 SystemSessionConfig systemConfig_; 887 bool needSnapshot_ = false; 888 float snapshotScale_ = 0.5; 889 sptr<ScenePersistence> scenePersistence_ = nullptr; 890 891 /* 892 * Window Layout 893 */ 894 static bool isBackgroundUpdateRectNotifyEnabled_; 895 RequestVsyncFunc requestNextVsyncFunc_; 896 WSRect lastLayoutRect_; // rect saved when go background 897 WSRect layoutRect_; // rect of root view 898 NotifySessionRectChangeFunc sessionRectChangeFunc_; 899 NotifySessionDisplayIdChangeFunc sessionDisplayIdChangeFunc_; 900 NotifyUpdateFloatingBallFunc updateFloatingBallFunc_; 901 NotifyStopFloatingBallFunc stopFloatingBallFunc_; 902 NotifyRestoreFloatingBallMainWindowFunc restoreFloatingBallMainWindowFunc_; 903 sptr<LayoutController> layoutController_ = nullptr; 904 void SetClientScale(float scaleX, float scaleY, float pivotX, float pivotY); 905 DisplayId clientDisplayId_ = 0; // Window displayId on the client 906 DisplayId configDisplayId_ = DISPLAY_ID_INVALID; 907 SuperFoldStatus lastScreenFoldStatus_ = SuperFoldStatus::UNKNOWN; 908 virtual bool IsNeedConvertToRelativeRect( 909 SizeChangeReason reason = SizeChangeReason::UNDEFINED) const { return false; } IsDragStart()910 bool IsDragStart() const { return isDragStart_; } 911 void SetDragStart(bool isDragStart); 912 std::vector<AppExecFwk::SupportWindowMode> ExtractSupportWindowModeFromMetaData( 913 const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo); 914 std::vector<AppExecFwk::SupportWindowMode> ParseWindowModeFromMetaData( 915 const std::string& supportModesInFreeMultiWindow); 916 HasRequestedVsyncFunc hasRequestedVsyncFunc_; 917 RequestNextVsyncWhenModeChangeFunc requestNextVsyncWhenModeChangeFunc_; 918 WSError RequestNextVsyncWhenModeChange(); 919 void OnVsyncReceivedAfterModeChanged(); 920 void InitVsyncCallbackForModeChangeAndRequestNextVsync(); 921 922 /* 923 * Window ZOrder 924 */ 925 uint32_t zOrder_ = 0; 926 uint32_t lastZOrder_ = 0; 927 928 /* 929 * Window Focus 930 */ 931 bool isFocused_ = false; 932 bool blockingFocus_ { false }; 933 bool isHighlighted_ { false }; 934 935 uint32_t uiNodeId_ = 0; 936 std::map<MMI::WindowArea, WSRectF> windowAreas_; 937 bool isTerminating_ = false; 938 float floatingScale_ = 1.0f; 939 bool scbKeepKeyboardFlag_ = false; 940 mutable std::shared_mutex dialogVecMutex_; 941 std::vector<sptr<Session>> dialogVec_; 942 mutable std::shared_mutex parentSessionMutex_; 943 sptr<Session> parentSession_; 944 sptr<IWindowEventChannel> windowEventChannel_; 945 946 mutable std::mutex pointerEventMutex_; 947 mutable std::shared_mutex keyEventMutex_; 948 bool rectChangeListenerRegistered_ = false; 949 950 /* 951 * Window Hierarchy 952 */ 953 NotifyRaiseMainWindowAboveTargetFunc onRaiseMainWindowAboveTarget_; 954 NotifyClickModalWindowOutsideFunc clickModalWindowOutsideFunc_; 955 956 /* 957 * Window Pattern 958 */ 959 std::atomic<bool> isAttach_ { false }; 960 std::atomic<bool> needNotifyAttachState_ = { false }; 961 uint32_t lastSnapshotScreen_ = SCREEN_UNKNOWN; 962 SnapshotStatus capacity_ = defaultCapacity; 963 964 /* 965 * Window Pipeline 966 */ 967 uint32_t dirtyFlags_ = 0; // only accessed on SSM thread 968 bool isNeedSyncSessionRect_ { true }; // where need sync to session rect, currently use in split drag 969 bool isStarting_ = false; // when start app, session is starting state until foreground 970 std::atomic_bool mainUIStateDirty_ = false; 971 static bool isScbCoreEnabled_; 972 973 /* 974 *CompatibleMode Window scale 975 */ 976 uint32_t compatibleDragScaleFlags_ = 0; 977 978 /* 979 * Keyboard Window 980 */ 981 NotifyKeyboardStateChangeFunc keyboardStateChangeFunc_; 982 983 /* 984 * Window Property 985 */ 986 uint32_t propertyDirtyFlags_ = 0; 987 988 private: 989 void HandleDialogForeground(); 990 void HandleDialogBackground(); 991 WSError HandleSubWindowClick(int32_t action, int32_t sourceType, bool isExecuteDelayRaise = false); 992 993 template<typename T> 994 bool RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener); 995 template<typename T> 996 bool UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener); 997 bool IsStateMatch(bool isAttach) const; 998 bool IsSupportDetectWindow(bool isAttach); 999 bool ShouldCreateDetectTask(bool isAttach, WindowMode windowMode) const; 1000 bool ShouldCreateDetectTaskInRecent(bool newShowRecent, bool oldShowRecent, bool isAttach) const; 1001 void CreateDetectStateTask(bool isAttach, WindowMode windowMode); 1002 void PostSpecificSessionLifeCycleTimeoutTask(const std::string& eventName); // only report for specific window 1003 bool IsNeedReportTimeout() const; 1004 1005 /* 1006 * Window Rotate Animation 1007 */ 1008 int32_t GetRotateAnimationDuration(); 1009 1010 /* 1011 * Window Property 1012 */ 1013 void InitSessionPropertyWhenConnect(const sptr<WindowSessionProperty>& property); 1014 void InitSystemSessionDragEnable(const sptr<WindowSessionProperty>& property); 1015 1016 void UpdateGravityWhenUpdateWindowMode(WindowMode mode); 1017 1018 template<typename T1, typename T2, typename Ret> 1019 using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type; 1020 template<typename T> GetListeners()1021 inline EnableIfSame<T, ILifecycleListener, std::vector<std::weak_ptr<ILifecycleListener>>> GetListeners() 1022 { 1023 std::vector<std::weak_ptr<ILifecycleListener>> lifecycleListeners; 1024 { 1025 std::lock_guard<std::recursive_mutex> lock(lifecycleListenersMutex_); 1026 for (auto& listener : lifecycleListeners_) { 1027 lifecycleListeners.push_back(listener); 1028 } 1029 } 1030 return lifecycleListeners; 1031 } 1032 1033 std::recursive_mutex lifecycleListenersMutex_; 1034 std::vector<std::shared_ptr<ILifecycleListener>> lifecycleListeners_; 1035 std::shared_ptr<AppExecFwk::EventHandler> handler_; 1036 std::shared_ptr<AppExecFwk::EventHandler> exportHandler_; 1037 std::function<bool()> isScreenLockedCallback_; 1038 1039 sptr<WindowSessionProperty> property_; 1040 1041 /* 1042 * Window Focus 1043 */ 1044 mutable std::shared_mutex uiRequestFocusMutex_; 1045 mutable std::shared_mutex uiLostFocusMutex_; 1046 bool focusedOnShow_ = true; 1047 std::atomic_bool systemFocusable_ = true; 1048 bool focusableOnShow_ = true; // if false, ignore request focus when session onAttach 1049 bool isStartingBeforeVisible_ = false; 1050 1051 bool showRecent_ = false; 1052 bool bufferAvailable_ = false; 1053 1054 /* 1055 * Multi Window 1056 */ 1057 bool isMidScene_ = false; 1058 1059 WSRect preRect_; 1060 int32_t callingPid_ = -1; 1061 int32_t callingUid_ = -1; 1062 int32_t appIndex_ = { 0 }; 1063 std::string callingBundleName_ { "unknown" }; 1064 bool isRSVisible_ {false}; 1065 WindowVisibilityState visibilityState_ { WINDOW_LAYER_STATE_MAX}; 1066 bool needNotify_ {true}; 1067 bool isRSDrawing_ {false}; 1068 sptr<IRemoteObject> abilityToken_ = nullptr; 1069 float vpr_ { 1.5f }; 1070 bool forceTouchable_ { true }; 1071 bool systemTouchable_ { true }; 1072 std::atomic_bool foregroundInteractiveStatus_ { true }; 1073 1074 /* 1075 * Window Lifecycle 1076 */ 1077 void RecordWindowStateAttachExceptionEvent(bool isAttached); 1078 bool SetLifeCycleTaskRunning(const sptr<SessionLifeCycleTask>& lifeCycleTask); 1079 1080 std::atomic<bool> isPendingToBackgroundState_ { false }; 1081 std::atomic<bool> isActivatedAfterScreenLocked_ { true }; 1082 sptr<IPatternDetachCallback> detachCallback_ = nullptr; 1083 1084 std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode_; 1085 mutable std::mutex leashWinSurfaceNodeMutex_; 1086 DetectTaskInfo detectTaskInfo_; 1087 mutable std::shared_mutex detectTaskInfoMutex_; 1088 1089 /* 1090 * Starting Window 1091 */ 1092 bool enableRemoveStartingWindow_ { false }; 1093 bool appBufferReady_ { false }; 1094 bool useStartingWindowAboveLocked_ { false }; 1095 bool hidingStartWindow_ { false }; 1096 1097 /* 1098 * Window Layout 1099 */ 1100 std::optional<bool> clientDragEnable_; 1101 bool dragActivated_ = true; 1102 SingleHandTransform singleHandTransform_; 1103 bool singleHandModeFlag_ = false; 1104 SingleHandScreenInfo singleHandScreenInfo_; 1105 bool isDragStart_ = { false }; 1106 std::atomic_bool isWindowModeDirty_ = false; 1107 std::atomic<int32_t> timesToWaitForVsync_ = 0; 1108 SizeChangeReason globalDisplayRectSizeChangeReason_ = SizeChangeReason::END; 1109 1110 /* 1111 * Screen Lock 1112 */ 1113 bool isScreenLockWindow_ { false }; 1114 1115 /* 1116 * Window Scene Snapshot 1117 */ 1118 std::atomic<bool> enableAddSnapshot_ = true; 1119 Task saveSnapshotCallback_ = []() {}; 1120 Task removeSnapshotCallback_ = []() {}; 1121 Task addSnapshotCallback_ = []() {}; 1122 std::mutex saveSnapshotCallbackMutex_; 1123 std::mutex removeSnapshotCallbackMutex_; 1124 std::mutex addSnapshotCallbackMutex_; 1125 1126 /* 1127 * Window Pattern 1128 */ 1129 bool borderUnoccupied_ = false; 1130 void DeletePersistentImageFit(); 1131 uint32_t GetBackgroundColor() const; 1132 1133 /* 1134 * Specific Window 1135 */ 1136 int32_t windowAnimationDuration_; 1137 1138 /* 1139 * RS Client Multi Instance 1140 */ 1141 uint64_t screenIdOfRSUIContext_ = SCREEN_ID_INVALID; 1142 std::shared_ptr<RSUIContext> rsUIContext_; 1143 }; 1144 } // namespace OHOS::Rosen 1145 1146 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_H