• 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 <unordered_map>
21 #include <mutex>
22 #include <shared_mutex>
23 
24 #ifndef OHOS_BUILD_ENABLE_SECURITY_COMPONENT // pointer_envent.h
25 #define OHOS_BUILD_ENABLE_SECURITY_COMPONENT
26 #endif
27 #ifndef SUPPORT_SCREEN
28 #define SUPPORT_SCREEN
29 #endif
30 
31 #include "ability_info.h"
32 #include "agent_death_recipient.h"
33 #include "app_debug_listener_interface.h"
34 #include "app_mgr_client.h"
35 #include "common/include/task_scheduler.h"
36 #include "display_change_info.h"
37 #include "display_change_listener.h"
38 #include "display_info.h"
39 #include "future.h"
40 #include "include/core/SkRegion.h"
41 #include "interfaces/include/ws_common.h"
42 #include "mission_snapshot.h"
43 #include "scb_session_handler.h"
44 #include "scene_session_converter.h"
45 #include "screen_fold_data.h"
46 #include "screen_session_manager_client.h"
47 #include "session/host/include/keyboard_session.h"
48 #include "session/host/include/session.h"
49 #include "session/host/include/root_scene_session.h"
50 #include "session_listener_controller.h"
51 #include "session_manager/include/ffrt_queue_helper.h"
52 #include "session_manager/include/window_manager_lru.h"
53 #include "session_manager/include/zidl/scene_session_manager_stub.h"
54 #include "thread_safety_annotations.h"
55 #include "transaction/rs_interfaces.h"
56 #include "window_focus_controller.h"
57 #include "window_scene_config.h"
58 #include "wm_single_instance.h"
59 #include "zidl/session_lifecycle_listener_interface.h"
60 
61 namespace OHOS::AAFwk {
62 class SessionInfo;
63 } // namespace OHOS::AAFwk
64 
65 namespace OHOS::AppExecFwk {
66 class IBundleMgr;
67 struct AbilityInfo;
68 struct BundleInfo;
69 class LauncherService;
70 } // namespace OHOS::AppExecFwk
71 
72 namespace OHOS::Global::Resource {
73 class ResourceManager;
74 } // namespace OHOS::Global::Resource
75 
76 namespace OHOS::Rosen {
77 class RSNode;
78 namespace AncoConsts {
79     constexpr const char* ANCO_MISSION_ID = "ohos.anco.param.missionId";
80     constexpr const char* ANCO_SESSION_ID = "ohos.anco.param.sessionId";
81 }
82 
83 struct SCBAbilityInfo {
84     AppExecFwk::AbilityInfo abilityInfo_;
85     uint32_t sdkVersion_;
86     std::string codePath_;
87 };
88 
89 struct SessionIdentityInfo {
90     std::string bundleName_;
91     std::string moduleName_;
92     std::string abilityName_;
93     int32_t appIndex_ = 0;
94     std::string instanceKey_;
95     uint32_t windowType_ = static_cast<uint32_t>(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
96     bool isAtomicService_ = false;
97     std::string specifiedFlag_;
98 };
99 
100 class SceneSession;
101 struct SecSurfaceInfo;
102 class RSUIExtensionData;
103 class AccessibilityWindowInfo;
104 class UnreliableWindowInfo;
105 class ScbDumpSubscriber;
106 
107 using NotifyCreateSystemSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
108 using NotifyCreateKeyboardSessionFunc = std::function<void(const sptr<SceneSession>& keyboardSession,
109     const sptr<SceneSession>& panelSession)>;
110 using NotifyCreateSubSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
111 using NotifyRecoverSceneSessionFunc =
112     std::function<void(const sptr<SceneSession>& session, const SessionInfo& sessionInfo)>;
113 using ProcessStatusBarEnabledChangeFunc = std::function<void(bool enable, const std::string& bundleName)>;
114 using ProcessGestureNavigationEnabledChangeFunc = std::function<void(bool enable, const std::string& bundleName,
115     GestureBackType type)>;
116 using ProcessOutsideDownEventFunc = std::function<void(int32_t x, int32_t y)>;
117 using ProcessShiftFocusFunc = std::function<void(int32_t persistentId, DisplayId displayGroupId)>;
118 using NotifySetFocusSessionFunc = std::function<void(const sptr<SceneSession>& session)>;
119 using DumpRootSceneElementInfoFunc = std::function<void(const std::vector<std::string>& params,
120     std::vector<std::string>& infos)>;
121 using WindowChangedFunc = std::function<void(int32_t persistentId, WindowUpdateType type)>;
122 using TraverseFunc = std::function<bool(const sptr<SceneSession>& session)>;
123 using CmpFunc = std::function<bool(std::pair<int32_t, sptr<SceneSession>>& lhs,
124     std::pair<int32_t, sptr<SceneSession>>& rhs)>;
125 using ProcessStartUIAbilityErrorFunc = std::function<void(int32_t startUIAbilityError)>;
126 using NotifySCBAfterUpdateFocusFunc = std::function<void()>;
127 using ProcessCallingSessionIdChangeFunc = std::function<void(uint32_t callingSessionId)>;
128 using FlushWindowInfoTask = std::function<void()>;
129 using ProcessVirtualPixelRatioChangeFunc = std::function<void(float density, const Rect& rect)>;
130 using DumpUITreeFunc = std::function<void(std::string& dumpInfo)>;
131 using RootSceneProcessBackEventFunc = std::function<void()>;
132 using ProcessCloseTargetFloatWindowFunc = std::function<void(const std::string& bundleName)>;
133 using AbilityManagerCollaboratorRegisteredFunc = std::function<void()>;
134 using OnFlushUIParamsFunc = std::function<void()>;
135 using IsRootSceneLastFrameLayoutFinishedFunc = std::function<bool()>;
136 using NotifyStartPiPFailedFunc = std::function<void()>;
137 using NotifyAppUseControlListFunc =
138     std::function<void(ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList)>;
139 using NotifyRootSceneAvoidAreaChangeFunc = std::function<void(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)>;
140 using NotifyWatchGestureConsumeResultFunc = std::function<void(int32_t keyCode, bool isConsumed)>;
141 using NotifyWatchFocusActiveChangeFunc = std::function<void(bool isActive)>;
142 using NotifyRootSceneOccupiedAreaChangeFunc = std::function<void(const sptr<OccupiedAreaChangeInfo>& info)>;
143 using GetRSNodeByStringIDFunc = std::function<std::shared_ptr<Rosen::RSNode>(const std::string& id)>;
144 using SetTopWindowBoundaryByIDFunc = std::function<void(const std::string& id)>;
145 
146 class AppAnrListener : public IRemoteStub<AppExecFwk::IAppDebugListener> {
147 public:
148     void OnAppDebugStarted(const std::vector<AppExecFwk::AppDebugInfo>& debugInfos) override;
149     void OnAppDebugStoped(const std::vector<AppExecFwk::AppDebugInfo>& debugInfos) override;
150 };
151 
152 class DisplayChangeListener : public IDisplayChangeListener {
153 public:
154     void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
155         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) override;
156     void OnScreenshot(DisplayId displayId) override;
157     void OnImmersiveStateChange(ScreenId screenId, bool& immersive) override;
158     void OnGetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds,
159         std::vector<uint64_t>& surfaceNodeIds, bool isBlackList = false) override;
160 
161     /*
162      * Fold Screen Status Change Report
163      */
164     void OnScreenFoldStatusChanged(const std::vector<std::string>& screenFoldInfo) override;
165 };
166 
167 class ScreenConnectionChangeListener : public IScreenConnectionChangeListener {
168 public:
169     void OnScreenConnected(const sptr<ScreenSession>& screenSession) override;
170     void OnScreenDisconnected(const sptr<ScreenSession>& screenSession) override;
171 };
172 
173 class SceneSessionManager : public SceneSessionManagerStub {
174 WM_DECLARE_SINGLE_INSTANCE_BASE(SceneSessionManager)
175 public:
176     friend class AnomalyDetection;
177     bool IsSessionVisible(const sptr<SceneSession>& session) const;
178     bool IsSessionVisibleForeground(const sptr<SceneSession>& session) const;
179 
180     void SetRootSceneContext(const std::weak_ptr<AbilityRuntime::Context>& contextWeak);
181     sptr<RootSceneSession> GetRootSceneSession();
182     sptr<SceneSession> GetSceneSession(int32_t persistentId);
183     sptr<SceneSession> GetMainParentSceneSession(int32_t persistentId,
184         const std::map<int32_t, sptr<SceneSession>>& sessionMap);
185     void PostFlushWindowInfoTask(FlushWindowInfoTask&& task, const std::string& taskName, const int delayTime);
186 
187     sptr<SceneSession> GetSceneSessionByIdentityInfo(const SessionIdentityInfo& info);
188     sptr<SceneSession> GetSceneSessionByType(WindowType type);
189     sptr<SceneSession> GetSceneSessionByBundleName(const std::string& bundleName);
190 
191     WSError CreateAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
192         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
193         sptr<WindowSessionProperty> property, int32_t& persistentId, sptr<ISession>& session,
194         SystemSessionConfig& systemConfig, sptr<IRemoteObject> token = nullptr) override;
195     WSError DestroyAndDisconnectSpecificSession(const int32_t persistentId) override;
196     WSError DestroyAndDisconnectSpecificSessionWithDetachCallback(const int32_t persistentId,
197         const sptr<IRemoteObject>& callback) override;
198     void SetCreateSystemSessionListener(const NotifyCreateSystemSessionFunc& func);
199     void SetCreateKeyboardSessionListener(const NotifyCreateKeyboardSessionFunc& func);
200     void SetStatusBarEnabledChangeListener(const ProcessStatusBarEnabledChangeFunc& func);
201     void SetStartUIAbilityErrorListener(const ProcessStartUIAbilityErrorFunc& func);
202     void SetGestureNavigationEnabledChangeListener(const ProcessGestureNavigationEnabledChangeFunc& func);
203     void SetDumpRootSceneElementInfoListener(const DumpRootSceneElementInfoFunc& func);
204     void SetOutsideDownEventListener(const ProcessOutsideDownEventFunc& func);
205     void SetShiftFocusListener(const ProcessShiftFocusFunc& func);
206     void SetSCBFocusedListener(const NotifySCBAfterUpdateFocusFunc& func);
207     void SetSCBUnfocusedListener(const NotifySCBAfterUpdateFocusFunc& func);
208     void SetCallingSessionIdSessionListenser(const ProcessCallingSessionIdChangeFunc& func);
209     void SetDumpUITreeFunc(const DumpUITreeFunc& func);
210     const AppWindowSceneConfig& GetWindowSceneConfig() const;
211 
212     /*
213      * Window Recover
214      */
215     WSError RecoverAndConnectSpecificSession(const sptr<ISessionStage>& sessionStage,
216         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
217         sptr<WindowSessionProperty> property, sptr<ISession>& session, sptr<IRemoteObject> token = nullptr) override;
218     WSError RecoverAndReconnectSceneSession(const sptr<ISessionStage>& sessionStage,
219         const sptr<IWindowEventChannel>& eventChannel, const std::shared_ptr<RSSurfaceNode>& surfaceNode,
220         sptr<ISession>& session, sptr<WindowSessionProperty> property = nullptr,
221         sptr<IRemoteObject> token = nullptr) override;
222     WSError GetBatchAbilityInfos(const std::vector<std::string>& bundleNames, int32_t userId,
223         std::vector<SCBAbilityInfo>& scbAbilityInfos);
224     void SetRecoverSceneSessionListener(const NotifyRecoverSceneSessionFunc& func);
225     void UpdateRecoveredSessionInfo(const std::vector<int32_t>& recoveredPersistentIds);
226     void NotifyRecoveringFinished();
227     bool IsInputEventEnabled() const;
228     void SetEnableInputEvent(bool enabled);
229     void SetAlivePersistentIds(const std::vector<int32_t>& alivePersistentIds);
230 
231     /*
232      * Window Input Event
233      */
234     void RegisterWatchGestureConsumeResultCallback(NotifyWatchGestureConsumeResultFunc&& func);
235     WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed) override;
236     void RegisterWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeFunc&& func);
237     WMError NotifyWatchFocusActiveChange(bool isActive) override;
238     void RegisterFlushWindowInfoCallback();
239     void FlushWindowInfoToMMI(const bool forceFlush = false);
240     void SendCancelEventBeforeEraseSession(const sptr<SceneSession>& sceneSession);
241     void BuildCancelPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, int32_t fingerId,
242                                  int32_t action, int32_t wid);
243 
244     /*
245      * Window Rotate Animation
246      */
247     void UpdateRotateAnimationConfig(const RotateAnimationConfig& config);
248 
249     WSError ProcessBackEvent();
250     WSError BindDialogSessionTarget(uint64_t persistentId, sptr<IRemoteObject> targetToken) override;
251     void GetStartupPage(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor);
252     WMError SetGestureNavigationEnabled(bool enable) override;
253     WMError RegisterWindowManagerAgent(WindowManagerAgentType type,
254         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
255     WMError UnregisterWindowManagerAgent(WindowManagerAgentType type,
256         const sptr<IWindowManagerAgent>& windowManagerAgent) override;
257 
258     /*
259      * Dump
260      */
261     WSError GetAllSessionDumpInfo(std::string& info);
262     WSError GetAllSessionDumpDetailInfo(std::string& info);
263     WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector<std::string>& params,
264         const std::string& strId);
265     WSError GetSCBDebugDumpInfo(std::string&& cmd, std::string& dumpInfo);
266     WSError GetSessionDumpInfo(const std::vector<std::string>& params, std::string& info) override;
267     WSError DumpSessionAll(std::vector<std::string>& infos) override;
268     WSError DumpSessionWithId(int32_t persistentId, std::vector<std::string>& infos) override;
269 
270     /*
271      * Window Focus
272      */
273     WSError SetFocusedSessionId(const int32_t persistentId, const DisplayId displayId);
274     int32_t GetFocusedSessionId(DisplayId displayId = DEFAULT_DISPLAY_ID) const;
GetFocusChangeReason()275     FocusChangeReason GetFocusChangeReason() const { return focusChangeReason_; }
276     WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = true,
277         FocusChangeReason reason = FocusChangeReason::DEFAULT) override;
278     WMError RequestFocusStatusBySCB(int32_t persistentId, bool isFocused, bool byForeground = true,
279         FocusChangeReason reason = FocusChangeReason::DEFAULT);
280     WMError RequestFocusStatusBySA(int32_t persistentId, bool isFocused = true,
281         bool byForeground = true, FocusChangeReason reason = FocusChangeReason::SA_REQUEST) override;
282     void RequestAllAppSessionUnfocus();
283     WSError UpdateFocus(int32_t persistentId, bool isFocused);
284     WSError ShiftAppWindowFocus(int32_t sourcePersistentId, int32_t targetPersistentId) override;
285     void GetFocusWindowInfo(FocusChangeInfo& focusInfo, DisplayId displayId = DEFAULT_DISPLAY_ID) override;
286     WSError GetFocusSessionToken(sptr<IRemoteObject>& token, DisplayId displayId = DEFAULT_DISPLAY_ID) override;
287     WSError GetFocusSessionElement(AppExecFwk::ElementName& element, DisplayId displayId = DEFAULT_DISPLAY_ID) override;
288     WSError AddFocusGroup(DisplayId displayId);
289     WSError RemoveFocusGroup(DisplayId displayId);
290 
291     WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode);
292     WSError SendTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, uint32_t zIndex);
293     WSError RaiseWindowToTop(int32_t persistentId) override;
294     void SetScreenLocked(const bool isScreenLocked);
295     bool IsScreenLocked() const;
296 
297     /*
298      * Multi User
299      */
300     WSError InitUserInfo(int32_t userId, std::string& fileDir);
301     void HandleUserSwitch(const UserSwitchEventType type, const bool isUserActive);
302     int32_t GetCurrentUserId() const;
303 
304     void StartWindowInfoReportLoop();
305 
306     void NotifyCompleteFirstFrameDrawing(int32_t persistentId);
307     void NotifySessionMovedToFront(int32_t persistentId);
308     WSError SetSessionLabel(const sptr<IRemoteObject>& token, const std::string& label) override;
309     WSError SetSessionIcon(const sptr<IRemoteObject>& token, const std::shared_ptr<Media::PixelMap>& icon) override;
310     WSError IsValidSessionIds(const std::vector<int32_t>& sessionIds, std::vector<bool>& results) override;
311     void HandleTurnScreenOn(const sptr<SceneSession>& sceneSession);
312     void HandleKeepScreenOn(const sptr<SceneSession>& sceneSession, bool requireLock,
313         const std::string& screenLockPrefix, std::shared_ptr<PowerMgr::RunningLock>& screenLock);
314     void InitWithRenderServiceAdded();
315 
316     WSError RegisterSessionListener(const sptr<ISessionListener>& listener) override;
317     WSError UnRegisterSessionListener(const sptr<ISessionListener>& listener) override;
318     WSError GetSessionInfos(const std::string& deviceId, int32_t numMax,
319         std::vector<SessionInfoBean>& sessionInfos) override;
320     WSError GetMainWindowStatesByPid(int32_t pid, std::vector<MainWindowState>& windowStates);
321     WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo) override;
322     WSError GetSessionInfoByContinueSessionId(const std::string& continueSessionId,
323         SessionInfoBean& sessionInfo) override;
324     WSError GetAllAbilityInfos(const AAFwk::Want& want, int32_t userId,
325         std::vector<SCBAbilityInfo>& scbAbilityInfos);
326     WSError GetAbilityInfo(const std::string& bundleName, const std::string& moduleName,
327         const std::string& abilityName, int32_t userId, SCBAbilityInfo& scbAbilityInfo);
328     WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate);
329 
330     WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) override;
331     WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId,
332                                SessionSnapshot& snapshot, bool isLowResolution) override;
333     WMError GetSessionSnapshotById(int32_t persistentId, SessionSnapshot& snapshot) override;
334     WSError SetVmaCacheStatus(bool flag);
335     WSError GetUIContentRemoteObj(int32_t persistentId, sptr<IRemoteObject>& uiContentRemoteObj) override;
336     WSError SetSessionContinueState(const sptr<IRemoteObject>& token, const ContinueState& continueState) override;
337     WSError LockSession(int32_t sessionId) override;
338     WSError UnlockSession(int32_t sessionId) override;
339     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override;
340     WMError GetParentMainWindowId(int32_t windowId, int32_t& mainWindowId) override;
341 
342     /*
343      * PC Window
344      */
345     WMError IsPcWindow(bool& isPcWindow) override;
346     WMError IsPcOrPadFreeMultiWindowMode(bool& isPcOrPadFreeMultiWindowMode) override;
347     WMError IsWindowRectAutoSave(const std::string& key, bool& enabled, int persistentId) override;
348     void SetIsWindowRectAutoSave(const std::string& key, bool enabled);
349     int32_t ChangeUIAbilityVisibilityBySCB(const sptr<SceneSession>& sceneSession, bool visibility,
350         bool isFromClient = true);
351     WMError ShiftAppWindowPointerEvent(int32_t sourcePersistentId, int32_t targetPersistentId) override;
352     void SetFocusedSessionDisplayIdIfNeeded(sptr<SceneSession>& newSession);
353 
354     /*
355      * Sub Window
356      */
357     WMError SetParentWindow(int32_t subWindowId, int32_t newParentWindowId) override;
358 
359     std::map<int32_t, sptr<SceneSession>>& GetSessionMapByScreenId(ScreenId id);
360     void UpdatePrivateStateAndNotify(uint32_t persistentId);
361     void InitPersistentStorage();
362     void OnOutsideDownEvent(int32_t x, int32_t y);
363     void NotifySessionTouchOutside(int32_t persistentId);
364 
365     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) override;
366     WMError GetUnreliableWindowInfo(int32_t windowId,
367         std::vector<sptr<UnreliableWindowInfo>>& infos) override;
368     WSError SetWindowFlags(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property);
369 
370     void OnScreenshot(DisplayId displayId);
371     void NotifyDumpInfoResult(const std::vector<std::string>& info) override;
372     void SetVirtualPixelRatioChangeListener(const ProcessVirtualPixelRatioChangeFunc& func);
373     void ProcessVirtualPixelRatioChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
374         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
375     void ProcessUpdateRotationChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
376         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
377 
378     void SetRootSceneProcessBackEventFunc(const RootSceneProcessBackEventFunc& processBackEventFunc);
379     void RegisterWindowChanged(const WindowChangedFunc& func);
380     WSError CloneWindow(int32_t fromPersistentId, int32_t toPersistentId);
381 
382     /*
383      * Collaborator
384      */
385     void SetAbilityManagerCollaboratorRegisteredFunc(const AbilityManagerCollaboratorRegisteredFunc& func);
386     WSError RegisterIAbilityManagerCollaborator(int32_t type,
387         const sptr<AAFwk::IAbilityManagerCollaborator>& impl) override;
388     WSError UnregisterIAbilityManagerCollaborator(int32_t type) override;
389     void ClearAllCollaboratorSessions();
390 
391     WMError CheckWindowId(int32_t windowId, int32_t& pid) override;
392     void GetSceneSessionPrivacyModeBundles(DisplayId displayId, std::unordered_set<std::string>& privacyBundles);
393     BrokerStates CheckIfReuseSession(SessionInfo& sessionInfo);
394     bool CheckCollaboratorType(int32_t type);
395     sptr<SceneSession> FindSessionByAffinity(const std::string& affinity);
396     void AddWindowDragHotArea(DisplayId displayId, uint32_t type, WSRect& area);
397     void PreloadInLakeApp(const std::string& bundleName);
398     WSError UpdateMaximizeMode(int32_t persistentId, bool isMaximize);
399     WSError UpdateSessionDisplayId(int32_t persistentId, uint64_t screenId);
400     WSError NotifyStackEmpty(int32_t persistentId);
401     void NotifySessionUpdate(const SessionInfo& sessionInfo, ActionType type,
402         ScreenId fromScreenId = SCREEN_ID_INVALID);
403     WMError GetSurfaceNodeIdsFromMissionIds(std::vector<uint64_t>& missionIds,
404         std::vector<uint64_t>& surfaceNodeIds, bool isBlackList = false);
405     WSError UpdateTitleInTargetPos(int32_t persistentId, bool isShow, int32_t height);
406 
407     /*
408      * Window Immersive
409      */
410     WSError GetIsLayoutFullScreen(bool& isLayoutFullScreen);
411     WSError UpdateSessionAvoidAreaListener(int32_t persistentId, bool haveListener) override;
412     void RegisterNotifyRootSceneAvoidAreaChangeFunc(NotifyRootSceneAvoidAreaChangeFunc&& func);
413     void UpdateRootSceneAvoidArea();
414     bool GetImmersiveState(ScreenId screenId);
415     WSError NotifyStatusBarShowStatus(int32_t persistentId, bool isVisible);
416     void NotifyStatusBarConstantlyShow(DisplayId displayId, bool isVisible);
417     void GetStatusBarConstantlyShow(DisplayId displayId, bool& isVisible) const;
418     WSError NotifyAINavigationBarShowStatus(bool isVisible, WSRect barArea, uint64_t displayId);
419     WSRect GetAINavigationBarArea(uint64_t displayId);
420     void ClearDisplayStatusBarTemporarilyFlags();
421     AvoidArea GetRootSessionAvoidAreaByType(AvoidAreaType type);
422     void SetOnFlushUIParamsFunc(OnFlushUIParamsFunc&& func);
423     void SetIsRootSceneLastFrameLayoutFinishedFunc(IsRootSceneLastFrameLayoutFinishedFunc&& func);
424     void SetStatusBarDefaultVisibilityPerDisplay(DisplayId displayId, bool visible);
425     bool GetStatusBarDefaultVisibilityByDisplayId(DisplayId displayId);
426     void SetStatusBarAvoidHeight(int32_t height);
427     void GetStatusBarAvoidHeight(WSRect& barArea);
428 
429     WSError NotifyWindowExtensionVisibilityChange(int32_t pid, int32_t uid, bool visible) override;
430     void DealwithVisibilityChange(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfos,
431     const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData);
432     void NotifyUpdateRectAfterLayout();
433     void FlushUIParams(ScreenId screenId, std::unordered_map<int32_t, SessionUIParam>&& uiParams);
434     WSError UpdateSessionWindowVisibilityListener(int32_t persistentId, bool haveListener) override;
435     WMError SetSystemAnimatedScenes(SystemAnimatedSceneType sceneType, bool isRegularAnimation = false);
436 
437     std::shared_ptr<Media::PixelMap> GetSessionSnapshotPixelMap(const int32_t persistentId, const float scaleParam);
438     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) override;
439     const std::map<int32_t, sptr<SceneSession>> GetSceneSessionMap();
440     void GetAllSceneSession(std::vector<sptr<SceneSession>>& sceneSessions);
441     void GetAllWindowVisibilityInfos(std::vector<std::pair<int32_t, uint32_t>>& windowVisibilityInfos);
442 
443     /*
444      * Keyboard Window
445      */
446     void RequestInputMethodCloseKeyboard(int32_t persistentId);
447     void RegisterNotifyRootSceneOccupiedAreaChangeFunc(NotifyRootSceneOccupiedAreaChangeFunc&& func);
448 
449     /*
450      * UIExtension
451      */
452     uint32_t GetLockScreenZOrder();
453     WMError CheckUIExtensionCreation(int32_t windowId, uint32_t tokenId, const AppExecFwk::ElementName& element,
454         AppExecFwk::ExtensionAbilityType extensionAbilityType, int32_t& pid);
455     void OnNotifyAboveLockScreen(const std::vector<int32_t>& windowIds);
456     void AddExtensionWindowStageToSCB(const sptr<ISessionStage>& sessionStage,
457         const sptr<IRemoteObject>& token, uint64_t surfaceNodeId, bool isConstrainedModal = false) override;
458     void RemoveExtensionWindowStageFromSCB(const sptr<ISessionStage>& sessionStage,
459         const sptr<IRemoteObject>& token, bool isConstrainedModal = false) override;
460     void UpdateModalExtensionRect(const sptr<IRemoteObject>& token, Rect rect) override;
461     void ProcessModalExtensionPointDown(const sptr<IRemoteObject>& token, int32_t posX, int32_t posY) override;
462     WSError AddOrRemoveSecureSession(int32_t persistentId, bool shouldHide) override;
463     WSError CheckExtWindowFlagsPermission(ExtensionWindowFlags& actions) const;
464     WSError UpdateExtWindowFlags(const sptr<IRemoteObject>& token, uint32_t extWindowFlags,
465         uint32_t extWindowActions) override;
466     void CheckSceneZOrder();
467     WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) override;
468     WMError GetCallingWindowWindowStatus(int32_t persistentId, WindowStatus& windowStatus) override;
469     WMError GetCallingWindowRect(int32_t persistentId, Rect& rect) override;
470     WMError GetWindowModeType(WindowModeType& windowModeType) override;
471     WMError GetWindowIdsByCoordinate(DisplayId displayId, int32_t windowNumber,
472         int32_t x, int32_t y, std::vector<int32_t>& windowIds) override;
473 
474     int32_t ReclaimPurgeableCleanMem();
475     void OnBundleUpdated(const std::string& bundleName, int userId);
476     void OnConfigurationUpdated(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
477 
GetTaskScheduler()478     std::shared_ptr<TaskScheduler> GetTaskScheduler() { return taskScheduler_; }
479 
480     int32_t GetCustomDecorHeight(int32_t persistentId);
481 
482     /*
483      * Free Multi Window
484      */
485     WSError SwitchFreeMultiWindow(bool enable);
486     WSError GetFreeMultiWindowEnableState(bool& enable) override;
487 
488     const SystemSessionConfig& GetSystemSessionConfig() const;
489     WSError NotifyEnterRecentTask(bool enterRecent);
490     WMError UpdateDisplayHookInfo(int32_t uid, uint32_t width, uint32_t height, float_t density, bool enable);
491     WMError UpdateAppHookDisplayInfo(int32_t uid, const HookInfo& hookInfo, bool enable);
492     void InitScheduleUtils();
493     void ProcessDisplayScale(sptr<DisplayInfo>& displayInfo);
494     WMError GetRootMainWindowId(int32_t persistentId, int32_t& hostWindowId);
495 
496     /*
497      * Move Drag
498      */
499     WMError SetGlobalDragResizeType(DragResizeType dragResizeType) override;
500     WMError GetGlobalDragResizeType(DragResizeType& dragResizeType) override;
501     WMError SetAppDragResizeType(const std::string& bundleName, DragResizeType dragResizeType) override;
502     WMError GetAppDragResizeType(const std::string& bundleName, DragResizeType& dragResizeType) override;
503     WMError SetAppDragResizeTypeInner(const std::string& bundleName, DragResizeType dragResizeType);
504 
505     /*
506      * Window Layout
507      */
508     SingleHandTransform GetNormalSingleHandTransform() const;
509     SingleHandScreenInfo GetSingleHandScreenInfo() const;
510     WSRect GetOriginRect() const;
511     WSRect GetSingleHandRect() const;
512     void NotifySingleHandInfoChange(SingleHandScreenInfo singleHandScreenInfo, WSRect originRect,
513         WSRect singleHandRect);
514     void RegisterGetRSNodeByStringIDFunc(GetRSNodeByStringIDFunc&& func);
515     void RegisterSetTopWindowBoundaryByIDFunc(SetTopWindowBoundaryByIDFunc&& func);
516     void RegisterSingleHandContainerNode(const std::string& stringId);
517     const SingleHandCompatibleModeConfig& GetSingleHandCompatibleModeConfig() const;
518     void ConfigSupportFollowParentWindowLayout();
519 
520     /*
521      * Window Property
522      */
523     WMError UpdateScreenLockStatusForApp(const std::string& bundleName, bool isRelease) override;
524     void DealwithDrawingContentChange(const std::vector<std::pair<uint64_t, bool>>& drawingContentChangeInfo);
525     WMError ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector<sptr<WindowInfo>>& infos) override;
526     WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector<sptr<WindowLayoutInfo>>& infos) override;
527     WMError AddSkipSelfWhenShowOnVirtualScreenList(const std::vector<int32_t>& persistentIds) override;
528     WMError RemoveSkipSelfWhenShowOnVirtualScreenList(const std::vector<int32_t>& persistentIds) override;
529 
530     /*
531      * Multi Window
532      */
533     void SetCloseTargetFloatWindowFunc(const ProcessCloseTargetFloatWindowFunc& func);
534     WMError CloseTargetFloatWindow(const std::string& bundleName);
535 
536     /*
537      * Fold Screen Status Change Report
538      */
539     WMError ReportScreenFoldStatusChange(const std::vector<std::string>& screenFoldInfo);
540 
541     void UpdateSecSurfaceInfo(std::shared_ptr<RSUIExtensionData> secExtensionData, uint64_t userId);
542     void UpdateConstrainedModalUIExtInfo(std::shared_ptr<RSUIExtensionData> constrainedModalUIExtData, uint64_t userId);
543     WSError SetAppForceLandscapeConfig(const std::string& bundleName, const AppForceLandscapeConfig& config);
544     AppForceLandscapeConfig GetAppForceLandscapeConfig(const std::string& bundleName);
545     WMError GetWindowStyleType(WindowStyleType& windowStyletype) override;
546     WMError GetProcessSurfaceNodeIdByPersistentId(const int32_t pid,
547         const std::vector<int32_t>& persistentIds, std::vector<uint64_t>& surfaceNodeIds) override;
548 
549     /*
550      * Window ZOrder: PC
551      */
552     void RefreshPcZOrderList(uint32_t startZOrder, std::vector<int32_t>&& persistentIds);
553 
554     /*
555      * PiP Window
556      */
557     WMError CloseTargetPiPWindow(const std::string& bundleName);
558     WMError GetCurrentPiPWindowInfo(std::string& bundleName);
559     void SetStartPiPFailedListener(NotifyStartPiPFailedFunc&& func);
560 
561     /*
562      * Window Watermark
563      */
564     WMError SetProcessWatermark(int32_t pid, const std::string& watermarkName, bool isEnabled) override;
565 
566     /*
567      * Window Snapshot
568      */
569     WMError SkipSnapshotForAppProcess(int32_t pid, bool skip) override;
570     WMError SkipSnapshotByUserIdAndBundleNames(int32_t userId,
571         const std::vector<std::string>& bundleNameList) override;
572 
573     /*
574      * Multi Instance
575      */
576     int32_t GetMaxInstanceCount(const std::string& bundleName);
577     int32_t GetInstanceCount(const std::string& bundleName);
578     std::string GetLastInstanceKey(const std::string& bundleName);
579     void RefreshAppInfo(const std::string& bundleName);
580 
581     /*
582      * Screen Manager
583      */
584     WMError GetDisplayIdByWindowId(const std::vector<uint64_t>& windowIds,
585         std::unordered_map<uint64_t, DisplayId>& windowDisplayIdMap) override;
586 
587     /*
588      * Specific Window
589      */
590     void RegisterCreateSubSessionListener(int32_t persistentId, const NotifyCreateSubSessionFunc& func);
591     void RegisterBindDialogTargetListener(const sptr<SceneSession>& session, NotifyBindDialogSessionFunc&& func);
592     void UnregisterSpecificSessionCreateListener(int32_t persistentId);
593     WMError HasFloatingWindowForeground(const sptr<IRemoteObject>& abilityToken,
594         bool& hasOrNot) override;
595 
596     /*
597      * Window Lifecycle
598      */
599     void GetMainSessionByBundleNameAndAppIndex(
600         const std::string& bundleName, int32_t appIndex, std::vector<sptr<SceneSession>>& mainSessions);
601     WSError NotifyAppUseControlList(
602         ControlAppType type, int32_t userId, const std::vector<AppUseControlInfo>& controlList);
603     void RegisterNotifyAppUseControlListCallback(NotifyAppUseControlListFunc&& func);
604     WMError MinimizeMainSession(const std::string& bundleName, int32_t appIndex, int32_t userId);
605     sptr<SceneSession> RequestSceneSession(const SessionInfo& sessionInfo,
606         sptr<WindowSessionProperty> property = nullptr);
607     void UpdateSceneSessionWant(const SessionInfo& sessionInfo);
608     WSError RequestSceneSessionActivation(const sptr<SceneSession>& sceneSession, bool isNewActive);
609     WSError RequestSceneSessionBackground(const sptr<SceneSession>& sceneSession, const bool isDelegator = false,
610         const bool isToDesktop = false, const bool isSaveSnapshot = true);
611     WSError RequestSceneSessionDestruction(const sptr<SceneSession>& sceneSession, bool needRemoveSession = true,
612         bool isSaveSnapshot = true, const bool isForceClean = false, bool isUserRequestedExit = false);
613     WSError RequestSceneSessionDestructionInner(sptr<SceneSession>& sceneSession,
614         sptr<AAFwk::SessionInfo> sceneSessionInfo, const bool needRemoveSession, const bool isForceClean = false,
615         bool isUserRequestedExit = false);
616     void NotifyForegroundInteractiveStatus(const sptr<SceneSession>& sceneSession, bool interactive);
617     WSError RequestSceneSessionByCall(const sptr<SceneSession>& sceneSession);
618     void StartAbilityBySpecified(const SessionInfo& sessionInfo);
619     void NotifyWindowStateErrorFromMMI(int32_t pid, int32_t persistentId);
620     void RemoveLifeCycleTaskByPersistentId(int32_t persistentId, const LifeCycleTaskType taskType);
621     WSError PendingSessionToForeground(const sptr<IRemoteObject>& token) override;
622     WSError PendingSessionToBackgroundForDelegator(const sptr<IRemoteObject>& token,
623         bool shouldBackToCaller = true) override;
624     WSError TerminateSessionNew(
625         const sptr<AAFwk::SessionInfo> info, bool needStartCaller, bool isFromBroker = false) override;
626     WSError ClearSession(int32_t persistentId) override;
627     WSError ClearAllSessions() override;
628     WSError MoveSessionsToForeground(const std::vector<int32_t>& sessionIds, int32_t topSessionId) override;
629     WSError MoveSessionsToBackground(const std::vector<int32_t>& sessionIds, std::vector<int32_t>& result) override;
630     int32_t StartUIAbilityBySCB(sptr<AAFwk::SessionInfo>& abilitySessionInfo);
631     int32_t StartUIAbilityBySCB(sptr<SceneSession>& sceneSessions);
632     WMError GetMainWindowInfos(int32_t topNum, std::vector<MainWindowInfo>& topNInfo);
633     WMError GetCallingWindowInfo(CallingWindowInfo& callingWindowInfo);
634     WMError GetAllMainWindowInfos(std::vector<MainWindowInfo>& infos) const;
635     WMError ClearMainSessions(const std::vector<int32_t>& persistentIds, std::vector<int32_t>& clearFailedIds);
636     WMError TerminateSessionByPersistentId(int32_t persistentId);
637     void SetUserAuthPassed(bool isUserAuthPassed);
638     bool IsUserAuthPassed() const;
639     void GetMainSessionByAbilityInfo(const AbilityInfoBase& abilityInfo,
640         std::vector<sptr<SceneSession>>& mainSessions) const;
641     WMError LockSessionByAbilityInfo(const AbilityInfoBase& abilityInfo, bool isLock);
642     WMError RegisterSessionLifecycleListener(const sptr<ISessionLifecycleListener>& listener,
643         const std::vector<int32_t>& persistentIdList);
644     WMError RegisterSessionLifecycleListener(const sptr<ISessionLifecycleListener>& listener,
645         const std::vector<std::string>& bundleNameList);
646     WMError UnregisterSessionLifecycleListener(const sptr<ISessionLifecycleListener>& listener);
647     bool IsMainWindowByPersistentId(int32_t persistentId);
648     WMError MinimizeByWindowId(const std::vector<int32_t>& windowIds) override;
649 
650     /*
651      * Window Pattern
652      */
653     void InitSnapshotCache();
654     void VisitSnapshotFromCache(int32_t persistentId);
655     void PutSnapshotToCache(int32_t persistentId);
656     void RemoveSnapshotFromCache(int32_t persistentId);
657 
658 protected:
659     SceneSessionManager();
660     virtual ~SceneSessionManager();
661 
662 private:
663     std::atomic<bool> enterRecent_ { false };
664     bool isKeyboardPanelEnabled_ = false;
665     static sptr<SceneSessionManager> CreateInstance();
666     void Init();
667     void RegisterAppListener();
668     void InitPrepareTerminateConfig();
669     void LoadWindowSceneXml();
670     void LoadWindowParameter();
671     void ConfigWindowSceneXml();
672     void ConfigWindowSceneXml(const WindowSceneConfig::ConfigItem& config);
673     void ConfigWindowEffect(const WindowSceneConfig::ConfigItem& effectConfig);
674     void ConfigWindowImmersive(const WindowSceneConfig::ConfigItem& immersiveConfig);
675     void ConfigKeyboardAnimation(const WindowSceneConfig::ConfigItem& animationConfig);
676     void ConfigDefaultKeyboardAnimation(KeyboardSceneAnimationConfig& animationIn,
677         KeyboardSceneAnimationConfig& animationOut);
678     bool ConfigAppWindowCornerRadius(const WindowSceneConfig::ConfigItem& item, float& out);
679     bool ConfigAppWindowShadow(const WindowSceneConfig::ConfigItem& shadowConfig, WindowShadowConfig& outShadow);
680     bool ConfigStatusBar(const WindowSceneConfig::ConfigItem& config, StatusBarConfig& statusBarConfig);
681     void ConfigSystemUIStatusBar(const WindowSceneConfig::ConfigItem& statusBarConfig);
682     void ConfigDecor(const WindowSceneConfig::ConfigItem& decorConfig, bool mainConfig = true);
683     void ConfigWindowAnimation(const WindowSceneConfig::ConfigItem& windowAnimationConfig);
684     void ConfigStartingWindowAnimation(const WindowSceneConfig::ConfigItem& startingWindowConfig);
685     void ConfigWindowSizeLimits();
686     void ConfigMainWindowSizeLimits(const WindowSceneConfig::ConfigItem& mainWindowSizeConifg);
687     void ConfigSubWindowSizeLimits(const WindowSceneConfig::ConfigItem& subWindowSizeConifg);
688     void ConfigDialogWindowSizeLimits(const WindowSceneConfig::ConfigItem& dialogWindowSizeConifg);
689     void ConfigSnapshotScale();
690     void ConfigFreeMultiWindow();
691     void LoadFreeMultiWindowConfig(bool enable);
692 
693     std::tuple<std::string, std::vector<float>> CreateCurve(const WindowSceneConfig::ConfigItem& curveConfig);
694     void LoadKeyboardAnimation(const WindowSceneConfig::ConfigItem& item, KeyboardSceneAnimationConfig& config);
695     sptr<SceneSession::SpecificSessionCallback> CreateSpecificSessionCallback();
696     sptr<KeyboardSession::KeyboardSessionCallback> CreateKeyboardSessionCallback();
697     void FillSessionInfo(sptr<SceneSession>& sceneSession);
698     std::shared_ptr<AppExecFwk::AbilityInfo> QueryAbilityInfoFromBMS(const int32_t uId, const std::string& bundleName,
699         const std::string& abilityName, const std::string& moduleName);
700     std::vector<sptr<SceneSession>> GetSubSceneSession(int32_t parentWindowId);
701     void RemoveDuplicateSubSession(const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfo,
702         std::vector<sptr<SceneSession>>& subSessions);
703     void SetSessionVisibilityInfo(const sptr<SceneSession>& session, WindowVisibilityState visibleState,
704         std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos, std::string& visibilityInfo);
705     void UpdateSubWindowVisibility(const sptr<SceneSession>& session, WindowVisibilityState visibleState,
706         const std::vector<std::pair<uint64_t, WindowVisibilityState>>& visibilityChangeInfo,
707         std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos, std::string& visibilityInfo,
708         const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData);
709     bool GetSessionRSVisible(const sptr<Session>& session,
710         const std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData);
711 
712     /*
713      * Window Pipeline
714      */
715     void ProcessFocusZOrderChange(uint32_t dirty);
716     void PostProcessFocus();
717     void PostProcessProperty(uint32_t dirty);
718 
719     /*
720      * Window Lifecycle
721      */
722     bool isUserAuthPassed_ {false};
723     sptr<SceneSession> GetSceneSessionBySessionInfo(const SessionInfo& sessionInfo);
724     void CreateRootSceneSession();
725     void InitSceneSession(sptr<SceneSession>& sceneSession, const SessionInfo& sessionInfo,
726         const sptr<WindowSessionProperty>& property) REQUIRES(SCENE_GUARD);
727     void RegisterSessionExceptionFunc(const sptr<SceneSession>& sceneSession);
728     void NotifySessionForeground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation);
729     void NotifySessionBackground(const sptr<SceneSession>& session, uint32_t reason, bool withAnimation,
730         bool isFromInnerkits);
731     WSError ClearSession(sptr<SceneSession> sceneSession);
732     bool IsSessionClearable(sptr<SceneSession> sceneSession);
733     void GetAllClearableSessions(std::vector<sptr<SceneSession>>& sessionVector);
734     sptr<AAFwk::SessionInfo> SetAbilitySessionInfo(const sptr<SceneSession>& sceneSession);
735     void ResetWantInfo(const sptr<SceneSession>& sceneSession);
736     void ResetSceneSessionInfoWant(const sptr<AAFwk::SessionInfo>& sceneSessionInfo);
737     int32_t StartUIAbilityBySCBTimeoutCheck(const sptr<AAFwk::SessionInfo>& abilitySessionInfo,
738         const uint32_t& windowStateChangeReason, bool& isColdStart);
739 
740     /*
741      * Window Focus
742      */
743     std::mutex highlightIdsMutex_;
744     std::unordered_set<int32_t> highlightIds_;
745     std::vector<std::pair<int32_t, sptr<SceneSession>>> GetSceneSessionVector(CmpFunc cmp);
746     void TraverseSessionTree(TraverseFunc func, bool isFromTopToBottom);
747     void TraverseSessionTreeFromTopToBottom(TraverseFunc func);
748     void TraverseSessionTreeFromBottomToTop(TraverseFunc func);
749 
750     /*
751      * Window Focus
752      */
753     WSError RequestSessionFocus(int32_t persistentId, bool byForeground = true,
754         FocusChangeReason reason = FocusChangeReason::DEFAULT);
755     WSError RequestSessionFocusImmediately(int32_t persistentId, bool blockNotifyUntilVisible = true);
756     WSError RequestSessionUnfocus(int32_t persistentId, FocusChangeReason reason = FocusChangeReason::DEFAULT);
757     WSError RequestAllAppSessionUnfocusInner();
758     WSError RequestFocusBasicCheck(int32_t persistentId, const sptr<FocusGroup>& focusGroup);
759     bool CheckLastFocusedAppSessionFocus(const sptr<SceneSession>& focusedSession,
760         const sptr<SceneSession>& nextSession);
761     WSError RequestFocusSpecificCheck(DisplayId displayId, const sptr<SceneSession>& sceneSession, bool byForeground,
762         FocusChangeReason reason = FocusChangeReason::DEFAULT);
763     bool CheckTopmostWindowFocus(const sptr<SceneSession>& focusedSession, const sptr<SceneSession>& sceneSession);
764     bool CheckRequestFocusImmdediately(const sptr<SceneSession>& sceneSession);
765     bool CheckFocusIsDownThroughBlockingType(const sptr<SceneSession>& requestSceneSession,
766         const sptr<SceneSession>& focusedSession, bool includingAppSession);
767     bool CheckClickFocusIsDownThroughFullScreen(const sptr<SceneSession>& focusedSession,
768         const sptr<SceneSession>& sceneSession, FocusChangeReason reason);
769     bool IsParentSessionVisible(const sptr<SceneSession>& session);
770     sptr<SceneSession> GetNextFocusableSession(DisplayId displayId, int32_t persistentId);
771     sptr<SceneSession> GetTopNearestBlockingFocusSession(DisplayId displayId, uint32_t zOrder,
772         bool includingAppSession);
773     sptr<SceneSession> GetTopFocusableNonAppSession();
774     WSError ShiftFocus(DisplayId displayId, const sptr<SceneSession>& nextSession, bool isProactiveUnfocus,
775         FocusChangeReason reason = FocusChangeReason::DEFAULT);
776     void UpdateFocusStatus(DisplayId displayId, const sptr<SceneSession>& sceneSession, bool isFocused);
777     void NotifyFocusStatus(const sptr<SceneSession>& sceneSession, bool isFocused,
778         const sptr<FocusGroup>& focusGroup);
779     int32_t NotifyRssThawApp(const int32_t uid, const std::string& bundleName, const std::string& reason);
780     void NotifyFocusStatusByMission(const sptr<SceneSession>& prevSession, const sptr<SceneSession>& currSession);
781     void NotifyUnFocusedByMission(const sptr<SceneSession>& sceneSession);
782     void NotifyFocusedByMission(const sptr<SceneSession>& sceneSession);
783     bool MissionChanged(const sptr<SceneSession>& prevSession, const sptr<SceneSession>& currSession);
784     std::string GetAllSessionFocusInfo();
785     void RegisterRequestFocusStatusNotifyManagerFunc(const sptr<SceneSession>& sceneSession);
786     void ProcessUpdateLastFocusedAppId(const std::vector<uint32_t>& zOrderList);
787     WSError ProcessDialogRequestFocusImmdediately(const sptr<SceneSession>& sceneSession);
788     WSError ProcessModalTopmostRequestFocusImmdediately(const sptr<SceneSession>& sceneSession);
789 
790     void RegisterGetStateFromManagerFunc(sptr<SceneSession>& sceneSession);
791     void RegisterSessionChangeByActionNotifyManagerFunc(sptr<SceneSession>& sceneSession);
792 
793     WSError DestroyDialogWithMainWindow(const sptr<SceneSession>& sceneSession) REQUIRES(SCENE_GUARD);
794     sptr<SceneSession> FindMainWindowWithToken(sptr<IRemoteObject> targetToken);
795     WSError UpdateParentSessionForDialog(const sptr<SceneSession>& sceneSession, sptr<WindowSessionProperty> property);
796     void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing);
797     void UpdateFocusableProperty(int32_t persistentId);
798     WMError UpdateTopmostProperty(const sptr<WindowSessionProperty>& property, const sptr<SceneSession>& sceneSession);
799     std::vector<sptr<SceneSession>> GetSceneSessionVectorByTypeAndDisplayId(WindowType type, uint64_t displayId);
800     std::vector<sptr<SceneSession>> GetSceneSessionVectorByType(WindowType type);
801     void UpdateOccupiedAreaIfNeed(int32_t persistentId);
802     void NotifyMMIWindowPidChange(int32_t windowId, bool startMoving);
803     void UpdateHighlightStatus(DisplayId displayId, const sptr<SceneSession>& preSceneSession,
804         const sptr<SceneSession>& currSceneSession, bool isProactiveUnfocus);
805     void SetHighlightSessionIds(const sptr<SceneSession>& sceneSession, bool needBlockHighlightNotify);
806     void AddHighlightSessionIds(const sptr<SceneSession>& sceneSession, bool needBlockHighlightNotify);
807     void RemoveHighlightSessionIds(const sptr<SceneSession>& sceneSession);
808     std::string GetHighlightIdsStr();
809 
810     /*
811      * PC Window
812      */
813     WMError ShiftAppWindowPointerEventInner(
814         int32_t sourceWindowId, int32_t targetWindowId, DisplayId targetDisplayId);
815 
816     /*
817      * Sub Window
818      */
819     WMError SetParentWindowInner(const sptr<SceneSession>& subSession,
820         const sptr<SceneSession>& oldParentSession, const sptr<SceneSession>& newParentSession);
821 
822     /*
823      * Window Immersive
824      */
825     void UpdateAvoidSessionAvoidArea(WindowType type);
826     void UpdateNormalSessionAvoidArea(int32_t persistentId, const sptr<SceneSession>& sceneSession, bool& needUpdate);
827     void UpdateAvoidArea(int32_t persistentId);
828     void UpdateRootSceneSessionAvoidArea(int32_t persistentId, bool& needUpdate);
829 
830     WSError IsLastFrameLayoutFinished(bool& isLayoutFinished);
831     void HandleSpecificSystemBarProperty(WindowType type, const sptr<WindowSessionProperty>& property,
832         const sptr<SceneSession>& sceneSession);
833 
834     sptr<AppExecFwk::IBundleMgr> GetBundleManager();
835     std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager(const AppExecFwk::AbilityInfo& abilityInfo);
836     bool GetStartupPageFromResource(const AppExecFwk::AbilityInfo& abilityInfo, std::string& path, uint32_t& bgColor);
837     bool GetStartingWindowInfoFromCache(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor);
838     void CacheStartingWindowInfo(
839         const AppExecFwk::AbilityInfo& abilityInfo, const std::string& path, const uint32_t& bgColor);
840 
841     bool CheckIsRemote(const std::string& deviceId);
842     bool GetLocalDeviceId(std::string& localDeviceId);
843     std::string AnonymizeDeviceId(const std::string& deviceId);
844     int GetRemoteSessionInfos(const std::string& deviceId, int32_t numMax,
845                               std::vector<SessionInfoBean>& sessionInfos);
846     int GetRemoteSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo);
847     WSError GetTotalUITreeInfo(std::string& dumpInfo);
848 
849     void PerformRegisterInRequestSceneSession(sptr<SceneSession>& sceneSession);
850     WSError RequestSceneSessionActivationInner(sptr<SceneSession>& sceneSession, bool isNewActive)
851         REQUIRES(SCENE_GUARD);
852     WSError SetBrightness(const sptr<SceneSession>& sceneSession, float brightness);
853     void PostBrightnessTask(float brightness);
854     WSError UpdateBrightness(int32_t persistentId);
855     void SetDisplayBrightness(float brightness);
856     float GetDisplayBrightness() const;
857     void HandleHideNonSystemFloatingWindows(const sptr<WindowSessionProperty>& property,
858         const sptr<SceneSession>& sceneSession);
859     void UpdateForceHideState(const sptr<SceneSession>& sceneSession, const sptr<WindowSessionProperty>& property,
860         bool add);
861     void NotifyWindowInfoChange(int32_t persistentId, WindowUpdateType type);
862     void NotifyWindowInfoChangeFromSession(int32_t persistentid);
863     bool FillWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos,
864         const sptr<SceneSession>& sceneSession);
865     std::vector<std::pair<uint64_t, WindowVisibilityState>> GetWindowVisibilityChangeInfo(
866         std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData);
867     void GetWindowLayerChangeInfo(std::shared_ptr<RSOcclusionData> occlusionData,
868         std::vector<std::pair<uint64_t, WindowVisibilityState>>& currVisibleData,
869         std::vector<std::pair<uint64_t, bool>>& currDrawingContentData);
870     void WindowLayerInfoChangeCallback(std::shared_ptr<RSOcclusionData> occlusiontionData);
871     sptr<SceneSession> SelectSesssionFromMap(const uint64_t& surfaceId);
872     void WindowDestroyNotifyVisibility(const sptr<SceneSession>& sceneSession);
873     void RegisterSessionSnapshotFunc(const sptr<SceneSession>& sceneSession);
874 
875     /*
876      * Window Property
877      */
878     std::unordered_map<std::string, std::unordered_set<int32_t>> releasedScreenLockMap_;
879     std::vector<std::pair<uint64_t, bool>> GetWindowDrawingContentChangeInfo(
880         const std::vector<std::pair<uint64_t, bool>>& currDrawingContentData);
881     bool GetPreWindowDrawingState(uint64_t surfaceId, bool currentWindowDrawing, int32_t& pid);
882     bool GetProcessDrawingState(uint64_t surfaceId, int32_t pid);
883     void UpdateWindowDrawingData(uint64_t surfaceId, int32_t pid, int32_t uid);
884     bool GetSpecifiedDrawingData(uint64_t surfaceId, int32_t& pid, int32_t& uid);
885     void RemoveSpecifiedDrawingData(uint64_t surfaceId);
886     WMError ReleaseScreenLockForApp(const std::string& bundleName);
887     WMError RelockScreenLockForApp(const std::string& bundleName);
888     void GetAllSessionsToReleaseScreenLock(
889         std::vector<sptr<SceneSession>>& sessionsToReleaseScreenLock, const std::string& bundleName);
890     bool FilterForListWindowInfo(const WindowInfoOption& windowInfoOption,
891         const sptr<SceneSession>& sceneSession) const;
892     void FilterForGetAllWindowLayoutInfo(DisplayId displayId, bool isVirtualDisplay,
893         std::vector<sptr<SceneSession>>& filteredSessions);
894     bool IsGetWindowLayoutInfoNeeded(const sptr<SceneSession>& session) const;
895     int32_t GetFoldLowerScreenPosY() const;
896     DisplayId UpdateSpecificSessionClientDisplayId(const sptr<WindowSessionProperty>& property);
897     void UpdateSessionDisplayIdBySessionInfo(sptr<SceneSession> sceneSession, const SessionInfo& sessionInfo);
898     void CheckFloatWindowIsAnco(pid_t pid, const sptr<SceneSession>& newSession);
899     bool IsNeedUpdateBrightness(float brightness);
900 
901     /*
902      * Window Rotate Animation
903      */
904     void RegisterAcquireRotateAnimationConfigFunc(const sptr<SceneSession>& sceneSession);
905 
906     void RegisterVisibilityChangedDetectFunc(const sptr<SceneSession>& sceneSession);
907     void NotifySessionForCallback(const sptr<SceneSession>& sceneSession, const bool needRemoveSession);
908     void AddClientDeathRecipient(const sptr<ISessionStage>& sessionStage, const sptr<SceneSession>& sceneSession);
909     void DestroySpecificSession(const sptr<IRemoteObject>& remoteObject);
910     bool GetExtensionWindowIds(const sptr<IRemoteObject>& token, int32_t& persistentId, int32_t& parentId);
911     void DestroyExtensionSession(const sptr<IRemoteObject>& remoteExtSession, bool isConstrainedModal = false);
912     void EraseSceneSessionMapById(int32_t persistentId);
913     void EraseSceneSessionAndMarkDirtyLocked(int32_t persistentId);
914     WSError GetAbilityInfosFromBundleInfo(const std::vector<AppExecFwk::BundleInfo>& bundleInfos,
915         std::vector<SCBAbilityInfo>& scbAbilityInfos);
916     void GetOrientationFromResourceManager(AppExecFwk::AbilityInfo& abilityInfo);
917     void UpdatePrivateStateAndNotifyForAllScreens();
918 
919     void ClosePipWindowIfExist(WindowType type);
920     void NotifySessionAINavigationBarChange(int32_t persistentId);
921     void ReportWindowProfileInfos();
922     void UpdateCameraWindowStatus(uint32_t accessTokenId, bool isShowing);
923     void GetAllSceneSessionForAccessibility(std::vector<sptr<SceneSession>>& sceneSessionList);
924     void FillAccessibilityInfo(std::vector<sptr<SceneSession>>& sceneSessionList,
925         std::vector<sptr<AccessibilityWindowInfo>>& accessibilityInfo);
926     void FilterSceneSessionCovered(std::vector<sptr<SceneSession>>& sceneSessionList);
927     void NotifyAllAccessibilityInfo();
928     void SetSkipSelfWhenShowOnVirtualScreen(uint64_t surfaceNodeId, bool isSkip);
929     void RegisterSecSurfaceInfoListener();
930     void RegisterConstrainedModalUIExtInfoListener();
931     void UpdatePiPWindowStateChanged(const std::string& bundleName, bool isForeground);
932 
933     /*
934      * UIExtension
935      */
936     void DestroyUIServiceExtensionSubWindow(const sptr<SceneSession>& sceneSession);
937     WSError CheckSubSessionStartedByExtensionAndSetDisplayId(const sptr<IRemoteObject>& token,
938         const sptr<WindowSessionProperty>& property, const sptr<ISessionStage>& sessionStage);
939     void ReportSubWindowCreationFailure(int32_t pid, const std::string& abilityName,
940         const std::string& parentBundleName, const std::string& hostBundleName);
941 
942     /*
943      * Multi User
944      */
945     bool IsPcSceneSessionLifecycle(const sptr<SceneSession>& sceneSession);
946     bool IsNeedChangeLifeCycleOnUserSwitch(const sptr<SceneSession>& sceneSession, int32_t pid);
947     WSError StartOrMinimizeUIAbilityBySCB(const sptr<SceneSession>& sceneSession, bool isUserActive);
948     void ProcessUIAbilityOnUserSwitch(bool isUserActive);
949     void HandleUserSwitching(bool isUserActive);
950     void HandleUserSwitched(bool isUserActive);
951 
952     /*
953      * Window Recover
954      */
955     bool IsWindowSupportCacheForRecovering(const sptr<SceneSession>& sceneSession,
956         const sptr<WindowSessionProperty>& property);
957     void CacheSpecificSessionForRecovering(const sptr<SceneSession>& sceneSession,
958         const sptr<WindowSessionProperty>& property);
959     void RecoverCachedSubSession(int32_t persistentId);
960     void RecoverCachedDialogSession(int32_t persistentId);
961     void RemoveFailRecoveredSession();
962     void ClearUnrecoveredSessions(const std::vector<int32_t>& recoveredPersistentIds) REQUIRES(SCENE_GUARD);
963     SessionInfo RecoverSessionInfo(const sptr<WindowSessionProperty>& property);
964     bool IsNeedRecover(const int32_t persistentId);
965     WSError CheckSessionPropertyOnRecovery(const sptr<WindowSessionProperty>& property, bool isSpecificSession);
966     void UpdateRecoverPropertyForSuperFold(const sptr<WindowSessionProperty>& property);
967 
968     /*
969      * Gesture Back
970      */
971     void UpdateGestureBackEnabled(int32_t persistentId);
972     std::unordered_set<int32_t> gestureBackEnableWindowIdSet_; // ONLY Accessed on OS_sceneSession thread
973 
974     /*
975      * Window Input Event
976      */
977     NotifyWatchGestureConsumeResultFunc onWatchGestureConsumeResultFunc_;
978     NotifyWatchFocusActiveChangeFunc onWatchFocusActiveChangeFunc_;
979 
980     sptr<RootSceneSession> rootSceneSession_;
981     std::weak_ptr<AbilityRuntime::Context> rootSceneContextWeak_;
982     mutable std::shared_mutex sceneSessionMapMutex_;
983     std::map<int32_t, sptr<SceneSession>> sceneSessionMap_;
984     std::map<int32_t, sptr<SceneSession>> systemTopSceneSessionMap_;
985     std::map<int32_t, sptr<SceneSession>> nonSystemFloatSceneSessionMap_;
986     sptr<ScbSessionHandler> scbSessionHandler_;
987     std::shared_ptr<SessionListenerController> listenerController_;
988     std::unordered_map<sptr<IRemoteObject>, int32_t, SptrHash<IRemoteObject>> remoteObjectMap_;
989 
990     /*
991      * UIExtension
992      */
993     std::unordered_map<sptr<IRemoteObject>, sptr<IRemoteObject>, SptrHash<IRemoteObject>> remoteExtSessionMap_;
994     std::unordered_map<sptr<IRemoteObject>,
995         ExtensionWindowAbilityInfo, SptrHash<IRemoteObject>> extSessionInfoMap_;
996     std::unordered_map<int32_t, ExtensionWindowFlags> extWindowFlagsMap_;
997     ExtensionWindowFlags combinedExtWindowFlags_ { 0 };
998     std::atomic_bool shouldHideNonSecureFloatingWindows_ { false };
999     std::atomic_bool specialExtWindowHasPrivacyMode_ { false };
1000     bool lastWaterMarkShowState_ { false };
1001     sptr<AgentDeathRecipient> extensionDeath_ = new AgentDeathRecipient(
1002         [this](const sptr<IRemoteObject>& remoteExtSession) { this->DestroyExtensionSession(remoteExtSession); });
1003 
1004     std::set<int32_t> touchOutsideListenerSessionSet_;
1005     std::set<int32_t> windowVisibilityListenerSessionSet_;
1006 
1007     NotifyCreateSystemSessionFunc createSystemSessionFunc_;
1008     NotifyCreateKeyboardSessionFunc createKeyboardSessionFunc_;
1009     ProcessStatusBarEnabledChangeFunc statusBarEnabledChangeFunc_;
1010     ProcessGestureNavigationEnabledChangeFunc gestureNavigationEnabledChangeFunc_;
1011     ProcessOutsideDownEventFunc outsideDownEventFunc_;
1012     ProcessShiftFocusFunc shiftFocusFunc_;
1013     NotifySCBAfterUpdateFocusFunc notifySCBAfterFocusedFunc_;
1014     NotifySCBAfterUpdateFocusFunc notifySCBAfterUnfocusedFunc_;
1015     ProcessCallingSessionIdChangeFunc callingSessionIdChangeFunc_;
1016     ProcessStartUIAbilityErrorFunc startUIAbilityErrorFunc_;
1017     DumpRootSceneElementInfoFunc dumpRootSceneFunc_;
1018     DumpUITreeFunc dumpUITreeFunc_;
1019     ProcessVirtualPixelRatioChangeFunc processVirtualPixelRatioChangeFunc_ = nullptr;
1020     ProcessCloseTargetFloatWindowFunc closeTargetFloatWindowFunc_;
1021 
1022     AppWindowSceneConfig appWindowSceneConfig_;
1023 
1024     /*
1025      * Window Recover
1026      */
1027     bool recoveringFinished_ = false;
1028     NotifyRecoverSceneSessionFunc recoverSceneSessionFunc_;
1029     std::set<int32_t> failRecoveredPersistentIdSet_;
1030 
1031     /*
1032      * Window Rotate Animation
1033      */
1034     RotateAnimationConfig rotateAnimationConfig_;
1035 
1036     /*
1037      * PiP Window
1038      */
1039     NotifyStartPiPFailedFunc startPiPFailedFunc_;
1040 
1041     SystemSessionConfig systemConfig_;
1042     float snapshotScale_ = 0.5;
1043     int32_t brightnessSessionId_ = INVALID_SESSION_ID;
1044     float displayBrightness_ = UNDEFINED_BRIGHTNESS;
1045     bool isScreenLocked_ { false };
1046     bool isPrepareTerminateEnable_ { false };
1047 
1048     /*
1049      * Window Focus
1050      */
1051     sptr<WindowFocusController> windowFocusController_;
1052     FocusChangeReason focusChangeReason_ = FocusChangeReason::DEFAULT;
1053     bool needBlockNotifyFocusStatusUntilForeground_ { false };
1054     bool needBlockNotifyUnfocusStatus_ { false };
1055 
1056     /*
1057      * DFX
1058      */
1059     bool openDebugTrace_ { false };
1060 
1061     std::atomic<bool> enableInputEvent_ = true;
1062     std::vector<int32_t> alivePersistentIds_ = {};
1063     std::vector<VisibleWindowNumInfo> lastInfo_ = {};
1064     std::shared_mutex lastInfoMutex_;
1065 
1066     std::shared_ptr<AppExecFwk::EventHandler> mainHandler_;
1067     std::shared_ptr<TaskScheduler> taskScheduler_;
1068     sptr<AppExecFwk::IBundleMgr> bundleMgr_;
1069     sptr<AppAnrListener> appAnrListener_;
1070     sptr<AppExecFwk::LauncherService> launcherService_;
1071     std::shared_mutex startingWindowMapMutex_;
1072     const size_t MAX_CACHE_COUNT = 100;
1073     std::map<std::string, std::map<std::string, StartingWindowInfo>> startingWindowMap_;
1074     std::unordered_map<std::string, AppForceLandscapeConfig> appForceLandscapeMap_;
1075     std::shared_mutex appForceLandscapeMutex_;
1076 
1077     std::mutex privacyBundleMapMutex_;
1078     std::unordered_map<DisplayId, std::unordered_set<std::string>> privacyBundleMap_;
1079 
1080     WindowModeType lastWindowModeType_ { WindowModeType::WINDOW_MODE_OTHER };
1081 
1082     /*
1083      * Multi User
1084      */
1085     static constexpr int32_t DEFAULT_USERID = -1;
1086     std::atomic<int32_t> currentUserId_ { DEFAULT_USERID };
1087     bool isUserBackground_ = false; // Only accessed on SSM thread
1088 
1089     // displayRegionMap_ stores the screen display area for AccessibilityNotification,
1090     // the read and write operations must be performed in the same thread, current is in task thread.
1091     std::unordered_map<DisplayId, std::shared_ptr<SkRegion>> displayRegionMap_;
1092     std::shared_ptr<SkRegion> GetDisplayRegion(DisplayId displayId);
1093     void UpdateDisplayRegion(const sptr<DisplayInfo>& displayInfo);
1094 
1095     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
1096     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
1097     bool isReportTaskStart_ = false;
1098     std::vector<std::pair<uint64_t, WindowVisibilityState> > lastVisibleData_;
1099     RSInterfaces& rsInterface_;
1100     void RegisterSessionStateChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession);
1101     void RegisterSessionInfoChangeNotifyManagerFunc(sptr<SceneSession>& sceneSession);
1102     void OnSessionStateChange(int32_t persistentId, const SessionState& state) REQUIRES(SCENE_GUARD);
1103     void ProcessFocusWhenForeground(sptr<SceneSession>& sceneSession);
1104     void ProcessFocusWhenForegroundScbCore(sptr<SceneSession>& sceneSession);
1105     void ProcessSubSessionForeground(sptr<SceneSession>& sceneSession);
1106     void ProcessSubSessionBackground(sptr<SceneSession>& sceneSession);
1107     sptr<SceneSession> FindSessionByToken(const sptr<IRemoteObject>& token,
1108         WindowType type = WindowType::APP_MAIN_WINDOW_BASE);
1109 
1110     void CheckAndNotifyWaterMarkChangedResult();
1111     WSError NotifyWaterMarkFlagChangedResult(bool hasWaterMark);
1112     void ProcessPreload(const AppExecFwk::AbilityInfo& abilityInfo) const;
1113     WindowChangedFunc WindowChangedFunc_;
1114     sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient(
1115         [this](const sptr<IRemoteObject>& remoteObject) { this->DestroySpecificSession(remoteObject); });
1116 
1117     int GetRemoteSessionSnapshotInfo(const std::string& deviceId, int32_t sessionId,
1118                                      AAFwk::MissionSnapshot& sessionSnapshot);
1119 
1120     /*
1121      * Collaborator
1122      */
1123     AbilityManagerCollaboratorRegisteredFunc abilityManagerCollaboratorRegisteredFunc_;
1124     const int32_t BROKER_UID = 5557;
1125     const int32_t BROKER_RESERVE_UID = 5005;
1126     std::shared_mutex collaboratorMapLock_;
1127     std::unordered_map<int32_t, sptr<AAFwk::IAbilityManagerCollaborator>> collaboratorMap_;
1128     std::atomic<int64_t> containerStartAbilityTime_ { 0 };
1129     sptr<AgentDeathRecipient> collaboratorDeathRecipient_;
1130     BrokerStates NotifyStartAbility(
1131         int32_t collaboratorType, const SessionInfo& sessionInfo, int32_t persistentId = 0);
1132     void NotifySessionCreate(const sptr<SceneSession> sceneSession, const SessionInfo& sessionInfo);
1133     void NotifyLoadAbility(int32_t collaboratorType, sptr<AAFwk::SessionInfo> abilitySessionInfo,
1134         std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo);
1135     void NotifyUpdateSessionInfo(const sptr<SceneSession> sceneSession);
1136     void NotifyClearSession(int32_t collaboratorType, int32_t persistentId);
1137     void NotifyMoveSessionToForeground(int32_t collaboratorType, int32_t persistentId);
1138     bool PreHandleCollaboratorStartAbility(sptr<SceneSession>& sceneSession, int32_t persistentId = 0);
1139     bool PreHandleCollaborator(sptr<SceneSession>& sceneSession, int32_t persistentId = 0);
1140     void NotifyCollaboratorAfterStart(sptr<SceneSession>& sceneSession, sptr<AAFwk::SessionInfo>& sceneSessionInfo);
1141     void UpdateCollaboratorSessionWant(sptr<SceneSession>& session, int32_t persistentId = 0);
1142     sptr<AAFwk::IAbilityManagerCollaborator> GetCollaboratorByType(int32_t collaboratorType);
1143 
1144     std::vector<uint64_t> skipSurfaceNodeIds_;
1145     std::atomic_bool processingFlushUIParams_ { false };
1146 
1147     /*
1148      * PiP Window
1149      */
1150     uint64_t pipWindowSurfaceId_ = 0;
1151     bool CheckPiPPriority(const PiPTemplateInfo& pipTemplateInfo);
1152     bool IsEnablePiPCreate(const sptr<WindowSessionProperty>& property);
1153     bool IsPiPForbidden(const sptr<WindowSessionProperty>& property, const WindowType& type);
1154     bool IsLastPiPWindowVisible(uint64_t surfaceId, WindowVisibilityState lastVisibilityState);
1155     void NotifyPiPWindowVisibleChange(bool isScreenLocked);
1156 
1157     void DestroySubSession(const sptr<SceneSession>& sceneSession);
1158     void DestroyToastSession(const sptr<SceneSession>& sceneSession);
1159     void NotifyCreateSubSession(int32_t persistentId, sptr<SceneSession> session, uint32_t windowFlags = 0);
1160     void NotifyCreateToastSession(int32_t persistentId, sptr<SceneSession> session);
1161     void NotifySessionUnfocusedToClient(int32_t persistentId);
1162     void NotifyCreateSpecificSession(sptr<SceneSession> session,
1163         sptr<WindowSessionProperty> property, const WindowType& type);
1164     sptr<SceneSession> CreateSceneSession(const SessionInfo& sessionInfo, sptr<WindowSessionProperty> property);
1165 
1166     /*
1167      * Keyboard
1168      */
1169     void CreateKeyboardPanelSession(sptr<SceneSession> keyboardSession);
1170     sptr<SceneSession> RequestKeyboardPanelSession(const std::string& panelName, uint64_t displayId);
1171     sptr<SceneSession> GetKeyboardSession(DisplayId displayId, bool isSystemKeyboard);
1172     void HandleKeyboardAvoidChange(const sptr<SceneSession>& sceneSession, DisplayId displayId,
1173         SystemKeyboardAvoidChangeReason reason);
1174     void UpdateKeyboardAvoidAreaActive(bool systemKeyboardAvoidAreaActive);
1175     NotifyRootSceneOccupiedAreaChangeFunc onNotifyOccupiedAreaChangeForRootFunc_;
1176 
1177     /*
1178      * Specific Window
1179      */
1180     void ClearSpecificSessionRemoteObjectMap(int32_t persistentId);
1181     WSError DestroyAndDisconnectSpecificSessionInner(const int32_t persistentId);
1182 
1183     WSError GetAppMainSceneSession(int32_t persistentId, sptr<SceneSession>& sceneSession);
1184     void CalculateCombinedExtWindowFlags();
1185     void UpdateSpecialExtWindowFlags(int32_t persistentId, ExtensionWindowFlags flags, ExtensionWindowFlags actions);
1186     void HideNonSecureFloatingWindows();
1187     void HideNonSecureSubWindows(const sptr<SceneSession>& sceneSession);
1188     WSError HandleSecureSessionShouldHide(const sptr<SceneSession>& sceneSession);
1189     bool CheckSystemWindowPermission(const sptr<WindowSessionProperty>& property);
1190     bool CheckModalSubWindowPermission(const sptr<WindowSessionProperty>& property);
1191 
1192     /*
1193      * Window Snapshot
1194      */
1195     void SetSessionSnapshotSkipForAppProcess(const sptr<SceneSession>& sceneSession) REQUIRES(SCENE_GUARD);
1196     void RemoveProcessSnapshotSkip(int32_t pid) REQUIRES(SCENE_GUARD);
1197     void SetSessionSnapshotSkipForAppBundleName(const sptr<SceneSession>& sceneSession) REQUIRES(SCENE_GUARD);
1198 
1199     void HandleSpecialExtWindowFlagsChange(int32_t persistentId, ExtensionWindowFlags extWindowFlags,
1200         ExtensionWindowFlags extWindowActions);
1201     void ProcessWindowModeType();
1202     WindowModeType CheckWindowModeType();
1203     void NotifyRSSWindowModeTypeUpdate();
1204     void CacVisibleWindowNum();
1205     bool IsVectorSame(const std::vector<VisibleWindowNumInfo>& lastInfo,
1206         const std::vector<VisibleWindowNumInfo>& currentInfo);
1207     bool IsKeyboardForeground();
1208     WindowStatus GetWindowStatus(WindowMode mode, SessionState sessionState,
1209         const sptr<WindowSessionProperty>& property);
1210     void DeleteStateDetectTask();
1211     bool JudgeNeedNotifyPrivacyInfo(DisplayId displayId, const std::unordered_set<std::string>& privacyBundles);
1212 
1213     /*
1214      * Window Visibility
1215      */
1216     bool NotifyVisibleChange(int32_t persistentId);
1217 
1218     /*
1219      * Fold Screen Status Change Report
1220      */
1221     WMError MakeScreenFoldData(const std::vector<std::string>& screenFoldInfo, ScreenFoldData& screenFoldData);
1222     WMError CheckAndReportScreenFoldStatus(ScreenFoldData& data);
1223     WMError ReportScreenFoldStatus(const ScreenFoldData& data);
1224     void RecoveryVisibilityPidCount(int32_t pid) REQUIRES(SCENE_GUARD);
1225 
1226     /*
1227      * Window Watermark
1228      */
1229     bool SetSessionWatermarkForAppProcess(const sptr<SceneSession>& sceneSession);
1230     void RemoveProcessWatermarkPid(int32_t pid);
1231 
1232     /*
1233      * Window Layout
1234      */
1235     std::shared_ptr<VsyncCallback> vsyncCallback_ = nullptr;
1236     std::shared_ptr<VsyncStation> vsyncStation_ = nullptr;
1237     SingleHandTransform singleHandTransform_;
1238     WSRect originRect_;
1239     WSRect singleHandRect_;
1240     SingleHandScreenInfo singleHandScreenInfo_;
1241     GetRSNodeByStringIDFunc getRSNodeByStringIDFunc_;
1242     SetTopWindowBoundaryByIDFunc setTopWindowBoundaryByIDFunc_;
1243     SingleHandCompatibleModeConfig singleHandCompatibleModeConfig_;
1244     void InitVsyncStation();
1245     void RegisterRequestVsyncFunc(const sptr<SceneSession>& sceneSession);
1246     bool GetDisplaySizeById(DisplayId displayId, int32_t& displayWidth, int32_t& displayHeight);
1247     void UpdateSessionCrossAxisState(DisplayId displayId, SuperFoldStatus status, SuperFoldStatus prevStatus);
1248     void ConfigSingleHandCompatibleMode(const WindowSceneConfig::ConfigItem& configItem);
1249 
1250     /*
1251      * Window Snapshot
1252      */
1253     std::unordered_set<int32_t> snapshotSkipPidSet_ GUARDED_BY(SCENE_GUARD); // ONLY Accessed on OS_sceneSession thread
1254     std::unordered_set<std::string> snapshotSkipBundleNameSet_ GUARDED_BY(SCENE_GUARD);
1255 
1256     uint32_t sessionMapDirty_ { 0 };
1257     std::condition_variable nextFlushCompletedCV_;
1258     std::mutex nextFlushCompletedMutex_;
1259     RootSceneProcessBackEventFunc rootSceneProcessBackEventFunc_ = nullptr;
1260 
1261     /*
1262      * Window Watermark
1263      */
1264     std::unordered_map<int32_t, std::string> processWatermarkPidMap_; // ONLY Accessed on OS_sceneSession thread
1265 
1266     /*
1267      * Dump
1268      */
1269     std::shared_ptr<ScbDumpSubscriber> scbDumpSubscriber_;
1270     RunnableFuture<std::vector<std::string>> dumpInfoFuture_;
1271     void DumpSessionInfo(const sptr<SceneSession>& session, std::ostringstream& oss);
1272     void DumpFocusInfo(std::ostringstream& oss);
1273     void DumpSessionElementInfo(const sptr<SceneSession>& session,
1274         const std::vector<std::string>& params, std::string& dumpInfo);
1275     void DumpAllSessionFocusableInfo(int32_t persistentId);
1276 
1277     /*
1278      * Screen Manager
1279      */
1280     bool IsInDefaultScreen(const sptr<SceneSession>& sceneSession);
1281 
1282     /*
1283      * Window Mode Type
1284      */
1285     bool IsNeedSkipWindowModeTypeCheck(const sptr<SceneSession>& sceneSession, bool isSmallFold);
1286 
1287     /*
1288      * Window Immersive
1289      */
1290     NotifyRootSceneAvoidAreaChangeFunc onNotifyAvoidAreaChangeForRootFunc_;
1291     OnFlushUIParamsFunc onFlushUIParamsFunc_;
1292     IsRootSceneLastFrameLayoutFinishedFunc isRootSceneLastFrameLayoutFinishedFunc_;
1293     bool isAINavigationBarVisible_ = false;
1294     std::shared_mutex currAINavigationBarAreaMapMutex_;
1295     std::map<uint64_t, WSRect> currAINavigationBarAreaMap_;
1296     std::unordered_map<DisplayId, bool> statusBarDefaultVisibilityPerDisplay_;
1297     std::set<int32_t> avoidAreaListenerSessionSet_;
1298     static constexpr int32_t INVALID_STATUS_BAR_AVOID_HEIGHT = -1;
1299     int32_t statusBarAvoidHeight_ = INVALID_STATUS_BAR_AVOID_HEIGHT;
1300     std::unordered_map<DisplayId, bool> statusBarConstantlyShowMap_;
1301 
1302     struct SessionInfoList {
1303         int32_t uid_;
1304         std::string bundleName_;
1305         std::string abilityName_;
1306         std::string moduleName_;
1307         bool operator==(const SessionInfoList& list) const
1308         {
1309             return this->uid_ == list.uid_ && this->bundleName_ == list.bundleName_ &&
1310                 this->abilityName_ == list.abilityName_ && this->moduleName_ == list.moduleName_;
1311         }
1312         friend struct SessionHasher;
1313     };
1314     struct SessionHasher {
operatorSessionHasher1315         size_t operator()(const SessionInfoList& sessionInfo) const
1316         {
1317             return std::hash<int32_t>()(sessionInfo.uid_) + std::hash<std::string>()(sessionInfo.bundleName_) +
1318                 std::hash<std::string>()(sessionInfo.abilityName_) + std::hash<std::string>()(sessionInfo.moduleName_);
1319         }
1320     };
1321     std::unordered_map<SessionInfoList, std::shared_ptr<AppExecFwk::AbilityInfo>, SessionHasher> abilityInfoMap_;
1322 
1323     /*
1324      * Window Property
1325      */
1326     void UpdateDarkColorModeToRS();
1327     struct DrawingSessionInfo {
1328         int32_t pid_ = 0;
1329         int32_t uid_ = 0;
1330     };
1331     std::unordered_map<uint64_t, DrawingSessionInfo> lastDrawingSessionInfoMap_;
1332 
1333     /*
1334      * Move Drag
1335      */
1336     std::mutex dragResizeTypeMutex_;
1337     DragResizeType globalDragResizeType_ = DragResizeType::RESIZE_TYPE_UNDEFINED;
1338     std::unordered_map<std::string, DragResizeType> appDragResizeTypeMap_;
1339     void GetEffectiveDragResizeType(DragResizeType& dragResizeType);
1340     WMError GetAppDragResizeTypeInner(const std::string& bundleName, DragResizeType& dragResizeType);
1341 
1342     /*
1343      * Specific Window
1344      */
1345     std::unordered_map<int32_t, NotifyCreateSubSessionFunc> createSubSessionFuncMap_;
1346     std::unordered_map<int32_t, std::vector<sptr<SceneSession>>> recoverSubSessionCacheMap_;
1347     std::unordered_map<int32_t, NotifyBindDialogSessionFunc> bindDialogTargetFuncMap_;
1348     std::unordered_map<int32_t, std::vector<sptr<SceneSession>>> recoverDialogSessionCacheMap_;
1349 
1350     /*
1351      * PC Window
1352      */
1353     std::mutex isWindowRectAutoSaveMapMutex_;
1354     std::unordered_map<std::string, bool> isWindowRectAutoSaveMap_;
1355 
1356     /*
1357      * Window Lifecycle
1358      */
1359     NotifyAppUseControlListFunc notifyAppUseControlListFunc_;
1360     std::unordered_map<int32_t, int32_t> visibleWindowCountMap_ GUARDED_BY(SCENE_GUARD);
1361     std::unordered_set<std::string> sessionLockedStateCacheSet_;
1362     std::shared_ptr<FfrtQueueHelper> ffrtQueueHelper_ = nullptr;
1363 
1364     /*
1365      * Window Pattern
1366      */
1367     std::unique_ptr<LruCache> snapshotLruCache_;
1368     std::size_t snapshotCapacity_ = 0;
1369     bool GetIconFromDesk(const SessionInfo& sessionInfo, std::string& startupPagePath) const;
1370 };
1371 } // namespace OHOS::Rosen
1372 
1373 #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_MANAGER_H
1374