From 538b4bb931b5ed076ebb55ee294030ec0cb13208 Mon Sep 17 00:00:00 2001 From: l00574490 Date: Mon, 13 Nov 2023 16:17:48 +0800 Subject: [PATCH] No.2 Refactoring of sub window and system window Signed-off-by: l00574490 Change-Id: Idc2451fe2cfb1c21cb9cf50015e4da2230a6c506 --- .../scenesessionmanager_fuzzer.cpp | 4 +- .../sessioninterface_fuzzer.cpp | 7 - .../js_scene_session.cpp | 33 +-- .../scene_session_manager/js_scene_session.h | 4 +- .../js_scene_session_manager.cpp | 30 +-- .../js_scene_session_manager.h | 4 +- .../session/host/include/scene_session.h | 163 +++++++-------- window_scene/session/host/include/session.h | 4 +- .../session/host/include/sub_session.h | 3 + .../session/host/include/system_session.h | 7 + .../host/include/zidl/session_interface.h | 7 +- .../include/zidl/session_ipc_interface_code.h | 4 +- .../session/host/include/zidl/session_proxy.h | 7 +- .../session/host/include/zidl/session_stub.h | 4 +- .../session/host/src/main_session.cpp | 26 +++ .../session/host/src/scb_system_session.cpp | 9 + .../session/host/src/scene_session.cpp | 188 ++---------------- window_scene/session/host/src/session.cpp | 14 +- window_scene/session/host/src/sub_session.cpp | 47 +++++ .../session/host/src/system_session.cpp | 76 +++++++ .../session/host/src/zidl/session_proxy.cpp | 127 +++++------- .../session/host/src/zidl/session_stub.cpp | 79 +++----- .../include/scene_session_manager.h | 99 ++++----- .../session_manager/include/session_manager.h | 9 - .../zidl/scene_session_manager_interface.h | 9 - .../zidl/scene_session_manager_proxy.h | 4 +- .../src/scene_session_manager.cpp | 143 ++++++++++--- .../session_manager/src/session_manager.cpp | 75 ------- .../src/zidl/scene_session_manager_proxy.cpp | 5 +- .../src/zidl/scene_session_manager_stub.cpp | 4 +- window_scene/test/mock/mock_session_stub.h | 4 +- .../unittest/scene_session_manager_test.cpp | 24 +-- .../test/unittest/scene_session_test.cpp | 95 ++------- .../test/unittest/session_proxy_test.cpp | 15 -- .../test/unittest/session_stub_test.cpp | 4 - window_scene/test/unittest/session_test.cpp | 73 ++----- wm/include/window_adapter.h | 12 ++ wm/src/window_adapter.cpp | 40 ++++ wm/src/window_scene_session_impl.cpp | 71 ++++--- wm/src/window_session_impl.cpp | 6 +- .../include/zidl/window_manager_interface.h | 30 ++- 41 files changed, 753 insertions(+), 816 deletions(-) diff --git a/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp b/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp index 964fc01c18..5205d3d5b4 100644 --- a/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp +++ b/test/fuzztest/window_scene/scenesessionmanager_fuzzer/scenesessionmanager_fuzzer.cpp @@ -238,7 +238,7 @@ void ProxyInterfaceFuzzTestPart1(const uint8_t* data, size_t size) sptr property = UnmarshallingDataTo(data, size); WSPropertyChangeAction action = source.GetObject(); - proxy->UpdateProperty(property, action); + proxy->UpdateSessionProperty(property, action); FocusChangeInfo focusInfo; proxy->GetFocusWindowInfo(focusInfo); @@ -356,7 +356,7 @@ void ProxyInterfaceFuzzTestPart4(const uint8_t* data, size_t size) proxy->SetSessionContinueState(token, continueState); uint64_t persistentId = source.GetObject(); - proxy->BindDialogTarget(persistentId, token); + proxy->BindDialogSessionTarget(persistentId, token); proxy->PendingSessionToForeground(token); proxy->PendingSessionToBackgroundForDelegator(token); diff --git a/test/fuzztest/window_scene/sessioninterface_fuzzer/sessioninterface_fuzzer.cpp b/test/fuzztest/window_scene/sessioninterface_fuzzer/sessioninterface_fuzzer.cpp index efd9052800..4ed425e2f9 100644 --- a/test/fuzztest/window_scene/sessioninterface_fuzzer/sessioninterface_fuzzer.cpp +++ b/test/fuzztest/window_scene/sessioninterface_fuzzer/sessioninterface_fuzzer.cpp @@ -116,10 +116,6 @@ void IPCSpecificInterfaceFuzzTest1(sptr proxy, MessageParcel& sen sendData, reply, option); proxy->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT), sendData, reply, option); - proxy->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), - sendData, reply, option); - proxy->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION), - sendData, reply, option); proxy->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP), sendData, reply, option); proxy->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_BACKPRESSED), @@ -216,9 +212,6 @@ void ProxyInterfaceFuzzTestPart1(const uint8_t* data, size_t size) bool needMoveToBackground = source.GetObject(); proxy->RequestSessionBack(needMoveToBackground); - - int32_t persistentId = source.GetObject(); - proxy->DestroyAndDisconnectSpecificSession(persistentId); } void ProxyInterfaceFuzzTestPart2(const uint8_t* data, size_t size) diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp index 61243fbc9b..3dbd57cc09 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.cpp @@ -28,7 +28,7 @@ const std::string PENDING_SCENE_CB = "pendingSceneSessionActivation"; const std::string SESSION_STATE_CHANGE_CB = "sessionStateChange"; const std::string SESSION_EVENT_CB = "sessionEvent"; const std::string SESSION_RECT_CHANGE_CB = "sessionRectChange"; -const std::string CREATE_SPECIFIC_SCENE_CB = "createSpecificSession"; +const std::string CREATE_SUB_SESSION_CB = "createSpecificSession"; const std::string BIND_DIALOG_TARGET_CB = "bindDialogTarget"; const std::string RAISE_TO_TOP_CB = "raiseToTop"; const std::string RAISE_TO_TOP_POINT_DOWN_CB = "raiseToTopForPointDown"; @@ -118,7 +118,7 @@ JsSceneSession::JsSceneSession(napi_env env, const sptr& session) { SESSION_STATE_CHANGE_CB, &JsSceneSession::ProcessSessionStateChangeRegister }, { SESSION_EVENT_CB, &JsSceneSession::ProcessSessionEventRegister }, { SESSION_RECT_CHANGE_CB, &JsSceneSession::ProcessSessionRectChangeRegister }, - { CREATE_SPECIFIC_SCENE_CB, &JsSceneSession::ProcessCreateSpecificSessionRegister }, + { CREATE_SUB_SESSION_CB, &JsSceneSession::ProcessCreateSubSessionRegister }, { BIND_DIALOG_TARGET_CB, &JsSceneSession::ProcessBindDialogTargetRegister }, { RAISE_TO_TOP_CB, &JsSceneSession::ProcessRaiseToTopRegister }, { RAISE_TO_TOP_POINT_DOWN_CB, &JsSceneSession::ProcessRaiseToTopForPointDownRegister }, @@ -171,6 +171,7 @@ JsSceneSession::~JsSceneSession() return; } session->UnregisterSessionChangeListeners(); + SceneSessionManager::GetInstance().UnregisterCreateSubSessionListener(session->GetPersistentId()); } void JsSceneSession::ProcessWindowDragHotAreaRegister() @@ -307,16 +308,18 @@ void JsSceneSession::ProcessSessionStateChangeRegister() WLOGFD("ProcessSessionStateChangeRegister success"); } -void JsSceneSession::ProcessCreateSpecificSessionRegister() +void JsSceneSession::ProcessCreateSubSessionRegister() { - auto sessionchangeCallback = sessionchangeCallback_.promote(); - if (sessionchangeCallback == nullptr) { - WLOGFE("sessionchangeCallback is nullptr"); + NotifyCreateSubSessionFunc func = [this](const sptr& sceneSession) { + this->OnCreateSubSession(sceneSession); + }; + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("session is nullptr"); return; } - sessionchangeCallback->onCreateSpecificSession_ = std::bind(&JsSceneSession::OnCreateSpecificSession, - this, std::placeholders::_1); - WLOGFD("ProcessCreateSpecificSessionRegister success"); + SceneSessionManager::GetInstance().RegisterCreateSubSessionListener(session->GetPersistentId(), func); + WLOGFD("ProcessCreateSubSessionRegister success, id: %{public}d", session->GetPersistentId()); } void JsSceneSession::ProcessBindDialogTargetRegister() @@ -982,20 +985,20 @@ napi_value JsSceneSession::OnUpdateSizeChangeReason(napi_env env, napi_callback_ return NapiGetUndefined(env); } -void JsSceneSession::OnCreateSpecificSession(const sptr& sceneSession) +void JsSceneSession::OnCreateSubSession(const sptr& sceneSession) { - WLOGFD("OnCreateSpecificSession"); if (sceneSession == nullptr) { - WLOGFI("[NAPI]sceneSession is nullptr"); + WLOGFE("[NAPI]sceneSession is nullptr"); return; } - WLOGFD("[NAPI]OnCreateSpecificSession"); - auto iter = jsCbMap_.find(CREATE_SPECIFIC_SCENE_CB); + auto iter = jsCbMap_.find(CREATE_SUB_SESSION_CB); if (iter == jsCbMap_.end()) { + WLOGFE("[NAPI]Can't find callback, id: %{public}d", sceneSession->GetPersistentId()); return; } + WLOGFD("[NAPI]OnCreateSubSession, id: %{public}d", sceneSession->GetPersistentId()); auto jsCallBack = iter->second; wptr weakSession(sceneSession); auto task = [this, weakSession, jsCallBack, env = env_]() { @@ -1009,7 +1012,7 @@ void JsSceneSession::OnCreateSpecificSession(const sptr& sceneSess WLOGFE("[NAPI]jsSceneSessionObj or jsCallBack is nullptr"); return; } - WLOGFI("CreateJsSceneSessionObject success"); + WLOGFI("CreateJsSceneSessionObject success, id: %{public}d", specificSession->GetPersistentId()); napi_value argv[] = {jsSceneSessionObj}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h index 1c7c9eeb1e..8d74771a86 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session.h @@ -68,7 +68,7 @@ private: void ProcessPendingSceneSessionActivationRegister(); void ProcessSessionStateChangeRegister(); void ProcessSessionEventRegister(); - void ProcessCreateSpecificSessionRegister(); + void ProcessCreateSubSessionRegister(); void ProcessBindDialogTargetRegister(); void ProcessSessionRectChangeRegister(); void ProcessRaiseToTopRegister(); @@ -101,7 +101,7 @@ private: void PendingSessionActivationInner(SessionInfo& info); void OnSessionStateChange(const SessionState& state); void OnSessionEvent(uint32_t eventId); - void OnCreateSpecificSession(const sptr& sceneSession); + void OnCreateSubSession(const sptr& sceneSession); void OnBindDialogTarget(const sptr& sceneSession); void OnSessionRectChange(const WSRect& rect, const SizeChangeReason& reason = SizeChangeReason::UNDEFINED); void OnRaiseToTop(); diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp index ab429c5fe7..44b0754078 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.cpp @@ -44,7 +44,7 @@ constexpr int WAIT_FOR_SECONDS = 2; constexpr int MIN_ARG_COUNT = 3; constexpr int ARG_INDEX_1 = 1; constexpr int ARG_INDEX_2 = 2; -const std::string CREATE_SPECIFIC_SCENE_CB = "createSpecificSession"; +const std::string CREATE_SYSTEM_SESSION_CB = "createSpecificSession"; const std::string STATUS_BAR_ENABLED_CHANGE_CB = "statusBarEnabledChange"; const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange"; const std::string OUTSIDE_DOWN_EVENT_CB = "outsideDownEvent"; @@ -118,30 +118,30 @@ napi_value JsSceneSessionManager::Init(napi_env env, napi_value exportObj) JsSceneSessionManager::JsSceneSessionManager(napi_env env) : env_(env) { listenerFunc_ = { - { CREATE_SPECIFIC_SCENE_CB, &JsSceneSessionManager::ProcessCreateSpecificSessionRegister }, + { CREATE_SYSTEM_SESSION_CB, &JsSceneSessionManager::ProcessCreateSystemSessionRegister }, { STATUS_BAR_ENABLED_CHANGE_CB, &JsSceneSessionManager::ProcessStatusBarEnabledChangeListener}, + { OUTSIDE_DOWN_EVENT_CB, &JsSceneSessionManager::ProcessOutsideDownEvent }, + { SHIFT_FOCUS_CB, &JsSceneSessionManager::ProcessShiftFocus }, + { SHOW_PIP_MAIN_WINDOW_CB, &JsSceneSessionManager::ProcessShowPiPMainWindow }, { GESTURE_NAVIGATION_ENABLED_CHANGE_CB, &JsSceneSessionManager::ProcessGestureNavigationEnabledChangeListener }, - { OUTSIDE_DOWN_EVENT_CB, &JsSceneSessionManager::ProcessOutsideDownEvent }, - { SHIFT_FOCUS_CB, &JsSceneSessionManager::ProcessShiftFocus }, - { SHOW_PIP_MAIN_WINDOW_CB, &JsSceneSessionManager::ProcessShowPiPMainWindow }, }; taskScheduler_ = std::make_shared(env); } -void JsSceneSessionManager::OnCreateSpecificSession(const sptr& sceneSession) +void JsSceneSessionManager::OnCreateSystemSession(const sptr& sceneSession) { if (sceneSession == nullptr) { WLOGFI("[NAPI]sceneSession is nullptr"); return; } - - WLOGFD("[NAPI]OnCreateSpecificSession"); - auto iter = jsCbMap_.find(CREATE_SPECIFIC_SCENE_CB); + auto iter = jsCbMap_.find(CREATE_SYSTEM_SESSION_CB); if (iter == jsCbMap_.end()) { + WLOGFE("[NAPI]Can't find callback, id: %{public}d", sceneSession->GetPersistentId()); return; } + WLOGFD("[NAPI]OnCreateSystemSession, id: %{public}d", sceneSession->GetPersistentId()); auto jsCallBack = iter->second; wptr weakSession(sceneSession); auto task = [this, weakSession, jsCallBack, env = env_]() { @@ -158,7 +158,7 @@ void JsSceneSessionManager::OnCreateSpecificSession(const sptr& sc napi_value argv[] = {jsSceneSessionObj}; napi_call_function(env, NapiGetUndefined(env), jsCallBack->GetNapiValue(), ArraySize(argv), argv, nullptr); }; - taskScheduler_->PostMainThreadTask(task, "OnCreateSpecificSession"); + taskScheduler_->PostMainThreadTask(task, "OnCreateSystemSession"); } void JsSceneSessionManager::OnStatusBarEnabledUpdate(bool enable) @@ -251,13 +251,13 @@ void JsSceneSessionManager::OnShowPiPMainWindow(int32_t persistentId) taskScheduler_->PostMainThreadTask(task, "OnShowPiPMainWindow, persistentId:" + std::to_string(persistentId)); } -void JsSceneSessionManager::ProcessCreateSpecificSessionRegister() +void JsSceneSessionManager::ProcessCreateSystemSessionRegister() { - NotifyCreateSpecificSessionFunc func = [this](const sptr& session) { - WLOGFD("NotifyCreateSpecificSessionFunc"); - this->OnCreateSpecificSession(session); + NotifyCreateSystemSessionFunc func = [this](const sptr& session) { + WLOGFD("NotifyCreateSystemSessionFunc"); + this->OnCreateSystemSession(session); }; - SceneSessionManager::GetInstance().SetCreateSpecificSessionListener(func); + SceneSessionManager::GetInstance().SetCreateSystemSessionListener(func); } void JsSceneSessionManager::ProcessStatusBarEnabledChangeListener() diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h index 05e8306372..c2a83f1826 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_session_manager.h @@ -105,11 +105,11 @@ private: void OnStatusBarEnabledUpdate(bool enable); void OnGestureNavigationEnabledUpdate(bool enable); - void OnCreateSpecificSession(const sptr& sceneSession); + void OnCreateSystemSession(const sptr& sceneSession); void OnOutsideDownEvent(int32_t x, int32_t y); void OnShiftFocus(int32_t persistentId); void OnShowPiPMainWindow(int32_t persistentId); - void ProcessCreateSpecificSessionRegister(); + void ProcessCreateSystemSessionRegister(); void ProcessStatusBarEnabledChangeListener(); void ProcessGestureNavigationEnabledChangeListener(); void ProcessOutsideDownEvent(); diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index a88b0208de..c27f4125ec 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -46,8 +46,6 @@ using NotifyWindowInfoUpdateCallback = std::function; using GetAINavigationBarArea = std::function; using RecoveryCallback = std::function; - -using NotifyCreateSpecificSessionFunc = std::function& session)>; using NotifyBindDialogSessionFunc = std::function& session)>; using NotifySessionRectChangeFunc = std::function; using NotifySessionEventFunc = std::function; @@ -82,7 +80,6 @@ public: // callback for notify SceneBoard struct SessionChangeCallback : public RefBase { - NotifyCreateSpecificSessionFunc onCreateSpecificSession_; NotifyBindDialogSessionFunc onBindDialogTarget_; NotifySessionRectChangeFunc onRectChange_; NotifyRaiseToTopFunc onRaiseToTop_; @@ -122,130 +119,127 @@ public: WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, const std::shared_ptr& rsTransaction = nullptr) override; WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) override; - WSError CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr) override; - WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; WSError PendingSessionActivation(const sptr info) override; WSError TerminateSession(const sptr info) override; WSError NotifySessionException(const sptr info) override; WSError NotifyClientToUpdateRect() override; - - WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); WSError OnNeedAvoid(bool status) override; - void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea); - void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); - void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); - void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); - void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea); AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; - WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type); - WSError OnShowWhenLocked(bool showWhenLocked); - bool IsShowWhenLocked() const; - void RegisterSessionChangeCallback(const sptr& sessionChangeCallback); - WSError TransferPointerEvent(const std::shared_ptr& pointerEvent) override; WSError RequestSessionBack(bool needMoveToBackground) override; - WSError SetAspectRatio(float ratio) override; WSError SetGlobalMaximizeMode(MaximizeMode mode) override; WSError GetGlobalMaximizeMode(MaximizeMode& mode) override; - - std::string GetSessionSnapshotFilePath(); - void SaveUpdatedIcon(const std::shared_ptr &icon); - std::string GetUpdatedIconPath(); - void RegisterSetWindowPatternFunc(sptr func) - { - setWindowScenePatternFunc_ = func; - }; WSError UpdateWindowSceneAfterCustomAnimation(bool isAdd) override; WSError UpdateWindowAnimationFlag(bool needDefaultAnimationFlag) override; - void SetWindowAnimationFlag(bool needDefaultAnimationFlag); void SetZOrder(uint32_t zOrder) override; std::vector GetTouchHotAreas() const override; - Rect GetHotAreaRect(int32_t action); - void NotifyTouchOutside(); - bool CheckOutTouchOutsideRegister(); void SetFloatingScale(float floatingScale) override; + WSError RaiseAboveTarget(int32_t subWindowId) override; + WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; + WSError UpdatePiPRect(uint32_t width, uint32_t height, PiPRectUpdateReason reason) override; + void NotifyPiPWindowPrepareClose() override; + WSError RecoveryPullPiPMainWindow(int32_t persistentId) override; - static MaximizeMode maximizeMode_; - + WSError SetKeepScreenOn(bool keepScreenOn); void SetParentPersistentId(int32_t parentId); - int32_t GetParentPersistentId() const; WSError SetTurnScreenOn(bool turnScreenOn); - bool IsTurnScreenOn() const; - WSError SetKeepScreenOn(bool keepScreenOn); - bool IsKeepScreenOn() const; - const std::string& GetWindowName() const; - void UpdateNativeVisibility(bool visible); - void UpdateRotationAvoidArea(); void SetPrivacyMode(bool isPrivacy); void SetSystemSceneOcclusionAlpha(double alpha); + void SetRequestedOrientation(Orientation orientation); + void SetWindowAnimationFlag(bool needDefaultAnimationFlag); + void SetCollaboratorType(int32_t collaboratorType); + void SetSelfToken(sptr selfToken); + void SetLastSafeRect(WSRect rect); + WSError SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty); + void SetAbilitySessionInfo(std::shared_ptr abilityInfo); + void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func); + void SetSessionRectChangeCallback(const NotifySessionRectChangeFunc& func); + + int32_t GetCollaboratorType() const; + sptr GetSelfToken() const; + WSRect GetLastSafeRect() const; + WSRect GetSessionTargetRect() const; + std::string GetUpdatedIconPath() const; + std::string GetSessionSnapshotFilePath() const; + int32_t GetParentPersistentId() const; + const std::string& GetWindowName() const; + Orientation GetRequestedOrientation() const; + void GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) const; + std::vector> GetSubSession() const; + std::shared_ptr GetAbilityInfo() const; + bool IsVisible() const; + bool IsDecorEnable() const; + bool IsAppSession() const; + bool IsTurnScreenOn() const; + bool IsKeepScreenOn() const; + bool IsShowWhenLocked() const; bool IsFloatingWindowAppType() const; + bool IsNeedDefaultAnimation() const; + bool IsDirtyWindow(); + + WSError UpdateAvoidArea(const sptr& avoidArea, AvoidAreaType type); + WSError OnShowWhenLocked(bool showWhenLocked); + void SaveUpdatedIcon(const std::shared_ptr &icon); + void NotifyTouchOutside(); + bool CheckOutTouchOutsideRegister(); + void UpdateNativeVisibility(bool visible); + void UpdateRotationAvoidArea(); void DumpSessionElementInfo(const std::vector& params); void NotifyForceHideChange(bool hide); - static const wptr GetEnterWindow(); - static void ClearEnterWindow(); - void SetRequestedOrientation(Orientation orientation); - Orientation GetRequestedOrientation() const; - WSError BindDialogTarget(const sptr& sceneSession); + WSError BindDialogSessionTarget(const sptr& sceneSession); void DumpSessionInfo(std::vector &info) const; bool AddSubSession(const sptr& subSession); bool RemoveSubSession(int32_t persistentId); - std::vector> GetSubSession() const; + void NotifySessionForeground(uint32_t reason, bool withAnimation); + void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits); + void RegisterSessionChangeCallback(const sptr& sessionChangeCallback); + WSError UpdateSizeChangeReason(SizeChangeReason reason); + void ClearSpecificSessionCbMap(); + double textFieldPositionY_ = 0.0; + double textFieldHeight_ = 0.0; std::shared_ptr keepScreenLock_; - bool IsDecorEnable(); - int32_t GetCollaboratorType() const; - void SetCollaboratorType(int32_t collaboratorType); - std::shared_ptr GetAbilityInfo(); - void SetAbilitySessionInfo(std::shared_ptr abilityInfo); - void SetSelfToken(sptr selfToken); - sptr GetSelfToken(); - WSError RaiseAboveTarget(int32_t subWindowId) override; - void SetSessionRectChangeCallback(const NotifySessionRectChangeFunc& func); - WSRect GetLastSafeRect(); - void SetLastSafeRect(WSRect rect); - bool IsNeedDefaultAnimation(); - bool IsAppSession() const; + static const wptr GetEnterWindow(); + static void ClearEnterWindow(); + static MaximizeMode maximizeMode_; static std::map windowDragHotAreaMap_; - void SetWindowDragHotAreaListener(const NotifyWindowDragHotAreaFunc& func); - WSRect GetSessionTargetRect(); - void NotifySessionForeground(uint32_t reason, bool withAnimation); - void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits); - void NotifyPiPWindowPrepareClose() override; - WSError UpdatePiPRect(uint32_t width, uint32_t height, PiPRectUpdateReason reason) override; - WSError RecoveryPullPiPMainWindow(int32_t persistentId) override; - WSError UpdateSizeChangeReason(SizeChangeReason reason); - bool IsDirtyWindow(); - void ClearSpecificSessionCbMap(); +protected: + void NotifyIsCustomAnimationPlaying(bool isPlaying); + void SetMoveDragCallback(); + std::string GetRatioPreferenceKey(); + + sptr specificCallback_ = nullptr; + sptr sessionChangeCallback_ = nullptr; + sptr moveDragController_ = nullptr; + private: + void CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const; + void GetSystemAvoidArea(WSRect& rect, AvoidArea& avoidArea); + void GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea); + void GetKeyboardAvoidArea(WSRect& rect, AvoidArea& avoidArea); void HandleStyleEvent(MMI::WindowArea area) override; WSError HandleEnterWinwdowArea(int32_t windowX, int32_t windowY); WSError HandlePointerStyle(const std::shared_ptr& pointerEvent); - void UpdateCameraFloatWindowStatus(bool isShowing); void NotifySessionRectChange(const WSRect& rect, const SizeChangeReason& reason = SizeChangeReason::UNDEFINED); - void SetMoveDragCallback(); void OnMoveDragCallback(const SizeChangeReason& reason); void FixRectByLimits(WindowLimits limits, WSRect& rect, float ratio, bool isDecor, float vpr); bool FixRectByAspectRatio(WSRect& rect); - std::string GetRatioPreferenceKey(); bool SaveAspectRatio(float ratio); - void NotifyIsCustomAnimationPlaying(bool isPlaying); void NotifyPropertyWhenConnect(); void SetSurfaceBounds(const WSRect& rect); void UpdateWinRectForSystemBar(WSRect& rect); bool UpdateInputMethodSessionRect(const WSRect& rect, WSRect& newWinRect, WSRect& newRequestRect); + bool InitPiPRectInfo(); + void ClearPiPRectPivotInfo(); + void SavePiPRectInfo(); + void GetNewPiPRect(const uint32_t displayWidth, const uint32_t displayHeight, Rect& rect); + void ProcessUpdatePiPRect(SizeChangeReason reason); - sptr specificCallback_ = nullptr; - sptr sessionChangeCallback_ = nullptr; - sptr moveDragController_ = nullptr; - sptr setWindowScenePatternFunc_ = nullptr; NotifySessionRectChangeFunc sessionRectChangeFunc_; bool isVisible_ = false; static wptr enterSession_; @@ -256,21 +250,10 @@ private: WSRect lastSafeRect = { 0, 0, 0, 0 }; std::vector> subSession_; bool needDefaultAnimationFlag_ = true; - PiPRectInfo pipRectInfo_; - bool InitPiPRectInfo(); - void ClearPiPRectPivotInfo(); - void SavePiPRectInfo(); - void GetNewPiPRect(const uint32_t displayWidth, const uint32_t displayHeight, Rect& rect); - void ProcessUpdatePiPRect(SizeChangeReason reason); SizeChangeReason reason_ = SizeChangeReason::UNDEFINED; std::recursive_mutex sizeChangeMutex_; bool isDirty_ = false; - -public: - double textFieldPositionY_ = 0.0; - double textFieldHeight_ = 0.0; - WSError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SCENE_SESSION_H diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index 63a418ce35..d5c4b13c06 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -94,6 +94,8 @@ public: WSError Foreground(sptr property) override; WSError Background() override; WSError Disconnect() override; + WSError Show(sptr property) override; + WSError Hide() override; bool RegisterLifecycleListener(const std::shared_ptr& listener); bool UnregisterLifecycleListener(const std::shared_ptr& listener); @@ -131,7 +133,7 @@ public: std::shared_ptr GetSurfaceNode() const; std::shared_ptr GetLeashWinSurfaceNode() const; std::shared_ptr GetSnapshot() const; - std::shared_ptr Snapshot(); + std::shared_ptr Snapshot() const; SessionState GetSessionState() const; void SetSessionState(SessionState state); void SetSessionInfoAncoSceneState(int32_t ancoSceneState); diff --git a/window_scene/session/host/include/sub_session.h b/window_scene/session/host/include/sub_session.h index 24b8e79f98..af2a036a72 100644 --- a/window_scene/session/host/include/sub_session.h +++ b/window_scene/session/host/include/sub_session.h @@ -23,6 +23,9 @@ class SubSession : public SceneSession { public: SubSession(const SessionInfo& info, const sptr& specificCallback); ~SubSession(); + + WSError Show(sptr property) override; + WSError Hide() override; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SUB_SESSION_H diff --git a/window_scene/session/host/include/system_session.h b/window_scene/session/host/include/system_session.h index 8bf6ce66df..052ea3a660 100644 --- a/window_scene/session/host/include/system_session.h +++ b/window_scene/session/host/include/system_session.h @@ -23,6 +23,13 @@ class SystemSession : public SceneSession { public: SystemSession(const SessionInfo& info, const sptr& specificCallback); ~SystemSession(); + + WSError Show(sptr property) override; + WSError Hide() override; + WSError Disconnect() override; + +private: + void UpdateCameraFloatWindowStatus(bool isShowing); }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SYSTEM_SESSION_H diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index bcc2822762..a09581345b 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -39,17 +39,14 @@ public: virtual WSError Foreground(sptr property) = 0; virtual WSError Background() = 0; virtual WSError Disconnect() = 0; + virtual WSError Show(sptr property) = 0; + virtual WSError Hide() = 0; // scene session virtual WSError UpdateActiveStatus(bool isActive) { return WSError::WS_OK; } virtual WSError OnSessionEvent(SessionEvent event) { return WSError::WS_OK; } virtual WSError RaiseToAppTop() { return WSError::WS_OK; } virtual WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) { return WSError::WS_OK; } - virtual WSError CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr) { return WSError::WS_OK; } - virtual WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) { return WSError::WS_OK; } virtual WSError OnNeedAvoid(bool status) { return WSError::WS_OK; } virtual AvoidArea GetAvoidAreaByType(AvoidAreaType type) { return {}; } virtual WSError RequestSessionBack(bool needMoveToBackground) { return WSError::WS_OK; } diff --git a/window_scene/session/host/include/zidl/session_ipc_interface_code.h b/window_scene/session/host/include/zidl/session_ipc_interface_code.h index 5151fe598a..db3ba2dd37 100644 --- a/window_scene/session/host/include/zidl/session_ipc_interface_code.h +++ b/window_scene/session/host/include/zidl/session_ipc_interface_code.h @@ -24,6 +24,8 @@ enum class SessionInterfaceCode { TRANS_ID_FOREGROUND, TRANS_ID_BACKGROUND, TRANS_ID_DISCONNECT, + TRANS_ID_SHOW, + TRANS_ID_HIDE, TRANS_ID_ACTIVE_PENDING_SESSION, TRANS_ID_UPDATE_ACTIVE_STATUS, TRANS_ID_TERMINATE, @@ -32,8 +34,6 @@ enum class SessionInterfaceCode { // Scene TRANS_ID_SESSION_EVENT = 100, TRANS_ID_UPDATE_SESSION_RECT, - TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION, - TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION, TRANS_ID_RAISE_TO_APP_TOP, TRANS_ID_BACKPRESSED, TRANS_ID_MARK_PROCESSED, diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index 9c55f49065..4845ca1dbe 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -29,6 +29,8 @@ public: WSError Foreground(sptr property) override; WSError Background() override; WSError Disconnect() override; + WSError Show(sptr property) override; + WSError Hide() override; WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, SystemSessionConfig& systemConfig, sptr property = nullptr, sptr token = nullptr, @@ -41,11 +43,6 @@ public: WSError OnSessionEvent(SessionEvent event) override; WSError RaiseToAppTop() override; WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) override; - WSError CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr) override; - WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; WSError OnNeedAvoid(bool status) override; AvoidArea GetAvoidAreaByType(AvoidAreaType type) override; WSError RequestSessionBack(bool needMoveToBackground) override; diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index b43415076e..b96361d595 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -38,13 +38,13 @@ private: int HandleForeground(MessageParcel& data, MessageParcel& reply); int HandleBackground(MessageParcel& data, MessageParcel& reply); int HandleDisconnect(MessageParcel& data, MessageParcel& reply); + int HandleShow(MessageParcel& data, MessageParcel& reply); + int HandleHide(MessageParcel& data, MessageParcel& reply); // scene session int HandleUpdateActivateStatus(MessageParcel& data, MessageParcel& reply); int HandleSessionEvent(MessageParcel& data, MessageParcel& reply); int HandleUpdateSessionRect(MessageParcel& data, MessageParcel& reply); - int HandleCreateAndConnectSpecificSession(MessageParcel& data, MessageParcel& reply); - int HandleDestroyAndDisconnectSpecificSession(MessageParcel& data, MessageParcel& reply); int HandleRaiseToAppTop(MessageParcel& data, MessageParcel& reply); int HandleBackPressed(MessageParcel& data, MessageParcel& reply); int HandleMarkProcessed(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session/host/src/main_session.cpp b/window_scene/session/host/src/main_session.cpp index af3acba3b6..0803f9e6a3 100644 --- a/window_scene/session/host/src/main_session.cpp +++ b/window_scene/session/host/src/main_session.cpp @@ -15,6 +15,10 @@ #include "session/host/include/main_session.h" +#include + +#include "session_helper.h" +#include "session/host/include/scene_persistent_storage.h" #include "window_manager_hilog.h" namespace OHOS::Rosen { @@ -25,6 +29,28 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "MainSe MainSession::MainSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) { + moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId()); + SetMoveDragCallback(); + std::string key = GetRatioPreferenceKey(); + if (!key.empty()) { + if (ScenePersistentStorage::HasKey(key, ScenePersistentStorageType::ASPECT_RATIO)) { + ScenePersistentStorage::Get(key, aspectRatio_, ScenePersistentStorageType::ASPECT_RATIO); + WLOGD("SceneSession init aspectRatio , key %{public}s, value: %{public}f", key.c_str(), aspectRatio_); + if (moveDragController_) { + moveDragController_->SetAspectRatio(aspectRatio_); + } + } + } + + auto name = sessionInfo_.bundleName_; + auto pos = name.find_last_of('.'); + name = (pos == std::string::npos) ? name : name.substr(pos + 1); // skip '.' + if (SessionHelper::IsMainWindow(GetWindowType())) { + scenePersistence_ = new ScenePersistence(info.bundleName_, GetPersistentId()); + RSSurfaceNodeConfig config; + config.SurfaceNodeName = "WindowScene_" + name + std::to_string(GetPersistentId()); + leashWinSurfaceNode_ = Rosen::RSSurfaceNode::Create(config, Rosen::RSSurfaceNodeType::LEASH_WINDOW_NODE); + } WLOGFD("Create MainSession"); } diff --git a/window_scene/session/host/src/scb_system_session.cpp b/window_scene/session/host/src/scb_system_session.cpp index b9fcbbda76..560ab6dae8 100644 --- a/window_scene/session/host/src/scb_system_session.cpp +++ b/window_scene/session/host/src/scb_system_session.cpp @@ -15,6 +15,7 @@ #include "session/host/include/scb_system_session.h" +#include #include "window_manager_hilog.h" namespace OHOS::Rosen { @@ -25,6 +26,14 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SCBSys SCBSystemSession::SCBSystemSession(const SessionInfo& info, const sptr& specificCallback) : SceneSession(info, specificCallback) { + auto name = sessionInfo_.bundleName_; + auto pos = name.find_last_of('.'); + name = (pos == std::string::npos) ? name : name.substr(pos + 1); // skip '.' + if (sessionInfo_.isSystem_) { + RSSurfaceNodeConfig config; + config.SurfaceNodeName = name; + surfaceNode_ = Rosen::RSSurfaceNode::Create(config, Rosen::RSSurfaceNodeType::APP_WINDOW_NODE); + } WLOGFD("Create SCBSystemSession"); } diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 2612a8a3bd..4b09a155e5 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -55,35 +55,6 @@ SceneSession::SceneSession(const SessionInfo& info, const sptrSetAspectRatio(aspectRatio_); - } - } - } - - auto name = sessionInfo_.bundleName_; - auto pos = name.find_last_of('.'); - name = (pos == std::string::npos) ? name : name.substr(pos + 1); // skip '.' - - if (WindowHelper::IsMainWindow(GetWindowType())) { - scenePersistence_ = new ScenePersistence(info.bundleName_, GetPersistentId()); - RSSurfaceNodeConfig config; - config.SurfaceNodeName = "WindowScene_" + name + std::to_string(GetPersistentId()); - leashWinSurfaceNode_ = Rosen::RSSurfaceNode::Create(config, Rosen::RSSurfaceNodeType::LEASH_WINDOW_NODE); - } - - if (sessionInfo_.isSystem_) { - RSSurfaceNodeConfig config; - config.SurfaceNodeName = name; - surfaceNode_ = Rosen::RSSurfaceNode::Create(config, Rosen::RSSurfaceNodeType::APP_WINDOW_NODE); - } SetCollaboratorType(info.collaboratorType_); WLOGFD("Create SceneSession"); } @@ -123,9 +94,9 @@ WSError SceneSession::Foreground(sptr property) if (GetWindowType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW && GetStateFromManager(ManagerState::MANAGER_STATE_SCREEN_LOCKED) && !IsShowWhenLocked()) { - WLOGFW("Foreground failed: Screen is locked, session %{public}d show without ShowWhenLocked flag", - GetPersistentId()); - return WSError::WS_ERROR_INVALID_SHOW_WHEN_LOCKED; + WLOGFW("Foreground failed: Screen is locked, session %{public}d show without ShowWhenLocked flag", + GetPersistentId()); + return WSError::WS_ERROR_INVALID_SHOW_WHEN_LOCKED; } PostTask([weakThis = wptr(this), property]() { @@ -134,21 +105,12 @@ WSError SceneSession::Foreground(sptr property) WLOGFE("session is null"); return WSError::WS_ERROR_DESTROYED_OBJECT; } - // use property from client - if (property && property->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { - session->GetSessionProperty()->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); - session->NotifyIsCustomAnimationPlaying(true); - if (session->setWindowScenePatternFunc_ && session->setWindowScenePatternFunc_->setOpacityFunc_) { - session->setWindowScenePatternFunc_->setOpacityFunc_(0.0f); - } - } weakThis->SetTextFieldAvoidInfo(property->GetTextFieldPositionY(), property->GetTextFieldHeight()); auto ret = session->Session::Foreground(property); if (ret != WSError::WS_OK) { return ret; } session->NotifyForeground(); - session->UpdateCameraFloatWindowStatus(true); if (session->specificCallback_ != nullptr) { session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); session->specificCallback_->onWindowInfoUpdate_( @@ -167,13 +129,6 @@ WSError SceneSession::Background() WLOGFE("session is null"); return WSError::WS_ERROR_DESTROYED_OBJECT; } - // background will remove surfaceNode, custom not execute - // not animation playing when already background; inactive may be animation playing - if (session->GetSessionProperty() && - session->GetSessionProperty()->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { - session->NotifyIsCustomAnimationPlaying(true); - return WSError::WS_OK; - } auto ret = session->Session::Background(); if (ret != WSError::WS_OK) { return ret; @@ -186,7 +141,6 @@ WSError SceneSession::Background() } session->NotifyBackground(); session->snapshot_.reset(); - session->UpdateCameraFloatWindowStatus(false); if (session->specificCallback_ != nullptr) { session->specificCallback_->onUpdateAvoidArea_(session->GetPersistentId()); session->specificCallback_->onWindowInfoUpdate_( @@ -233,9 +187,6 @@ WSError SceneSession::Disconnect() session->Session::Disconnect(); session->snapshot_.reset(); session->isTerminating = false; - if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { - session->NotifyCallingSessionBackground(); - } return WSError::WS_OK; }); return WSError::WS_OK; @@ -596,51 +547,7 @@ WSError SceneSession::RaiseAboveTarget(int32_t subWindowId) }); } -WSError SceneSession::CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, sptr token) -{ - // Get pid and uid before posting task. - auto pid = IPCSkeleton::GetCallingPid(); - auto uid = IPCSkeleton::GetCallingUid(); - return PostSyncTask([weakThis = wptr(this), sessionStage, eventChannel, surfaceNode, property, - &persistentId, &session, token, pid, uid]() { - auto self = weakThis.promote(); - if (!self) { - WLOGFE("session is null"); - return WSError::WS_ERROR_DESTROYED_OBJECT; - } - WLOGFI("CreateAndConnectSpecificSession id: %{public}d", self->GetPersistentId()); - sptr sceneSession; - if (self->specificCallback_) { - SessionInfo sessionInfo; - if (property) { - sessionInfo.windowType_ = static_cast(property->GetWindowType()); - } - sceneSession = self->specificCallback_->onCreate_(sessionInfo, property); - } - if (sceneSession == nullptr) { - return WSError::WS_ERROR_NULLPTR; - } - auto errCode = sceneSession->Connect( - sessionStage, eventChannel, surfaceNode, self->systemConfig_, property, token, pid, uid); - if (property) { - persistentId = property->GetPersistentId(); - } - if (self->sessionChangeCallback_ && self->sessionChangeCallback_->onCreateSpecificSession_) { - self->sessionChangeCallback_->onCreateSpecificSession_(sceneSession); - } - session = sceneSession; - bool res = self->AddSubSession(sceneSession); - if (!res) { - return WSError::WS_ERROR_INVALID_SESSION; - } - sceneSession->SetParentSession(self); - return errCode; - }); -} - -WSError SceneSession::BindDialogTarget(const sptr& sceneSession) +WSError SceneSession::BindDialogSessionTarget(const sptr& sceneSession) { if (sceneSession == nullptr) { WLOGFE("dialog session is null"); @@ -652,37 +559,6 @@ WSError SceneSession::BindDialogTarget(const sptr& sceneSession) return WSError::WS_OK; } -WSError SceneSession::DestroyAndDisconnectSpecificSession(const int32_t& persistentId) -{ - return PostSyncTask([weakThis = wptr(this), persistentId]() { - auto session = weakThis.promote(); - if (!session) { - WLOGFE("session is null"); - return WSError::WS_ERROR_DESTROYED_OBJECT; - } - if (!session->specificCallback_) { - WLOGFE("specificCallback_ is null"); - return WSError::WS_ERROR_NULLPTR; - } - auto ret = session->specificCallback_->onDestroy_(persistentId); - if (ret != WSError::WS_OK) { - return ret; - } - bool res = session->RemoveSubSession(persistentId); - if (!res) { - ret = WSError::WS_ERROR_INVALID_SESSION; - } - return ret; - }); -} - -void SceneSession::UpdateCameraFloatWindowStatus(bool isShowing) -{ - if (GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA && specificCallback_ != nullptr) { - specificCallback_->onCameraFloatSessionChange_(GetSessionProperty()->GetAccessTokenId(), isShowing); - } -} - WSError SceneSession::SetSystemBarProperty(WindowType type, SystemBarProperty systemBarProperty) { auto property = GetSessionProperty(); @@ -741,7 +617,7 @@ bool SceneSession::IsShowWhenLocked() const return GetSessionProperty()->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); } -void SceneSession::CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) +void SceneSession::CalculateAvoidAreaRect(WSRect& rect, WSRect& avoidRect, AvoidArea& avoidArea) const { if (SessionHelper::IsEmptyRect(rect) || SessionHelper::IsEmptyRect(avoidRect)) { return; @@ -857,7 +733,7 @@ void SceneSession::GetCutoutAvoidArea(WSRect& rect, AvoidArea& avoidArea) return; } -void SceneSession::GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) +void SceneSession::GetAINavigationBarArea(WSRect rect, AvoidArea& avoidArea) const { WSRect barArea = specificCallback_->onGetAINavigationBarArea_(); CalculateAvoidAreaRect(rect, barArea, avoidArea); @@ -1134,7 +1010,7 @@ void SceneSession::NotifySessionRectChange(const WSRect& rect, const SizeChangeR } } -bool SceneSession::IsDecorEnable() +bool SceneSession::IsDecorEnable() const { auto property = GetSessionProperty(); if (property == nullptr) { @@ -1394,7 +1270,7 @@ bool SceneSession::IsKeepScreenOn() const return GetSessionProperty()->IsKeepScreenOn(); } -std::string SceneSession::GetSessionSnapshotFilePath() +std::string SceneSession::GetSessionSnapshotFilePath() const { WLOGFI("GetSessionSnapshotFilePath id %{public}d", GetPersistentId()); if (Session::GetSessionState() < SessionState::STATE_BACKGROUND) { @@ -1418,7 +1294,7 @@ void SceneSession::SaveUpdatedIcon(const std::shared_ptr &icon) } } -std::string SceneSession::GetUpdatedIconPath() +std::string SceneSession::GetUpdatedIconPath() const { WLOGFI("run GetUpdatedIconPath"); if (scenePersistence_ != nullptr) { @@ -1530,7 +1406,7 @@ void SceneSession::SetWindowAnimationFlag(bool needDefaultAnimationFlag) return; } -bool SceneSession::IsNeedDefaultAnimation() +bool SceneSession::IsNeedDefaultAnimation() const { return needDefaultAnimationFlag_; } @@ -1562,13 +1438,11 @@ WSError SceneSession::UpdateWindowSceneAfterCustomAnimation(bool isAdd) WLOGFE("session is null"); return WSError::WS_ERROR_DESTROYED_OBJECT; } - WLOGFI("id %{public}d", session->GetPersistentId()); + WLOGFI("UpdateWindowSceneAfterCustomAnimation, id %{public}d, isAdd: %{public}d", + session->GetPersistentId(), isAdd); if (isAdd) { - if (!session->setWindowScenePatternFunc_ || !session->setWindowScenePatternFunc_->setOpacityFunc_) { - WLOGFE("SetOpacityFunc not register %{public}d", session->GetPersistentId()); - return WSError::WS_ERROR_INVALID_OPERATION; - } - session->setWindowScenePatternFunc_->setOpacityFunc_(1); + WLOGFE("SetOpacityFunc not register %{public}d", session->GetPersistentId()); + return WSError::WS_ERROR_INVALID_OPERATION; } else { WLOGFI("background after custom animation id %{public}d", session->GetPersistentId()); // since background will remove surfaceNode @@ -1607,32 +1481,6 @@ void SceneSession::DumpSessionElementInfo(const std::vector& params return sessionStage_->DumpSessionElementInfo(params); } -Rect SceneSession::GetHotAreaRect(int32_t action) -{ - Rect hotAreaRect; - WSRect rect = GetSessionRect(); - - float vpr = 1.5f; // 1.5f: default virtual pixel ratio - auto display = DisplayManager::GetInstance().GetDefaultDisplay(); - if (display) { - vpr = display->GetVirtualPixelRatio(); - WLOGD("vpr = %{public}f", vpr); - } - - float hotZone = 0.0; - if (action == MMI::PointerEvent::POINTER_ACTION_DOWN) { - hotZone = HOTZONE_TOUCH; - } else if (action == MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN) { - hotZone = HOTZONE_POINTER; - } - hotAreaRect.posX_ = rect.posX_ - static_cast(vpr * hotZone); - hotAreaRect.posY_ = rect.posY_ - static_cast(vpr * hotZone); - hotAreaRect.width_ = rect.width_ + static_cast(vpr * hotZone * 2); // 2: double hotZone - hotAreaRect.height_ = rect.height_ + static_cast(vpr * hotZone * 2); // 2: double hotZone - - return hotAreaRect; -} - void SceneSession::NotifyTouchOutside() { WLOGFD("id: %{public}d NotifyTouchOutside", GetPersistentId()); @@ -1717,7 +1565,7 @@ void SceneSession::DumpSessionInfo(std::vector &info) const info.push_back(dumpInfo); } -std::shared_ptr SceneSession::GetAbilityInfo() +std::shared_ptr SceneSession::GetAbilityInfo() const { const SessionInfo& sessionInfo = GetSessionInfo(); return sessionInfo.abilityInfo; @@ -1733,7 +1581,7 @@ void SceneSession::SetSelfToken(sptr selfToken) selfToken_ = selfToken; } -sptr SceneSession::GetSelfToken() +sptr SceneSession::GetSelfToken() const { return selfToken_; } @@ -1863,7 +1711,7 @@ WSError SceneSession::NotifySessionException(const sptr abil return WSError::WS_OK; } -WSRect SceneSession::GetLastSafeRect() +WSRect SceneSession::GetLastSafeRect() const { return lastSafeRect; } @@ -1954,7 +1802,7 @@ std::vector> SceneSession::GetSubSession() const return subSession_; } -WSRect SceneSession::GetSessionTargetRect() +WSRect SceneSession::GetSessionTargetRect() const { WSRect rect; if (moveDragController_) { diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index cabaf4da24..891e0b2276 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -797,6 +797,18 @@ WSError Session::Disconnect() return WSError::WS_OK; } +WSError Session::Show(sptr property) +{ + WLOGFD("Show session, id: %{public}d", GetPersistentId()); + return WSError::WS_OK; +} + +WSError Session::Hide() +{ + WLOGFD("Hide session, id: %{public}d", GetPersistentId()); + return WSError::WS_OK; +} + WSError Session::SetActive(bool active) { SessionState state = GetSessionState(); @@ -1438,7 +1450,7 @@ WSError Session::UpdateConfiguration() return WSError::WS_OK; } -std::shared_ptr Session::Snapshot() +std::shared_ptr Session::Snapshot() const { if (!surfaceNode_ || !surfaceNode_->IsBufferAvailable()) { return nullptr; diff --git a/window_scene/session/host/src/sub_session.cpp b/window_scene/session/host/src/sub_session.cpp index 37692fa91f..35cd37a96a 100644 --- a/window_scene/session/host/src/sub_session.cpp +++ b/window_scene/session/host/src/sub_session.cpp @@ -32,4 +32,51 @@ SubSession::~SubSession() { WLOGD("~SubSession, id: %{public}d", GetPersistentId()); } + +WSError SubSession::Show(sptr property) +{ + PostTask([weakThis = wptr(this), property]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + WLOGFD("Show session, id: %{public}d", session->GetPersistentId()); + + // use property from client + if (property && property->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { + session->GetSessionProperty()->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); + session->NotifyIsCustomAnimationPlaying(true); + } + auto ret = session->SceneSession::Foreground(property); + return ret; + }); + return WSError::WS_OK; +} + +WSError SubSession::Hide() +{ + PostTask([weakThis = wptr(this)]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + WLOGFD("Hide session, id: %{public}d", session->GetPersistentId()); + auto ret = session->SetActive(false); + if (ret != WSError::WS_OK) { + return ret; + } + // background will remove surfaceNode, custom not execute + // not animation playing when already background; inactive may be animation playing + if (session->GetSessionProperty() && + session->GetSessionProperty()->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { + session->NotifyIsCustomAnimationPlaying(true); + return WSError::WS_OK; + } + ret = session->SceneSession::Background(); + return ret; + }); + return WSError::WS_OK; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/system_session.cpp b/window_scene/session/host/src/system_session.cpp index 17821e791a..97ab6be218 100644 --- a/window_scene/session/host/src/system_session.cpp +++ b/window_scene/session/host/src/system_session.cpp @@ -32,4 +32,80 @@ SystemSession::~SystemSession() { WLOGD("~SystemSession, id: %{public}d", GetPersistentId()); } + +void SystemSession::UpdateCameraFloatWindowStatus(bool isShowing) +{ + if (GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA && specificCallback_ != nullptr) { + WLOGFD("CameraFloat status: %{public}d, id: %{public}d", isShowing, GetPersistentId()); + specificCallback_->onCameraFloatSessionChange_(GetSessionProperty()->GetAccessTokenId(), isShowing); + } +} + +WSError SystemSession::Show(sptr property) +{ + PostTask([weakThis = wptr(this), property]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + WLOGFD("Show session, id: %{public}d", session->GetPersistentId()); + + // use property from client + if (property && property->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { + session->GetSessionProperty()->SetAnimationFlag(static_cast(WindowAnimation::CUSTOM)); + session->NotifyIsCustomAnimationPlaying(true); + } + session->UpdateCameraFloatWindowStatus(true); + auto ret = session->SceneSession::Foreground(property); + return ret; + }); + return WSError::WS_OK; +} + +WSError SystemSession::Hide() +{ + PostTask([weakThis = wptr(this)]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + WLOGFD("Hide session, id: %{public}d", session->GetPersistentId()); + + auto ret = session->SetActive(false); + if (ret != WSError::WS_OK) { + return ret; + } + // background will remove surfaceNode, custom not execute + // not animation playing when already background; inactive may be animation playing + if (session->GetSessionProperty() && + session->GetSessionProperty()->GetAnimationFlag() == static_cast(WindowAnimation::CUSTOM)) { + session->NotifyIsCustomAnimationPlaying(true); + return WSError::WS_OK; + } + session->UpdateCameraFloatWindowStatus(false); + ret = session->SceneSession::Background(); + return ret; + }); + return WSError::WS_OK; +} + +WSError SystemSession::Disconnect() +{ + PostTask([weakThis = wptr(this)]() { + auto session = weakThis.promote(); + if (!session) { + WLOGFE("session is null"); + return WSError::WS_ERROR_DESTROYED_OBJECT; + } + session->SceneSession::Disconnect(); + if (session->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) { + session->NotifyCallingSessionBackground(); + } + session->UpdateCameraFloatWindowStatus(false); + return WSError::WS_OK; + }); + return WSError::WS_OK; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/zidl/session_proxy.cpp b/window_scene/session/host/src/zidl/session_proxy.cpp index 0fd317f014..a06355a453 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -80,6 +80,56 @@ WSError SessionProxy::Background() return static_cast(ret); } +WSError SessionProxy::Show(sptr property) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (property) { + if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) { + WLOGFE("Write property failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + } else { + if (!data.WriteBool(false)) { + WLOGFE("Write property failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + } + + if (Remote()->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_SHOW), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + +WSError SessionProxy::Hide() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(static_cast(SessionInterfaceCode::TRANS_ID_HIDE), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); + return static_cast(ret); +} + WSError SessionProxy::Disconnect() { MessageParcel data; @@ -386,83 +436,6 @@ WSError SessionProxy::UpdateSessionRect(const WSRect& rect, const SizeChangeReas return static_cast(ret); } -WSError SessionProxy::CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, sptr token) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteRemoteObject(sessionStage->AsObject())) { - WLOGFE("Write ISessionStage failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteRemoteObject(eventChannel->AsObject())) { - WLOGFE("Write IWindowEventChannel failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!surfaceNode->Marshalling(data)) { - WLOGFE("Write surfaceNode failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - - if (property) { - if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) { - return WSError::WS_ERROR_IPC_FAILED; - } - } else { - if (!data.WriteBool(false)) { - return WSError::WS_ERROR_IPC_FAILED; - } - } - if (token != nullptr) { - if (!data.WriteRemoteObject(token)) { - return WSError::WS_ERROR_IPC_FAILED; - } - } - if (Remote()->SendRequest(static_cast( - SessionInterfaceCode::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), - data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - persistentId = reply.ReadInt32(); - sptr sessionObject = reply.ReadRemoteObject(); - if (sessionObject == nullptr) { - WLOGFE("ReadRemoteObject failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - session = iface_cast(sessionObject); - int32_t ret = reply.ReadInt32(); - return static_cast(ret); -} - -WSError SessionProxy::DestroyAndDisconnectSpecificSession(const int32_t& persistentId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - if (!data.WriteInt32(persistentId)) { - WLOGFE("Write persistentId failed"); - } - if (Remote()->SendRequest(static_cast( - SessionInterfaceCode::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION), - data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); - return WSError::WS_ERROR_IPC_FAILED; - } - int32_t ret = reply.ReadInt32(); - return static_cast(ret); -} - WSError SessionProxy::RaiseToAppTop() { MessageParcel data; diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 092523fa16..5bd265c8dc 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -40,6 +40,10 @@ const std::map SessionStub::stubFuncMap_ { &SessionStub::HandleBackground), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_DISCONNECT), &SessionStub::HandleDisconnect), + std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_SHOW), + &SessionStub::HandleShow), + std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_HIDE), + &SessionStub::HandleHide), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_ACTIVE_STATUS), &SessionStub::HandleUpdateActivateStatus), @@ -47,10 +51,6 @@ const std::map SessionStub::stubFuncMap_ { &SessionStub::HandleSessionEvent), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_UPDATE_SESSION_RECT), &SessionStub::HandleUpdateSessionRect), - std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), - &SessionStub::HandleCreateAndConnectSpecificSession), - std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION), - &SessionStub::HandleDestroyAndDisconnectSpecificSession), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_RAISE_TO_APP_TOP), &SessionStub::HandleRaiseToAppTop), std::make_pair(static_cast(SessionInterfaceCode::TRANS_ID_BACKPRESSED), @@ -161,6 +161,29 @@ int SessionStub::HandleDisconnect(MessageParcel& data, MessageParcel& reply) return ERR_NONE; } +int SessionStub::HandleShow(MessageParcel& data, MessageParcel& reply) +{ + WLOGFD("Show!"); + sptr property = nullptr; + if (data.ReadBool()) { + property = data.ReadStrongParcelable(); + } else { + WLOGFW("Property not exist!"); + property = new WindowSessionProperty(); + } + const WSError& errCode = Show(property); + reply.WriteUint32(static_cast(errCode)); + return ERR_NONE; +} + +int SessionStub::HandleHide(MessageParcel& data, MessageParcel& reply) +{ + WLOGFD("Hide!"); + const WSError& errCode = Hide(); + reply.WriteUint32(static_cast(errCode)); + return ERR_NONE; +} + int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply) { WLOGFD("Connect!"); @@ -284,54 +307,6 @@ int SessionStub::HandleUpdateSessionRect(MessageParcel& data, MessageParcel& rep return ERR_NONE; } -int SessionStub::HandleCreateAndConnectSpecificSession(MessageParcel& data, MessageParcel& reply) -{ - WLOGFD("HandleCreateAndConnectSpecificSession!"); - sptr sessionStageObject = data.ReadRemoteObject(); - sptr sessionStage = iface_cast(sessionStageObject); - sptr eventChannelObject = data.ReadRemoteObject(); - sptr eventChannel = iface_cast(eventChannelObject); - std::shared_ptr surfaceNode = RSSurfaceNode::Unmarshalling(data); - if (sessionStage == nullptr || eventChannel == nullptr || surfaceNode == nullptr) { - WLOGFE("Failed to read scene session stage object or event channel object!"); - return ERR_INVALID_DATA; - } - - sptr property = nullptr; - if (data.ReadBool()) { - property = data.ReadStrongParcelable(); - } else { - WLOGFW("Property not exist!"); - } - - sptr token = nullptr; - if (property && property->GetTokenState()) { - token = data.ReadRemoteObject(); - } else { - WLOGI("accept token is nullptr"); - } - - auto persistentId = INVALID_SESSION_ID; - sptr sceneSession; - CreateAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode, - property, persistentId, sceneSession, token); - if (sceneSession== nullptr) { - return ERR_INVALID_STATE; - } - reply.WriteInt32(persistentId); - reply.WriteRemoteObject(sceneSession->AsObject()); - reply.WriteUint32(static_cast(WSError::WS_OK)); - return ERR_NONE; -} - -int SessionStub::HandleDestroyAndDisconnectSpecificSession(MessageParcel& data, MessageParcel& reply) -{ - auto persistentId = data.ReadUint32(); - const WSError& ret = DestroyAndDisconnectSpecificSession(persistentId); - reply.WriteUint32(static_cast(ret)); - return ERR_NONE; -} - int SessionStub::HandleRaiseToAppTop(MessageParcel& data, MessageParcel& reply) { WLOGFD("RaiseToAppTop!"); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index 35921940c6..35629a0e50 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -59,7 +59,8 @@ namespace AncoConsts { class SceneSession; class AccessibilityWindowInfo; -using NotifyCreateSpecificSessionFunc = std::function& session)>; +using NotifyCreateSystemSessionFunc = std::function& session)>; +using NotifyCreateSubSessionFunc = std::function& session)>; using ProcessStatusBarEnabledChangeFunc = std::function; using ProcessGestureNavigationEnabledChangeFunc = std::function; using ProcessOutsideDownEventFunc = std::function; @@ -105,10 +106,10 @@ public: WSError CreateAndConnectSpecificSession(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr); - WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId); - WMError UpdateProperty(sptr& property, WSPropertyChangeAction action); - void SetCreateSpecificSessionListener(const NotifyCreateSpecificSessionFunc& func); + sptr token = nullptr) override; + WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; + WMError UpdateSessionProperty(const sptr& property, WSPropertyChangeAction action) override; + void SetCreateSystemSessionListener(const NotifyCreateSystemSessionFunc& func); void SetStatusBarEnabledChangeListener(const ProcessStatusBarEnabledChangeFunc& func); void SetGestureNavigationEnabledChangeListener(const ProcessGestureNavigationEnabledChangeFunc& func); void SetDumpRootSceneElementInfoListener(const DumpRootSceneElementInfoFunc& func); @@ -117,21 +118,21 @@ public: void SetShowPiPMainWindowListener(const ProcessShowPiPMainWindowFunc& func); const AppWindowSceneConfig& GetWindowSceneConfig() const; WSError ProcessBackEvent(); - WSError BindDialogTarget(uint64_t persistentId, sptr targetToken); + WSError BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) override; void GetStartupPage(const SessionInfo& sessionInfo, std::string& path, uint32_t& bgColor); - WMError SetGestureNavigaionEnabled(bool enable); + WMError SetGestureNavigaionEnabled(bool enable) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); + const sptr& windowManagerAgent) override; WMError UnregisterWindowManagerAgent(WindowManagerAgentType type, - const sptr& windowManagerAgent); + const sptr& windowManagerAgent) override; WSError SetFocusedSession(int32_t persistentId); int32_t GetFocusedSession() const; WSError GetAllSessionDumpInfo(std::string& info); WSError GetSpecifiedSessionDumpInfo(std::string& dumpInfo, const std::vector& params, const std::string& strId); - WSError GetSessionDumpInfo(const std::vector& params, std::string& info); - WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = false); + WSError GetSessionDumpInfo(const std::vector& params, std::string& info) override; + WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = false) override; WSError UpdateFocus(int32_t persistentId, bool isFocused); WSError UpdateWindowMode(int32_t persistentId, int32_t windowMode); WSError SendTouchEvent(const std::shared_ptr& pointerEvent, uint32_t zIndex); @@ -141,44 +142,45 @@ public: WSError SwitchUser(int32_t oldUserId, int32_t newUserId, std::string &fileDir); int32_t GetCurrentUserId() const; void StartWindowInfoReportLoop(); - void GetFocusWindowInfo(FocusChangeInfo& focusInfo); + void GetFocusWindowInfo(FocusChangeInfo& focusInfo) override; void NotifyCompleteFirstFrameDrawing(int32_t persistentId); void NotifySessionMovedToFront(int32_t persistentId); - WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); - WSError SetSessionLabel(const sptr &token, const std::string &label); - WSError SetSessionIcon(const sptr &token, const std::shared_ptr &icon); - WSError IsValidSessionIds(const std::vector &sessionIds, std::vector &results); - WSError RegisterSessionListener(const sptr sessionListener); - void UnregisterSessionListener(); + WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) override; + WSError SetSessionLabel(const sptr &token, const std::string &label) override; + WSError SetSessionIcon(const sptr &token, const std::shared_ptr &icon) override; + WSError IsValidSessionIds(const std::vector &sessionIds, std::vector &results) override; + WSError RegisterSessionListener(const sptr sessionListener) override; + void UnregisterSessionListener() override; void HandleTurnScreenOn(const sptr& sceneSession); void HandleKeepScreenOn(const sptr& sceneSession, bool requireLock); void InitWithRenderServiceAdded(); - WSError PendingSessionToForeground(const sptr &token); - WSError PendingSessionToBackgroundForDelegator(const sptr &token); - WSError GetFocusSessionToken(sptr &token); - - WSError RegisterSessionListener(const sptr& listener); - WSError UnRegisterSessionListener(const sptr& listener); - WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, std::vector& sessionInfos); - WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo); - WSError DumpSessionAll(std::vector &infos); - WSError DumpSessionWithId(int32_t persistentId, std::vector &infos); + WSError PendingSessionToForeground(const sptr &token) override; + WSError PendingSessionToBackgroundForDelegator(const sptr &token) override; + WSError GetFocusSessionToken(sptr &token) override; + + WSError RegisterSessionListener(const sptr& listener) override; + WSError UnRegisterSessionListener(const sptr& listener) override; + WSError GetSessionInfos(const std::string& deviceId, int32_t numMax, + std::vector& sessionInfos) override; + WSError GetSessionInfo(const std::string& deviceId, int32_t persistentId, SessionInfoBean& sessionInfo) override; + WSError DumpSessionAll(std::vector &infos) override; + WSError DumpSessionWithId(int32_t persistentId, std::vector &infos) override; WSError GetAllAbilityInfos(const AAFwk::Want &want, int32_t userId, std::vector &abilityInfos); WSError PrepareTerminate(int32_t persistentId, bool& isPrepareTerminate); - WSError TerminateSessionNew(const sptr info, bool needStartCaller); - WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); - WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); + WSError TerminateSessionNew(const sptr info, bool needStartCaller) override; + WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) override; + WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) override; WSError GetSessionSnapshot(const std::string& deviceId, int32_t persistentId, - SessionSnapshot& snapshot, bool isLowResolution); - WSError SetSessionContinueState(const sptr &token, const ContinueState& continueState); - WSError ClearSession(int32_t persistentId); - WSError ClearAllSessions(); - WSError LockSession(int32_t sessionId); - WSError UnlockSession(int32_t sessionId); - WSError MoveSessionsToForeground(const std::vector& sessionIds, int32_t topSessionId); - WSError MoveSessionsToBackground(const std::vector& sessionIds, std::vector& result); + SessionSnapshot& snapshot, bool isLowResolution) override; + WSError SetSessionContinueState(const sptr &token, const ContinueState& continueState) override; + WSError ClearSession(int32_t persistentId) override; + WSError ClearAllSessions() override; + WSError LockSession(int32_t sessionId) override; + WSError UnlockSession(int32_t sessionId) override; + WSError MoveSessionsToForeground(const std::vector& sessionIds, int32_t topSessionId) override; + WSError MoveSessionsToBackground(const std::vector& sessionIds, std::vector& result) override; std::map>& GetSessionMapByScreenId(ScreenId id); void UpdatePrivateStateAndNotify(uint32_t persistentId); @@ -187,13 +189,13 @@ public: void OnOutsideDownEvent(int32_t x, int32_t y); void NotifySessionTouchOutside(int32_t persistentId); - WMError GetAccessibilityWindowInfo(std::vector>& infos); + WMError GetAccessibilityWindowInfo(std::vector>& infos) override; WSError SetWindowFlags(const sptr& sceneSession, uint32_t flags); void NotifyOccupiedAreaChangeInfo(const sptr sceneSession, const WSRect& rect, const WSRect& occupiedArea); void OnScreenshot(DisplayId displayId); - void NotifyDumpInfoResult(const std::vector& info); + void NotifyDumpInfoResult(const std::vector& info) override; void SetVirtualPixelRatioChangeListener(const ProcessVirtualPixelRatioChangeFunc& func); void ProcessVirtualPixelRatioChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map>& displayInfoMap, DisplayStateChangeType type); @@ -203,11 +205,12 @@ public: RunnableFuture> dumpInfoFuture_; void RegisterWindowChanged(const WindowChangedFunc& func); - WSError RegisterIAbilityManagerCollaborator(int32_t type, const sptr &impl); - WSError UnregisterIAbilityManagerCollaborator(int32_t type); + WSError RegisterIAbilityManagerCollaborator(int32_t type, + const sptr &impl) override; + WSError UnregisterIAbilityManagerCollaborator(int32_t type) override; WSError RecoveryPullPiPMainWindow(const int32_t& persistentId); - WMError CheckWindowId(int32_t windowId, int32_t &pid); + WMError CheckWindowId(int32_t windowId, int32_t &pid) override; int GetSceneSessionPrivacyModeCount(); BrokerStates CheckIfReuseSession(SessionInfo& sessionInfo); bool CheckCollaboratorType(int32_t type); @@ -222,6 +225,8 @@ public: WSRect GetAINavigationBarArea(); bool UpdateImmersiveState(); WSError UpdateTitleInTargetPos(int32_t persistentId, bool isShow, int32_t height); + void RegisterCreateSubSessionListener(int32_t persistentId, const NotifyCreateSubSessionFunc& func); + void UnregisterCreateSubSessionListener(int32_t persistentId); void NotifyUpdateRectAfterLayout(); public: @@ -361,7 +366,8 @@ private: std::set touchOutsideListenerSessionSet_; std::map> lastUpdatedAvoidArea_; - NotifyCreateSpecificSessionFunc createSpecificSessionFunc_; + NotifyCreateSystemSessionFunc createSystemSessionFunc_; + std::map createSubSessionFuncMap_; ProcessStatusBarEnabledChangeFunc statusBarEnabledChangeFunc_; ProcessGestureNavigationEnabledChangeFunc gestureNavigationEnabledChangeFunc_; ProcessOutsideDownEventFunc outsideDownEventFunc_; @@ -441,6 +447,9 @@ private: void NotifySessionForeground(const sptr& session, uint32_t reason, bool withAnimation); void NotifySessionBackground(const sptr& session, uint32_t reason, bool withAnimation, bool isFromInnerkits); + void NotifyCreateSubSession(int32_t persistentId, sptr session); + void NotifyCreateSpecificSession(sptr session, + sptr property, const WindowType& type); sptr CreateSceneSession(const SessionInfo& sessionInfo, sptr property); void ProcessPiPSessionForeground(const sptr sceneSession); diff --git a/window_scene/session_manager/include/session_manager.h b/window_scene/session_manager/include/session_manager.h index 599b9b0f75..2404d55e93 100644 --- a/window_scene/session_manager/include/session_manager.h +++ b/window_scene/session_manager/include/session_manager.h @@ -32,15 +32,6 @@ public: class SessionManager { WM_DECLARE_SINGLE_INSTANCE_BASE(SessionManager); public: - void CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr); - void DestroyAndDisconnectSpecificSession(const int32_t& persistentId); - WMError UpdateProperty(sptr& property, WSPropertyChangeAction action); - WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); - WMError BindDialogTarget(uint64_t persistentId, sptr targetToken); - WMError RequestFocusStatus(int32_t persistentId, bool isFocused); void ClearSessionManagerProxy(); void Clear(); diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index df3d29e09f..83512be9af 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -90,14 +90,6 @@ public: TRANS_ID_UPDATE_TOUCHOUTSIDE_LISTENER, }; - virtual WSError CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, - sptr token = nullptr) = 0; - virtual WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) = 0; - virtual WMError UpdateProperty(sptr& property, WSPropertyChangeAction action) = 0; - virtual WSError BindDialogTarget(uint64_t persistentId, sptr targetToken) = 0; - virtual WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) = 0; virtual WSError SetSessionLabel(const sptr &token, const std::string &label) = 0; virtual WSError SetSessionIcon(const sptr &token, const std::shared_ptr &icon) = 0; virtual WSError IsValidSessionIds(const std::vector &sessionIds, std::vector &results) = 0; @@ -142,7 +134,6 @@ public: WMError RemoveWindow(uint32_t windowId, bool isFromInnerkits) override { return WMError::WM_OK; } WMError DestroyWindow(uint32_t windowId, bool onlySelf = false) override { return WMError::WM_OK; } WMError RequestFocus(uint32_t windowId) override { return WMError::WM_OK; } - virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = false) = 0; AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type) override { return {}; } WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId) override { return WMError::WM_OK; } void NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr& windowProperty, diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index 507957407d..6f91de024f 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -32,8 +32,8 @@ public: sptr property, int32_t& persistentId, sptr& session, sptr token = nullptr) override; WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) override; - WMError UpdateProperty(sptr& property, WSPropertyChangeAction action) override; - WSError BindDialogTarget(uint64_t persistentId, sptr targetToken) override; + WMError UpdateSessionProperty(const sptr& property, WSPropertyChangeAction action) override; + WSError BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) override; WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = false) override; WMError RegisterWindowManagerAgent(WindowManagerAgentType type, diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index c4dcc37ce2..fed041b4d4 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -786,7 +786,7 @@ WSError SceneSessionManager::UpdateParentSessionForDialog(const sptrBindDialogTarget(sceneSession); + parentSession->BindDialogSessionTarget(sceneSession); parentSession->BindDialogToParentSession(sceneSession); sceneSession->SetParentSession(parentSession); WLOGFD("Update parent of dialog success, id %{public}d, parentId %{public}d", @@ -1431,30 +1431,27 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrGetWindowType(); // create specific session SessionInfo info; - if (property) { - info.windowType_ = static_cast(property->GetWindowType()); - } - ClosePipWindowIfExist(property->GetWindowType()); - sptr sceneSession = RequestSceneSession(info, property); - if (sceneSession == nullptr) { + info.windowType_ = static_cast(type); + ClosePipWindowIfExist(type); + sptr newSession = RequestSceneSession(info, property); + if (newSession == nullptr) { return WSError::WS_ERROR_NULLPTR; } - auto errCode = sceneSession->Connect( + auto errCode = newSession->Connect( sessionStage, eventChannel, surfaceNode, systemConfig_, property, token, pid, uid); if (property) { persistentId = property->GetPersistentId(); } - if (createSpecificSessionFunc_ && info.windowType_ != static_cast(WindowType::WINDOW_TYPE_DIALOG)) { - createSpecificSessionFunc_(sceneSession); - } - session = sceneSession; - AddClientDeathRecipient(sessionStage, sceneSession); - if (WindowHelper::IsMainWindow(sceneSession->GetWindowType())) { - auto sessionInfo = sceneSession->GetSessionInfo(); - WindowInfoReporter::GetInstance().InsertCreateReportInfo(sessionInfo.bundleName_); - } + + NotifyCreateSpecificSession(newSession, property, type); + session = newSession; + AddClientDeathRecipient(sessionStage, newSession); return errCode; }; @@ -1507,9 +1504,96 @@ bool SceneSessionManager::CheckSystemWindowPermission(const sptrPostSyncTask(task); +} + +void SceneSessionManager::NotifyCreateSpecificSession(sptr newSession, + sptr property, const WindowType& type) +{ + if (newSession == nullptr) { + WLOGFE("newSession is nullptr"); + return; + } + if (property == nullptr) { + WLOGFE("property is nullptr"); + return; + } + if (SessionHelper::IsSystemWindow(type)) { + if (createSystemSessionFunc_ && type != WindowType::WINDOW_TYPE_DIALOG) { + createSystemSessionFunc_(newSession); + WLOGFD("Create system session, id:%{public}d, type: %{public}d", newSession->GetPersistentId(), type); + } else { + WLOGFW("Didn't create jsSceneSession for this system type, id:%{public}d, type: %{public}d", + newSession->GetPersistentId(), type); + return; + } + } else if (SessionHelper::IsSubWindow(type)) { + NotifyCreateSubSession(property->GetParentPersistentId(), newSession); + WLOGFD("Notify sub jsSceneSession, id:%{public}d, parentId: %{public}d, type: %{public}d", + newSession->GetPersistentId(), property->GetParentPersistentId(), type); + } else { + WLOGFW("Invalid session type, id:%{public}d, type: %{public}d", newSession->GetPersistentId(), type); + } +} + +void SceneSessionManager::NotifyCreateSubSession(int32_t persistentId, sptr session) +{ + if (session == nullptr) { + WLOGFE("SubSession is nullptr"); + return; + } + auto iter = createSubSessionFuncMap_.find(persistentId); + if (iter == createSubSessionFuncMap_.end()) { + WLOGFW("Can't find CreateSubSessionListener, parentId: %{public}d", persistentId); + return; + } + + auto parentSession = GetSceneSession(persistentId); + if (parentSession == nullptr) { + WLOGFE("Can't find CreateSubSessionListener, parentId: %{public}d, subId: %{public}d", + persistentId, session->GetPersistentId()); + return; + } + parentSession->AddSubSession(session); + session->SetParentSession(parentSession); + if (iter->second) { + iter->second(session); + } + WLOGFD("NotifyCreateSubSession success, parentId: %{public}d, subId: %{public}d", + persistentId, session->GetPersistentId()); +} + +void SceneSessionManager::UnregisterCreateSubSessionListener(int32_t persistentId) +{ + WLOGFI("UnregisterCreateSubSessionListener, id: %{public}d", persistentId); + auto task = [this, persistentId]() { + auto iter = createSubSessionFuncMap_.find(persistentId); + if (iter != createSubSessionFuncMap_.end()) { + createSubSessionFuncMap_.erase(persistentId); + } else { + WLOGFW("Can't find CreateSubSessionListener, id: %{public}d", persistentId); + } + return WMError::WM_OK; + }; + taskScheduler_->PostSyncTask(task); } void SceneSessionManager::NotifyStatusBarEnabledChange(bool enable) @@ -1619,15 +1703,21 @@ WSError SceneSessionManager::DestroyAndDisconnectSpecificSession(const int32_t& } ret = sceneSession->Disconnect(); sceneSession->ClearSpecificSessionCbMap(); + if (SessionHelper::IsSubWindow(sceneSession->GetWindowType())) { + auto parentSession = GetSceneSession(sceneSession->GetParentPersistentId()); + if (parentSession != nullptr) { + WLOGFD("Find parentSession, id: %{public}d", persistentId); + parentSession->RemoveSubSession(sceneSession->GetPersistentId()); + } else { + WLOGFW("ParentSession is nullptr, id: %{public}d", persistentId); + } + } { std::unique_lock lock(sceneSessionMapMutex_); sceneSessionMap_.erase(persistentId); systemTopSceneSessionMap_.erase(persistentId); nonSystemFloatSceneSessionMap_.erase(persistentId); - } - if (WindowHelper::IsMainWindow(sceneSession->GetWindowType())) { - auto sessionInfo = sceneSession->GetSessionInfo(); - WindowInfoReporter::GetInstance().InsertDestroyReportInfo(sessionInfo.bundleName_); + UnregisterCreateSubSessionListener(persistentId); } return ret; }; @@ -1887,7 +1977,8 @@ std::shared_ptr SceneSessionManager::QueryAbilityInfoFr return abilityInfo; } -WMError SceneSessionManager::UpdateProperty(sptr& property, WSPropertyChangeAction action) +WMError SceneSessionManager::UpdateSessionProperty(const sptr& property, + WSPropertyChangeAction action) { if (property == nullptr) { WLOGFE("property is nullptr"); @@ -4132,10 +4223,10 @@ sptr SceneSessionManager::FindMainWindowWithToken(sptrsecond; } -WSError SceneSessionManager::BindDialogTarget(uint64_t persistentId, sptr targetToken) +WSError SceneSessionManager::BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) { if (!SessionPermission::IsSystemCalling()) { - WLOGFE("BindDialogTarget permission denied!"); + WLOGFE("BindDialogSessionTarget permission denied!"); return WSError::WS_ERROR_NOT_SYSTEM_APP; } if (targetToken == nullptr) { diff --git a/window_scene/session_manager/src/session_manager.cpp b/window_scene/session_manager/src/session_manager.cpp index 43a8cab20f..95bdd38ee2 100644 --- a/window_scene/session_manager/src/session_manager.cpp +++ b/window_scene/session_manager/src/session_manager.cpp @@ -149,79 +149,4 @@ void SSMDeathRecipient::OnRemoteDied(const wptr& wptrDeath) SingletonContainer::Get().Clear(); SingletonContainer::Get().ClearSessionManagerProxy(); } - -void SessionManager::CreateAndConnectSpecificSession(const sptr& sessionStage, - const sptr& eventChannel, const std::shared_ptr& surfaceNode, - sptr property, int32_t& persistentId, sptr& session, sptr token) -{ - WLOGFD("CreateAndConnectSpecificSession"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return; - } - sceneSessionManagerProxy_->CreateAndConnectSpecificSession(sessionStage, eventChannel, - surfaceNode, property, persistentId, session, token); -} - -void SessionManager::DestroyAndDisconnectSpecificSession(const int32_t& persistentId) -{ - WLOGFD("DestroyAndDisconnectSpecificSession"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return; - } - sceneSessionManagerProxy_->DestroyAndDisconnectSpecificSession(persistentId); -} - -WMError SessionManager::UpdateProperty(sptr& property, WSPropertyChangeAction action) -{ - WLOGFD("UpdateProperty"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return WMError::WM_DO_NOTHING; - } - return sceneSessionManagerProxy_->UpdateProperty(property, action); -} - -WMError SessionManager::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) -{ - WLOGFD("SetWindowGravity"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return WMError::WM_DO_NOTHING; - } - return static_cast(sceneSessionManagerProxy_->SetSessionGravity(persistentId, gravity, percent)); -} - -WMError SessionManager::BindDialogTarget(uint64_t persistentId, sptr targetToken) -{ - WLOGFD("BindDialogTarget"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return WMError::WM_DO_NOTHING; - } - return static_cast(sceneSessionManagerProxy_->BindDialogTarget(persistentId, targetToken)); -} - -WMError SessionManager::RequestFocusStatus(int32_t persistentId, bool isFocused) -{ - WLOGFD("RequestFocusStatus"); - std::lock_guard lock(mutex_); - GetSceneSessionManagerProxy(); - if (!sceneSessionManagerProxy_) { - WLOGFE("sceneSessionManagerProxy_ is nullptr"); - return WMError::WM_DO_NOTHING; - } - return static_cast(sceneSessionManagerProxy_->RequestFocusStatus(persistentId, isFocused)); -} } // namespace OHOS::Rosen diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index b93eb941ea..be2bf0b9cc 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -107,7 +107,8 @@ WSError SceneSessionManagerProxy::DestroyAndDisconnectSpecificSession(const int3 return static_cast(ret); } -WMError SceneSessionManagerProxy::UpdateProperty(sptr& property, WSPropertyChangeAction action) +WMError SceneSessionManagerProxy::UpdateSessionProperty(const sptr& property, + WSPropertyChangeAction action) { MessageParcel data; MessageParcel reply; @@ -170,7 +171,7 @@ WMError SceneSessionManagerProxy::RequestFocusStatus(int32_t persistentId, bool return static_cast(ret); } -WSError SceneSessionManagerProxy::BindDialogTarget(uint64_t persistentId, sptr targetToken) +WSError SceneSessionManagerProxy::BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) { MessageParcel data; MessageParcel reply; diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index 31febe5566..5199b8b191 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -194,7 +194,7 @@ int SceneSessionManagerStub::HandleUpdateProperty(MessageParcel &data, MessagePa } else { WLOGFW("Property not exist!"); } - const WMError& ret = UpdateProperty(property, action); + const WMError& ret = UpdateSessionProperty(property, action); reply.WriteInt32(static_cast(ret)); return ERR_NONE; } @@ -531,7 +531,7 @@ int SceneSessionManagerStub::HandleBindDialogTarget(MessageParcel &data, Message WLOGFI("run HandleBindDialogTarget!"); auto persistentId = data.ReadUint64(); sptr remoteObject = data.ReadRemoteObject(); - const WSError& ret = BindDialogTarget(persistentId, remoteObject); + const WSError& ret = BindDialogSessionTarget(persistentId, remoteObject); reply.WriteUint32(static_cast(ret)); return ERR_NONE; } diff --git a/window_scene/test/mock/mock_session_stub.h b/window_scene/test/mock/mock_session_stub.h index 8a6220dda0..d3635ebaee 100644 --- a/window_scene/test/mock/mock_session_stub.h +++ b/window_scene/test/mock/mock_session_stub.h @@ -37,6 +37,8 @@ public: MOCK_METHOD1(Foreground, WSError(sptr property)); MOCK_METHOD0(Background, WSError(void)); MOCK_METHOD0(Disconnect, WSError(void)); + MOCK_METHOD1(Show, WSError(sptr property)); + MOCK_METHOD0(Hide, WSError(void)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); @@ -47,8 +49,6 @@ public: MOCK_METHOD2(HandleUpdateActivateStatus, int(MessageParcel &data, MessageParcel &reply)); MOCK_METHOD2(HandleSessionEvent, int(MessageParcel &data, MessageParcel &reply)); MOCK_METHOD2(HandleUpdateSessionRect, int(MessageParcel &data, MessageParcel &reply)); - MOCK_METHOD2(HandleCreateAndConnectSpecificSession, int(MessageParcel &data, MessageParcel &reply)); - MOCK_METHOD2(HandleDestroyAndDisconnectSpecificSession, int(MessageParcel &data, MessageParcel &reply)); MOCK_METHOD2(HandleRaiseToAppTop, int(MessageParcel &data, MessageParcel &reply)); MOCK_METHOD2(HandleBackPressed, int(MessageParcel &data, MessageParcel &reply)); MOCK_METHOD2(HandleMarkProcessed, int(MessageParcel &data, MessageParcel &reply)); diff --git a/window_scene/test/unittest/scene_session_manager_test.cpp b/window_scene/test/unittest/scene_session_manager_test.cpp index 88b73e0d6b..aababd5321 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -649,7 +649,7 @@ HWTEST_F(SceneSessionManagerTest, ConfigDecor06, Function | SmallTest | Level3) /** * @tc.name: ConfigWindowSceneXml01 - * @tc.desc: call defaultWindowMode + * @tc.desc: call defaultWindowMode * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest, ConfigWindowSceneXml01, Function | SmallTest | Level3) @@ -705,7 +705,7 @@ HWTEST_F(SceneSessionManagerTest, ConfigWindowSceneXml02, Function | SmallTest | /** * @tc.name: ConfigWindowSceneXml03 - * @tc.desc: call defaultMaximizeMode + * @tc.desc: call defaultMaximizeMode * @tc.type: FUNC */ HWTEST_F(SceneSessionManagerTest, ConfigWindowSceneXml03, Function | SmallTest | Level3) @@ -1907,14 +1907,14 @@ HWTEST_F(SceneSessionManagerTest, DestroySpecificSession, Function | SmallTest | } /** - * @tc.name: SetCreateSpecificSessionListener + * @tc.name: SetCreateSystemSessionListener * @tc.desc: SceneSesionManager set create specific session listener * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, SetCreateSpecificSessionListener, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, SetCreateSystemSessionListener, Function | SmallTest | Level3) { int ret = 0; - ssm_->SetCreateSpecificSessionListener(nullptr); + ssm_->SetCreateSystemSessionListener(nullptr); ASSERT_EQ(ret, 0); } @@ -2208,15 +2208,15 @@ HWTEST_F(SceneSessionManagerTest, IsSessionClearable, Function | SmallTest | Lev } /** - * @tc.name: UpdateProperty + * @tc.name: UpdateSessionProperty * @tc.desc: SceneSesionManager update property * @tc.type: FUNC */ -HWTEST_F(SceneSessionManagerTest, UpdateProperty, Function | SmallTest | Level3) +HWTEST_F(SceneSessionManagerTest, UpdateSessionProperty, Function | SmallTest | Level3) { sptr property = new WindowSessionProperty(); WSPropertyChangeAction action = WSPropertyChangeAction::ACTION_UPDATE_TOUCHABLE; - WMError result = ssm_->UpdateProperty(property, action); + WMError result = ssm_->UpdateSessionProperty(property, action); ASSERT_EQ(result, WMError::WM_OK); SessionInfo info; info.abilityName_ = "Foreground01"; @@ -2252,7 +2252,7 @@ HWTEST_F(SceneSessionManagerTest, HandleUpdateProperty01, Function | SmallTest | ssm_->HandleUpdateProperty(property, action, scensession); action = WSPropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS; ssm_->HandleUpdateProperty(property, action, scensession); - WMError result = ssm_->UpdateProperty(property, action); + WMError result = ssm_->UpdateSessionProperty(property, action); EXPECT_EQ(result, WMError::WM_OK); ssm_->HandleUpdateProperty(property, action, scensession); action = WSPropertyChangeAction::ACTION_UPDATE_ORIENTATION; @@ -2297,7 +2297,7 @@ HWTEST_F(SceneSessionManagerTest, HandleUpdateProperty02, Function | SmallTest | ssm_->HandleUpdateProperty(property, action, scensession); action = WSPropertyChangeAction::ACTION_UPDATE_RAISEENABLED; ssm_->HandleUpdateProperty(property, action, scensession); - WMError result = ssm_->UpdateProperty(property, action); + WMError result = ssm_->UpdateSessionProperty(property, action); EXPECT_EQ(result, WMError::WM_OK); action = WSPropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE; ssm_->HandleUpdateProperty(property, action, scensession); @@ -2324,7 +2324,7 @@ HWTEST_F(SceneSessionManagerTest, HandleTurnScreenOn, Function | SmallTest | Lev ssm_->HandleKeepScreenOn(scensession, requireLock); requireLock = false; ssm_->HandleKeepScreenOn(scensession, requireLock); - WMError result = ssm_->UpdateProperty(property, action); + WMError result = ssm_->UpdateSessionProperty(property, action); ASSERT_EQ(result, WMError::WM_OK); delete scensession; delete property; @@ -2798,7 +2798,7 @@ HWTEST_F(SceneSessionManagerTest, FindMainWindowWithToken, Function | SmallTest sptr result = ssm_->FindMainWindowWithToken(targetToken); EXPECT_EQ(result, nullptr); uint64_t persistentId = 1423; - WSError result01 = ssm_->BindDialogTarget(persistentId, targetToken); + WSError result01 = ssm_->BindDialogSessionTarget(persistentId, targetToken); EXPECT_EQ(result01, WSError::WS_ERROR_NULLPTR); } diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index 25f15d6e0f..c98e59eeb9 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -15,6 +15,8 @@ #include #include "session/host/include/scene_session.h" +#include "session/host/include/sub_session.h" +#include "session/host/include/system_session.h" #include "wm_common.h" #include "mock/mock_session_stage.h" #include "input_event.h" @@ -195,10 +197,6 @@ HWTEST_F(SceneSessionTest, UpdateWindowSceneAfterCustomAnimation01, Function | S ASSERT_EQ(result, WSError::WS_OK); result = scensession->UpdateWindowSceneAfterCustomAnimation(true); ASSERT_EQ(result, WSError::WS_OK); - sptr setWindowScenePatternFunc = - new (std::nothrow) SceneSession::SetWindowScenePatternFunc(); - scensession->setWindowScenePatternFunc_ = setWindowScenePatternFunc; - ASSERT_EQ(result = scensession->UpdateWindowSceneAfterCustomAnimation(true), WSError::WS_OK); } /** @@ -302,34 +300,6 @@ HWTEST_F(SceneSessionTest, UpdateWindowAnimationFlag01, Function | SmallTest | L ASSERT_EQ(WSError::WS_OK, scensession->UpdateWindowAnimationFlag(false)); } -/** - * @tc.name: GetHotAreaRect01 - * @tc.desc: GetHotAreaRect - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionTest, GetHotAreaRect01, Function | SmallTest | Level2) -{ - SessionInfo info; - info.abilityName_ = "Background01"; - info.bundleName_ = "GetHotAreaRect01"; - sptr session_; - sptr specificCallback_ = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCallback_, nullptr); - sptr scensession; - scensession = new (std::nothrow) SceneSession(info, nullptr); - EXPECT_NE(scensession, nullptr); - Rect windowRect = { 1, 1, 1, 1 }; - std::vector rects; - uint32_t hotAreasNum = 10; - uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum; - uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum; - for (uint32_t i = 0; i < hotAreasNum; ++i) { - rects.emplace_back(Rect{ hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight }); - } - ASSERT_NE(windowRect, scensession->GetHotAreaRect(2)); -} - /** * @tc.name: ClearEnterWindow01 * @tc.desc: ClearEnterWindow @@ -1023,22 +993,22 @@ HWTEST_F(SceneSessionTest, UpdateCameraFloatWindowStatus, Function | SmallTest | sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); - sptr scensession; - scensession = new (std::nothrow) SceneSession(info, specificCallback_); - EXPECT_NE(scensession, nullptr); + sptr sysSession; + sysSession = new (std::nothrow) SystemSession(info, specificCallback_); + EXPECT_NE(sysSession, nullptr); int ret = 1; specificCallback_->onCameraFloatSessionChange_ = [](uint32_t accessTokenId, bool isShowing) {}; - scensession->UpdateCameraFloatWindowStatus(false); - scensession = new (std::nothrow) SceneSession(info, specificCallback_); - scensession->UpdateCameraFloatWindowStatus(false); + sysSession->UpdateCameraFloatWindowStatus(false); + sysSession = new (std::nothrow) SystemSession(info, specificCallback_); + sysSession->UpdateCameraFloatWindowStatus(false); sptr property = new WindowSessionProperty(); property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); - scensession->property_ = property; - scensession->UpdateCameraFloatWindowStatus(false); + sysSession->property_ = property; + sysSession->UpdateCameraFloatWindowStatus(false); property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA); - scensession->property_ = property; - scensession->UpdateCameraFloatWindowStatus(false); + sysSession->property_ = property; + sysSession->UpdateCameraFloatWindowStatus(false); ASSERT_EQ(ret, 1); } @@ -1640,15 +1610,15 @@ HWTEST_F(SceneSessionTest, RaiseAboveTarget, Function | SmallTest | Level2) } /** - * @tc.name: BindDialogTarget + * @tc.name: BindDialogSessionTarget * @tc.desc: normal function * @tc.type: FUNC */ -HWTEST_F(SceneSessionTest, BindDialogTarget, Function | SmallTest | Level2) +HWTEST_F(SceneSessionTest, BindDialogSessionTarget, Function | SmallTest | Level2) { SessionInfo info; - info.abilityName_ = "BindDialogTarget"; - info.bundleName_ = "BindDialogTarget"; + info.abilityName_ = "BindDialogSessionTarget"; + info.bundleName_ = "BindDialogSessionTarget"; sptr session_; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); @@ -1664,44 +1634,15 @@ HWTEST_F(SceneSessionTest, BindDialogTarget, Function | SmallTest | Level2) scensession->SetSessionProperty(property); sptr sceneSession = nullptr; - WSError result = scensession->BindDialogTarget(sceneSession); + WSError result = scensession->BindDialogSessionTarget(sceneSession); ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); sptr sceneSession1 = scensession; - result = scensession->BindDialogTarget(sceneSession1); + result = scensession->BindDialogSessionTarget(sceneSession1); ASSERT_EQ(result, WSError::WS_OK); delete scensession; } -/** - * @tc.name: DestroyAndDisconnectSpecificSession - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SceneSessionTest, DestroyAndDisconnectSpecificSession, Function | SmallTest | Level2) -{ - SessionInfo info; - info.abilityName_ = "DestroyAndDisconnectSpecificSession"; - info.bundleName_ = "DestroyAndDisconnectSpecificSession"; - sptr session_; - sptr specificCallback_ = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCallback_, nullptr); - sptr scensession = new (std::nothrow) SceneSession(info, nullptr); - EXPECT_NE(scensession, nullptr); - scensession->isActive_ = true; - - sptr property = new(std::nothrow) WindowSessionProperty(); - property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); - uint32_t p = 10; - property->SetSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p); - scensession->SetSessionProperty(property); - - WSError result = scensession->DestroyAndDisconnectSpecificSession(0); - ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); - delete scensession; -} - /** * @tc.name: NotifyPropertyWhenConnect1 * @tc.desc: NotifyPropertyWhenConnect1 diff --git a/window_scene/test/unittest/session_proxy_test.cpp b/window_scene/test/unittest/session_proxy_test.cpp index be0158a685..f1f79014aa 100644 --- a/window_scene/test/unittest/session_proxy_test.cpp +++ b/window_scene/test/unittest/session_proxy_test.cpp @@ -446,21 +446,6 @@ HWTEST_F(SessionProxyTest, UpdateWindowAnimationFlag, Function | SmallTest | Lev GTEST_LOG_(INFO) << "SessionProxyTest: UpdateWindowAnimationFlag end"; } - -/** - * @tc.name: DestroyAndDisconnectSpecificSession - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(SessionProxyTest, DestroyAndDisconnectSpecificSession, Function | SmallTest | Level2) -{ - GTEST_LOG_(INFO) << "SessionProxyTest: DestroyAndDisconnectSpecificSession start"; - sptr iRemoteObjectMocker = new IRemoteObjectMocker(); - SessionProxy* sProxy = new(std::nothrow) SessionProxy(iRemoteObjectMocker); - int32_t persistentId = 0; - sProxy->DestroyAndDisconnectSpecificSession(persistentId); - GTEST_LOG_(INFO) << "SessionProxyTest: DestroyAndDisconnectSpecificSession end"; -} } // namespace } // namespace Rosen } // namespace OHOS diff --git a/window_scene/test/unittest/session_stub_test.cpp b/window_scene/test/unittest/session_stub_test.cpp index c63c29e5c6..8a37f9db9b 100644 --- a/window_scene/test/unittest/session_stub_test.cpp +++ b/window_scene/test/unittest/session_stub_test.cpp @@ -119,10 +119,6 @@ HWTEST_F(SessionStubTest, sessionStubTest01, Function | SmallTest | Level2) ASSERT_EQ(0, res); res = session_->HandleUpdateSessionRect(data, reply); ASSERT_EQ(0, res); - res = session_->HandleCreateAndConnectSpecificSession(data, reply); - ASSERT_EQ(5, res); - res = session_->HandleDestroyAndDisconnectSpecificSession(data, reply); - ASSERT_EQ(0, res); res = session_->HandleRaiseToAppTop(data, reply); ASSERT_EQ(0, res); } diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 95430d3040..c90a5f62db 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -534,47 +534,6 @@ HWTEST_F(WindowSessionTest, UpdateSessionRect01, Function | SmallTest | Level2) ASSERT_EQ(result, WSError::WS_OK); } -/** - * @tc.name: CreateAndConnectSpecificSession02 - * @tc.desc: CreateAndConnectSpecificSession - * @tc.type: FUNC - */ -HWTEST_F(WindowSessionTest, CreateAndConnectSpecificSession2, Function | SmallTest | Level2) -{ - SessionInfo info; - info.abilityName_ = "testSession1"; - info.bundleName_ = "testSession3"; - sptr session_; - auto surfaceNode_ = CreateRSSurfaceNode(); - sptr property_ = nullptr; - int32_t persistentId = 0; - sptr mockSessionStage = new (std::nothrow) SessionStageMocker(); - EXPECT_NE(mockSessionStage, nullptr); - sptr specificCallback_ = - new (std::nothrow) SceneSession::SpecificSessionCallback(); - EXPECT_NE(specificCallback_, nullptr); - int resultValue = 0; - sptr scensession; - sptr testWindowEventChannel = new (std::nothrow) TestWindowEventChannel(); - EXPECT_NE(testWindowEventChannel, nullptr); - - scensession = new (std::nothrow) SceneSession(info, nullptr); - EXPECT_NE(scensession, nullptr); - auto result = scensession->CreateAndConnectSpecificSession(mockSessionStage, testWindowEventChannel, surfaceNode_, - property_, persistentId, session_); - ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR); - specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info, - sptr property) -> sptr - { - sptr scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_); - EXPECT_NE(scensessionreturn, nullptr); - resultValue = 1; - return scensessionreturn; - }; - scensession = new (std::nothrow) SceneSession(info, specificCallback_); - EXPECT_NE(scensession, nullptr); -} - /** * @tc.name: OnSessionEvent01 * @tc.desc: OnSessionEvent @@ -1021,7 +980,7 @@ HWTEST_F(WindowSessionTest, NotifyForeground, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); session_->state_ = SessionState::STATE_DISCONNECT; session_->NotifyForeground(); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1035,7 +994,7 @@ HWTEST_F(WindowSessionTest, NotifyBackground, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); session_->state_ = SessionState::STATE_DISCONNECT; session_->NotifyBackground(); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1049,7 +1008,7 @@ HWTEST_F(WindowSessionTest, NotifyExtensionDied, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); session_->state_ = SessionState::STATE_DISCONNECT; session_->NotifyExtensionDied(); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1076,7 +1035,7 @@ HWTEST_F(WindowSessionTest, UpdateSessionTouchable, Function | SmallTest | Level session_->state_ = SessionState::STATE_DISCONNECT; session_->UpdateSessionTouchable(false); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1129,7 +1088,7 @@ HWTEST_F(WindowSessionTest, SetNeedNotify, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); session_->state_ = SessionState::STATE_DISCONNECT; session_->SetNeedNotify(false); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1271,7 +1230,7 @@ HWTEST_F(WindowSessionTest, SetTerminateSessionListener, Function | SmallTest | session_->state_ = SessionState::STATE_DISCONNECT; NotifyTerminateSessionFunc func = nullptr; session_->SetTerminateSessionListener(func); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1326,7 +1285,7 @@ HWTEST_F(WindowSessionTest, SetTerminateSessionListenerTotal, Function | SmallTe session_->state_ = SessionState::STATE_DISCONNECT; NotifyTerminateSessionFuncTotal func = nullptr; session_->SetTerminateSessionListenerTotal(func); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1354,7 +1313,7 @@ HWTEST_F(WindowSessionTest, SetUpdateSessionLabelListener, Function | SmallTest session_->state_ = SessionState::STATE_DISCONNECT; NofitySessionLabelUpdatedFunc func = nullptr; session_->SetUpdateSessionLabelListener(func); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1369,7 +1328,7 @@ HWTEST_F(WindowSessionTest, SetPendingSessionToForegroundListener, Function | Sm session_->state_ = SessionState::STATE_DISCONNECT; NotifyPendingSessionToForegroundFunc func = nullptr; session_->SetPendingSessionToForegroundListener(func); - + ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1410,7 +1369,7 @@ HWTEST_F(WindowSessionTest, NotifyTouchDialogTarget, Function | SmallTest | Leve ASSERT_NE(session_, nullptr); session_->sessionStage_ = nullptr; session_->NotifyTouchDialogTarget(); - + session_->property_ = new WindowSessionProperty(); ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1425,7 +1384,7 @@ HWTEST_F(WindowSessionTest, NotifyScreenshot, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); session_->sessionStage_ = nullptr; session_->NotifyScreenshot(); - + session_->property_ = new WindowSessionProperty(); ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1444,7 +1403,7 @@ HWTEST_F(WindowSessionTest, SetParentSession, Function | SmallTest | Level2) info.bundleName_ = "testSession3"; sptr session = new (std::nothrow) Session(info); session_->SetParentSession(session); - + session_->property_ = new WindowSessionProperty(); ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1463,7 +1422,7 @@ HWTEST_F(WindowSessionTest, BindDialogToParentSession, Function | SmallTest | Le info.bundleName_ = "testSession3"; sptr session = new (std::nothrow) Session(info); session_->BindDialogToParentSession(session); - + session_->property_ = new WindowSessionProperty(); ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1482,7 +1441,7 @@ HWTEST_F(WindowSessionTest, RemoveDialogToParentSession, Function | SmallTest | info.bundleName_ = "testSession3"; sptr session = new (std::nothrow) Session(info); session_->RemoveDialogToParentSession(session); - + session_->property_ = new WindowSessionProperty(); ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false)); } @@ -1635,7 +1594,7 @@ HWTEST_F(WindowSessionTest, TransferKeyEvent03, Function | SmallTest | Level2) ASSERT_NE(dialogSession, nullptr); dialogSession->state_ = SessionState::STATE_ACTIVE; session_->dialogVec_.push_back(dialogSession); - + ASSERT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, session_->TransferKeyEvent(keyEvent)); } @@ -1665,7 +1624,7 @@ HWTEST_F(WindowSessionTest, TransferKeyEvent04, Function | SmallTest | Level2) dialogSession->state_ = SessionState::STATE_ACTIVE; session_->dialogVec_.push_back(dialogSession); session_->parentSession_ = session_; - + ASSERT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, session_->TransferKeyEvent(keyEvent)); } diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 34ca54060f..5f952fe17c 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -19,12 +19,14 @@ #include #include +#include "common/include/window_session_property.h" #include "window.h" #include "zidl/window_interface.h" #include "singleton_delegator.h" #include "window_property.h" #include "wm_single_instance.h" #include "zidl/window_manager_interface.h" + namespace OHOS { namespace Rosen { class WMSDeathRecipient : public IRemoteObject::DeathRecipient { @@ -88,6 +90,16 @@ public: virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo); virtual WMError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener); virtual WMError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener); + + virtual void CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, int32_t& persistentId, sptr& session, + sptr token = nullptr); + virtual void DestroyAndDisconnectSpecificSession(const int32_t& persistentId); + virtual WMError UpdateSessionProperty(const sptr& property, WSPropertyChangeAction action); + virtual WMError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent); + virtual WMError BindDialogSessionTarget(uint64_t persistentId, sptr targetToken); + virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused); private: static inline SingletonDelegator delegator; bool InitWMSProxy(); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 70ff8e6de5..253edc3e58 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -406,5 +406,45 @@ WMError WindowAdapter::UpdateSessionTouchOutsideListener(int32_t& persistentId, INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); return static_cast(windowManagerServiceProxy_->UpdateSessionTouchOutsideListener(persistentId, haveListener)); } + +void WindowAdapter::CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, int32_t& persistentId, sptr& session, sptr token) +{ + INIT_PROXY_CHECK_RETURN(); + windowManagerServiceProxy_->CreateAndConnectSpecificSession(sessionStage, eventChannel, + surfaceNode, property, persistentId, session, token); +} + +void WindowAdapter::DestroyAndDisconnectSpecificSession(const int32_t& persistentId) +{ + INIT_PROXY_CHECK_RETURN(); + windowManagerServiceProxy_->DestroyAndDisconnectSpecificSession(persistentId); +} + +WMError WindowAdapter::UpdateSessionProperty(const sptr& property, + WSPropertyChangeAction action) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); + return windowManagerServiceProxy_->UpdateSessionProperty(property, action); +} + +WMError WindowAdapter::SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); + return static_cast(windowManagerServiceProxy_->SetSessionGravity(persistentId, gravity, percent)); +} + +WMError WindowAdapter::BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); + return static_cast(windowManagerServiceProxy_->BindDialogSessionTarget(persistentId, targetToken)); +} + +WMError WindowAdapter::RequestFocusStatus(int32_t persistentId, bool isFocused) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_DO_NOTHING); + return static_cast(windowManagerServiceProxy_->RequestFocusStatus(persistentId, isFocused)); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 7e46f3b275..d7bcb85274 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -146,8 +146,8 @@ WMError WindowSceneSessionImpl::CreateAndConnectSpecificSession() property_->SetParentPersistentId(parentSession->GetPersistentId()); windowSystemConfig_ = parentSession->GetSystemSessionConfig(); // creat sub session by parent session - parentSession->GetHostSession()->CreateAndConnectSpecificSession(iSessionStage, eventChannel, surfaceNode_, - property_, persistentId, session, token); + SingletonContainer::Get().CreateAndConnectSpecificSession(iSessionStage, eventChannel, + surfaceNode_, property_, persistentId, session, token); // update subWindowSessionMap_ subWindowSessionMap_[parentSession->GetPersistentId()].push_back(this); } else { // system window @@ -164,8 +164,8 @@ WMError WindowSceneSessionImpl::CreateAndConnectSpecificSession() } } PreProcessCreate(); - SessionManager::GetInstance().CreateAndConnectSpecificSession(iSessionStage, eventChannel, surfaceNode_, - property_, persistentId, session, token); + SingletonContainer::Get().CreateAndConnectSpecificSession(iSessionStage, eventChannel, + surfaceNode_, property_, persistentId, session, token); } property_->SetPersistentId(persistentId); if (session == nullptr) { @@ -421,9 +421,10 @@ void WindowSceneSessionImpl::UpdateSubWindowStateAndNotify(int32_t parentPersist WMError WindowSceneSessionImpl::Show(uint32_t reason, bool withAnimation) { + const auto& type = GetType(); WLOGFD("Window Show [name:%{public}s, id:%{public}d, type:%{public}u], reason:%{public}u," " state:%{public}u, requestState:%{public}u", property_->GetWindowName().c_str(), - property_->GetPersistentId(), GetType(), reason, state_, requestState_); + property_->GetPersistentId(), type, reason, state_, requestState_); if (IsWindowSessionInvalid()) { WLOGFE("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; @@ -431,7 +432,7 @@ WMError WindowSceneSessionImpl::Show(uint32_t reason, bool withAnimation) UpdateDecorEnable(true); if (state_ == WindowState::STATE_SHOWN) { WLOGFD("window session is alreay shown [name:%{public}s, id:%{public}d, type: %{public}u]", - property_->GetWindowName().c_str(), property_->GetPersistentId(), GetType()); + property_->GetWindowName().c_str(), property_->GetPersistentId(), type); NotifyAfterForeground(true, false); return WMError::WM_OK; } @@ -444,10 +445,17 @@ WMError WindowSceneSessionImpl::Show(uint32_t reason, bool withAnimation) return ret; } UpdateTitleButtonVisibility(); - ret = static_cast(hostSession_->Foreground(property_)); + if (WindowHelper::IsMainWindow(type)) { + ret = static_cast(hostSession_->Foreground(property_)); + } else if (WindowHelper::IsSubWindow(type) || WindowHelper::IsSystemWindow(type)) { + ret = static_cast(hostSession_->Show(property_)); + } else { + ret = WMError::WM_ERROR_INVALID_WINDOW; + } + if (ret == WMError::WM_OK) { // update sub window state if this is main window - if (WindowHelper::IsMainWindow(GetType())) { + if (WindowHelper::IsMainWindow(type)) { UpdateSubWindowStateAndNotify(GetPersistentId(), WindowState::STATE_SHOWN); } state_ = WindowState::STATE_SHOWN; @@ -461,17 +469,17 @@ WMError WindowSceneSessionImpl::Show(uint32_t reason, bool withAnimation) WMError WindowSceneSessionImpl::Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) { - WLOGFD("id:%{public}d Hide, reason:%{public}u, state:%{public}u, requestState:%{public}u", - property_->GetPersistentId(), reason, state_, requestState_); + const auto& type = GetType(); + WLOGFD("Window Hide [id:%{public}d, type: %{public}d, reason:%{public}u, state:%{public}u, " + "requestState:%{public}u", property_->GetPersistentId(), type, reason, state_, requestState_); if (IsWindowSessionInvalid()) { WLOGFE("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - WindowState validState = WindowHelper::IsSubWindow(GetType()) ? requestState_ : state_; + WindowState validState = WindowHelper::IsSubWindow(type) ? requestState_ : state_; if (validState == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) { - WLOGFD("window session is alreay hidden [name:%{public}s, id:%{public}d, type: %{public}u]", - property_->GetWindowName().c_str(), property_->GetPersistentId(), GetType()); + WLOGFD("window session is alreay hidden, id:%{public}d", property_->GetPersistentId()); return WMError::WM_OK; } @@ -487,22 +495,31 @@ WMError WindowSceneSessionImpl::Hide(uint32_t reason, bool withAnimation, bool i RSTransaction::FlushImplicitTransaction(); } - // delete after replace WSError with WMError - // main window no need to notify host, since host knows hide first - // main window notify host temporarily, since host background may failed - // need to SetActive(false) for host session before background - res = static_cast(SetActive(false)); - if (res != WMError::WM_OK) { - return res; + /* + * delete after replace WSError with WMError + * main window no need to notify host, since host knows hide first + * main window notify host temporarily, since host background may failed + * need to SetActive(false) for host session before background + */ + + if (WindowHelper::IsMainWindow(type)) { + res = static_cast(SetActive(false)); + if (res != WMError::WM_OK) { + return res; + } + res = static_cast(hostSession_->Background()); + } else if (WindowHelper::IsSubWindow(type) || WindowHelper::IsSystemWindow(type)) { + res = static_cast(hostSession_->Hide()); + } else { + res = WMError::WM_ERROR_INVALID_WINDOW; } - res = static_cast(hostSession_->Background()); + if (res == WMError::WM_OK) { // update sub window state if this is main window - if (WindowHelper::IsMainWindow(GetType())) { + if (WindowHelper::IsMainWindow(type)) { UpdateSubWindowStateAndNotify(GetPersistentId(), WindowState::STATE_HIDDEN); } - - if (WindowHelper::IsSubWindow(GetType())) { + if (WindowHelper::IsSubWindow(type)) { if (state_ == WindowState::STATE_SHOWN) { NotifyAfterBackground(); } @@ -635,13 +652,13 @@ WMError WindowSceneSessionImpl::Destroy(bool needNotifyServer, bool needClearLis if (!WindowHelper::IsMainWindow(GetType()) && needNotifyServer) { if (WindowHelper::IsSystemWindow(GetType())) { // main window no need to notify host, since host knows hide first - SessionManager::GetInstance().DestroyAndDisconnectSpecificSession(property_->GetPersistentId()); + SingletonContainer::Get().DestroyAndDisconnectSpecificSession(property_->GetPersistentId()); } else if (WindowHelper::IsSubWindow(GetType())) { auto parentSession = FindParentSessionByParentId(GetParentId()); if (parentSession == nullptr || parentSession->GetHostSession() == nullptr) { return WMError::WM_ERROR_NULLPTR; } - parentSession->GetHostSession()->DestroyAndDisconnectSpecificSession(property_->GetPersistentId()); + SingletonContainer::Get().DestroyAndDisconnectSpecificSession(property_->GetPersistentId()); } } // delete after replace WSError with WMError @@ -1891,7 +1908,7 @@ WMError WindowSceneSessionImpl::SetAlpha(float alpha) WMError WindowSceneSessionImpl::BindDialogTarget(sptr targetToken) { auto persistentId = property_->GetPersistentId(); - WMError ret = SessionManager::GetInstance().BindDialogTarget(persistentId, targetToken); + WMError ret = SingletonContainer::Get().BindDialogSessionTarget(persistentId, targetToken); if (ret != WMError::WM_OK) { WLOGFE("bind window failed with errCode:%{public}d", static_cast(ret)); } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index d7ed65f8dd..eed44155ed 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -491,7 +491,7 @@ WMError WindowSessionImpl::RequestFocus() const WLOGFD("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - return SessionManager::GetInstance().RequestFocusStatus(GetPersistentId(), true); + return SingletonContainer::Get().RequestFocusStatus(GetPersistentId(), true); } void WindowSessionImpl::NotifyForegroundInteractiveStatus(bool interactive) @@ -1564,7 +1564,7 @@ WMError WindowSessionImpl::UpdateProperty(WSPropertyChangeAction action) WLOGFE("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW; } - return SessionManager::GetInstance().UpdateProperty(property_, action); + return SingletonContainer::Get().UpdateSessionProperty(property_, action); } sptr WindowSessionImpl::Find(const std::string& name) @@ -1661,7 +1661,7 @@ WMError WindowSessionImpl::SetLayoutFullScreenByApiVersion(bool status) WMError WindowSessionImpl::SetWindowGravity(WindowGravity gravity, uint32_t percent) { - return SessionManager::GetInstance().SetSessionGravity(GetPersistentId(), + return SingletonContainer::Get().SetSessionGravity(GetPersistentId(), static_cast(gravity), percent); } diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index cca8b879a9..66cda19344 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -19,7 +19,11 @@ #include #include +#include "common/include/window_session_property.h" +#include "interfaces/include/ws_common_inner.h" #include "pixel_map.h" +#include "session/container/include/zidl/session_stage_interface.h" +#include "session/container/include/zidl/window_event_channel_interface.h" #include "window_property.h" #include "window_transition_info.h" #include "zidl/window_interface.h" @@ -132,7 +136,31 @@ public: virtual void GetFocusWindowInfo(FocusChangeInfo& focusInfo) = 0; virtual WMError CheckWindowId(int32_t windowId, int32_t &pid) { return WMError::WM_OK; } virtual WSError UpdateSessionAvoidAreaListener(int32_t& persistentId, bool haveListener) { return WSError::WS_OK; } - virtual WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) { return WSError::WS_OK; } + virtual WSError UpdateSessionTouchOutsideListener(int32_t& persistentId, bool haveListener) + { + return WSError::WS_OK; + } + virtual WSError CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, int32_t& persistentId, sptr& session, + sptr token = nullptr) { return WSError::WS_OK; } + virtual WSError DestroyAndDisconnectSpecificSession(const int32_t& persistentId) { return WSError::WS_OK; }; + virtual WMError UpdateSessionProperty(const sptr& property, WSPropertyChangeAction action) + { + return WMError::WM_OK; + } + virtual WSError BindDialogSessionTarget(uint64_t persistentId, sptr targetToken) + { + return WSError::WS_OK; + } + virtual WSError SetSessionGravity(int32_t persistentId, SessionGravity gravity, uint32_t percent) + { + return WSError::WS_OK; + } + virtual WMError RequestFocusStatus(int32_t persistentId, bool isFocused, bool byForeground = false) + { + return WMError::WM_OK; + } }; } } -- Gitee