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