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