• 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_SESSION_H
17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_H
18 #include <list>
19 #include <mutex>
20 #include <shared_mutex>
21 #include <vector>
22 
23 #include <event_handler.h>
24 
25 #include "accessibility_element_info.h"
26 #include "interfaces/include/ws_common.h"
27 #include "session/container/include/zidl/session_stage_interface.h"
28 #include "session/host/include/zidl/session_stub.h"
29 #include "session/host/include/scene_persistence.h"
30 #include "wm_common.h"
31 #include "occupied_area_change_info.h"
32 #include "window_visibility_info.h"
33 
34 namespace OHOS::MMI {
35 class PointerEvent;
36 class KeyEvent;
37 class AxisEvent;
38 enum class WindowArea;
39 } // namespace OHOS::MMI
40 
41 namespace OHOS::Media {
42 class PixelMap;
43 } // namespace OHOS::Media
44 
45 namespace OHOS::Rosen {
46 class RSSurfaceNode;
47 class RSTransaction;
48 class RSSyncTransactionController;
49 using NotifyPendingSessionActivationFunc = std::function<void(SessionInfo& info)>;
50 using NotifySessionStateChangeFunc = std::function<void(const SessionState& state)>;
51 using NotifyBufferAvailableChangeFunc = std::function<void(const bool isAvailable)>;
52 using NotifySessionStateChangeNotifyManagerFunc = std::function<void(int32_t persistentId, const SessionState& state)>;
53 using NotifyRequestFocusStatusNotifyManagerFunc =
54     std::function<void(int32_t persistentId, const bool isFocused, const bool byForeground)>;
55 using NotifyBackPressedFunc = std::function<void(const bool needMoveToBackground)>;
56 using NotifySessionFocusableChangeFunc = std::function<void(const bool isFocusable)>;
57 using NotifySessionTouchableChangeFunc = std::function<void(const bool touchable)>;
58 using NotifyClickFunc = std::function<void()>;
59 using NotifyTerminateSessionFunc = std::function<void(const SessionInfo& info)>;
60 using NotifyTerminateSessionFuncNew = std::function<void(const SessionInfo& info, bool needStartCaller)>;
61 using NotifyTerminateSessionFuncTotal = std::function<void(const SessionInfo& info, TerminateType terminateType)>;
62 using NofitySessionLabelUpdatedFunc = std::function<void(const std::string &label)>;
63 using NofitySessionIconUpdatedFunc = std::function<void(const std::string &iconPath)>;
64 using NotifySessionExceptionFunc = std::function<void(const SessionInfo& info, bool needRemoveSession)>;
65 using NotifySessionSnapshotFunc = std::function<void(const int32_t& persistentId)>;
66 using NotifyPendingSessionToForegroundFunc = std::function<void(const SessionInfo& info)>;
67 using NotifyPendingSessionToBackgroundForDelegatorFunc = std::function<void(const SessionInfo& info)>;
68 using NotifyCallingSessionUpdateRectFunc = std::function<void(const int32_t& persistentId)>;
69 using NotifyCallingSessionForegroundFunc = std::function<void(const int32_t& persistentId)>;
70 using NotifyCallingSessionBackgroundFunc = std::function<void()>;
71 using NotifyRaiseToTopForPointDownFunc = std::function<void()>;
72 using NotifyUIRequestFocusFunc = std::function<void()>;
73 using NotifyUILostFocusFunc = std::function<void()>;
74 using GetStateFromManagerFunc = std::function<bool(const ManagerState key)>;
75 using NotifySessionInfoLockedStateChangeFunc = std::function<void(const bool lockedState)>;
76 using NotifySystemSessionPointerEventFunc = std::function<void(std::shared_ptr<MMI::PointerEvent> pointerEvent)>;
77 using NotifySessionInfoChangeNotifyManagerFunc = std::function<void(int32_t persistentid)>;
78 using NotifySystemSessionKeyEventFunc = std::function<void(std::shared_ptr<MMI::KeyEvent> keyEvent)>;
79 
80 class ILifecycleListener {
81 public:
82     virtual void OnActivation() = 0;
83     virtual void OnConnect() = 0;
84     virtual void OnForeground() = 0;
85     virtual void OnBackground() = 0;
86     virtual void OnDisconnect() = 0;
87     virtual void OnExtensionDied() = 0;
88     virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
89         int64_t uiExtensionIdLevel) = 0;
90 };
91 
92 enum class LifeCycleTaskType : uint32_t {
93     START,
94     STOP
95 };
96 
97 class Session : public SessionStub {
98 public:
99     using Task = std::function<void()>;
100     explicit Session(const SessionInfo& info);
101     virtual ~Session() = default;
102 
103     void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler>& handler,
104         const std::shared_ptr<AppExecFwk::EventHandler>& exportHandler = nullptr);
105 
106     WSError Connect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
107         const std::shared_ptr<RSSurfaceNode>& surfaceNode, SystemSessionConfig& systemConfig,
108         sptr<WindowSessionProperty> property = nullptr, sptr<IRemoteObject> token = nullptr,
109         int32_t pid = -1, int32_t uid = -1) override;
110     WSError Reconnect(const sptr<ISessionStage>& sessionStage, const sptr<IWindowEventChannel>& eventChannel,
111         const std::shared_ptr<RSSurfaceNode>& surfaceNode, sptr<WindowSessionProperty> property = nullptr,
112         sptr<IRemoteObject> token = nullptr, int32_t pid = -1, int32_t uid = -1);
113     WSError Foreground(sptr<WindowSessionProperty> property) override;
114     WSError Background() override;
115     WSError Disconnect(bool isFromClient = false) override;
116     WSError Show(sptr<WindowSessionProperty> property) override;
117     WSError Hide() override;
118 
119     bool RegisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener);
120     bool UnregisterLifecycleListener(const std::shared_ptr<ILifecycleListener>& listener);
121 
122     void NotifyActivation();
123     void NotifyConnect();
124     void NotifyForeground();
125     void NotifyBackground();
126     void NotifyDisconnect();
127     void NotifyExtensionDied() override;
128     void NotifyTransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
129         int64_t uiExtensionIdLevel) override;
130 
131     virtual WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
132         bool needNotifyClient = true);
133     virtual WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
134 
135     virtual WSError TransferSearchElementInfo(int64_t elementId, int32_t mode, int64_t baseParent,
136         std::list<Accessibility::AccessibilityElementInfo>& infos);
137     virtual WSError TransferSearchElementInfosByText(int64_t elementId, const std::string& text, int64_t baseParent,
138         std::list<Accessibility::AccessibilityElementInfo>& infos);
139     virtual WSError TransferFindFocusedElementInfo(int64_t elementId, int32_t focusType, int64_t baseParent,
140         Accessibility::AccessibilityElementInfo& info);
141     virtual WSError TransferFocusMoveSearch(int64_t elementId, int32_t direction, int64_t baseParent,
142         Accessibility::AccessibilityElementInfo& info);
NotifyClientToUpdateRect(std::shared_ptr<RSTransaction> rsTransaction)143     virtual WSError NotifyClientToUpdateRect(std::shared_ptr<RSTransaction> rsTransaction) { return WSError::WS_OK; }
144     WSError TransferBackPressedEventForConsumed(bool& isConsumed);
145     WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed);
146     WSError TransferFocusActiveEvent(bool isFocusActive);
147     WSError TransferFocusStateEvent(bool focusState);
148     virtual WSError TransferExecuteAction(int64_t elementId, const std::map<std::string, std::string>& actionArguments,
149         int32_t action, int64_t baseParent);
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)150     virtual WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) { return WSError::WS_OK; }
151 
152     int32_t GetPersistentId() const;
153     std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const;
154     void SetLeashWinSurfaceNode(std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode);
155     std::shared_ptr<RSSurfaceNode> GetLeashWinSurfaceNode() const;
156     std::shared_ptr<Media::PixelMap> GetSnapshot() const;
157     std::shared_ptr<Media::PixelMap> Snapshot(const float scaleParam = 0.0f) const;
158     SessionState GetSessionState() const;
159     virtual void SetSessionState(SessionState state);
160     void SetSessionInfoAncoSceneState(int32_t ancoSceneState);
161     void SetSessionInfoTime(const std::string& time);
162     void SetSessionInfoAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo>& abilityInfo);
163     void SetSessionInfoWant(const std::shared_ptr<AAFwk::Want>& want);
164     void SetSessionInfoPersistentId(int32_t persistentId);
165     void SetSessionInfoCallerPersistentId(int32_t callerPersistentId);
166     void SetSessionInfoContinueState(ContinueState state);
167     void SetSessionInfoLockedState(bool lockedState);
168     void SetSessionInfoIsClearSession(bool isClearSession);
169     void SetSessionInfoAffinity(std::string affinity);
170     void GetCloseAbilityWantAndClean(AAFwk::Want& outWant);
171     void SetSessionInfo(const SessionInfo& info);
172     const SessionInfo& GetSessionInfo() const;
173     void SetScreenId(uint64_t screenId);
174     WindowType GetWindowType() const;
175     float GetAspectRatio() const;
176     WSError SetAspectRatio(float ratio) override;
177     WSError SetSessionProperty(const sptr<WindowSessionProperty>& property) override;
178     sptr<WindowSessionProperty> GetSessionProperty() const;
179     void SetSessionRect(const WSRect& rect);
180     WSRect GetSessionRect() const;
181     void SetSessionRequestRect(const WSRect& rect);
182     WSRect GetSessionRequestRect() const;
183 
184     virtual WSError SetActive(bool active);
185     virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason,
186         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr);
187     WSError UpdateDensity();
188 
189     void SetShowRecent(bool showRecent);
190     void SetSystemActive(bool systemActive);
191     bool GetShowRecent() const;
192     void SetOffset(float x, float y);
193     float GetOffsetX() const;
194     float GetOffsetY() const;
195     void SetBounds(const WSRectF& bounds);
196     WSRectF GetBounds();
197     void SetBufferAvailable(bool bufferAvailable);
198     bool GetBufferAvailable() const;
199     void SetNeedSnapshot(bool needSnapshot);
200 
201     void SetPendingSessionActivationEventListener(const NotifyPendingSessionActivationFunc& func);
202     void SetTerminateSessionListener(const NotifyTerminateSessionFunc& func);
203     WSError TerminateSessionNew(const sptr<AAFwk::SessionInfo> info, bool needStartCaller);
204     void SetTerminateSessionListenerNew(const NotifyTerminateSessionFuncNew& func);
205     void SetSessionExceptionListener(const NotifySessionExceptionFunc& func, bool fromJsScene);
206     void SetSessionSnapshotListener(const NotifySessionSnapshotFunc& func);
207     WSError TerminateSessionTotal(const sptr<AAFwk::SessionInfo> info, TerminateType terminateType);
208     void SetTerminateSessionListenerTotal(const NotifyTerminateSessionFuncTotal& func);
209     WSError Clear();
210     WSError SetSessionLabel(const std::string &label);
211     void SetUpdateSessionLabelListener(const NofitySessionLabelUpdatedFunc& func);
212     WSError SetSessionIcon(const std::shared_ptr<Media::PixelMap> &icon);
213     void SetUpdateSessionIconListener(const NofitySessionIconUpdatedFunc& func);
214     void SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& func);
215     void SetBufferAvailableChangeListener(const NotifyBufferAvailableChangeFunc& func);
216     void UnregisterSessionChangeListeners();
217     void SetSessionStateChangeNotifyManagerListener(const NotifySessionStateChangeNotifyManagerFunc& func);
218     void SetSessionInfoChangeNotifyManagerListener(const NotifySessionInfoChangeNotifyManagerFunc& func);
219     void SetRequestFocusStatusNotifyManagerListener(const NotifyRequestFocusStatusNotifyManagerFunc& func);
220     void SetNotifyUIRequestFocusFunc(const NotifyUIRequestFocusFunc& func);
221     void SetNotifyUILostFocusFunc(const NotifyUILostFocusFunc& func);
222     void SetGetStateFromManagerListener(const GetStateFromManagerFunc& func);
223 
224     void SetSystemConfig(const SystemSessionConfig& systemConfig);
225     void SetSnapshotScale(const float snapshotScale);
226     void SetBackPressedListenser(const NotifyBackPressedFunc& func);
227     WSError ProcessBackEvent(); // send back event to session_stage
228     WSError MarkProcessed(int32_t eventId) override;
229 
230     sptr<ScenePersistence> GetScenePersistence() const;
231     void SetParentSession(const sptr<Session>& session);
232     sptr<Session> GetParentSession() const;
233     void BindDialogToParentSession(const sptr<Session>& session);
234     void RemoveDialogToParentSession(const sptr<Session>& session);
235     std::vector<sptr<Session>> GetDialogVector() const;
236     void ClearDialogVector();
237     WSError NotifyDestroy();
238     WSError NotifyCloseExistPipWindow();
239 
240     void SetPendingSessionToForegroundListener(const NotifyPendingSessionToForegroundFunc& func);
241     WSError PendingSessionToForeground();
242     void SetPendingSessionToBackgroundForDelegatorListener(const NotifyPendingSessionToBackgroundForDelegatorFunc&
243         func);
244     WSError PendingSessionToBackgroundForDelegator();
245 
246     void SetSessionFocusableChangeListener(const NotifySessionFocusableChangeFunc& func);
247     void SetSessionTouchableChangeListener(const NotifySessionTouchableChangeFunc& func);
248     void SetClickListener(const NotifyClickFunc& func);
249     void NotifySessionFocusableChange(bool isFocusable);
250     void NotifySessionTouchableChange(bool touchable);
251     void NotifyClick();
252     void NotifyRequestFocusStatusNotifyManager(bool isFocused, bool byForeground = true);
253     void NotifyUIRequestFocus();
254     virtual void NotifyUILostFocus();
255     bool GetStateFromManager(const ManagerState key);
256     void PresentFoucusIfNeed(int32_t pointerAcrion);
257     WSError UpdateFocus(bool isFocused);
258     WSError NotifyFocusStatus(bool isFocused);
259     WSError UpdateWindowMode(WindowMode mode);
260     WSError SetSystemSceneBlockingFocus(bool blocking);
261     bool GetBlockingFocus() const;
262     WSError SetFocusable(bool isFocusable);
263     bool NeedNotify() const;
264     void SetNeedNotify(bool needNotify);
265     bool GetFocusable() const;
266     WSError SetTouchable(bool touchable);
267     bool GetTouchable() const;
268     virtual void SetSystemTouchable(bool touchable);
269     bool GetSystemTouchable() const;
270     virtual WSError SetVisible(bool isVisible);
271     bool GetVisible() const;
272     WSError SetVisibilityState(WindowVisibilityState state);
273     WindowVisibilityState GetVisibilityState() const;
274     WSError SetDrawingContentState(bool isRSDrawing);
275     bool GetDrawingContentState() const;
276     WSError SetBrightness(float brightness);
277     float GetBrightness() const;
278     void NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info);
279     void SetSessionInfoLockedStateChangeListener(const NotifySessionInfoLockedStateChangeFunc& func);
280     void NotifySessionInfoLockedStateChange(bool lockedState);
281 
282     bool IsSessionValid() const;
283     bool IsActive() const;
284     bool IsSystemActive() const;
285     bool IsSystemSession() const;
286     bool IsTerminated() const;
287     bool IsSessionForeground() const;
288 
289     sptr<IRemoteObject> dialogTargetToken_ = nullptr;
290     int32_t GetWindowId() const;
291     void SetAppIndex(const int32_t appIndex);
292     int32_t GetAppIndex() const;
293     void SetCallingPid(int32_t id);
294     void SetCallingUid(int32_t id);
295     int32_t GetCallingPid() const;
296     int32_t GetCallingUid() const;
297     void SetAbilityToken(sptr<IRemoteObject> token);
298     sptr<IRemoteObject> GetAbilityToken() const;
299     WindowMode GetWindowMode();
300     virtual void SetZOrder(uint32_t zOrder);
301     uint32_t GetZOrder() const;
302     void SetUINodeId(uint32_t uiNodeId);
303     uint32_t GetUINodeId() const;
304     virtual void SetFloatingScale(float floatingScale);
305     float GetFloatingScale() const;
306     void SetSCBKeepKeyboard(bool scbKeepKeyboardFlag);
307     bool GetSCBKeepKeyboardFlag() const;
308     virtual void SetScale(float scaleX, float scaleY, float pivotX, float pivotY);
309     float GetScaleX() const;
310     float GetScaleY() const;
311     float GetPivotX() const;
312     float GetPivotY() const;
313 
314     void SetNotifyCallingSessionUpdateRectFunc(const NotifyCallingSessionUpdateRectFunc& func);
315     void NotifyCallingSessionUpdateRect();
316     void SetNotifyCallingSessionForegroundFunc(const NotifyCallingSessionForegroundFunc& func);
317     void NotifyCallingSessionForeground();
318     void SetNotifyCallingSessionBackgroundFunc(const NotifyCallingSessionBackgroundFunc& func);
319     void SetRaiseToAppTopForPointDownFunc(const NotifyRaiseToTopForPointDownFunc& func);
320     void NotifyCallingSessionBackground();
321     void NotifyScreenshot();
322     void RemoveLifeCycleTask(const LifeCycleTaskType &taskType);
323     void PostLifeCycleTask(Task &&task, const std::string &name, const LifeCycleTaskType &taskType);
324     WSError UpdateMaximizeMode(bool isMaximize);
325     void NotifySessionForeground(uint32_t reason, bool withAnimation);
326     void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits);
327     void HandlePointDownDialog();
328     bool CheckDialogOnForeground();
329     void PresentFocusIfPointDown();
330     void ResetSnapshot();
331     std::shared_ptr<Media::PixelMap> GetSnapshotPixelMap(const float oriScale = 1.0f, const float newScale = 1.0f);
GetTouchHotAreas()332     virtual std::vector<Rect> GetTouchHotAreas() const
333     {
334         return std::vector<Rect>();
335     }
336 
337     virtual void SetTouchHotAreas(const std::vector<Rect>& touchHotAreas);
338 
SetVpr(float vpr)339     void SetVpr(float vpr)
340     {
341         vpr_ = vpr;
342     }
343 
344     bool operator==(const Session* session) const
345     {
346         if (session == nullptr) {
347             return false;
348         }
349         return (persistentId_ == session->persistentId_ && callingPid_ == session->callingPid_);
350     }
351 
352     bool operator!=(const Session* session) const
353     {
354         return !this->operator==(session);
355     }
356 
HandleStyleEvent(MMI::WindowArea area)357     virtual void HandleStyleEvent(MMI::WindowArea area) {};
358     WSError SetPointerStyle(MMI::WindowArea area);
359     const char* DumpPointerWindowArea(MMI::WindowArea area) const;
360     WSRectF UpdateHotRect(const WSRect& rect);
361     WSError RaiseToAppTopForPointDown();
362 
363     void NotifyForegroundInteractiveStatus(bool interactive);
364     WSError UpdateTitleInTargetPos(bool isShow, int32_t height);
365     void SetNotifySystemSessionPointerEventFunc(const NotifySystemSessionPointerEventFunc& func);
366     void SetNotifySystemSessionKeyEventFunc(const NotifySystemSessionKeyEventFunc& func);
367     bool IsSystemInput();
368     bool GetForegroundInteractiveStatus() const;
369     virtual void SetForegroundInteractiveStatus(bool interactive);
370 
371 protected:
372     class SessionLifeCycleTask : public virtual RefBase {
373     public:
SessionLifeCycleTask(const Task & task,const std::string & name,const LifeCycleTaskType & type)374         SessionLifeCycleTask(const Task &task, const std::string &name, const LifeCycleTaskType &type)
375             : task(task), name(name), type(type) {}
376         Task task;
377         const std::string name;
378         LifeCycleTaskType type;
379         std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
380         bool running = false;
381     };
382     void StartLifeCycleTask(sptr<SessionLifeCycleTask> lifeCycleTask);
383     void GeneratePersistentId(bool isExtension, int32_t persistentId);
384     virtual void UpdateSessionState(SessionState state);
385     void NotifySessionStateChange(const SessionState& state);
386     void UpdateSessionTouchable(bool touchable);
387 
388     WSRectF UpdateTopBottomArea(const WSRectF& rect, MMI::WindowArea area);
389     WSRectF UpdateLeftRightArea(const WSRectF& rect, MMI::WindowArea area);
390     WSRectF UpdateInnerAngleArea(const WSRectF& rect, MMI::WindowArea area);
391     void UpdatePointerArea(const WSRect& rect);
392     bool CheckPointerEventDispatch(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const;
393     bool CheckKeyEventDispatch(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const;
394     bool IsTopDialog() const;
395     bool NeedSystemPermission(WindowType type);
396     void HandlePointDownDialog(int32_t pointAction);
397 
398     void PostTask(Task&& task, const std::string& name = "sessionTask", int64_t delayTime = 0);
399     void PostExportTask(Task&& task, const std::string& name = "sessionExportTask", int64_t delayTime = 0);
400     template<typename SyncTask, typename Return = std::invoke_result_t<SyncTask>>
401     Return PostSyncTask(SyncTask&& task, const std::string& name = "sessionTask")
402     {
403         Return ret;
404         if (!handler_ || handler_->GetEventRunner()->IsCurrentRunnerThread()) {
405             StartTraceForSyncTask(name);
406             ret = task();
407             FinishTraceForSyncTask();
408             return ret;
409         }
410         auto syncTask = [&ret, &task, name]() {
411             StartTraceForSyncTask(name);
412             ret = task();
413             FinishTraceForSyncTask();
414         };
415         handler_->PostSyncTask(std::move(syncTask), name, AppExecFwk::EventQueue::Priority::IMMEDIATE);
416         return ret;
417     }
418 
419     int32_t persistentId_ = INVALID_SESSION_ID;
420     SessionState state_ = SessionState::STATE_DISCONNECT;
421     SessionInfo sessionInfo_;
422     std::recursive_mutex sessionInfoMutex_;
423     std::shared_ptr<RSSurfaceNode> surfaceNode_;
424     std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode_;
425     std::shared_ptr<Media::PixelMap> snapshot_;
426     sptr<ISessionStage> sessionStage_;
427     std::mutex lifeCycleTaskQueueMutex_;
428     std::list<sptr<SessionLifeCycleTask>> lifeCycleTaskQueue_;
429     bool isActive_ = false;
430     bool isSystemActive_ = false;
431     WSRect winRect_;
432     WSRectF bounds_;
433     float offsetX_ = 0.0f;
434     float offsetY_ = 0.0f;
435     bool isVisible_ = false;
436 
437     NotifyPendingSessionActivationFunc pendingSessionActivationFunc_;
438     NotifySessionStateChangeFunc sessionStateChangeFunc_;
439     NotifyBufferAvailableChangeFunc bufferAvailableChangeFunc_;
440     NotifySessionInfoChangeNotifyManagerFunc sessionInfoChangeNotifyManagerFunc_;
441     NotifySessionStateChangeNotifyManagerFunc sessionStateChangeNotifyManagerFunc_;
442     NotifyRequestFocusStatusNotifyManagerFunc requestFocusStatusNotifyManagerFunc_;
443     NotifyUIRequestFocusFunc requestFocusFunc_;
444     NotifyUILostFocusFunc lostFocusFunc_;
445     GetStateFromManagerFunc getStateFromManagerFunc_;
446     NotifyBackPressedFunc backPressedFunc_;
447     NotifySessionFocusableChangeFunc sessionFocusableChangeFunc_;
448     NotifySessionTouchableChangeFunc sessionTouchableChangeFunc_;
449     NotifyClickFunc clickFunc_;
450     NotifyTerminateSessionFunc terminateSessionFunc_;
451     NotifyTerminateSessionFuncNew terminateSessionFuncNew_;
452     NotifyTerminateSessionFuncTotal terminateSessionFuncTotal_;
453     NofitySessionLabelUpdatedFunc updateSessionLabelFunc_;
454     NofitySessionIconUpdatedFunc updateSessionIconFunc_;
455     std::shared_ptr<NotifySessionExceptionFunc> sessionExceptionFunc_;
456     std::shared_ptr<NotifySessionExceptionFunc> jsSceneSessionExceptionFunc_;
457     NotifySessionSnapshotFunc notifySessionSnapshotFunc_;
458     NotifyPendingSessionToForegroundFunc pendingSessionToForegroundFunc_;
459     NotifyPendingSessionToBackgroundForDelegatorFunc pendingSessionToBackgroundForDelegatorFunc_;
460     NotifyCallingSessionUpdateRectFunc notifyCallingSessionUpdateRectFunc_;
461     NotifyCallingSessionForegroundFunc notifyCallingSessionForegroundFunc_;
462     NotifyCallingSessionBackgroundFunc notifyCallingSessionBackgroundFunc_;
463     NotifyRaiseToTopForPointDownFunc raiseToTopForPointDownFunc_;
464     NotifySessionInfoLockedStateChangeFunc sessionInfoLockedStateChangeFunc_;
465     NotifySystemSessionPointerEventFunc systemSessionPointerEventFunc_;
466     NotifySystemSessionKeyEventFunc systemSessionKeyEventFunc_;
467     SystemSessionConfig systemConfig_;
468     bool needSnapshot_ = false;
469     float snapshotScale_ = 0.5;
470     sptr<ScenePersistence> scenePersistence_ = nullptr;
471     uint32_t zOrder_ = 0;
472     uint32_t uiNodeId_ = 0;
473     bool isFocused_ = false;
474     bool blockingFocus_ {false};
475     float aspectRatio_ = 0.0f;
476     std::map<MMI::WindowArea, WSRectF> windowAreas_;
477     bool isTerminating = false;
478     float floatingScale_ = 1.0f;
479     bool scbKeepKeyboardFlag_ = false;
480     bool isDirty_ = false;
481     float scaleX_ = 1.0f;
482     float scaleY_ = 1.0f;
483     float pivotX_ = 0.0f;
484     float pivotY_ = 0.0f;
485     mutable std::mutex dialogVecMutex_;
486     std::vector<sptr<Session>> dialogVec_;
487     sptr<Session> parentSession_;
488 
489     mutable std::mutex pointerEventMutex_;
490     mutable std::mutex keyEventMutex_;
491 
492 private:
493     void HandleDialogForeground();
494     void HandleDialogBackground();
495     void NotifyPointerEventToRs(int32_t pointAction);
496     void NotifySessionInfoChange();
497     WSError HandleSubWindowClick(int32_t action);
498 
499     template<typename T>
500     bool RegisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener);
501     template<typename T>
502     bool UnregisterListenerLocked(std::vector<std::shared_ptr<T>>& holder, const std::shared_ptr<T>& listener);
503 
504     template<typename T1, typename T2, typename Ret>
505     using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type;
506     template<typename T>
GetListeners()507     inline EnableIfSame<T, ILifecycleListener, std::vector<std::weak_ptr<ILifecycleListener>>> GetListeners()
508     {
509         std::vector<std::weak_ptr<ILifecycleListener>> lifecycleListeners;
510         {
511             std::lock_guard<std::recursive_mutex> lock(lifecycleListenersMutex_);
512             for (auto& listener : lifecycleListeners_) {
513                 lifecycleListeners.push_back(listener);
514             }
515         }
516         return lifecycleListeners;
517     }
518 
519     std::recursive_mutex lifecycleListenersMutex_;
520     std::vector<std::shared_ptr<ILifecycleListener>> lifecycleListeners_;
521     sptr<IWindowEventChannel> windowEventChannel_;
522     std::shared_ptr<AppExecFwk::EventHandler> handler_;
523     std::shared_ptr<AppExecFwk::EventHandler> mainHandler_;
524     std::shared_ptr<AppExecFwk::EventHandler> exportHandler_;
525 
526     mutable std::shared_mutex propertyMutex_;
527     sptr<WindowSessionProperty> property_;
528 
529     bool showRecent_ = false;
530     bool bufferAvailable_ = false;
531     WSRect preRect_;
532     int32_t callingPid_ = -1;
533     int32_t callingUid_ = -1;
534     int32_t appIndex_ = { 0 };
535     std::string callingBundleName_ { "unknow" };
536     bool isRSVisible_ {false};
537     WindowVisibilityState visibilityState_ { WINDOW_LAYER_STATE_MAX};
538     bool needNotify_ {true};
539     bool isRSDrawing_ {false};
540     sptr<IRemoteObject> abilityToken_ = nullptr;
541     float vpr_ { 1.5f };
542     bool systemTouchable_ { true };
543     std::atomic_bool foregroundInteractiveStatus_ { true };
544 };
545 } // namespace OHOS::Rosen
546 
547 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_H
548