• 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_manager/include/zidl/scene_session_manager_stub.h"
35 #include "wm_single_instance.h"
36 #include "window_scene_config.h"
37 #include "display_info.h"
38 #include "display_change_info.h"
39 #include "display_change_listener.h"
40 #include "app_debug_listener_interface.h"
41 #include "app_mgr_client.h"
42 
43 namespace OHOS::AAFwk {
44 class SessionInfo;
45 } // namespace OHOS::AAFwk
46 
47 namespace OHOS::AppExecFwk {
48 class IBundleMgr;
49 struct AbilityInfo;
50 struct BundleInfo;
51 } // namespace OHOS::AppExecFwk
52 
53 namespace OHOS::Global::Resource {
54 class ResourceManager;
55 } // namespace OHOS::Global::Resource
56 
57 namespace OHOS::Rosen {
58 namespace AncoConsts {
59     constexpr const char* ANCO_MISSION_ID = "ohos.anco.param.missionId";
60     constexpr const char* ANCO_SESSION_ID = "ohos.anco.param.sessionId";
61 }
62 
63 class SceneSession;
64 class AccessibilityWindowInfo;
65 using NotifyCreateSystemSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
66 using NotifyCreateSubSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
67 using NotifyRecoverSceneSessionFunc =
68     std::function<void(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)>;
69 using ProcessStatusBarEnabledChangeFunc = std::function<void(bool enable)>;
70 using ProcessGestureNavigationEnabledChangeFunc = std::function<void(bool enable)>;
71 using ProcessOutsideDownEventFunc = std::function<void(int32_t x, int32_t y)>;
72 using ProcessShiftFocusFunc = std::function<void(int32_t persistentId)>;
73 using NotifySetFocusSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
74 using DumpRootSceneElementInfoFunc = std::function<void(const std::vector<std::string>& params,
75     std::vector<std::string>& infos)>;
76 using WindowChangedFunc = std::function<void(int32_t persistentId, WindowUpdateType type)>;
77 using TraverseFunc = std::function<bool(const sptr<SceneSession>& session)>;
78 using CmpFunc = std::function<bool(std::pair<int32_t, sptr<SceneSession>>& lhs,
79     std::pair<int32_t, sptr<SceneSession>>& rhs)>;
80 using ProcessShowPiPMainWindowFunc = std::function<void(int32_t persistentId)>;
81 using ProcessStartUIAbilityErrorFunc = std::function<void(int32_t startUIAbilityError)>;
82 using NotifySCBAfterUpdateFocusFunc = std::function<void()>;
83 using ProcessCallingWindowIdChangeFunc = std::function<void(uint32_t callingWindowId)>;
84 using FlushWindowInfoTask = std::function<void()>;
85 using ProcessVirtualPixelRatioChangeFunc = std::function<void(float density, const Rect& rect)>;
86 
87 class AppAnrListener : public IRemoteStub<AppExecFwk::IAppDebugListener> {
88 public:
89     void OnAppDebugStarted(const std::vector<AppExecFwk::AppDebugInfo> &debugInfos) override;
90 
91     void OnAppDebugStoped(const std::vector<AppExecFwk::AppDebugInfo> &debugInfos) override;
92 };
93 
94 class DisplayChangeListener : public IDisplayChangeListener {
95 public:
96     virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
97         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override;
98     virtual void OnScreenshot(DisplayId displayId) override;
99     virtual void OnImmersiveStateChange(bool& immersive) override;
100     virtual void OnGetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds,
101         std::vector<uint64_t>& surfaceNodeIds) override;
102 };
103 
104 class SceneSessionManager : public SceneSessionManagerStub {
105 WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager)
106 public:
107     bool IsSessionVisible(const sptr<SceneSession>& session);
108     sptr<SceneSession> RequestSceneSession(const SessionInfo& sessionInfo,
109         sptr<WindowSessionProperty> property = nullptr);
110     void UpdateSceneSessionWant(const SessionInfo& sessionInfo);
111     std::future<int32_t> RequestSceneSessionActivation(const sptr<SceneSession>& sceneSession, bool isNewActive);
112     WSError RequestSceneSessionBackground(const sptr<SceneSession>& sceneSession, const bool isDelegator = false,
113         const bool isToDesktop = false);
114     WSError RequestSceneSessionDestruction(
115         const sptr<SceneSession>& sceneSession, const bool needRemoveSession = true);
116     WSError RequestSceneSessionDestructionInner(sptr<SceneSession> &scnSession, sptr<AAFwk::SessionInfo> scnSessionInfo,
117         const bool needRemoveSession);
118     void NotifyForegroundInteractiveStatus(const sptr<SceneSession>& sceneSession, bool interactive);
119     WSError RequestSceneSessionByCall(const sptr<SceneSession>& sceneSession);
120     void StartAbilityBySpecified(const SessionInfo& sessionInfo);
121 
122     void SetRootSceneContext(const std::weak_ptr<AbilityRuntime::Context>& contextWeak);
123     sptr<RootSceneSession> GetRootSceneSession();
124     sptr<SceneSession> GetSceneSession(int32_t persistentId);
125 
126     sptr<SceneSession> GetSceneSessionByName(const std::string& bundleName,
127         const std::string& moduleName, const std::string& abilityName, const int32_t appIndex);
128 
129     WSError CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
130         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
131         sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
132         sptr<IRemoteObject> token = nullptr) override;
133     WSError RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
134         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
135         sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr) override;
136     WSError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
137         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
138         sptr<ISession>& session, sptr<WindowSessionProperty> property = nullptr,
139         sptr<IRemoteObject> token = nullptr) override;
140     WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override;
141     WMError UpdateSessionProperty(const sptr<WindowSessionProperty>& property, WSPropertyChangeAction action) override;
142     void SetCreateSystemSessionListener(const NotifyCreateSystemSessionFunc& func);
143     void SetStatusBarEnabledChangeListener(const ProcessStatusBarEnabledChangeFunc& func);
144     void SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func);
145     void SetRecoverSceneSessionListener(const NotifyRecoverSceneSessionFunc& func);
146     void SetGestureNavigationEnabledChangeListener(const ProcessGestureNavigationEnabledChangeFunc& func);
147     void SetDumpRootSceneElementInfoListener(const DumpRootSceneElementInfoFunc& func);
148     void SetOutsideDownEventListener(const ProcessOutsideDownEventFunc& func);
149     void SetShiftFocusListener(const ProcessShiftFocusFunc& func);
150     void SetSCBFocusedListener(const NotifySCBAfterUpdateFocusFunc& func);
151     void SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocusFunc& func);
152     void SetShowPiPMainWindowListener(const ProcessShowPiPMainWindowFunc& func);
153     void SetCallingWindowIdChangeListenser(const ProcessCallingWindowIdChangeFunc& func);
154     const AppWindowSceneConfig& GetWindowSceneConfig() const;
155     WSError ProcessBackEvent();
156     WSError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken) override;
157     void GetStartupPage(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor);
158     WMError SetGestureNavigaionEnabled(bool enable) override;
159     WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
160         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
161     WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
162         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
163 
164     WSError SetFocusedSession(int32_t persistentId);
165     int32_t GetFocusedSession() const;
166     WSError GetAllSessionDumpInfo(std::string& info);
167     WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector<std::string>& params,
168         const std::string& strId);
169     WSError GetSessionDumpInfo(const std::vector<std::string>& params, std::string& info) override;
170     WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = true) override;
171     void RequestAllAppSessionUnfocus();
172     WSError UpdateFocus(int32_t persistentId, bool isFocused);
173     WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode);
174     WSError SendTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, uint32_t zIndex);
175     void SetScreenLocked(const bool isScreenLocked);
176     bool IsScreenLocked() const;
177     WSError RaiseWindowToTop(int32_t persistentId) override;
178 
179     WSError SwitchUser(int32_t oldUserId, int32_t newUserId, std::string &fileDir);
180     int32_t GetCurrentUserId() const;
181     void StartWindowInfoReportLoop();
182     void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override;
183     void NotifyCompleteFirstFrameDrawing(int32_t persistentId);
184     void NotifySessionMovedToFront(int32_t persistentId);
185     WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) override;
186     WSError SetSessionLabel(const sptr<IRemoteObject> &token, const std::string &label) override;
187     WSError SetSessionIcon(const sptr<IRemoteObject> &token, const std::shared_ptr<Media::PixelMap> &icon) override;
188     WSError IsValidSessionIds(const std::vector<int32_t> &sessionIds, std::vector<bool> &results) override;
189     WSError RegisterSessionListener(const sptr<ISessionChangeListener> sessionListener) override;
190     void UnregisterSessionListener() override;
191     void HandleTurnScreenOn(const sptr<SceneSession>& sceneSession);
192     void HandleKeepScreenOn(const sptr<SceneSession>& sceneSession, bool requireLock);
193     void InitWithRenderServiceAdded();
194     WSError PendingSessionToForeground(const sptr<IRemoteObject> &token) override;
195     WSError PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject> &token) override;
196     WSError GetFocusSessionToken(sptr<IRemoteObject> &token) override;
197 
198     WSError RegisterSessionListener(const sptr<ISessionListener>& listener) override;
199     WSError UnRegisterSessionListener(const sptr<ISessionListener>& listener) override;
200     WSError GetSessionInfos(const std::string& deviceId, int32_t numMax,
201         std::vector<SessionInfoBean>& sessionInfos) override;
202     WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo) override;
203     WSError DumpSessionAll(std::vector<std::string> &infos) override;
204     WSError DumpSessionWithId(int32_t persistentId, std::vector<std::string> &infos) override;
205     WSError GetAllAbilityInfos(const AAFwk::Want &want, int32_t userId,
206         std::vector<AppExecFwk::AbilityInfo> &abilityInfos);
207     WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate);
208 
209     WSError TerminateSessionNew(const sptr<AAFwk::SessionInfo> info, bool needStartCaller) override;
210     WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) override;
211     WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) override;
212     WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
213                                SessionSnapshot& snapshot, bool isLowResolution) override;
214     WSError SetSessionContinueState(const sptr<IRemoteObject> &token, const ContinueState& continueState) override;
215     WSError ClearSession(int32_t persistentId) override;
216     WSError ClearAllSessions() override;
217     WSError LockSession(int32_t sessionId) override;
218     WSError UnlockSession(int32_t sessionId) override;
219     WSError MoveSessionsToForeground(const std::vector<int32_t>& sessionIds, int32_t topSessionId) override;
220     WSError MoveSessionsToBackground(const std::vector<int32_t>& sessionIds, std::vector<int32_t>& result) override;
221     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override;
222 
223     std::map<int32_t, sptr<SceneSession>>& GetSessionMapByScreenId(ScreenId id);
224     void UpdatePrivateStateAndNotify(uint32_t persistentId);
225     void InitPersistentStorage();
226     std::string GetSessionSnapshotFilePath(int32_t persistentId);
227     void OnOutsideDownEvent(int32_t x, int32_t y);
228     void NotifySessionTouchOutside(int32_t persistentId);
229 
230     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) override;
231     WSError SetWindowFlags(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property);
232 
233     void NotifyOccupiedAreaChangeInfo(const sptr<SceneSession> sceneSession,
234         const WSRect& rect, const WSRect& occupiedArea);
235     void OnScreenshot(DisplayId displayId);
236     void NotifyDumpInfoResult(const std::vector<std::string>& info) override;
237     void SetVirtualPixelRatioChangeListener(const ProcessVirtualPixelRatioChangeFunc& func);
238     void ProcessVirtualPixelRatioChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
239         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
240     void ProcessUpdateRotationChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
241         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
242 
243     RunnableFuture<std::vector<std::string>> dumpInfoFuture_;
244     void RegisterWindowChanged(const WindowChangedFunc& func);
245 
246     WSError RegisterIAbilityManagerCollaborator(int32_t type,
247         const sptr<AAFwk::IAbilityManagerCollaborator> &impl) override;
248     WSError UnregisterIAbilityManagerCollaborator(int32_t type) override;
249     WSError RecoveryPullPiPMainWindow(const int32_t& persistentId, const Rect& rect);
250 
251     bool IsInputEventEnabled();
252     void SetEnableInputEvent(bool enabled);
253     void UpdateRecoveredSessionInfo(const std::vector<int32_t>& recoveredPersistentIds);
254     void SetAlivePersistentIds(const std::vector<int32_t>& alivePersistentIds);
255     void NotifyRecoveringFinished();
256 
257     WMError CheckWindowId(int32_t windowId, int32_t &pid) override;
258     int GetSceneSessionPrivacyModeCount();
259     BrokerStates CheckIfReuseSession(SessionInfo& sessionInfo);
260     bool CheckCollaboratorType(int32_t type);
261     sptr<SceneSession> FindSessionByAffinity(std::string affinity);
262     void PreloadInLakeApp(const std::string& bundleName);
263     void AddWindowDragHotArea(int32_t type, WSRect& area);
264     WSError UpdateMaximizeMode(int32_t persistentId, bool isMaximize);
265     WSError UpdateSessionDisplayId(int32_t persistentId, uint64_t screenId);
266     void NotifySessionUpdate(const SessionInfo& sessionInfo, ActionType type,
267         ScreenId fromScreenId = SCREEN_ID_INVALID);
268     WSError NotifyAINavigationBarShowStatus(bool isVisible, WSRect barArea);
269     WSRect GetAINavigationBarArea();
270     bool UpdateImmersiveState();
271     WMError GetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds,
272         std::vector<uint64_t>& surfaceNodeIds);
273     WSError UpdateTitleInTargetPos(int32_t persistentId, bool isShow, int32_t height);
274     void RegisterCreateSubSessionListener(int32_t persistentId, const NotifyCreateSubSessionFunc& func);
275     void UnregisterCreateSubSessionListener(int32_t persistentId);
276     WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override;
277     void DealwithVisibilityChange(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfos);
278     void DealwithDrawingContentChange(const std::vector<std::pair<uint64_t, bool>>& drawingChangeInfos);
279     void NotifyUpdateRectAfterLayout();
280     WSError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener) override;
281     WMError SetSystemAnimatedScenes(SystemAnimatedSceneType sceneType);
282     WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override;
283     std::shared_ptr<Media::PixelMap> GetSessionSnapshotPixelMap(const int32_t persistentId, const float scaleParam);
284     void RequestInputMethodCloseKeyboard(int32_t persistentId);
285     const std::map<int32_t, sptr<SceneSession>> GetSceneSessionMap();
286     void GetAllSceneSession(std::vector<sptr<SceneSession>>& sceneSessions);
287     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
288     void FlushWindowInfoToMMI();
289     void PostFlushWindowInfoTask(FlushWindowInfoTask &&task, const std::string taskName, const int delayTime);
290     WSError HideNonSecureWindows(bool shouldHide) override;
291 
292 public:
GetTaskScheduler()293     std::shared_ptr<TaskScheduler> GetTaskScheduler() {return taskScheduler_;};
294 protected:
295     SceneSessionManager();
296     virtual ~SceneSessionManager() = default;
297 
298 private:
299     void Init();
300     void InitScheduleUtils();
301     void RegisterAppListener();
302     void InitPrepareTerminateConfig();
303     void LoadWindowSceneXml();
304     void ConfigWindowSceneXml();
305     void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig);
306     void ConfigKeyboardAnimation(const WindowSceneConfig::ConfigItem& animationConfig);
307     void ConfigDefaultKeyboardAnimation();
308     bool ConfigAppWindowCornerRadius(const WindowSceneConfig::ConfigItem& item, float& out);
309     bool ConfigAppWindowShadow(const WindowSceneConfig::ConfigItem& shadowConfig, WindowShadowConfig& outShadow);
310     void ConfigDecor(const WindowSceneConfig::ConfigItem& decorConfig);
311     void ConfigWindowAnimation(const WindowSceneConfig::ConfigItem& windowAnimationConfig);
312     void ConfigStartingWindowAnimation(const WindowSceneConfig::ConfigItem& startingWindowConfig);
313     void ConfigWindowSizeLimits();
314     void ConfigMainWindowSizeLimits(const WindowSceneConfig::ConfigItem& mainWindowSizeConifg);
315     void ConfigSubWindowSizeLimits(const WindowSceneConfig::ConfigItem& subWindowSizeConifg);
316     void ConfigSnapshotScale();
317 
318     std::tuple<std::string, std::vector<float>> CreateCurve(const WindowSceneConfig::ConfigItem& curveConfig);
319     void LoadKeyboardAnimation(const WindowSceneConfig::ConfigItem& item, KeyboardSceneAnimationConfig& config);
320     sptr<SceneSession::SpecificSessionCallback> CreateSpecificSessionCallback();
321     void FillSessionInfo(sptr<SceneSession>& sceneSession);
322     std::shared_ptr<AppExecFwk::AbilityInfo> QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName,
323         const std::string& abilityName, const std::string& moduleName);
324 
325     std::vector<std::pair<int32_t, sptr<SceneSession>>> GetSceneSessionVector(CmpFunc cmp);
326     void TraverseSessionTree(TraverseFunc func, bool isFromTopToBottom);
327     void TraverseSessionTreeFromTopToBottom(TraverseFunc func);
328     void TraverseSessionTreeFromBottomToTop(TraverseFunc func);
329     WSError RequestSessionFocus(int32_t persistentId, bool byForeground = true);
330     WSError RequestSessionFocusImmediately(int32_t persistentId);
331     WSError RequestSessionUnfocus(int32_t persistentId);
332     WSError RequestAllAppSessionUnfocusInner();
333     WSError RequestFocusBasicCheck(int32_t persistentId);
334     WSError RequestFocusSpecificCheck(sptr<SceneSession>& sceneSession, bool byForeground);
335 
336     sptr<SceneSession> GetNextFocusableSession(int32_t persistentId);
337     sptr<SceneSession> GetTopFocusableNonAppSession();
338     WSError ShiftFocus(sptr<SceneSession>& nextSession);
339     void UpdateFocusStatus(sptr<SceneSession>& sceneSession, bool isFocused);
340     void NotifyFocusStatus(sptr<SceneSession>& sceneSession, bool isFocused);
341     std::string GetAllSessionFocusInfo();
342     void RegisterRequestFocusStatusNotifyManagerFunc(sptr<SceneSession>& sceneSession);
343     void RegisterGetStateFromManagerFunc(sptr<SceneSession>& sceneSession);
344 
345     void RelayoutKeyBoard(sptr<SceneSession> sceneSession);
346     void RestoreCallingSessionSizeIfNeed();
347     void ResizeSoftInputCallingSessionIfNeed(const sptr<SceneSession>& sceneSession, bool isInputUpdated = false);
348     void SetCallingSession(const sptr<SceneSession>& sceneSession, uint32_t newCallingWindowId);
349 
350     sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<SceneSession>& scnSession);
351     WSError DestroyDialogWithMainWindow(const sptr<SceneSession>& scnSession);
352     sptr<SceneSession> FindMainWindowWithToken(sptr<IRemoteObject> targetToken);
353     WSError UpdateParentSessionForDialog(const sptr<SceneSession>& sceneSession, sptr<WindowSessionProperty> property);
354     void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
355     void UpdateFocusableProperty(int32_t persistentId);
356     std::vector<sptr<SceneSession>> GetSceneSessionVectorByType(WindowType type);
357     bool UpdateSessionAvoidAreaIfNeed(const int32_t& persistentId,
358         const sptr<SceneSession>& sceneSession, const AvoidArea& avoidArea, AvoidAreaType avoidAreaType);
359     void UpdateAvoidSessionAvoidArea(WindowType type, bool& needUpdate);
360     void UpdateNormalSessionAvoidArea(const int32_t& persistentId, sptr<SceneSession>& sceneSession, bool& needUpdate);
361     void UpdateAvoidArea(const int32_t& persistentId);
362     void NotifyMMIWindowPidChange(int32_t windowId, bool startMoving);
363     int32_t GetStatusBarHeight();
364 
365     sptr<AppExecFwk::IBundleMgr> GetBundleManager();
366     std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo);
367     void GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, std::string& path, uint32_t& bgColor);
368 
369     bool CheckIsRemote(const std::string& deviceId);
370     bool GetLocalDeviceId(std::string& localDeviceId);
371     std::string AnonymizeDeviceId(const std::string& deviceId);
372     int GetRemoteSessionInfos(const std::string& deviceId, int32_t numMax,
373                               std::vector<SessionInfoBean> &sessionInfos);
374     int GetRemoteSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo);
375 
376     void PerformRegisterInRequestSceneSession(sptr<SceneSession>& sceneSession);
377     WSError RequestSceneSessionActivationInner(sptr<SceneSession>& scnSession,
378         bool isNewActive, const std::shared_ptr<std::promise<int32_t>>& promise);
379     WSError SetBrightness(const sptr<SceneSession>& sceneSession, float brightness);
380     WSError UpdateBrightness(int32_t persistentId);
381     void SetDisplayBrightness(float brightness);
382     float GetDisplayBrightness() const;
383     void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property,
384         const sptr<SceneSession>& sceneSession);
385     WMError HandleUpdateProperty(const sptr<WindowSessionProperty>& property, WSPropertyChangeAction action,
386         const sptr<SceneSession>& sceneSession);
387     void UpdateHideNonSystemFloatingWindows(const sptr<WindowSessionProperty>& property,
388         const sptr<SceneSession>& sceneSession);
389     void UpdateForceHideState(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property,
390         bool add);
391     void NotifyWindowInfoChange(int32_t persistentId, WindowUpdateType type);
392     void NotifyWindowInfoChangeFromSession(int32_t persistentid);
393     bool FillWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos,
394         const sptr<SceneSession>& sceneSession);
395     std::vector<std::pair<uint64_t, WindowVisibilityState>> GetWindowVisibilityChangeInfo(
396         std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData);
397     std::vector<std::pair<uint64_t, bool>> GetWindowDrawingContentChangeInfo(
398         std::vector<std::pair<uint64_t, bool>> currDrawingContentData);
399     void GetWindowLayerChangeInfo(std::shared_ptr<RSOcclusionData> occlusionData,
400         std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData,
401         std::vector<std::pair<uint64_t, bool>>& currDrawingContentData);
402     void WindowLayerInfoChangeCallback(std::shared_ptr<RSOcclusionData> occlusiontionData);
403     sptr<SceneSession> SelectSesssionFromMap(const uint64_t& surfaceId);
404     void WindowDestroyNotifyVisibility(const sptr<SceneSession>& sceneSession);
405     void RegisterInputMethodUpdateFunc(const sptr<SceneSession>& sceneSession);
406     void OnInputMethodUpdate(const int32_t& persistentId);
407     void RegisterInputMethodShownFunc(const sptr<SceneSession>& sceneSession);
408     void OnInputMethodShown(const int32_t& persistentId);
409     void RegisterInputMethodHideFunc(const sptr<SceneSession>& sceneSession);
410     void RegisterSessionExceptionFunc(const sptr<SceneSession>& sceneSession);
411     void RegisterSessionSnapshotFunc(const sptr<SceneSession>& sceneSession);
412     void NotifySessionForCallback(const sptr<SceneSession>& scnSession, const bool needRemoveSession);
413     void DumpSessionInfo(const sptr<SceneSession>& session, std::ostringstream& oss);
414     void DumpAllAppSessionInfo(std::ostringstream& oss, const std::map<int32_t, sptr<SceneSession>>& sceneSessionMap);
415     void DumpSessionElementInfo(const sptr<SceneSession>& session,
416         const std::vector<std::string>& params, std::string& dumpInfo);
417     void AddClientDeathRecipient(const sptr<ISessionStage>& sessionStage, const sptr<SceneSession>& sceneSession);
418     void DestroySpecificSession(const sptr<IRemoteObject>& remoteObject);
419     void CleanUserMap();
420     void EraseSceneSessionMapById(int32_t persistentId);
421     WSError GetAbilityInfosFromBundleInfo(std::vector<AppExecFwk::BundleInfo> &bundleInfos,
422         std::vector<AppExecFwk::AbilityInfo> &abilityInfos);
423 
424     WMError UpdatePropertyDragEnabled(const sptr<WindowSessionProperty>& property,
425                                       const sptr<SceneSession>& sceneSession);
426     WMError UpdatePropertyRaiseEnabled(const sptr<WindowSessionProperty>& property,
427                                        const sptr<SceneSession>& sceneSession);
428     void ClosePipWindowIfExist(WindowType type);
429     WSError DestroyAndDisconnectSpecificSessionInner(sptr<SceneSession> sceneSession);
430 
431     sptr<RootSceneSession> rootSceneSession_;
432     std::weak_ptr<AbilityRuntime::Context> rootSceneContextWeak_;
433     std::shared_mutex sceneSessionMapMutex_;
434     std::map<int32_t, sptr<SceneSession>> sceneSessionMap_;
435     std::map<int32_t, sptr<SceneSession>> systemTopSceneSessionMap_;
436     std::map<int32_t, sptr<SceneSession>> nonSystemFloatSceneSessionMap_;
437     sptr<ScbSessionHandler> scbSessionHandler_;
438     std::shared_ptr<SessionListenerController> listenerController_;
439     std::map<sptr<IRemoteObject>, int32_t> remoteObjectMap_;
440     std::set<int32_t> avoidAreaListenerSessionSet_;
441     std::set<int32_t> touchOutsideListenerSessionSet_;
442     std::set<int32_t> windowVisibilityListenerSessionSet_;
443     std::map<int32_t, std::map<AvoidAreaType, AvoidArea>> lastUpdatedAvoidArea_;
444 
445     NotifyCreateSystemSessionFunc createSystemSessionFunc_;
446     std::map<int32_t, NotifyCreateSubSessionFunc> createSubSessionFuncMap_;
447     std::map<int32_t, std::vector<sptr<SceneSession>>> recoverSubSessionCacheMap_;
448     bool recoveringFinished_ = false;
449     NotifyRecoverSceneSessionFunc recoverSceneSessionFunc_;
450     ProcessStatusBarEnabledChangeFunc statusBarEnabledChangeFunc_;
451     ProcessGestureNavigationEnabledChangeFunc gestureNavigationEnabledChangeFunc_;
452     ProcessOutsideDownEventFunc outsideDownEventFunc_;
453     DumpRootSceneElementInfoFunc dumpRootSceneFunc_;
454     ProcessShiftFocusFunc shiftFocusFunc_;
455     NotifySCBAfterUpdateFocusFunc notifySCBAfterFocusedFunc_;
456     NotifySCBAfterUpdateFocusFunc notifySCBAfterUnfocusedFunc_;
457     ProcessShowPiPMainWindowFunc showPiPMainWindowFunc_;
458     ProcessCallingWindowIdChangeFunc callingWindowIdChangeFunc_;
459     ProcessStartUIAbilityErrorFunc startUIAbilityErrorFunc_;
460     ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr;
461     AppWindowSceneConfig appWindowSceneConfig_;
462     SystemSessionConfig systemConfig_;
463     float snapshotScale_ = 0.5;
464     int32_t focusedSessionId_ = INVALID_SESSION_ID;
465     int32_t lastFocusedSessionId_ = INVALID_SESSION_ID;
466     int32_t brightnessSessionId_ = INVALID_SESSION_ID;
467     float displayBrightness_ = UNDEFINED_BRIGHTNESS;
468     bool needBlockNotifyFocusStatusUntilForeground_ {false};
469     bool needBlockNotifyUnfocusStatus_ {false};
470     bool isScreenLocked_ {false};
471     bool isPrepareTerminateEnable_ {false};
472     WSRect callingWindowRestoringRect_ = {0, 0, 0, 0};
473     WSRect callingWindowNewRect_ = {0, 0, 0, 0};
474     bool needUpdateSessionRect_ = false;
475     bool openDebugTrace {false};
476     int32_t currentUserId_;
477     std::atomic<bool> enableInputEvent_ = true;
478     bool gestureNavigationEnabled_ {true};
479     std::vector<int32_t> alivePersistentIds_ = {};
480 
481     std::shared_ptr<TaskScheduler> taskScheduler_;
482     sptr<AppExecFwk::IBundleMgr> bundleMgr_;
483     sptr<AppAnrListener> appAnrListener_;
484 
485     bool isAINavigationBarVisible_ = false;
486     WSRect currAINavigationBarArea_;
487 
488     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
489     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
490     bool isReportTaskStart_ = false;
491     std::vector<std::pair<uint64_t, WindowVisibilityState> > lastVisibleData_;
492     RSInterfaces& rsInterface_;
493     bool isNeedRecover(const int32_t persistentId);
494     void RegisterSessionStateChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession);
495     void RegisterSessionInfoChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession);
496     void OnSessionStateChange(int32_t persistentId, const SessionState& state);
497     void ProcessSubSessionForeground(sptr<SceneSession>& sceneSession);
498     void ProcessSubSessionBackground(sptr<SceneSession>& sceneSession);
499     WSError ProcessDialogRequestFocusImmdediately(sptr<SceneSession>& sceneSession);
500     sptr<ISessionChangeListener> sessionListener_;
501     sptr<SceneSession> FindSessionByToken(const sptr<IRemoteObject> &token);
502 
503     void CheckAndNotifyWaterMarkChangedResult();
504     WSError NotifyWaterMarkFlagChangedResult(bool hasWaterMark);
505     void ProcessPreload(const AppExecFwk::AbilityInfo& abilityInfo) const;
506     bool lastWaterMarkShowState_ { false };
507     WindowChangedFunc WindowChangedFunc_;
508     sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient(
509         std::bind(&SceneSessionManager::DestroySpecificSession, this, std::placeholders::_1));
510     sptr<SceneSession> callingSession_ = nullptr;
511     uint32_t callingWindowId_ = 0;
512 
513     WSError ClearSession(sptr<SceneSession> sceneSession);
514     bool IsSessionClearable(sptr<SceneSession> scnSession);
515     void GetAllClearableSessions(std::vector<sptr<SceneSession>>& sessionVector);
516     int GetRemoteSessionSnapshotInfo(const std::string& deviceId, int32_t sessionId,
517                                      AAFwk::MissionSnapshot& sessionSnapshot);
518 
519     const int32_t BROKER_UID = 5557;
520     const int32_t BROKER_RESERVE_UID = 5005;
521     std::shared_mutex collaboratorMapLock_;
522     std::unordered_map<int32_t, sptr<AAFwk::IAbilityManagerCollaborator>> collaboratorMap_;
523     std::atomic<int64_t> containerStartAbilityTime { 0 };
524 
525     BrokerStates NotifyStartAbility(
526         int32_t collaboratorType, const SessionInfo& sessionInfo, int32_t persistentId = 0);
527     void NotifySessionCreate(const sptr<SceneSession> sceneSession, const SessionInfo& sessionInfo);
528     void NotifyLoadAbility(int32_t collaboratorType, sptr<AAFwk::SessionInfo> abilitySessionInfo,
529         std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo);
530     void NotifyUpdateSessionInfo(const sptr<SceneSession> sceneSession);
531     void NotifyClearSession(int32_t collaboratorType, int32_t persistentId);
532     void NotifyMoveSessionToForeground(int32_t collaboratorType, int32_t persistendId);
533     void PreHandleCollaborator(sptr<SceneSession>& sceneSession, int32_t persistentId = 0);
534     void NotifyCollaboratorAfterStart(sptr<SceneSession>& scnSession, sptr<AAFwk::SessionInfo>& scnSessionInfo);
535     void UpdateCollaboratorSessionWant(sptr<SceneSession>& session, int32_t persistentId = 0);
536     bool CheckSystemWindowPermission(const sptr<WindowSessionProperty>& property);
537     void DestroySubSession(const sptr<SceneSession>& sceneSession);
538     void NotifyStatusBarEnabledChange(bool enable);
539     void NotifySessionForeground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation);
540     void NotifySessionBackground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation,
541                                 bool isFromInnerkits);
542     void NotifyCreateSubSession(int32_t persistentId, sptr<SceneSession> session);
543     void CacheSubSessionForRecovering(sptr<SceneSession> sceneSession, const sptr<WindowSessionProperty>& property);
544     void RecoverCachedSubSession(int32_t persistentId);
545     void RecoverWindowSessionProperty(sptr<SceneSession> sceneSession, const sptr<WindowSessionProperty>& property);
546     void NotifyCreateSpecificSession(sptr<SceneSession> session,
547         sptr<WindowSessionProperty> property, const WindowType& type);
548     sptr<SceneSession> CreateSceneSession(const SessionInfo& sessionInfo, sptr<WindowSessionProperty> property);
549     bool GetPreWindowDrawingState(uint64_t windowId, int32_t& pid, bool currentDrawingContentState);
550     bool GetProcessDrawingState(uint64_t windowId, int32_t pid, bool currentDrawingContentState);
551     void ProcessPiPSessionForeground(const sptr<SceneSession> sceneSession);
552     WSError GetAppMainSceneSession(sptr<SceneSession>& sceneSession, int32_t persistentId);
553 };
554 } // namespace OHOS::Rosen
555 
556 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H
557