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_MANAGER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <shared_mutex> 22 23 #include "mission_snapshot.h" 24 #include "transaction/rs_interfaces.h" 25 26 #include "agent_death_recipient.h" 27 #include "common/include/task_scheduler.h" 28 #include "future.h" 29 #include "interfaces/include/ws_common.h" 30 #include "session_listener_controller.h" 31 #include "scene_session_converter.h" 32 #include "scb_session_handler.h" 33 #include "session/host/include/root_scene_session.h" 34 #include "session/host/include/keyboard_session.h" 35 #include "session_manager/include/zidl/scene_session_manager_stub.h" 36 #include "wm_single_instance.h" 37 #include "window_scene_config.h" 38 #include "display_info.h" 39 #include "display_change_info.h" 40 #include "display_change_listener.h" 41 #include "app_debug_listener_interface.h" 42 #include "app_mgr_client.h" 43 #include "include/core/SkRegion.h" 44 #include "ability_info.h" 45 #include "screen_fold_data.h" 46 47 namespace OHOS::AAFwk { 48 class SessionInfo; 49 } // namespace OHOS::AAFwk 50 51 namespace OHOS::AppExecFwk { 52 class IBundleMgr; 53 struct AbilityInfo; 54 struct BundleInfo; 55 class LauncherService; 56 } // namespace OHOS::AppExecFwk 57 58 namespace OHOS::Global::Resource { 59 class ResourceManager; 60 } // namespace OHOS::Global::Resource 61 62 namespace OHOS::Rosen { 63 namespace AncoConsts { 64 constexpr const char* ANCO_MISSION_ID = "ohos.anco.param.missionId"; 65 constexpr const char* ANCO_SESSION_ID = "ohos.anco.param.sessionId"; 66 } 67 struct SCBAbilityInfo { 68 AppExecFwk::AbilityInfo abilityInfo_; 69 uint32_t sdkVersion_; 70 std::string codePath_; 71 }; 72 struct ComparedSessionInfo { 73 std::string bundleName_; 74 std::string moduleName_; 75 std::string abilityName_; 76 int32_t appIndex_ = 0; 77 uint32_t windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); 78 bool isAtomicService_ = false; 79 }; 80 class SceneSession; 81 struct SecSurfaceInfo; 82 class RSUIExtensionData; 83 class AccessibilityWindowInfo; 84 class UnreliableWindowInfo; 85 using NotifyCreateSystemSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 86 using NotifyCreateKeyboardSessionFunc = std::function<void(const sptr<SceneSession>& keyboardSession, 87 const sptr<SceneSession>& panelSession)>; 88 using NotifyCreateSubSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 89 using NotifyRecoverSceneSessionFunc = 90 std::function<void(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)>; 91 using ProcessStatusBarEnabledChangeFunc = std::function<void(bool enable, const std::string& bundleName)>; 92 using ProcessGestureNavigationEnabledChangeFunc = std::function<void(bool enable, const std::string& bundleName, 93 GestureBackType type)>; 94 using ProcessOutsideDownEventFunc = std::function<void(int32_t x, int32_t y)>; 95 using ProcessShiftFocusFunc = std::function<void(int32_t persistentId)>; 96 using NotifySetFocusSessionFunc = std::function<void(const sptr<SceneSession>& session)>; 97 using DumpRootSceneElementInfoFunc = std::function<void(const std::vector<std::string>& params, 98 std::vector<std::string>& infos)>; 99 using WindowChangedFunc = std::function<void(int32_t persistentId, WindowUpdateType type)>; 100 using TraverseFunc = std::function<bool(const sptr<SceneSession>& session)>; 101 using CmpFunc = std::function<bool(std::pair<int32_t, sptr<SceneSession>>& lhs, 102 std::pair<int32_t, sptr<SceneSession>>& rhs)>; 103 using ProcessStartUIAbilityErrorFunc = std::function<void(int32_t startUIAbilityError)>; 104 using NotifySCBAfterUpdateFocusFunc = std::function<void()>; 105 using ProcessCallingSessionIdChangeFunc = std::function<void(uint32_t callingSessionId)>; 106 using FlushWindowInfoTask = std::function<void()>; 107 using ProcessVirtualPixelRatioChangeFunc = std::function<void(float density, const Rect& rect)>; 108 using DumpUITreeFunc = std::function<void(std::string& dumpInfo)>; 109 using RootSceneProcessBackEventFunc = std::function<void()>; 110 using AbilityManagerCollaboratorRegisteredFunc = std::function<void()>; 111 using ProcessCloseTargetFloatWindowFunc = std::function<void(const std::string& bundleName)>; 112 using OnFlushUIParamsFunc = std::function<void()>; 113 using IsRootSceneLastFrameLayoutFinishedFunc = std::function<bool()>; 114 using NotifyStartPiPFailedFunc = std::function<void()>; 115 using NotifyAppUseControlListFunc = 116 std::function<void(ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)>; 117 118 class AppAnrListener : public IRemoteStub<AppExecFwk::IAppDebugListener> { 119 public: 120 void OnAppDebugStarted(const std::vector<AppExecFwk::AppDebugInfo>& debugInfos) override; 121 void OnAppDebugStoped(const std::vector<AppExecFwk::AppDebugInfo>& debugInfos) override; 122 }; 123 124 class DisplayChangeListener : public IDisplayChangeListener { 125 public: 126 virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 127 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override; 128 virtual void OnScreenshot(DisplayId displayId) override; 129 virtual void OnImmersiveStateChange(bool& immersive) override; 130 virtual void OnGetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds, 131 std::vector<uint64_t>& surfaceNodeIds, bool isBlackList = false) override; 132 133 /* 134 * Fold Screen Status Change Report 135 */ 136 virtual void OnScreenFoldStatusChanged(const std::vector<std::string>& screenFoldInfo) override; 137 }; 138 139 class SceneSessionManager : public SceneSessionManagerStub { 140 WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager) 141 public: 142 friend class AnomalyDetection; 143 bool IsSessionVisible(const sptr<SceneSession>& session); 144 bool IsSessionVisibleForeground(const sptr<SceneSession>& session); 145 sptr<SceneSession> RequestSceneSession(const SessionInfo& sessionInfo, 146 sptr<WindowSessionProperty> property = nullptr); 147 void UpdateSceneSessionWant(const SessionInfo& sessionInfo); 148 WSError RequestSceneSessionActivation(const sptr<SceneSession>& sceneSession, bool isNewActive); 149 WSError RequestSceneSessionBackground(const sptr<SceneSession>& sceneSession, const bool isDelegator = false, 150 const bool isToDesktop = false, const bool isSaveSnapshot = true); 151 WSError RequestSceneSessionDestruction(const sptr<SceneSession>& sceneSession, bool needRemoveSession = true, 152 bool isSaveSnapshot = true, const bool isForceClean = false); 153 WSError RequestSceneSessionDestructionInner(sptr<SceneSession> &scnSession, sptr<AAFwk::SessionInfo> scnSessionInfo, 154 const bool needRemoveSession, const bool isForceClean = false); 155 void NotifyForegroundInteractiveStatus(const sptr<SceneSession>& sceneSession, bool interactive); 156 WSError RequestSceneSessionByCall(const sptr<SceneSession>& sceneSession); 157 void StartAbilityBySpecified(const SessionInfo& sessionInfo); 158 void NotifyWindowStateErrorFromMMI(int32_t pid, int32_t persistentId); 159 160 void SetRootSceneContext(const std::weak_ptr<AbilityRuntime::Context>& contextWeak); 161 sptr<RootSceneSession> GetRootSceneSession(); 162 WSRect GetRootSessionAvoidSessionRect(AvoidAreaType type); 163 sptr<SceneSession> GetSceneSession(int32_t persistentId); 164 sptr<SceneSession> GetMainParentSceneSession(int32_t persistentId, 165 const std::map<int32_t, sptr<SceneSession>>& sessionMap); 166 void PostFlushWindowInfoTask(FlushWindowInfoTask &&task, const std::string taskName, const int delayTime); 167 168 sptr<SceneSession> GetSceneSessionByName(const ComparedSessionInfo& info); 169 sptr<SceneSession> GetSceneSessionByType(WindowType type); 170 sptr<SceneSession> GetSceneSessionByBundleName(const std::string& bundleName); 171 172 WSError CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 173 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 174 sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session, 175 SystemSessionConfig& systemConfig, sptr<IRemoteObject> token = nullptr) override; 176 WSError RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage, 177 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 178 sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr) override; 179 WSError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage, 180 const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode, 181 sptr<ISession>& session, sptr<WindowSessionProperty> property = nullptr, 182 sptr<IRemoteObject> token = nullptr) override; 183 WSError DestroyAndDisconnectSpecificSession(const int32_t persistentId) override; 184 WSError DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId, 185 const sptr<IRemoteObject>& callback) override; 186 void SetCreateSystemSessionListener(const NotifyCreateSystemSessionFunc& func); 187 void SetCreateKeyboardSessionListener(const NotifyCreateKeyboardSessionFunc& func); 188 void SetStatusBarEnabledChangeListener(const ProcessStatusBarEnabledChangeFunc& func); 189 void SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func); 190 void SetRecoverSceneSessionListener(const NotifyRecoverSceneSessionFunc& func); 191 void SetGestureNavigationEnabledChangeListener(const ProcessGestureNavigationEnabledChangeFunc& func); 192 void SetDumpRootSceneElementInfoListener(const DumpRootSceneElementInfoFunc& func); 193 void SetOutsideDownEventListener(const ProcessOutsideDownEventFunc& func); 194 void SetShiftFocusListener(const ProcessShiftFocusFunc& func); 195 void SetSCBFocusedListener(const NotifySCBAfterUpdateFocusFunc& func); 196 void SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocusFunc& func); 197 void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func); 198 void SetDumpUITreeFunc(const DumpUITreeFunc& func); 199 const AppWindowSceneConfig& GetWindowSceneConfig() const; 200 void UpdateRotateAnimationConfig(const RotateAnimationConfig& config); 201 WSError ProcessBackEvent(); 202 WSError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken) override; 203 void GetStartupPage(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor); 204 WMError SetGestureNavigaionEnabled(bool enable) override; 205 WMError RegisterWindowManagerAgent(WindowManagerAgentType type, 206 const sptr<IWindowManagerAgent>& windowManagerAgent) override; 207 WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, 208 const sptr<IWindowManagerAgent>& windowManagerAgent) override; 209 210 WSError SetFocusedSessionId(int32_t persistentId); 211 int32_t GetFocusedSessionId() const; GetFocusChangeReason()212 FocusChangeReason GetFocusChangeReason() const { return focusChangeReason_; } 213 WSError GetAllSessionDumpInfo(std::string& info); 214 WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector<std::string>& params, 215 const std::string& strId); 216 WSError GetSCBDebugDumpInfo(std::string& dumpInfo, const std::vector<std::string>& params); 217 WSError GetSessionDumpInfo(const std::vector<std::string>& params, std::string& info) override; 218 WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = true, 219 FocusChangeReason reason = FocusChangeReason::DEFAULT) override; 220 WMError RequestFocusStatusBySCB(int32_t persistentId, bool isFocused, bool byForeground = true, 221 FocusChangeReason reason = FocusChangeReason::DEFAULT); 222 void RequestAllAppSessionUnfocus(); 223 WSError UpdateFocus(int32_t persistentId, bool isFocused); 224 WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); 225 WSError SendTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, uint32_t zIndex); 226 WSError RaiseWindowToTop(int32_t persistentId) override; 227 void SetScreenLocked(const bool isScreenLocked); 228 bool IsScreenLocked() const; 229 230 WSError InitUserInfo(int32_t userId, std::string& fileDir); 231 void NotifySwitchingUser(const bool isUserActive); 232 int32_t GetCurrentUserId() const; 233 void StartWindowInfoReportLoop(); 234 void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; 235 void NotifyCompleteFirstFrameDrawing(int32_t persistentId); 236 void NotifySessionMovedToFront(int32_t persistentId); 237 WSError SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label) override; 238 WSError SetSessionIcon(const sptr<IRemoteObject>& token, const std::shared_ptr<Media::PixelMap>& icon) override; 239 WSError IsValidSessionIds(const std::vector<int32_t>& sessionIds, std::vector<bool>& results) override; 240 void HandleTurnScreenOn(const sptr<SceneSession>& sceneSession); 241 void HandleKeepScreenOn(const sptr<SceneSession>& sceneSession, bool requireLock); 242 void InitWithRenderServiceAdded(); 243 WSError PendingSessionToForeground(const sptr<IRemoteObject>& token) override; 244 WSError PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject>& token, 245 bool shouldBackToCaller = true) override; 246 WSError GetFocusSessionToken(sptr<IRemoteObject>& token) override; 247 WSError GetFocusSessionElement(AppExecFwk::ElementName& element) override; 248 WSError RegisterSessionListener(const sptr<ISessionListener>& listener) override; 249 WSError UnRegisterSessionListener(const sptr<ISessionListener>& listener) override; 250 WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, 251 std::vector<SessionInfoBean>& sessionInfos) override; 252 WSError GetMainWindowStatesByPid(int32_t pid, std::vector<MainWindowState>& windowStates); 253 WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo) override; 254 WSError GetSessionInfoByContinueSessionId(const std::string& continueSessionId, 255 SessionInfoBean& sessionInfo) override; 256 WSError DumpSessionAll(std::vector<std::string> &infos) override; 257 WSError DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos) override; 258 WSError GetAllAbilityInfos(const AAFwk::Want &want, int32_t userId, 259 std::vector<SCBAbilityInfo> &scbAbilityInfos); 260 WSError GetBatchAbilityInfos(const std::vector<std::string>& bundleNames, int32_t userId, 261 std::vector<SCBAbilityInfo>& scbAbilityInfos); 262 WSError GetAbilityInfo(const std::string& bundleName, const std::string& moduleName, 263 const std::string& abilityName, int32_t userId, SCBAbilityInfo& scbAbilityInfo); 264 WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate); 265 266 WSError TerminateSessionNew( 267 const sptr<AAFwk::SessionInfo> info, bool needStartCaller, bool isFromBroker = false) override; 268 WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) override; 269 WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, 270 SessionSnapshot& snapshot, bool isLowResolution) override; 271 WMError GetSessionSnapshotById(int32_t persistentId, SessionSnapshot& snapshot) override; 272 WSError SetVmaCacheStatus(bool flag); 273 WSError GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj) override; 274 WSError SetSessionContinueState(const sptr<IRemoteObject>& token, const ContinueState& continueState) override; 275 WSError ClearSession(int32_t persistentId) override; 276 WSError ClearAllSessions() override; 277 WSError LockSession(int32_t sessionId) override; 278 WSError UnlockSession(int32_t sessionId) override; 279 WSError MoveSessionsToForeground(const std::vector<int32_t>& sessionIds, int32_t topSessionId) override; 280 WSError MoveSessionsToBackground(const std::vector<int32_t>& sessionIds, std::vector<int32_t>& result) override; 281 WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override; 282 WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) override; 283 284 /* 285 * PC Window 286 */ 287 WMError IsPcWindow(bool& isPcWindow) override; 288 WMError IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode) override; 289 WMError IsWindowRectAutoSave(const std::string& key, bool& enabled) override; 290 void SetIsWindowRectAutoSave(const std::string& key, bool enabled); 291 292 std::map<int32_t, sptr<SceneSession>>& GetSessionMapByScreenId(ScreenId id); 293 void UpdatePrivateStateAndNotify(uint32_t persistentId); 294 void InitPersistentStorage(); 295 std::string GetSessionSnapshotFilePath(int32_t persistentId); 296 void OnOutsideDownEvent(int32_t x, int32_t y); 297 void NotifySessionTouchOutside(int32_t persistentId); 298 299 WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) override; 300 WMError GetUnreliableWindowInfo(int32_t windowId, 301 std::vector<sptr<UnreliableWindowInfo>>& infos) override; 302 WSError SetWindowFlags(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property); 303 304 void OnScreenshot(DisplayId displayId); 305 void NotifyDumpInfoResult(const std::vector<std::string>& info) override; 306 void SetVirtualPixelRatioChangeListener(const ProcessVirtualPixelRatioChangeFunc& func); 307 void ProcessVirtualPixelRatioChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 308 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 309 void ProcessUpdateRotationChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 310 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 311 312 void SetRootSceneProcessBackEventFunc(const RootSceneProcessBackEventFunc& processBackEventFunc); 313 void RegisterWindowChanged(const WindowChangedFunc& func); 314 315 /* 316 * Collaborator 317 */ 318 void SetAbilityManagerCollaboratorRegisteredFunc(const AbilityManagerCollaboratorRegisteredFunc& func); 319 WSError RegisterIAbilityManagerCollaborator(int32_t type, 320 const sptr<AAFwk::IAbilityManagerCollaborator>& impl) override; 321 WSError UnregisterIAbilityManagerCollaborator(int32_t type) override; 322 323 bool IsInputEventEnabled(); 324 void SetEnableInputEvent(bool enabled); 325 void UpdateRecoveredSessionInfo(const std::vector<int32_t>& recoveredPersistentIds); 326 void SetAlivePersistentIds(const std::vector<int32_t>& alivePersistentIds); 327 void NotifyRecoveringFinished(); 328 329 WMError CheckWindowId(int32_t windowId, int32_t& pid) override; 330 void GetSceneSessionPrivacyModeBundles(DisplayId displayId, std::unordered_set<std::string>& privacyBundles); 331 BrokerStates CheckIfReuseSession(SessionInfo& sessionInfo); 332 bool CheckCollaboratorType(int32_t type); 333 sptr<SceneSession> FindSessionByAffinity(std::string affinity); 334 void AddWindowDragHotArea(uint32_t type, WSRect& area); 335 void PreloadInLakeApp(const std::string& bundleName); 336 WSError UpdateMaximizeMode(int32_t persistentId, bool isMaximize); 337 bool GetImmersiveState(); 338 WSError UpdateSessionDisplayId(int32_t persistentId, uint64_t screenId); 339 WSError NotifyStackEmpty(int32_t persistentId); 340 void NotifySessionUpdate(const SessionInfo& sessionInfo, ActionType type, 341 ScreenId fromScreenId = SCREEN_ID_INVALID); 342 WSError NotifyStatusBarShowStatus(int32_t persistentId, bool isVisible); 343 WSError NotifyAINavigationBarShowStatus(bool isVisible, WSRect barArea, uint64_t displayId); 344 WSRect GetAINavigationBarArea(uint64_t displayId); 345 WMError GetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds, 346 std::vector<uint64_t>& surfaceNodeIds, bool isBlackList = false); 347 WSError UpdateTitleInTargetPos(int32_t persistentId, bool isShow, int32_t height); 348 void RegisterCreateSubSessionListener(int32_t persistentId, const NotifyCreateSubSessionFunc& func); 349 void UnregisterCreateSubSessionListener(int32_t persistentId); 350 351 /* 352 * Window Immersive 353 */ 354 WSError GetIsLayoutFullScreen(bool& isLayoutFullScreen); 355 WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) override; 356 void ClearDisplayStatusBarTemporarilyFlags(); 357 void SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func); 358 void SetIsRootSceneLastFrameLayoutFinishedFunc(IsRootSceneLastFrameLayoutFinishedFunc&& func); 359 void SetStatusBarDefaultVisibilityPerDisplay(DisplayId displayId, bool visible); 360 bool GetStatusBarDefaultVisibilityByDisplayId(DisplayId displayId); 361 362 WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override; 363 void DealwithVisibilityChange(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfos, 364 const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData); 365 void DealwithDrawingContentChange(const std::vector<std::pair<uint64_t, bool>>& drawingChangeInfos); 366 void NotifyUpdateRectAfterLayout(); 367 void FlushUIParams(ScreenId screenId, std::unordered_map<int32_t, SessionUIParam>&& uiParams); 368 WSError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener) override; 369 WMError SetSystemAnimatedScenes(SystemAnimatedSceneType sceneType); 370 WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override; 371 std::shared_ptr<Media::PixelMap> GetSessionSnapshotPixelMap(const int32_t persistentId, const float scaleParam); 372 void RequestInputMethodCloseKeyboard(int32_t persistentId); 373 WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override; 374 const std::map<int32_t, sptr<SceneSession>> GetSceneSessionMap(); 375 void GetAllSceneSession(std::vector<sptr<SceneSession>>& sceneSessions); 376 void GetAllWindowVisibilityInfos(std::vector<std::pair<int32_t, uint32_t>>& windowVisibilityInfos); 377 void FlushWindowInfoToMMI(const bool forceFlush = false); 378 int32_t StartUIAbilityBySCB(sptr<AAFwk::SessionInfo>& abilitySessionInfo); 379 int32_t StartUIAbilityBySCB(sptr<SceneSession>& sceneSessions); 380 int32_t ChangeUIAbilityVisibilityBySCB(sptr<SceneSession>& sceneSessions, bool visibility); 381 382 /* 383 * UIExtension 384 */ 385 uint32_t GetLockScreenZOrder(); 386 WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element, 387 AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid); 388 void OnNotifyAboveLockScreen(const std::vector<int32_t>& windowIds); 389 void AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage, 390 const sptr<IRemoteObject>& token, uint64_t surfaceNodeId) override; 391 void RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage, 392 const sptr<IRemoteObject>& token) override; 393 void UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect) override; 394 void ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY) override; 395 WSError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) override; 396 WSError CheckExtWindowFlagsPermission(ExtensionWindowFlags& actions) const; 397 WSError UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags, 398 uint32_t extWindowActions) override; 399 void CheckSceneZOrder(); 400 WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override; 401 WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override; 402 WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override; 403 WMError GetWindowModeType(WindowModeType& windowModeType) override; 404 WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber, 405 int32_t x, int32_t y, std::vector<int32_t>& windowIds) override; 406 407 int32_t ReclaimPurgeableCleanMem(); 408 void OnBundleUpdated(const std::string& bundleName, int userId); 409 void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 410 GetTaskScheduler()411 std::shared_ptr<TaskScheduler> GetTaskScheduler() {return taskScheduler_;}; 412 int32_t GetCustomDecorHeight(int32_t persistentId); 413 WSError SwitchFreeMultiWindow(bool enable); 414 WSError GetFreeMultiWindowEnableState(bool& enable) override; 415 const SystemSessionConfig& GetSystemSessionConfig() const; 416 WSError NotifyEnterRecentTask(bool enterRecent); 417 WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo); 418 WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const; 419 WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds); 420 WMError UpdateDisplayHookInfo(int32_t uid, uint32_t width, uint32_t height, float_t density, bool enable); 421 WMError UpdateAppHookDisplayInfo(int32_t uid, const HookInfo& hookInfo, bool enable); 422 void InitScheduleUtils(); 423 void ProcessDisplayScale(sptr<DisplayInfo>& displayInfo); 424 WMError GetRootMainWindowId(int32_t persistentId, int32_t& hostWindowId); 425 426 /* 427 * Move Drag 428 */ 429 WMError SetGlobalDragResizeType(DragResizeType dragResizeType) override; 430 WMError GetGlobalDragResizeType(DragResizeType& dragResizeType) override; 431 WMError SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType) override; 432 WMError GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType) override; 433 WMError SetAppDragResizeTypeInner(const std::string& bundleName, DragResizeType dragResizeType); 434 435 /* 436 * Multi Window 437 */ 438 void SetCloseTargetFloatWindowFunc(const ProcessCloseTargetFloatWindowFunc& func); 439 WMError CloseTargetFloatWindow(const std::string& bundleName); 440 441 /* 442 * Fold Screen Status Change Report 443 */ 444 WMError ReportScreenFoldStatusChange(const std::vector<std::string>& screenFoldInfo); 445 446 void UpdateSecSurfaceInfo(std::shared_ptr<RSUIExtensionData> secExtensionData, uint64_t userid); 447 WSError SetAppForceLandscapeConfig(const std::string& bundleName, const AppForceLandscapeConfig& config); 448 AppForceLandscapeConfig GetAppForceLandscapeConfig(const std::string& bundleName); 449 WMError GetWindowStyleType(WindowStyleType& windowStyletype) override; 450 WMError TerminateSessionByPersistentId(int32_t persistentId); 451 WMError GetProcessSurfaceNodeIdByPersistentId(const int32_t pid, 452 const std::vector<int32_t>& persistentIds, std::vector<uint64_t>& surfaceNodeIds) override; 453 454 /* 455 * Window Property 456 */ 457 WMError ReleaseForegroundSessionScreenLock() override; 458 459 /* 460 * PiP Window 461 */ 462 WMError CloseTargetPiPWindow(const std::string& bundleName); 463 WMError GetCurrentPiPWindowInfo(std::string& bundleName); 464 void SetStartPiPFailedListener(NotifyStartPiPFailedFunc&& func); 465 466 /* 467 * Screen Manager 468 */ 469 WMError GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds, 470 std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap) override; 471 472 /** 473 * Window Lifecycle 474 */ 475 void RemoveAppInfo(const std::string& bundleName); 476 void GetMainSessionByBundleNameAndAppIndex( 477 const std::string& bundleName, int32_t appIndex, std::vector<sptr<SceneSession>>& mainSessions); 478 WSError NotifyAppUseControlList( 479 ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList); 480 void RegisterNotifyAppUseControlListCallback(NotifyAppUseControlListFunc&& func); 481 void SetUserAuthPassed(bool isUserAuthPassed); 482 bool IsUserAuthPassed() const; 483 484 protected: 485 SceneSessionManager(); 486 virtual ~SceneSessionManager(); 487 488 private: 489 std::atomic<bool> enterRecent_ { false }; 490 bool isKeyboardPanelEnabled_ = false; 491 static sptr<SceneSessionManager> CreateInstance(); 492 void Init(); 493 void RegisterAppListener(); 494 void InitPrepareTerminateConfig(); 495 void LoadWindowSceneXml(); 496 void ConfigWindowSceneXml(); 497 void ConfigWindowSceneXml(const WindowSceneConfig::ConfigItem& config); 498 void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig); 499 void ConfigWindowImmersive(const WindowSceneConfig::ConfigItem& immersiveConfig); 500 void ConfigKeyboardAnimation(const WindowSceneConfig::ConfigItem& animationConfig); 501 void ConfigDefaultKeyboardAnimation(KeyboardSceneAnimationConfig& animationIn, 502 KeyboardSceneAnimationConfig& animationOut); 503 bool ConfigAppWindowCornerRadius(const WindowSceneConfig::ConfigItem& item, float& out); 504 bool ConfigAppWindowShadow(const WindowSceneConfig::ConfigItem& shadowConfig, WindowShadowConfig& outShadow); 505 bool ConfigStatusBar(const WindowSceneConfig::ConfigItem& config, StatusBarConfig& statusBarConfig); 506 void ConfigSystemUIStatusBar(const WindowSceneConfig::ConfigItem& statusBarConfig); 507 void ConfigDecor(const WindowSceneConfig::ConfigItem& decorConfig, bool mainConfig = true); 508 void ConfigWindowAnimation(const WindowSceneConfig::ConfigItem& windowAnimationConfig); 509 void ConfigStartingWindowAnimation(const WindowSceneConfig::ConfigItem& startingWindowConfig); 510 void ConfigWindowSizeLimits(); 511 void ConfigMainWindowSizeLimits(const WindowSceneConfig::ConfigItem& mainWindowSizeConifg); 512 void ConfigSubWindowSizeLimits(const WindowSceneConfig::ConfigItem& subWindowSizeConifg); 513 void ConfigSnapshotScale(); 514 void ConfigFreeMultiWindow(); 515 void LoadFreeMultiWindowConfig(bool enable); 516 517 std::tuple<std::string, std::vector<float>> CreateCurve(const WindowSceneConfig::ConfigItem& curveConfig); 518 void LoadKeyboardAnimation(const WindowSceneConfig::ConfigItem& item, KeyboardSceneAnimationConfig& config); 519 sptr<SceneSession::SpecificSessionCallback> CreateSpecificSessionCallback(); 520 sptr<KeyboardSession::KeyboardSessionCallback> CreateKeyboardSessionCallback(); 521 void FillSessionInfo(sptr<SceneSession>& sceneSession); 522 std::shared_ptr<AppExecFwk::AbilityInfo> QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName, 523 const std::string& abilityName, const std::string& moduleName); 524 std::vector<sptr<SceneSession>> GetSubSceneSession(int32_t parentWindowId); 525 void RemoveDuplicateSubSession(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfo, 526 std::vector<sptr<SceneSession>>& subSessions); 527 void SetSessionVisibilityInfo(const sptr<SceneSession>& session, WindowVisibilityState visibleState, 528 std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos, std::string& visibilityInfo); 529 void UpdateSubWindowVisibility(const sptr<SceneSession>& session, WindowVisibilityState visibleState, 530 const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfo, 531 std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos, std::string& visibilityInfo, 532 const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData); 533 bool GetSessionRSVisible(const sptr<Session>& session, 534 const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData); 535 536 /* 537 * Window Pipeline 538 */ 539 void ProcessFocusZOrderChange(uint32_t dirty); 540 void PostProcessFocus(); 541 void PostProcessProperty(uint32_t dirty); 542 543 /** 544 * Window Lifecycle 545 */ 546 bool isUserAuthPassed_ {false}; 547 sptr<SceneSession> GetSceneSessionBySessionInfo(const SessionInfo& sessionInfo); 548 549 std::vector<std::pair<int32_t, sptr<SceneSession>>> GetSceneSessionVector(CmpFunc cmp); 550 void TraverseSessionTree(TraverseFunc func, bool isFromTopToBottom); 551 void TraverseSessionTreeFromTopToBottom(TraverseFunc func); 552 void TraverseSessionTreeFromBottomToTop(TraverseFunc func); 553 WSError RequestSessionFocus(int32_t persistentId, bool byForeground = true, 554 FocusChangeReason reason = FocusChangeReason::DEFAULT); 555 WSError RequestSessionFocusImmediately(int32_t persistentId); 556 WSError RequestSessionUnfocus(int32_t persistentId, FocusChangeReason reason = FocusChangeReason::DEFAULT); 557 WSError RequestAllAppSessionUnfocusInner(); 558 WSError RequestFocusBasicCheck(int32_t persistentId); 559 bool CheckLastFocusedAppSessionFocus(sptr<SceneSession>& focusedSession, sptr<SceneSession>& nextSession); 560 WSError RequestFocusSpecificCheck(sptr<SceneSession>& sceneSession, bool byForeground, 561 FocusChangeReason reason = FocusChangeReason::DEFAULT); 562 bool CheckTopmostWindowFocus(sptr<SceneSession>& focusedSession, sptr<SceneSession>& sceneSession); 563 bool CheckRequestFocusImmdediately(sptr<SceneSession>& sceneSession); 564 bool CheckFocusIsDownThroughBlockingType(sptr<SceneSession>& requestSceneSession, 565 sptr<SceneSession>& focusedSession, bool includingAppSession); 566 bool CheckClickFocusIsDownThroughFullScreen(const sptr<SceneSession>& focusedSession, 567 const sptr<SceneSession>& sceneSession, FocusChangeReason reason); 568 bool CheckParentSessionVisible(const sptr<SceneSession>& session); 569 void InitSceneSession(sptr<SceneSession>& sceneSession, const SessionInfo& sessionInfo, 570 const sptr<WindowSessionProperty>& property); 571 void ResetSceneSessionInfoWant(const sptr<AAFwk::SessionInfo>& sceneSessionInfo); 572 573 sptr<SceneSession> GetNextFocusableSession(int32_t persistentId); 574 sptr<SceneSession> GetTopNearestBlockingFocusSession(uint32_t zOrder, bool includingAppSession); 575 sptr<SceneSession> GetTopFocusableNonAppSession(); 576 WSError ShiftFocus(sptr<SceneSession>& nextSession, FocusChangeReason reason = FocusChangeReason::DEFAULT); 577 void UpdateFocusStatus(sptr<SceneSession>& sceneSession, bool isFocused); 578 void NotifyFocusStatus(sptr<SceneSession>& sceneSession, bool isFocused); 579 int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, 580 const std::string& reason); 581 void NotifyFocusStatusByMission(sptr<SceneSession>& prevSession, sptr<SceneSession>& currSession); 582 void NotifyUnFocusedByMission(sptr<SceneSession>& sceneSession); 583 bool MissionChanged(sptr<SceneSession>& prevSession, sptr<SceneSession>& currSession); 584 std::string GetAllSessionFocusInfo(); 585 void RegisterRequestFocusStatusNotifyManagerFunc(sptr<SceneSession>& sceneSession); 586 void ProcessUpdateLastFocusedAppId(const std::vector<uint32_t>& zOrderList); 587 void RegisterGetStateFromManagerFunc(sptr<SceneSession>& sceneSession); 588 void RegisterSessionChangeByActionNotifyManagerFunc(sptr<SceneSession>& sceneSession); 589 590 sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<SceneSession>& scnSession); 591 WSError DestroyDialogWithMainWindow(const sptr<SceneSession>& scnSession); 592 sptr<SceneSession> FindMainWindowWithToken(sptr<IRemoteObject> targetToken); 593 WSError UpdateParentSessionForDialog(const sptr<SceneSession>& sceneSession, sptr<WindowSessionProperty> property); 594 void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing); 595 void UpdateFocusableProperty(int32_t persistentId); 596 WMError UpdateTopmostProperty(const sptr<WindowSessionProperty>& property, const sptr<SceneSession>& sceneSession); 597 std::vector<sptr<SceneSession>> GetSceneSessionVectorByType(WindowType type, uint64_t displayId); 598 void UpdateOccupiedAreaIfNeed(const int32_t& persistentId); 599 void NotifyMMIWindowPidChange(int32_t windowId, bool startMoving); 600 601 /** 602 * Window Immersive 603 */ 604 bool UpdateSessionAvoidAreaIfNeed(const int32_t& persistentId, 605 const sptr<SceneSession>& sceneSession, const AvoidArea& avoidArea, AvoidAreaType avoidAreaType); 606 void UpdateAvoidSessionAvoidArea(WindowType type, bool& needUpdate); 607 void UpdateNormalSessionAvoidArea(const int32_t& persistentId, sptr<SceneSession>& sceneSession, bool& needUpdate); 608 void UpdateAvoidArea(int32_t persistentId); 609 void UpdateAvoidAreaByType(int32_t persistentId, AvoidAreaType type); 610 WSError IsLastFrameLayoutFinished(bool& isLayoutFinished); 611 void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property, 612 const sptr<SceneSession>& sceneSession); 613 614 sptr<AppExecFwk::IBundleMgr> GetBundleManager(); 615 std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo); 616 bool GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, std::string& path, uint32_t& bgColor); 617 bool GetStartingWindowInfoFromCache(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor); 618 void CacheStartingWindowInfo( 619 const AppExecFwk::AbilityInfo& abilityInfo, const std::string& path, const uint32_t& bgColor); 620 621 bool CheckIsRemote(const std::string& deviceId); 622 bool GetLocalDeviceId(std::string& localDeviceId); 623 std::string AnonymizeDeviceId(const std::string& deviceId); 624 int GetRemoteSessionInfos(const std::string& deviceId, int32_t numMax, 625 std::vector<SessionInfoBean>& sessionInfos); 626 int GetRemoteSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo); 627 WSError GetTotalUITreeInfo(std::string& dumpInfo); 628 629 void PerformRegisterInRequestSceneSession(sptr<SceneSession>& sceneSession); 630 WSError RequestSceneSessionActivationInner(sptr<SceneSession>& scnSession, bool isNewActive); 631 WSError SetBrightness(const sptr<SceneSession>& sceneSession, float brightness); 632 void PostBrightnessTask(float brightness); 633 WSError UpdateBrightness(int32_t persistentId); 634 void SetDisplayBrightness(float brightness); 635 float GetDisplayBrightness() const; 636 void HandleHideNonSystemFloatingWindows(const sptr<WindowSessionProperty>& property, 637 const sptr<SceneSession>& sceneSession); 638 void UpdateForceHideState(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property, 639 bool add); 640 void NotifyWindowInfoChange(int32_t persistentId, WindowUpdateType type); 641 void NotifyWindowInfoChangeFromSession(int32_t persistentid); 642 bool FillWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos, 643 const sptr<SceneSession>& sceneSession); 644 std::vector<std::pair<uint64_t, WindowVisibilityState>> GetWindowVisibilityChangeInfo( 645 std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData); 646 std::vector<std::pair<uint64_t, bool>> GetWindowDrawingContentChangeInfo( 647 std::vector<std::pair<uint64_t, bool>> currDrawingContentData); 648 void GetWindowLayerChangeInfo(std::shared_ptr<RSOcclusionData> occlusionData, 649 std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData, 650 std::vector<std::pair<uint64_t, bool>>& currDrawingContentData); 651 void WindowLayerInfoChangeCallback(std::shared_ptr<RSOcclusionData> occlusiontionData); 652 sptr<SceneSession> SelectSesssionFromMap(const uint64_t& surfaceId); 653 void WindowDestroyNotifyVisibility(const sptr<SceneSession>& sceneSession); 654 void RegisterSessionExceptionFunc(const sptr<SceneSession>& sceneSession); 655 void RegisterSessionSnapshotFunc(const sptr<SceneSession>& sceneSession); 656 void RegisterAcquireRotateAnimationConfigFunc(const sptr<SceneSession>& sceneSession); 657 void NotifySessionForCallback(const sptr<SceneSession>& scnSession, const bool needRemoveSession); 658 void DumpSessionInfo(const sptr<SceneSession>& session, std::ostringstream& oss); 659 void DumpSessionElementInfo(const sptr<SceneSession>& session, 660 const std::vector<std::string>& params, std::string& dumpInfo); 661 void DumpAllSessionFocusableInfo(int32_t persistentId); 662 void AddClientDeathRecipient(const sptr<ISessionStage>& sessionStage, const sptr<SceneSession>& sceneSession); 663 void DestroySpecificSession(const sptr<IRemoteObject>& remoteObject); 664 bool GetExtensionWindowIds(const sptr<IRemoteObject>& token, int32_t& persistentId, int32_t& parentId); 665 void DestroyExtensionSession(const sptr<IRemoteObject>& remoteExtSession); 666 void EraseSceneSessionMapById(int32_t persistentId); 667 void EraseSceneSessionAndMarkDirtyLocked(int32_t persistentId); 668 WSError GetAbilityInfosFromBundleInfo(const std::vector<AppExecFwk::BundleInfo>& bundleInfos, 669 std::vector<SCBAbilityInfo>& scbAbilityInfos); 670 void GetOrientationFromResourceManager(AppExecFwk::AbilityInfo& abilityInfo); 671 void UpdatePrivateStateAndNotifyForAllScreens(); 672 673 void ClosePipWindowIfExist(WindowType type); 674 void NotifySessionAINavigationBarChange(int32_t persistentId); 675 void ReportWindowProfileInfos(); 676 void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing); 677 void removeFailRecoveredSession(); 678 void GetAllSceneSessionForAccessibility(std::vector<sptr<SceneSession>>& sceneSessionList); 679 void FillAccessibilityInfo(std::vector<sptr<SceneSession>>& sceneSessionList, 680 std::vector<sptr<AccessibilityWindowInfo>>& accessibilityInfo); 681 void FilterSceneSessionCovered(std::vector<sptr<SceneSession>>& sceneSessionList); 682 void NotifyAllAccessibilityInfo(); 683 void SetSkipSelfWhenShowOnVirtualScreen(uint64_t surfaceNodeId, bool isSkip); 684 void RegisterSecSurfaceInfoListener(); 685 void DestroyUIServiceExtensionSubWindow(const sptr<SceneSession>& sceneSession); 686 687 /** 688 * PiP Window 689 */ 690 void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground); 691 692 /* 693 * Gesture Back 694 */ 695 void UpdateGestureBackEnabled(int32_t persistentId); 696 std::unordered_set<int32_t> gestureBackEnableWindowIdSet_; // ONLY Accessed on OS_sceneSession thread 697 698 sptr<RootSceneSession> rootSceneSession_; 699 std::weak_ptr<AbilityRuntime::Context> rootSceneContextWeak_; 700 mutable std::shared_mutex sceneSessionMapMutex_; 701 std::map<int32_t, sptr<SceneSession>> sceneSessionMap_; 702 std::map<int32_t, sptr<SceneSession>> systemTopSceneSessionMap_; 703 std::map<int32_t, sptr<SceneSession>> nonSystemFloatSceneSessionMap_; 704 sptr<ScbSessionHandler> scbSessionHandler_; 705 std::shared_ptr<SessionListenerController> listenerController_; 706 std::map<sptr<IRemoteObject>, int32_t> remoteObjectMap_; 707 std::map<sptr<IRemoteObject>, sptr<IRemoteObject>> remoteExtSessionMap_; 708 std::map<sptr<IRemoteObject>, ExtensionWindowAbilityInfo> extSessionInfoMap_; 709 std::set<int32_t> touchOutsideListenerSessionSet_; 710 std::set<int32_t> windowVisibilityListenerSessionSet_; 711 ExtensionWindowFlags combinedExtWindowFlags_ { 0 }; 712 std::map<int32_t, ExtensionWindowFlags> extWindowFlagsMap_; 713 std::set<int32_t> failRecoveredPersistentIdSet_; 714 715 NotifyCreateSystemSessionFunc createSystemSessionFunc_; 716 NotifyCreateKeyboardSessionFunc createKeyboardSessionFunc_; 717 std::map<int32_t, NotifyCreateSubSessionFunc> createSubSessionFuncMap_; 718 std::map<int32_t, std::vector<sptr<SceneSession>>> recoverSubSessionCacheMap_; 719 bool recoveringFinished_ = false; 720 NotifyRecoverSceneSessionFunc recoverSceneSessionFunc_; 721 ProcessStatusBarEnabledChangeFunc statusBarEnabledChangeFunc_; 722 ProcessGestureNavigationEnabledChangeFunc gestureNavigationEnabledChangeFunc_; 723 ProcessOutsideDownEventFunc outsideDownEventFunc_; 724 DumpRootSceneElementInfoFunc dumpRootSceneFunc_; 725 ProcessShiftFocusFunc shiftFocusFunc_; 726 NotifySCBAfterUpdateFocusFunc notifySCBAfterFocusedFunc_; 727 NotifySCBAfterUpdateFocusFunc notifySCBAfterUnfocusedFunc_; 728 ProcessCallingSessionIdChangeFunc callingSessionIdChangeFunc_; 729 ProcessStartUIAbilityErrorFunc startUIAbilityErrorFunc_; 730 DumpUITreeFunc dumpUITreeFunc_; 731 ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr; 732 733 /** 734 * Multi Window 735 */ 736 ProcessCloseTargetFloatWindowFunc closeTargetFloatWindowFunc_; 737 738 AppWindowSceneConfig appWindowSceneConfig_; 739 RotateAnimationConfig rotateAnimationConfig_; 740 741 /* 742 * PiP Window 743 */ 744 NotifyStartPiPFailedFunc startPiPFailedFunc_; 745 746 SystemSessionConfig systemConfig_; 747 FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT; 748 float snapshotScale_ = 0.5; 749 int32_t focusedSessionId_ = INVALID_SESSION_ID; 750 int32_t lastFocusedSessionId_ = INVALID_SESSION_ID; 751 int32_t lastFocusedAppSessionId_ = INVALID_SESSION_ID; 752 int32_t brightnessSessionId_ = INVALID_SESSION_ID; 753 float displayBrightness_ = UNDEFINED_BRIGHTNESS; 754 bool isScreenLocked_ {false}; 755 bool needBlockNotifyFocusStatusUntilForeground_ {false}; 756 bool needBlockNotifyUnfocusStatus_ {false}; 757 bool isPrepareTerminateEnable_ {false}; 758 bool openDebugTrace {false}; 759 std::atomic<bool> enableInputEvent_ = true; 760 std::vector<int32_t> alivePersistentIds_ = {}; 761 std::vector<VisibleWindowNumInfo> lastInfo_ = {}; 762 std::shared_mutex lastInfoMutex_; 763 764 std::shared_ptr<TaskScheduler> taskScheduler_; 765 sptr<AppExecFwk::IBundleMgr> bundleMgr_; 766 sptr<AppAnrListener> appAnrListener_; 767 sptr<AppExecFwk::LauncherService> launcherService_; 768 std::shared_mutex startingWindowMapMutex_; 769 const size_t MAX_CACHE_COUNT = 100; 770 std::map<std::string, std::map<std::string, StartingWindowInfo>> startingWindowMap_; 771 std::unordered_map<std::string, AppForceLandscapeConfig> appForceLandscapeMap_; 772 std::shared_mutex appForceLandscapeMutex_; 773 774 std::mutex privacyBundleMapMutex_; 775 std::unordered_map<DisplayId, std::unordered_set<std::string>> privacyBundleMap_; 776 777 WindowModeType lastWindowModeType_ { WindowModeType::WINDOW_MODE_OTHER }; 778 779 // Multi User 780 static constexpr int32_t DEFAULT_USERID = -1; 781 std::atomic<int32_t> currentUserId_ { DEFAULT_USERID }; 782 bool isUserBackground_ = false; // Only accessed on SSM thread 783 784 // displayRegionMap_ stores the screen display area for AccessibilityNotification, 785 // the read and write operations must be performed in the same thread, current is in task thread. 786 std::unordered_map<DisplayId, std::shared_ptr<SkRegion>> displayRegionMap_; 787 std::shared_ptr<SkRegion> GetDisplayRegion(DisplayId displayId); 788 void UpdateDisplayRegion(const sptr<DisplayInfo>& displayInfo); 789 790 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 791 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 792 bool isReportTaskStart_ = false; 793 std::vector<std::pair<uint64_t, WindowVisibilityState> > lastVisibleData_; 794 RSInterfaces& rsInterface_; 795 void ClearUnrecoveredSessions(const std::vector<int32_t>& recoveredPersistentIds); 796 SessionInfo RecoverSessionInfo(const sptr<WindowSessionProperty>& property); 797 bool IsNeedRecover(const int32_t persistentId); 798 void RegisterSessionStateChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession); 799 void RegisterSessionInfoChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession); 800 void OnSessionStateChange(int32_t persistentId, const SessionState& state); 801 void ProcessFocusWhenForeground(sptr<SceneSession>& sceneSession); 802 void ProcessFocusWhenForegroundScbCore(sptr<SceneSession>& sceneSession); 803 void ProcessSubSessionForeground(sptr<SceneSession>& sceneSession); 804 void ProcessSubSessionBackground(sptr<SceneSession>& sceneSession); 805 WSError ProcessDialogRequestFocusImmdediately(sptr<SceneSession>& sceneSession); 806 WSError ProcessModalTopmostRequestFocusImmdediately(sptr<SceneSession>& sceneSession); 807 sptr<SceneSession> FindSessionByToken(const sptr<IRemoteObject>& token); 808 809 void CheckAndNotifyWaterMarkChangedResult(); 810 WSError NotifyWaterMarkFlagChangedResult(bool hasWaterMark); 811 void ProcessPreload(const AppExecFwk::AbilityInfo& abilityInfo) const; 812 std::atomic_bool shouldHideNonSecureFloatingWindows_ { false }; 813 std::atomic_bool specialExtWindowHasPrivacyMode_ { false }; 814 bool lastWaterMarkShowState_ { false }; 815 WindowChangedFunc WindowChangedFunc_; 816 sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient( 817 [this](const sptr<IRemoteObject>& remoteObject) { this->DestroySpecificSession(remoteObject); }); 818 sptr<AgentDeathRecipient> extensionDeath_ = new AgentDeathRecipient( 819 [this](const sptr<IRemoteObject>& remoteExtSession) { this->DestroyExtensionSession(remoteExtSession); }); 820 821 WSError ClearSession(sptr<SceneSession> sceneSession); 822 bool IsSessionClearable(sptr<SceneSession> scnSession); 823 void GetAllClearableSessions(std::vector<sptr<SceneSession>>& sessionVector); 824 int GetRemoteSessionSnapshotInfo(const std::string& deviceId, int32_t sessionId, 825 AAFwk::MissionSnapshot& sessionSnapshot); 826 sptr<AAFwk::IAbilityManagerCollaborator> GetCollaboratorByType(int32_t collaboratorType); 827 828 /* 829 * Collaborator 830 */ 831 AbilityManagerCollaboratorRegisteredFunc abilityManagerCollaboratorRegisteredFunc_; 832 const int32_t BROKER_UID = 5557; 833 const int32_t BROKER_RESERVE_UID = 5005; 834 std::shared_mutex collaboratorMapLock_; 835 std::unordered_map<int32_t, sptr<AAFwk::IAbilityManagerCollaborator>> collaboratorMap_; 836 std::atomic<int64_t> containerStartAbilityTime_ { 0 }; 837 838 std::vector<uint64_t> skipSurfaceNodeIds_; 839 840 std::atomic_bool processingFlushUIParams_ { false }; 841 842 BrokerStates NotifyStartAbility( 843 int32_t collaboratorType, const SessionInfo& sessionInfo, int32_t persistentId = 0); 844 void NotifySessionCreate(const sptr<SceneSession> sceneSession, const SessionInfo& sessionInfo); 845 void NotifyLoadAbility(int32_t collaboratorType, sptr<AAFwk::SessionInfo> abilitySessionInfo, 846 std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo); 847 void NotifyUpdateSessionInfo(const sptr<SceneSession> sceneSession); 848 void NotifyClearSession(int32_t collaboratorType, int32_t persistentId); 849 void NotifyMoveSessionToForeground(int32_t collaboratorType, int32_t persistentId); 850 bool PreHandleCollaboratorStartAbility(sptr<SceneSession>& sceneSession, int32_t persistentId = 0); 851 bool PreHandleCollaborator(sptr<SceneSession>& sceneSession, int32_t persistentId = 0); 852 void NotifyCollaboratorAfterStart(sptr<SceneSession>& scnSession, sptr<AAFwk::SessionInfo>& scnSessionInfo); 853 void UpdateCollaboratorSessionWant(sptr<SceneSession>& session, int32_t persistentId = 0); 854 bool CheckSystemWindowPermission(const sptr<WindowSessionProperty>& property); 855 bool CheckModalSubWindowPermission(const sptr<WindowSessionProperty>& property); 856 bool CheckPiPPriority(const PiPTemplateInfo& pipTemplateInfo); 857 bool isEnablePiPCreate(const sptr<WindowSessionProperty>& property); 858 void DestroySubSession(const sptr<SceneSession>& sceneSession); 859 void DestroyToastSession(const sptr<SceneSession>& sceneSession); 860 void NotifySessionForeground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation); 861 void NotifySessionBackground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation, 862 bool isFromInnerkits); 863 void NotifyCreateSubSession(int32_t persistentId, sptr<SceneSession> session, uint32_t windowFlags = 0); 864 void NotifyCreateToastSession(int32_t persistentId, sptr<SceneSession> session); 865 void CacheSubSessionForRecovering(sptr<SceneSession> sceneSession, const sptr<WindowSessionProperty>& property); 866 void RecoverCachedSubSession(int32_t persistentId); 867 void NotifySessionUnfocusedToClient(int32_t persistentId); 868 void NotifyCreateSpecificSession(sptr<SceneSession> session, 869 sptr<WindowSessionProperty> property, const WindowType& type); 870 void OnSCBSystemSessionBufferAvailable(const WindowType type); 871 sptr<SceneSession> CreateSceneSession(const SessionInfo& sessionInfo, sptr<WindowSessionProperty> property); 872 void CreateKeyboardPanelSession(sptr<SceneSession> keyboardSession); 873 bool GetPreWindowDrawingState(uint64_t windowId, int32_t& pid, bool currentDrawingContentState); 874 bool GetProcessDrawingState(uint64_t windowId, int32_t pid, bool currentDrawingContentState); 875 void ClearSpecificSessionRemoteObjectMap(int32_t persistentId); 876 WSError DestroyAndDisconnectSpecificSessionInner(const int32_t persistentId); 877 WSError GetAppMainSceneSession(sptr<SceneSession>& sceneSession, int32_t persistentId); 878 void CalculateCombinedExtWindowFlags(); 879 void UpdateSpecialExtWindowFlags(int32_t persistentId, ExtensionWindowFlags flags, ExtensionWindowFlags actions); 880 void HideNonSecureFloatingWindows(); 881 void HideNonSecureSubWindows(const sptr<SceneSession>& sceneSession); 882 WSError HandleSecureSessionShouldHide(const sptr<SceneSession>& sceneSession); 883 void HandleSpecialExtWindowFlagsChange(int32_t persistentId, ExtensionWindowFlags extWindowFlags, 884 ExtensionWindowFlags extWindowActions); 885 void ProcessWindowModeType(); 886 WindowModeType CheckWindowModeType(); 887 void NotifyRSSWindowModeTypeUpdate(); 888 void CacVisibleWindowNum(); 889 bool IsVectorSame(const std::vector<VisibleWindowNumInfo>& lastInfo, 890 const std::vector<VisibleWindowNumInfo>& currentInfo); 891 bool IsKeyboardForeground(); 892 WindowStatus GetWindowStatus(WindowMode mode, SessionState sessionState, 893 const sptr<WindowSessionProperty>& property); 894 void DeleteStateDetectTask(); 895 bool JudgeNeedNotifyPrivacyInfo(DisplayId displayId, const std::unordered_set<std::string>& privacyBundles); 896 WSError CheckSessionPropertyOnRecovery(const sptr<WindowSessionProperty>& property, bool isSpecificSession); 897 898 /* 899 * Window Visibility 900 */ 901 bool NotifyVisibleChange(int32_t persistentId); 902 903 /* 904 * Fold Screen Status Change Report 905 */ 906 WMError MakeScreenFoldData(const std::vector<std::string>& screenFoldInfo, ScreenFoldData& screenFoldData); 907 WMError CheckAndReportScreenFoldStatus(ScreenFoldData& data); 908 WMError ReportScreenFoldStatus(const ScreenFoldData& data); 909 910 void ResetWant(sptr<SceneSession>& sceneSession); 911 RunnableFuture<std::vector<std::string>> dumpInfoFuture_; 912 913 /* 914 * Window Pipeline 915 */ 916 uint32_t sessionMapDirty_ { 0 }; 917 std::condition_variable nextFlushCompletedCV_; 918 std::mutex nextFlushCompletedMutex_; 919 920 RootSceneProcessBackEventFunc rootSceneProcessBackEventFunc_ = nullptr; 921 922 /* 923 * Screen Manager 924 */ 925 bool IsInSecondaryScreen(const sptr<SceneSession>& sceneSession); 926 927 /* 928 * Window Property 929 */ 930 void UpdateDarkColorModeToRS(); 931 932 /* 933 * Window Immersive 934 */ 935 OnFlushUIParamsFunc onFlushUIParamsFunc_; 936 IsRootSceneLastFrameLayoutFinishedFunc isRootSceneLastFrameLayoutFinishedFunc_; 937 bool isAINavigationBarVisible_ = false; 938 std::shared_mutex currAINavigationBarAreaMapMutex_; 939 std::map<uint64_t, WSRect> currAINavigationBarAreaMap_; 940 std::unordered_map<DisplayId, bool> statusBarDefaultVisibilityPerDisplay_; 941 std::set<int32_t> avoidAreaListenerSessionSet_; 942 std::map<int32_t, std::map<AvoidAreaType, AvoidArea>> lastUpdatedAvoidArea_; 943 944 /** 945 * PC Window 946 */ 947 std::mutex isWindowRectAutoSaveMapMutex_; 948 std::unordered_map<std::string, bool> isWindowRectAutoSaveMap_; 949 950 /* 951 * Move Drag 952 */ 953 std::mutex dragResizeTypeMutex_; 954 DragResizeType globalDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED; 955 std::unordered_map<std::string, DragResizeType> appDragResizeTypeMap_; 956 void GetEffectiveDragResizeType(DragResizeType& dragResizeType); 957 WMError GetAppDragResizeTypeInner(const std::string& bundleName, DragResizeType& dragResizeType); 958 959 /** 960 * Window Lifecycle 961 */ 962 NotifyAppUseControlListFunc notifyAppUseControlListFunc_; 963 }; 964 } // namespace OHOS::Rosen 965 966 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H 967