diff --git a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp index 6ed64530316504e458823147802164b3e0551484..13857a474cc18b57bc087e73845d3c1438021bb4 100644 --- a/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp +++ b/interfaces/kits/napi/window_runtime/window_stage_napi/js_window_stage.cpp @@ -423,7 +423,7 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba return; } task.Resolve(engine, CreateJsWindowObject(engine, window)); - WLOGI("[NAPI]Create sub widdow %{public}s end", windowName.c_str()); + WLOGI("[NAPI]Create sub window %{public}s end", windowName.c_str()); }; NativeValue* callback = (info.argv[1] != nullptr && info.argv[1]->TypeOf() == NATIVE_FUNCTION) ? info.argv[1] : nullptr; diff --git a/window_scene/common/include/window_session_property.h b/window_scene/common/include/window_session_property.h index 0c5a02d1d3631a603dc94a38db212de924f079dc..753f30b572cd1b96a519c5517c890dc1622a1634 100644 --- a/window_scene/common/include/window_session_property.h +++ b/window_scene/common/include/window_session_property.h @@ -38,7 +38,9 @@ public: void SetTouchable(bool isTouchable); void SetDisplayId(uint64_t displayId); void SetWindowType(WindowType type); + void SetParentId(uint32_t parentId); void SetPersistentId(uint64_t persistentId); + void SetParentPersistentId(uint64_t persistentId); const std::string& GetWindowName() const; const SessionInfo& GetSessionInfo() const; @@ -47,8 +49,10 @@ public: WindowType GetWindowType() const; bool GetFocusable() const; bool GetTouchable() const; + uint32_t GetParentId() const; uint64_t GetDisplayId() const; uint64_t GetPersistentId() const; + uint64_t GetParentPersistentId() const; bool Marshalling(Parcel& parcel) const override; static WindowSessionProperty* Unmarshalling(Parcel& parcel); @@ -61,7 +65,9 @@ private: bool focusable_ { true }; bool touchable_ { true }; uint64_t displayId_ = 0; + uint32_t parentId_ = INVALID_SESSION_ID; // parentId of sceneSession, which is low 32 bite of parentPersistentId_ uint64_t persistentId_ = INVALID_SESSION_ID; + uint64_t parentPersistentId_ = INVALID_SESSION_ID; }; } // namespace Rosen } // namespace OHOS diff --git a/window_scene/common/src/window_session_property.cpp b/window_scene/common/src/window_session_property.cpp index ed52995c2359a4c1f10e3f367601d85c27d0a275..70a81a66a4b68e4f7f1f9a9c73699ae7587a2372 100644 --- a/window_scene/common/src/window_session_property.cpp +++ b/window_scene/common/src/window_session_property.cpp @@ -98,6 +98,16 @@ DisplayId WindowSessionProperty::GetDisplayId() const return displayId_; } +void WindowSessionProperty::SetParentId(uint32_t parentId) +{ + parentId_ = parentId; +} + +uint32_t WindowSessionProperty::GetParentId() const +{ + return parentId_; +} + void WindowSessionProperty::SetPersistentId(uint64_t persistentId) { persistentId_ = persistentId; @@ -108,6 +118,16 @@ uint64_t WindowSessionProperty::GetPersistentId() const return persistentId_; } +void WindowSessionProperty::SetParentPersistentId(uint64_t persistentId) +{ + parentPersistentId_ = persistentId; +} + +uint64_t WindowSessionProperty::GetParentPersistentId() const +{ + return parentPersistentId_; +} + bool WindowSessionProperty::Marshalling(Parcel& parcel) const { return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) && @@ -119,7 +139,8 @@ bool WindowSessionProperty::Marshalling(Parcel& parcel) const parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) && parcel.WriteUint64(displayId_) && parcel.WriteUint64(persistentId_) && parcel.WriteString(sessionInfo_.bundleName_) && - parcel.WriteString(sessionInfo_.abilityName_); + parcel.WriteString(sessionInfo_.abilityName_) && + parcel.WriteUint64(parentPersistentId_); } WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) @@ -140,6 +161,7 @@ WindowSessionProperty* WindowSessionProperty::Unmarshalling(Parcel& parcel) property->SetPersistentId(parcel.ReadUint64()); SessionInfo info = { parcel.ReadString(), parcel.ReadString(), nullptr }; property->SetSessionInfo(info); + property->SetParentPersistentId(parcel.ReadUint64()); return property; } } // namespace Rosen diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn b/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn index 8aeaa19db3ec517e30517bfcbe090913326c5066..811559476cd24789fc97a9062c1fc86744dec645 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn +++ b/window_scene/interfaces/kits/napi/scene_session_manager/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("scenesessionmanager_napi") { public_configs = [ ":scene_session_manager_napi_public_config" ] deps = [ + "${window_base_path}/window_scene/common:window_scene_common", "${window_base_path}/window_scene/session:scene_session", "${window_base_path}/window_scene/session_manager:scene_session_manager", ] 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 3406134a82c36300469cd42e72d65a7631fdd9fe..cb1a9d50261dc047dc526d659b829878b7648d8f 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 @@ -15,7 +15,6 @@ #include "js_scene_session.h" -#include "session/host/include/scene_session.h" #include "session_manager/include/scene_session_manager.h" #include "window_manager_hilog.h" @@ -28,6 +27,9 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "JsScen 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 RAISE_TO_TOP_CB = "raiseToTop"; } // namespace NativeValue* JsSceneSession::Create(NativeEngine& engine, const sptr& session) @@ -43,6 +45,8 @@ NativeValue* JsSceneSession::Create(NativeEngine& engine, const sptr jsSceneSession = std::make_unique(engine, session); object->SetNativePointer(jsSceneSession.release(), JsSceneSession::Finalizer, nullptr); object->SetProperty("persistentId", CreateJsValue(engine, static_cast(session->GetPersistentId()))); + object->SetProperty("parentId", CreateJsValue(engine, static_cast(session->GetParentPersistentId()))); + object->SetProperty("type", CreateJsValue(engine, static_cast(session->GetWindowType()))); const char* moduleName = "JsSceneSession"; BindNativeFunction(engine, *object, "on", moduleName, JsSceneSession::RegisterCallback); @@ -51,13 +55,26 @@ NativeValue* JsSceneSession::Create(NativeEngine& engine, const sptr& session) - : engine_(engine), session_(session) + : engine_(engine), weakSession_(session) { listenerFunc_ = { { PENDING_SCENE_CB, &JsSceneSession::ProcessPendingSceneSessionActivationRegister }, { SESSION_STATE_CHANGE_CB, &JsSceneSession::ProcessSessionStateChangeRegister }, { SESSION_EVENT_CB, &JsSceneSession::ProcessSessionEventRegister }, + { SESSION_RECT_CHANGE_CB, &JsSceneSession::ProcessSessionRectChangeRegister }, + { CREATE_SPECIFIC_SCENE_CB, &JsSceneSession::ProcessCreateSpecificSessionRegister }, + { RAISE_TO_TOP_CB, &JsSceneSession::ProcessRaiseToTopRegister }, }; + + sptr sessionchangeCallback = new (std::nothrow) + SceneSession::SessionChangeCallback(); + if (sessionchangeCallback != nullptr) { + if (session != nullptr) { + session->RegisterSessionChangeCallback(sessionchangeCallback); + } + sessionchangeCallback_ = sessionchangeCallback; + WLOGFD("RegisterSessionChangeCallback success"); + } } JsSceneSession::~JsSceneSession() @@ -70,7 +87,13 @@ void JsSceneSession::ProcessPendingSceneSessionActivationRegister() NotifyPendingSessionActivationFunc func = [this](const SessionInfo& info) { this->PendingSessionActivation(info); }; - session_->SetPendingSessionActivationEventListener(func); + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("session is nullptr"); + return; + } + session->SetPendingSessionActivationEventListener(func); + WLOGFD("ProcessPendingSceneSessionActivationRegister success"); } void JsSceneSession::ProcessSessionStateChangeRegister() @@ -78,15 +101,58 @@ void JsSceneSession::ProcessSessionStateChangeRegister() NotifySessionStateChangeFunc func = [this](const SessionState& state) { this->OnSessionStateChange(state); }; - session_->SetSessionStateChangeListenser(func); + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("session is nullptr"); + return; + } + session->SetSessionStateChangeListenser(func); + WLOGFD("ProcessSessionStateChangeRegister success"); +} + +void JsSceneSession::ProcessCreateSpecificSessionRegister() +{ + auto sessionchangeCallback = sessionchangeCallback_.promote(); + if (sessionchangeCallback == nullptr) { + WLOGFE("sessionchangeCallback is nullptr"); + return; + } + sessionchangeCallback->onCreateSpecificSession_ = std::bind(&JsSceneSession::OnCreateSpecificSession, + this, std::placeholders::_1); + WLOGFD("ProcessCreateSpecificSessionRegister success"); +} + +void JsSceneSession::ProcessSessionRectChangeRegister() +{ + auto sessionchangeCallback = sessionchangeCallback_.promote(); + if (sessionchangeCallback == nullptr) { + WLOGFE("sessionchangeCallback is nullptr"); + return; + } + sessionchangeCallback->onRectChange_ = std::bind(&JsSceneSession::OnSessionRectChange, this, std::placeholders::_1); + WLOGFD("ProcessSessionRectChangeRegister success"); +} + +void JsSceneSession::ProcessRaiseToTopRegister() +{ + auto sessionchangeCallback = sessionchangeCallback_.promote(); + if (sessionchangeCallback == nullptr) { + WLOGFE("sessionchangeCallback is nullptr"); + return; + } + sessionchangeCallback->onRaiseToTop_ = std::bind(&JsSceneSession::OnRaiseToTop, this); + WLOGFD("ProcessRaiseToTopRegister success"); } void JsSceneSession::ProcessSessionEventRegister() { - NotifySessionEventFunc func = [this](int32_t eventId) { - this->OnSessionEvent(eventId); - }; - session_->SetSessionEventListener(func); + auto sessionchangeCallback = sessionchangeCallback_.promote(); + if (sessionchangeCallback == nullptr) { + WLOGFE("sessionchangeCallback is nullptr"); + return; + } + sessionchangeCallback->OnSessionEvent_ = std::bind(&JsSceneSession::OnSessionEvent, this, std::placeholders::_1); + WLOGFD("ProcessSessionEventRegister success"); } void JsSceneSession::OnSessionEvent(uint32_t eventId) @@ -163,8 +229,9 @@ NativeValue* JsSceneSession::OnRegisterCallback(NativeEngine& engine, NativeCall if (IsCallbackRegistered(cbType, value)) { return engine.CreateUndefined(); } - if (session_ == nullptr) { - WLOGFE("[NAPI]session_ is nullptr"); + auto session = weakSession_.promote(); + if (session == nullptr) { + WLOGFE("[NAPI]session is nullptr"); engine.Throw(CreateJsError(engine, static_cast(WSErrorCode::WS_ERROR_INVALID_PARAM), "Input parameter is missing or invalid")); return engine.CreateUndefined(); @@ -178,6 +245,46 @@ NativeValue* JsSceneSession::OnRegisterCallback(NativeEngine& engine, NativeCall return engine.CreateUndefined(); } +void JsSceneSession::OnCreateSpecificSession(const sptr& sceneSession) +{ + WLOGFI("OnCreateSpecificSession"); + if (sceneSession == nullptr) { + WLOGFI("[NAPI]sceneSession is nullptr"); + return; + } + + WLOGFI("[NAPI]OnCreateSpecificSession"); + auto iter = jsCbMap_.find(CREATE_SPECIFIC_SCENE_CB); + if (iter == jsCbMap_.end()) { + return; + } + + auto jsCallBack = iter->second; + wptr weakSession(sceneSession); + auto complete = std::make_unique( + [this, weakSession, jsCallBack, eng = &engine_](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto specificSession = weakSession.promote(); + if (specificSession == nullptr) { + WLOGFE("[NAPI]root session or target session or engine is nullptr"); + return; + } + NativeValue* jsSceneSessionObj = Create(*eng, specificSession); + if (jsSceneSessionObj == nullptr || !jsCallBack) { + WLOGFE("[NAPI]jsSceneSessionObj or jsCallBack is nullptr"); + engine.Throw(CreateJsError( + engine, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal")); + } + WLOGFI("CreateJsSceneSessionObject success"); + NativeValue* argv[] = { jsSceneSessionObj }; + engine.CallFunction(engine.CreateUndefined(), jsCallBack->Get(), argv, ArraySize(argv)); + }); + + NativeReference* callback = nullptr; + std::unique_ptr execute = nullptr; + AsyncTask::Schedule("JsSceneSession::OnCreateSpecificSession", engine_, + std::make_unique(callback, std::move(execute), std::move(complete))); +} + void JsSceneSession::OnSessionStateChange(const SessionState& state) { WLOGFI("[NAPI]OnSessionStateChange, state: %{public}u", static_cast(state)); @@ -188,6 +295,11 @@ void JsSceneSession::OnSessionStateChange(const SessionState& state) auto jsCallBack = iter->second; auto complete = std::make_unique( [state, jsCallBack, eng = &engine_](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (!jsCallBack) { + WLOGFE("[NAPI]jsCallBack is nullptr"); + engine.Throw(CreateJsError( + engine, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal")); + } NativeValue* jsSessionStateObj = CreateJsValue(engine, state); NativeValue* argv[] = { jsSessionStateObj }; engine.CallFunction(engine.CreateUndefined(), jsCallBack->Get(), argv, ArraySize(argv)); @@ -199,6 +311,57 @@ void JsSceneSession::OnSessionStateChange(const SessionState& state) std::make_unique(callback, std::move(execute), std::move(complete))); } +void JsSceneSession::OnSessionRectChange(const WSRect& rect) +{ + WLOGFI("[NAPI]OnSessionRectChange"); + auto iter = jsCbMap_.find(SESSION_RECT_CHANGE_CB); + if (iter == jsCbMap_.end()) { + return; + } + auto jsCallBack = iter->second; + auto complete = std::make_unique( + [rect, jsCallBack, eng = &engine_](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (!jsCallBack) { + WLOGFE("[NAPI]jsCallBack is nullptr"); + engine.Throw(CreateJsError( + engine, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal")); + } + NativeValue* jsSessionStateObj = CreateJsSessionRect(engine, rect); + NativeValue* argv[] = { jsSessionStateObj }; + engine.CallFunction(engine.CreateUndefined(), jsCallBack->Get(), argv, ArraySize(argv)); + }); + + NativeReference* callback = nullptr; + std::unique_ptr execute = nullptr; + AsyncTask::Schedule("JsSceneSession::OnSessionRectChange", engine_, + std::make_unique(callback, std::move(execute), std::move(complete))); +} + +void JsSceneSession::OnRaiseToTop() +{ + WLOGFI("[NAPI]OnRaiseToTop"); + auto iter = jsCbMap_.find(RAISE_TO_TOP_CB); + if (iter == jsCbMap_.end()) { + return; + } + auto jsCallBack = iter->second; + auto complete = std::make_unique( + [jsCallBack, eng = &engine_](NativeEngine& engine, AsyncTask& task, int32_t status) { + if (!jsCallBack) { + WLOGFE("[NAPI]jsCallBack is nullptr"); + engine.Throw(CreateJsError( + engine, static_cast(WSErrorCode::WS_ERROR_STATE_ABNORMALLY), "System is abnormal")); + } + NativeValue* argv[] = {}; + engine.CallFunction(engine.CreateUndefined(), jsCallBack->Get(), argv, 0); + }); + + NativeReference* callback = nullptr; + std::unique_ptr execute = nullptr; + AsyncTask::Schedule("JsSceneSession::OnRaiseToTop", engine_, + std::make_unique(callback, std::move(execute), std::move(complete))); +} + void JsSceneSession::PendingSessionActivation(const SessionInfo& info) { WLOGFI("[NAPI]pending session activation: bundleName = %{public}s, id = %{public}s", info.bundleName_.c_str(), @@ -212,7 +375,7 @@ void JsSceneSession::PendingSessionActivation(const SessionInfo& info) auto complete = std::make_unique( [sessionWptr, info, jsCallBack](NativeEngine& engine, AsyncTask& task, int32_t status) { auto jsSessionWptr = sessionWptr.lock(); - if (jsSessionWptr == nullptr) { + if (jsSessionWptr == nullptr || !jsCallBack) { WLOGFE("[NAPI]root session or target session or engine is nullptr"); return; } @@ -232,6 +395,6 @@ void JsSceneSession::PendingSessionActivation(const SessionInfo& info) sptr JsSceneSession::GetNativeSession() const { - return session_; + return weakSession_.promote(); } } // namespace OHOS::Rosen 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 49e12f5e68ec94fa54d03f2636fa2a5c77e31431..1ccd0c16ff3cfd90e46ca2ef131823dd04c4fa59 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 @@ -24,6 +24,7 @@ #include #include "interfaces/include/ws_common.h" +#include "session/host/include/scene_session.h" namespace OHOS::Rosen { class SceneSession; @@ -45,13 +46,20 @@ private: void ProcessPendingSceneSessionActivationRegister(); void ProcessSessionStateChangeRegister(); void ProcessSessionEventRegister(); + void ProcessCreateSpecificSessionRegister(); + void ProcessSessionRectChangeRegister(); + void ProcessRaiseToTopRegister(); void PendingSessionActivation(const SessionInfo& info); void OnSessionStateChange(const SessionState& state); void OnSessionEvent(uint32_t actionId); + void OnCreateSpecificSession(const sptr& session); + void OnSessionRectChange(const WSRect& rect); + void OnRaiseToTop(); NativeEngine& engine_; - sptr session_; + wptr weakSession_ = nullptr; + wptr sessionchangeCallback_ = nullptr; std::map> jsCbMap_; using Func = void(JsSceneSession::*)(); std::map listenerFunc_; diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp index 03cf9950a820cd741909c579a08d39817ba1a6ce..65fb0be2e69cefa3609664159faf71874004fe84 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.cpp @@ -106,4 +106,26 @@ NativeValue* SessionStateInit(NativeEngine* engine) return objValue; } + +NativeValue* CreateJsSessionRect(NativeEngine& engine, const WSRect& rect) +{ + WLOGFD("CreateJsSessionRect."); + auto objValue = engine.CreateObject(); + if (objValue == nullptr) { + WLOGFE("Failed to create object!"); + return engine.CreateUndefined(); + } + + auto object = ConvertNativeValueTo(objValue); + if (object == nullptr) { + WLOGFE("Failed to convert object!"); + return engine.CreateUndefined(); + } + + object->SetProperty("posX_", CreateJsValue(engine, rect.posX_)); + object->SetProperty("posY_", CreateJsValue(engine, rect.posY_)); + object->SetProperty("width_", CreateJsValue(engine, rect.width_)); + object->SetProperty("height_", CreateJsValue(engine, rect.height_)); + return objValue; +} } // namespace OHOS::Rosen diff --git a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h index 81be26046d2586e13d01adbc72686bcac694d731..cbda09c1503fd04efe1105fa0896993d294eebf4 100644 --- a/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h +++ b/window_scene/interfaces/kits/napi/scene_session_manager/js_scene_utils.h @@ -27,6 +27,7 @@ bool GetAbilityInfoFromJs(NativeEngine& engine, NativeObject* jsObject, SessionI NativeValue* CreateJsSessionInfo(NativeEngine& engine, const SessionInfo& sessionInfo); NativeValue* CreateJsSessionState(NativeEngine& engine, const SessionState& state); NativeValue* SessionStateInit(NativeEngine* engine); +NativeValue* CreateJsSessionRect(NativeEngine& engine, const WSRect& rect); } // namespace OHOS::Rosen #endif // OHOS_WINDOW_SCENE_JS_SCENE_UTILS_H diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 8231914c715dbb1a0505d89b13334be5641347eb..229f9206e843d8d9131d839869ff8ff8f5d366d6 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -20,12 +20,44 @@ #include "session/host/include/session.h" namespace OHOS::Rosen { +class SceneSession; +using SpecificSessionCreateCallback = std::function(const SessionInfo& info)>; +using SpecificSessionDestroyCallback = std::function; +using NotifyCreateSpecificSessionFunc = std::function& session)>; +using NotifySessionRectChangeFunc = std::function; +using NotifySessionEventFunc = std::function; +using NotifyRaiseToTopFunc = std::function; class SceneSession : public Session { public: - SceneSession(const SessionInfo& info); + // callback for notify SceneSessionManager + struct SpecificSessionCallback : public RefBase { + SpecificSessionCreateCallback onCreate_; + SpecificSessionDestroyCallback onDestroy_; + }; + + // callback for notify SceneBoard + struct SessionChangeCallback : public RefBase { + NotifyCreateSpecificSessionFunc onCreateSpecificSession_; + NotifySessionRectChangeFunc onRectChange_; + NotifyRaiseToTopFunc onRaiseToTop_; + NotifySessionEventFunc OnSessionEvent_; + }; + + SceneSession(const SessionInfo& info, const sptr& specificCallback); ~SceneSession() = default; 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, uint64_t& persistentId, sptr& session) override; + WSError DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) override; + void RegisterSessionChangeCallback(const sptr& sessionChangeCallback); + +private: + sptr specificCallback_ = nullptr; + sptr sessionChangeCallback_ = nullptr; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index c6a2ca5ee728984bef72f077f68ede7d8e88984b..3a97412d1991f0fcf2466f8683094f8a3aa62212 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -39,7 +39,6 @@ namespace OHOS::Rosen { class RSSurfaceNode; using NotifyPendingSessionActivationFunc = std::function; using NotifySessionStateChangeFunc = std::function; -using NotifySessionEventFunc = std::function; class ILifecycleListener { public: @@ -55,13 +54,16 @@ public: void SetPersistentId(uint64_t persistentId); uint64_t GetPersistentId() const; + uint64_t GetParentPersistentId() const; void SetSessionRect(const WSRect& rect); - WSRect GetSessionRect() const; std::shared_ptr GetSurfaceNode() const; std::shared_ptr GetSnapshot() const; SessionState GetSessionState() const; const SessionInfo& GetSessionInfo() const; + sptr GetSessionProperty() const; + WSRect GetSessionRect() const; + WindowType GetWindowType() const; virtual WSError SetActive(bool active); virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason); @@ -88,7 +90,12 @@ public: void SetSessionStateChangeListenser(const NotifySessionStateChangeFunc& func); void NotifySessionStateChange(const SessionState& state); WSError UpdateActiveStatus(bool isActive) override; // update active status from session_stage - void SetSessionEventListener(const NotifySessionEventFunc& func); + 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, uint64_t& persistentId, sptr& session) override; + WSError DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) override; protected: void UpdateSessionState(SessionState state); @@ -99,7 +106,6 @@ protected: SessionInfo sessionInfo_; NotifyPendingSessionActivationFunc pendingSessionActivationFunc_; NotifySessionStateChangeFunc sessionStateChangeFunc_; - NotifySessionEventFunc sessionEventFunc_; sptr property_ = nullptr; private: template diff --git a/window_scene/session/host/include/zidl/session_interface.h b/window_scene/session/host/include/zidl/session_interface.h index 36732204d7c67000d37b406d1a744d14338dab14..86547e16d1ac87cb2fd02f1965bff1f2141850b8 100644 --- a/window_scene/session/host/include/zidl/session_interface.h +++ b/window_scene/session/host/include/zidl/session_interface.h @@ -38,7 +38,11 @@ public: TRANS_ID_UPDATE_ACTIVE_STATUS, // Scene - TRANS_ID_SESSION_EVENT = 100 + 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, }; virtual WSError Connect(const sptr& sessionStage, const sptr& eventChannel, const std::shared_ptr& surfaceNode, uint64_t& persistentId, @@ -51,6 +55,12 @@ public: // scene session virtual WSError OnSessionEvent(SessionEvent event) = 0; + virtual WSError RaiseToAppTop() = 0; + virtual WSError UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) = 0; + virtual WSError CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, uint64_t& persistentId, sptr& session) = 0; + virtual WSError DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) = 0; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_INTERFACE_H diff --git a/window_scene/session/host/include/zidl/session_proxy.h b/window_scene/session/host/include/zidl/session_proxy.h index 211665549ea7ac7254c28c5a61c9c44a4aff7364..9ba38bb3e04f671850b526c8830115562e7feabf 100644 --- a/window_scene/session/host/include/zidl/session_proxy.h +++ b/window_scene/session/host/include/zidl/session_proxy.h @@ -36,6 +36,12 @@ public: WSError UpdateActiveStatus(bool isActive) override; WSError PendingSessionActivation(const SessionInfo& info) override; 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, uint64_t& persistentId, sptr& session) override; + WSError DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/window_scene/session/host/include/zidl/session_stub.h b/window_scene/session/host/include/zidl/session_stub.h index b5d1b16af505b30fb6e1c2d777599c4d82ae129e..6c6c876b7c75d2f976e3366d11dac6c324532729 100644 --- a/window_scene/session/host/include/zidl/session_stub.h +++ b/window_scene/session/host/include/zidl/session_stub.h @@ -43,6 +43,10 @@ private: int HandleUpdateActivateStatus(MessageParcel& data, MessageParcel& reply); // for scene 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); }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_STUB_H diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 8d183b5e6bdc27591b436b8011ff51791aaf2cfe..08628222286beb55a77e0cd5945813c96e2c0922 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -21,14 +21,74 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SceneSession" }; } -SceneSession::SceneSession(const SessionInfo& info) : Session(info) {} +SceneSession::SceneSession(const SessionInfo& info, const sptr& specificCallback) + : Session(info) +{ + specificCallback_ = specificCallback; +} WSError SceneSession::OnSessionEvent(SessionEvent event) { WLOGFD("SceneSession OnSessionEvent event: %{public}d", static_cast(event)); - if (sessionEventFunc_) { - sessionEventFunc_(static_cast(event)); + if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->OnSessionEvent_) { + sessionChangeCallback_->OnSessionEvent_(static_cast(event)); } return WSError::WS_OK; } + +void SceneSession::RegisterSessionChangeCallback(const sptr& + sessionChangeCallback) +{ + sessionChangeCallback_ = sessionChangeCallback; +} + +WSError SceneSession::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) +{ + WLOGFI("UpdateSessionRect [%{public}d, %{public}d, %{public}u, %{public}u]", rect.posX_, rect.posY_, + rect.width_, rect.height_); + SetSessionRect(rect); + if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->onRectChange_) { + sessionChangeCallback_->onRectChange_(rect); + } + UpdateRect(rect, reason); + return WSError::WS_OK; +} + +WSError SceneSession::RaiseToAppTop() +{ + if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->onRaiseToTop_) { + sessionChangeCallback_->onRaiseToTop_(); + } + return WSError::WS_OK; +} + +WSError SceneSession::CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, uint64_t& persistentId, sptr& session) +{ + WLOGFI("CreateAndConnectSpecificSession id: %{public}" PRIu64 "", GetPersistentId()); + sptr sceneSession; + if (specificCallback_ != nullptr) { + sceneSession = specificCallback_->onCreate_(sessionInfo_); + } + if (sceneSession == nullptr) { + return WSError::WS_ERROR_NULLPTR; + } + // connect specific session and sessionStage + WSError errCode = sceneSession->Connect(sessionStage, eventChannel, surfaceNode, persistentId, property); + if (sessionChangeCallback_ != nullptr && sessionChangeCallback_->onCreateSpecificSession_) { + sessionChangeCallback_->onCreateSpecificSession_(sceneSession); + } + session = sceneSession; + return errCode; +} + +WSError SceneSession::DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) +{ + WSError ret = WSError::WS_OK; + if (specificCallback_ != nullptr) { + ret = specificCallback_->onDestroy_(persistentId); + } + return ret; +} } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 93cc3713b5c3a3f87a44854cb9145ae868ab8266..d325251f46b04403fd3169731f6f6c0ae837b885 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -44,6 +44,15 @@ uint64_t Session::GetPersistentId() const return persistentId_; } +uint64_t Session::GetParentPersistentId() const +{ + if (property_ != nullptr) { + WLOGFD("GetParentPersistentId, id:%{public}" PRIu64"", property_->GetParentPersistentId()); + return property_->GetParentPersistentId(); + } + return INVALID_SESSION_ID; +} + std::shared_ptr Session::GetSurfaceNode() const { return surfaceNode_; @@ -267,14 +276,9 @@ void Session::SetPendingSessionActivationEventListener(const NotifyPendingSessio pendingSessionActivationFunc_ = func; } -void Session::SetSessionEventListener(const NotifySessionEventFunc& func) -{ - sessionEventFunc_ = func; -} - WSError Session::TransferPointerEvent(const std::shared_ptr& pointerEvent) { - WLOGFD("Session TransferPointEvent"); + WLOGFD("Session TransferPointEvent, Id: %{public} " PRIu64"", persistentId_); if (!windowEventChannel_) { WLOGFE("windowEventChannel_ is null"); return WSError::WS_ERROR_NULLPTR; @@ -363,4 +367,41 @@ WSError Session::OnSessionEvent(SessionEvent event) WLOGFD("Session OnSessionEvent"); return WSError::WS_OK; } + +WSError Session::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) +{ + WLOGFD("UpdateSessionRect"); + return WSError::WS_OK; +} + +WSError Session::RaiseToAppTop() +{ + return WSError::WS_OK; +} + +WSError Session::CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, uint64_t& persistentId, sptr& session) +{ + return WSError::WS_OK; +} + +WSError Session::DestroyAndDisconnectSpecificSession(const uint64_t& persistentId) +{ + return WSError::WS_OK; +} + +sptr Session::GetSessionProperty() const +{ + return property_; +} + +WindowType Session::GetWindowType() const +{ + if (property_ != nullptr) { + WLOGFD("Type:%{public}" PRIu64"", property_->GetWindowType()); + return property_->GetWindowType(); + } + return WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; +} } // 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 fa2ed1c17d393f388a646f253336dd0bdc160104..6d95c091d3c4afdd34e8c09e2697d52f4c16f66b 100644 --- a/window_scene/session/host/src/zidl/session_proxy.cpp +++ b/window_scene/session/host/src/zidl/session_proxy.cpp @@ -42,7 +42,7 @@ WSError SessionProxy::Foreground() WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -61,7 +61,7 @@ WSError SessionProxy::Background() WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -80,7 +80,7 @@ WSError SessionProxy::Disconnect() WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -108,7 +108,7 @@ WSError SessionProxy::Connect(const sptr& sessionStage, const spt } if (property) { - if (!data.WriteBool(true) || !property->Marshalling(data)) { + if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) { WLOGFE("Write property failed"); return WSError::WS_ERROR_IPC_FAILED; } @@ -124,7 +124,7 @@ WSError SessionProxy::Connect(const sptr& sessionStage, const spt return WSError::WS_ERROR_IPC_FAILED; } persistentId = reply.ReadUint64(); - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -157,7 +157,7 @@ WSError SessionProxy::PendingSessionActivation(const SessionInfo& info) WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -180,7 +180,7 @@ WSError SessionProxy::UpdateActiveStatus(bool isActive) WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadInt32(); + uint32_t ret = reply.ReadUint32(); return static_cast(ret); } @@ -203,7 +203,132 @@ WSError SessionProxy::OnSessionEvent(SessionEvent event) WLOGFE("SendRequest failed"); return WSError::WS_ERROR_IPC_FAILED; } - int32_t ret = reply.ReadUint32(); + uint32_t ret = reply.ReadUint32(); + return static_cast(ret); +} + +WSError SessionProxy::UpdateSessionRect(const WSRect& rect, const SizeChangeReason& reason) +{ + WLOGFI("UpdateSessionRect [%{public}d, %{public}d, %{public}u, %{public}u]", rect.posX_, rect.posY_, + rect.width_, rect.height_); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (!((data.WriteInt32(static_cast(rect.posX_))) && + (data.WriteInt32(static_cast(rect.posY_))) && + (data.WriteUint32(static_cast(rect.width_))) && + (data.WriteUint32(static_cast(rect.height_))))) { + WLOGFE("Write rect failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (!data.WriteUint32(static_cast(reason))) { + WLOGFE("Write SessionSizeChangeReason failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + + if (Remote()->SendRequest(static_cast(SessionMessage::TRANS_ID_UPDATE_SESSION_RECT), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + uint32_t ret = reply.ReadUint32(); + return static_cast(ret); +} + +WSError SessionProxy::CreateAndConnectSpecificSession(const sptr& sessionStage, + const sptr& eventChannel, const std::shared_ptr& surfaceNode, + sptr property, uint64_t& persistentId, sptr& session) +{ + 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())) { + 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( + SessionMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + persistentId = reply.ReadUint64(); + 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 uint64_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.WriteUint64(persistentId)) { + WLOGFE("Write uint64_t failed"); + } + if (Remote()->SendRequest(static_cast( + SessionMessage::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; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + WLOGFE("WriteInterfaceToken failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + if (Remote()->SendRequest(static_cast(SessionMessage::TRANS_ID_RAISE_TO_APP_TOP), + data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + return WSError::WS_ERROR_IPC_FAILED; + } + int32_t ret = reply.ReadInt32(); return static_cast(ret); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session/host/src/zidl/session_stub.cpp b/window_scene/session/host/src/zidl/session_stub.cpp index 9b77181a4bbc8096782611ba8ec7975f43753051..c95350b53f7a0f8fad0e865a8d5e83518c5a6b55 100644 --- a/window_scene/session/host/src/zidl/session_stub.cpp +++ b/window_scene/session/host/src/zidl/session_stub.cpp @@ -36,6 +36,14 @@ const std::map SessionStub::stubFuncMap_{ // for scene only std::make_pair(static_cast(SessionMessage::TRANS_ID_SESSION_EVENT), &SessionStub::HandleSessionEvent), + std::make_pair(static_cast(SessionMessage::TRANS_ID_UPDATE_SESSION_RECT), + &SessionStub::HandleUpdateSessionRect), + std::make_pair(static_cast(SessionMessage::TRANS_ID_CREATE_AND_CONNECT_SPECIFIC_SESSION), + &SessionStub::HandleCreateAndConnectSpecificSession), + std::make_pair(static_cast(SessionMessage::TRANS_ID_DESTROY_AND_DISCONNECT_SPECIFIC_SESSION), + &SessionStub::HandleDestroyAndDisconnectSpecificSession), + std::make_pair(static_cast(SessionMessage::TRANS_ID_RAISE_TO_APP_TOP), + &SessionStub::HandleRaiseToAppTop), }; int SessionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -46,7 +54,7 @@ int SessionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParc return ERR_INVALID_STATE; } - const auto func = stubFuncMap_.find(code); + const auto& func = stubFuncMap_.find(code); if (func == stubFuncMap_.end()) { WLOGFE("Failed to find function handler!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -58,7 +66,7 @@ int SessionStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParc int SessionStub::HandleForeground(MessageParcel& data, MessageParcel& reply) { WLOGFD("Foreground!"); - WSError errCode = Foreground(); + const WSError& errCode = Foreground(); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } @@ -66,7 +74,7 @@ int SessionStub::HandleForeground(MessageParcel& data, MessageParcel& reply) int SessionStub::HandleBackground(MessageParcel& data, MessageParcel& reply) { WLOGFD("Background!"); - WSError errCode = Background(); + const WSError& errCode = Background(); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } @@ -74,7 +82,7 @@ int SessionStub::HandleBackground(MessageParcel& data, MessageParcel& reply) int SessionStub::HandleDisconnect(MessageParcel& data, MessageParcel& reply) { WLOGFD("Disconnect!"); - WSError errCode = Disconnect(); + const WSError& errCode = Disconnect(); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } @@ -99,7 +107,7 @@ int SessionStub::HandleConnect(MessageParcel& data, MessageParcel& reply) WLOGFW("Property not exist!"); } uint64_t persistentId = INVALID_SESSION_ID; - WSError errCode = Connect(sessionStage, eventChannel, surfaceNode, persistentId, property); + const WSError& errCode = Connect(sessionStage, eventChannel, surfaceNode, persistentId, property); reply.WriteUint64(persistentId); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; @@ -123,7 +131,7 @@ int SessionStub::HandlePendingSessionActivation(MessageParcel& data, MessageParc if (data.ReadBool()) { info.callerToken_ = data.ReadRemoteObject(); } - WSError errCode = PendingSessionActivation(info); + const WSError& errCode = PendingSessionActivation(info); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } @@ -132,7 +140,71 @@ int SessionStub::HandleUpdateActivateStatus(MessageParcel& data, MessageParcel& { WLOGFD("HandleUpdateActivateStatus!"); bool isActive = data.ReadBool(); - WSError errCode = UpdateActiveStatus(isActive); + const WSError& errCode = UpdateActiveStatus(isActive); + reply.WriteUint32(static_cast(errCode)); + return ERR_NONE; +} + +int SessionStub::HandleUpdateSessionRect(MessageParcel& data, MessageParcel& reply) +{ + WLOGFD("HandleUpdateSessionRect!"); + auto posX = data.ReadInt32(); + auto posY = data.ReadInt32(); + auto width = data.ReadUint32(); + auto height = data.ReadUint32(); + WSRect rect = {posX, posY, width, height}; + WLOGFI("HandleUpdateSessionRect [%{public}d, %{public}d, %{public}u, %{public}u]", posX, posY, + width, height); + const SizeChangeReason& reason = static_cast(data.ReadUint32()); + const WSError& errCode = UpdateSessionRect(rect, reason); + reply.WriteUint32(static_cast(errCode)); + 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!"); + } + uint64_t persistentId = INVALID_SESSION_ID; + sptr sceneSession; + CreateAndConnectSpecificSession(sessionStage, eventChannel, surfaceNode, + property, persistentId, sceneSession); + if (sceneSession== nullptr) { + return ERR_INVALID_STATE; + } + reply.WriteUint64(persistentId); + reply.WriteRemoteObject(sceneSession->AsObject()); + reply.WriteUint32(static_cast(WSError::WS_OK)); + return ERR_NONE; +} + +int SessionStub::HandleDestroyAndDisconnectSpecificSession(MessageParcel& data, MessageParcel& reply) +{ + uint64_t persistentId = data.ReadUint64(); + const WSError& ret = DestroyAndDisconnectSpecificSession(persistentId); + reply.WriteUint32(static_cast(ret)); + return ERR_NONE; +} + +int SessionStub::HandleRaiseToAppTop(MessageParcel& data, MessageParcel& reply) +{ + WLOGFD("RaiseToAppTop!"); + const WSError& errCode = RaiseToAppTop(); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; } diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index a96b95073c25687ff6d183f0b70417b059d47349..ed0edf8bf49afb9e28ab41d2e3c705d34312eb1a 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -80,10 +80,20 @@ sptr SceneSessionManager::GetSceneSession(uint64_t persistentId) sptr SceneSessionManager::RequestSceneSession(const SessionInfo& sessionInfo) { - auto task = [this, sessionInfo]() { + sptr specificCallback = new (std::nothrow) + SceneSession::SpecificSessionCallback(); + if (specificCallback == nullptr) { + WLOGFE("SpecificSessionCallback is nullptr"); + return nullptr; + } + specificCallback->onCreate_ = std::bind(&SceneSessionManager::RequestSceneSession, + this, std::placeholders::_1); + specificCallback->onDestroy_ = std::bind(&SceneSessionManager::DestroyAndDisconnectSpecificSession, + this, std::placeholders::_1); + auto task = [this, sessionInfo, specificCallback]() { WLOGFI("sessionInfo: bundleName: %{public}s, abilityName: %{public}s", sessionInfo.bundleName_.c_str(), sessionInfo.abilityName_.c_str()); - sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo); + sptr sceneSession = new (std::nothrow) SceneSession(sessionInfo, specificCallback); if (sceneSession == nullptr) { WLOGFE("sceneSession is nullptr!"); return sceneSession; @@ -220,11 +230,11 @@ WSError SceneSessionManager::CreateAndConnectSpecificSession(const sptrConnect(sessionStage, eventChannel, surfaceNode, persistentId, property); if (createSpecificSessionFunc_) { createSpecificSessionFunc_(sceneSession); } - // connect specific session and sessionStage - WSError errCode = sceneSession->Connect(sessionStage, eventChannel, surfaceNode, persistentId, property); session = sceneSession; return errCode; }; diff --git a/window_scene/session_manager/src/session_manager.cpp b/window_scene/session_manager/src/session_manager.cpp index 588f4099a707ee5da6d450a6df97d5c242866f9c..24fccfbd267643bce7c5902521357570924f1c68 100644 --- a/window_scene/session_manager/src/session_manager.cpp +++ b/window_scene/session_manager/src/session_manager.cpp @@ -144,6 +144,7 @@ void SessionManager::GetSceneSessionManagerProxy() } if (!sessionManagerServiceProxy_) { WLOGFE("sessionManagerServiceProxy_ is nullptr"); + return; } sptr remoteObject = sessionManagerServiceProxy_->GetSceneSessionManager(); 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 eec7f32fedd9e65cc9d41f61e5e5fea8d3debe51..9a31c837aebcabf553820323e2f93b70666c69d0 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 @@ -51,7 +51,7 @@ WSError SceneSessionManagerProxy::CreateAndConnectSpecificSession(const sptrMarshalling(data)) { + if (!data.WriteBool(true) || !data.WriteParcelable(property.GetRefPtr())) { WLOGFE("Write property failed"); return WSError::WS_ERROR_IPC_FAILED; } diff --git a/wm/include/window_scene_session_impl.h b/wm/include/window_scene_session_impl.h index 37d9cca6d2b33cf5eb35b56445cc3e3bdcf8fbb8..40ce4baabccc6cc8e1bbada3f2844d2109c99d36 100644 --- a/wm/include/window_scene_session_impl.h +++ b/wm/include/window_scene_session_impl.h @@ -28,6 +28,7 @@ public: WMError Create(const std::shared_ptr& context, const sptr& iSession) override; WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; + WMError Destroy(bool needClearListener) override; WSError SetActive(bool active) override; WMError DisableAppWindowDecor() override; bool IsDecorEnable() const override; @@ -37,12 +38,17 @@ public: void StartMove() override; WMError Close() override; WindowMode GetMode() const override; + WMError MoveTo(int32_t x, int32_t y) override; + WMError Resize(uint32_t width, uint32_t height) override; + WmErrorCode RaiseToAppTop() override; + protected: - WMError Destroy(bool needClearListener) override; + void DestroySubWindow(); + WMError CreateAndConnectSpecificSession(); + sptr FindParentSessionByParentId(uint32_t parentId); private: bool IsValidSystemWindowType(const WindowType& type); - WMError CreateAndConnectSpecificSession(); bool GetDebugPropForPC(); }; } // namespace Rosen diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index dcbbe648bbc81bb1fddf74df3cebe05374a79bc6..91ce2d61738b376bd86bb62d0283a79e51cbf052 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -43,6 +43,7 @@ public: WMError Show(uint32_t reason = 0, bool withAnimation = false) override; WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; WMError Destroy() override; + virtual WMError Destroy(bool needClearListener); WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override; std::shared_ptr GetSurfaceNode() const override; @@ -73,7 +74,10 @@ public: WMError RegisterWindowChangeListener(const sptr& listener) override; WMError UnregisterWindowChangeListener(const sptr& listener) override; void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; + uint32_t GetParentId() const; uint64_t GetPersistentId() const; + sptr GetProperty() const; + sptr GetHostSession() const; protected: WMError Connect(); @@ -81,8 +85,9 @@ protected: void NotifyAfterBackground(bool needNotifyListeners = true, bool needNotifyUiContent = true); void NotifyAfterActive(); void NotifyAfterInactive(); + void NotifyBeforeDestroy(std::string windowName); + void ClearListenersById(uint64_t persistentId); WMError WindowSessionCreateCheck(); - virtual WMError Destroy(bool needClearListener); void UpdateDecorEnable(bool needNotify = false); void NotifyModeChange(WindowMode mode, bool hasDeco = true); @@ -92,7 +97,10 @@ protected: std::shared_ptr surfaceNode_ = nullptr; sptr property_ = nullptr; WindowState state_ { WindowState::STATE_INITIAL }; + // map of windowSession: > static std::map>> windowSessionMap_; + // map of subSession: > + static std::map>> subWindowSessionMap_; std::recursive_mutex mutex_; WindowMode windowMode_ = WindowMode::WINDOW_MODE_UNDEFINED; bool enableWindowDecor_ = true; @@ -104,18 +112,13 @@ private: template EnableIfSame>> GetListeners(); template void ClearUselessListeners(std::map& listeners, uint64_t persistentId); - RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type); - void NotifyAfterForeground(bool needNotifyListeners = true, bool needNotifyUiContent = true); - void NotifyAfterFocused(); void NotifyAfterUnfocused(bool needNotifyUiContent = true); - void NotifyBeforeDestroy(std::string windowName); void NotifyForegroundFailed(WMError ret); void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason); - void ClearListenersById(uint64_t persistentId); void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); static std::map>> lifecycleListeners_; diff --git a/wm/src/window.cpp b/wm/src/window.cpp index d0b68251e89b896f6f76e359ef2449153197a339..b6518467f7c580772e3ba177cef67fc7925c085f 100644 --- a/wm/src/window.cpp +++ b/wm/src/window.cpp @@ -35,11 +35,13 @@ static sptr CreateWindowWithSession(sptr& option, const std::shared_ptr& context, WMError& errCode, sptr iSession = nullptr) { + WLOGFD("CreateWindowWithSession"); sptr windowSessionImpl = nullptr; auto sessionType = option->GetWindowSessionType(); if (sessionType == WindowSessionType::SCENE_SESSION) { windowSessionImpl = new(std::nothrow) WindowSceneSessionImpl(option); } else if (sessionType == WindowSessionType::EXTENSION_SESSION) { + option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); windowSessionImpl = new(std::nothrow) WindowExtensionSessionImpl(option); } @@ -52,6 +54,7 @@ static sptr CreateWindowWithSession(sptr& option, WMError error = windowSessionImpl->Create(context, iSession); if (error != WMError::WM_OK) { errCode = error; + WLOGFD("CreateWindowWithSession, error: %{public}", static_cast(errCode)); return nullptr; } return windowSessionImpl; diff --git a/wm/src/window_scene.cpp b/wm/src/window_scene.cpp index 2c6dcb23ad24edad916b3472279335ce1647ff05..81e3f6e0429ba30e262cd17554c8f25d8530aaac 100644 --- a/wm/src/window_scene.cpp +++ b/wm/src/window_scene.cpp @@ -103,6 +103,7 @@ sptr WindowScene::CreateWindow(const std::string& windowName, sptrSetParentId(mainWindow_->GetWindowId()); option->SetWindowTag(WindowTag::SUB_WINDOW); + WLOGFD("WindowScene Name: %{public}s, parentId: %{public}u", windowName.c_str(), mainWindow_->GetWindowId()); return SingletonContainer::Get().CreateWindow(windowName, option, mainWindow_->GetContext()); } diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 5e6cb9eafd0ec57a89ed4bdd87d716573c50f39f..dccbe19e494ccdba8fffccd32c1c62883c75def6 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -20,9 +20,10 @@ #include "permission.h" #include "session/container/include/window_event_channel.h" #include "session_manager/include/session_manager.h" -#include "wm_common.h" #include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_common.h" + #include "window_session_impl.h" namespace OHOS { @@ -50,6 +51,21 @@ bool WindowSceneSessionImpl::IsValidSystemWindowType(const WindowType& type) return true; } +sptr WindowSceneSessionImpl::FindParentSessionByParentId(uint32_t parentId) +{ + for (const auto& item : windowSessionMap_) { + if (item.second.second && item.second.second->GetProperty() && + item.second.second->GetWindowId() == parentId && + WindowHelper::IsMainWindow(item.second.second->GetType())) { + WLOGFD("Find parent, [parentName: %{public}s, parentId:%{public}u, selfPersistentId: %{public}" PRIu64"]", + item.second.second->GetProperty()->GetWindowName().c_str(), parentId, GetProperty()->GetPersistentId()); + return item.second.second; + } + } + WLOGFD("Can not find parent window"); + return nullptr; +} + WMError WindowSceneSessionImpl::CreateAndConnectSpecificSession() { sptr iSessionStage(this); @@ -60,15 +76,29 @@ WMError WindowSceneSessionImpl::CreateAndConnectSpecificSession() sptr eventChannel(channel); uint64_t persistentId = INVALID_SESSION_ID; sptr session; - SessionManager::GetInstance().CreateAndConnectSpecificSession(iSessionStage, eventChannel, surfaceNode_, - property_, persistentId, session); + if (WindowHelper::IsSubWindow(property_->GetWindowType())) { // sub window + auto parentSession = FindParentSessionByParentId(property_->GetParentId()); + if (parentSession == nullptr || parentSession->GetHostSession() == nullptr) { + return WMError::WM_ERROR_NULLPTR; + } + // set parent persistentId + property_->SetParentPersistentId(parentSession->GetPersistentId()); + // creat sub session by parent session + parentSession->GetHostSession()->CreateAndConnectSpecificSession(iSessionStage, eventChannel, surfaceNode_, + property_, persistentId, session); + // update subWindowSessionMap_ + subWindowSessionMap_[parentSession->GetPersistentId()].push_back(this); + } else { // system window + SessionManager::GetInstance().CreateAndConnectSpecificSession(iSessionStage, eventChannel, surfaceNode_, + property_, persistentId, session); + } property_->SetPersistentId(persistentId); if (session != nullptr) { hostSession_ = session; } else { return WMError::WM_ERROR_NULLPTR; } - WLOGFI("CreateAndConnectSpecificSession [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u], ", + WLOGFI("CreateAndConnectSpecificSession [name:%{public}s, id:%{public}" PRIu64 ", type: %{public}u]", property_->GetWindowName().c_str(), property_->GetPersistentId(), property_->GetWindowType()); return WMError::WM_OK; } @@ -89,17 +119,21 @@ WMError WindowSceneSessionImpl::Create(const std::shared_ptrGetWindowType())) { - return WMError::WM_OK; + } else { // system or sub window + if (WindowHelper::IsSystemWindow(property_->GetWindowType())) { + // Not valid system window type for session should return WMError::WM_OK; + if (!IsValidSystemWindowType(property_->GetWindowType())) { + return WMError::WM_OK; + } + } else if (!WindowHelper::IsSubWindow(property_->GetWindowType())) { + return WMError::WM_ERROR_INVALID_TYPE; } ret = CreateAndConnectSpecificSession(); } if (ret == WMError::WM_OK) { windowSessionMap_.insert(std::make_pair(property_->GetWindowName(), std::pair>(property_->GetPersistentId(), this))); + state_ = WindowState::STATE_CREATED; } if (GetDebugPropForPC()) { windowMode_ = WindowMode::WINDOW_MODE_FLOATING; @@ -159,19 +193,150 @@ WSError WindowSceneSessionImpl::SetActive(bool active) return WSError::WS_OK; } +void WindowSceneSessionImpl::DestroySubWindow() +{ + for (auto elem : subWindowSessionMap_) { + WLOGFE("Id: %{public}" PRIu64 ", size: %{public}u", elem.first, subWindowSessionMap_.size()); + } + + const uint64_t& parentPersistentId = property_->GetParentPersistentId(); + const uint64_t& persistentId = GetPersistentId(); + + WLOGFD("Id: %{public}" PRIu64 ", parentId: %{public}" PRIu64 "", persistentId, parentPersistentId); + + // remove from subWindowMap_ when destroy sub window + auto subIter = subWindowSessionMap_.find(parentPersistentId); + if (subIter != subWindowSessionMap_.end()) { + auto& subWindows = subIter->second; + for (auto iter = subWindows.begin(); iter != subWindows.end();) { + if ((*iter) == nullptr) { + iter++; + continue; + } + if ((*iter)->GetPersistentId() == persistentId) { + WLOGFD("Destroy sub window, persistentId: %{public}" PRIu64 "", persistentId); + iter = subWindows.erase(iter); + break; + } + } + } + + // remove from subWindowMap_ when destroy main window + auto mainIter = subWindowSessionMap_.find(persistentId); + if (mainIter != subWindowSessionMap_.end()) { + auto& subWindows = mainIter->second; + for (auto iter = subWindows.begin(); iter != subWindows.end();) { + if ((*iter) == nullptr) { + WLOGFD("Destroy sub window which is nullptr"); + iter = subWindows.erase(iter); + continue; + } + WLOGFD("Destroy sub window, persistentId: %{public}" PRIu64 "", (*iter)->GetPersistentId()); + (*iter)->Destroy(false); + iter++; + } + mainIter->second.clear(); + subWindowSessionMap_.erase(mainIter); + } +} + WMError WindowSceneSessionImpl::Destroy(bool needClearListener) { - WLOGFI("id:%{public}" PRIu64 " Destroy, state_:%{public}u", property_->GetPersistentId(), state_); + WLOGFI("Id:%{public}" PRIu64 " Destroy, state_:%{public}u", property_->GetPersistentId(), state_); if (IsWindowSessionInvalid()) { WLOGFE("session is invalid"); return WMError::WM_OK; } + WSError ret = WSError::WS_OK; if (!WindowHelper::IsMainWindow(GetType())) { - // main window no need to notify host, since host knows hide first - SessionManager::GetInstance().DestroyAndDisconnectSpecificSession(property_->GetPersistentId()); + if (WindowHelper::IsSystemWindow(GetType())) { + // main window no need to notify host, since host knows hide first + SessionManager::GetInstance().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()); + } } - WindowSessionImpl::Destroy(needClearListener); - return WMError::WM_OK; + // delete after replace WSError with WMError + WMError res = static_cast(ret); + NotifyBeforeDestroy(GetWindowName()); + if (needClearListener) { + ClearListenersById(GetPersistentId()); + } + { + std::lock_guard lock(mutex_); + state_ = WindowState::STATE_DESTROYED; + } + + DestroySubWindow(); + windowSessionMap_.erase(property_->GetWindowName()); + hostSession_ = nullptr; + return res; +} + +WMError WindowSceneSessionImpl::MoveTo(int32_t x, int32_t y) +{ + WLOGFD("Id:%{public}" PRIu64 " MoveTo %{public}d %{public}d", property_->GetPersistentId(), x, y); + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + const auto& rect = property_->GetWindowRect(); + Rect newRect = { x, y, rect.width_, rect.height_ }; // must keep x/y + property_->SetRequestRect(newRect); + if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) { + WLOGFD("Window is hidden or created! id: %{public}" PRIu64 ", oriPos: [%{public}d, %{public}d, " + "movePos: [%{public}d, %{public}d]", property_->GetPersistentId(), rect.posX_, rect.posY_, x, y); + return WMError::WM_OK; + } + + WSRect wsRect = { newRect.posX_, newRect.posY_, newRect.width_, newRect.height_ }; + const WSError& ret = hostSession_->UpdateSessionRect(wsRect, SizeChangeReason::MOVE); + return static_cast(ret); +} + +WMError WindowSceneSessionImpl::Resize(uint32_t width, uint32_t height) +{ + WLOGFD("Id:%{public}" PRIu64 " Resize %{public}u %{public}u", property_->GetPersistentId(), width, height); + if (IsWindowSessionInvalid()) { + return WMError::WM_ERROR_INVALID_WINDOW; + } + const auto& rect = property_->GetWindowRect(); + Rect newRect = { rect.posX_, rect.posY_, width, height }; // must keep w/h + property_->SetRequestRect(newRect); + if (state_ == WindowState::STATE_HIDDEN || state_ == WindowState::STATE_CREATED) { + WLOGFD("Window is hidden or created! id: %{public}" PRIu64 ", oriSize: [%{public}u, %{public}u, " + "newSize [%{public}u, %{public}u]", property_->GetPersistentId(), rect.width_, rect.height_, width, height); + return WMError::WM_OK; + } + + WSRect wsRect = { newRect.posX_, newRect.posY_, newRect.width_, newRect.height_ }; + const WSError& ret = hostSession_->UpdateSessionRect(wsRect, SizeChangeReason::RESIZE); + return static_cast(ret); +} + +WmErrorCode WindowSceneSessionImpl::RaiseToAppTop() +{ + auto parentId = GetParentId(); + if (parentId == INVALID_SESSION_ID) { + WLOGFE("Only the children of the main window can be raised!"); + return WmErrorCode::WM_ERROR_INVALID_PARENT; + } + + if (!WindowHelper::IsSubWindow(GetType())) { + WLOGFE("Must be app sub window window!"); + return WmErrorCode::WM_ERROR_INVALID_CALLING; + } + + if (state_ != WindowState::STATE_SHOWN) { + WLOGFE("The sub window must be shown!"); + return WmErrorCode::WM_ERROR_STATE_ABNORMALLY; + } + + const WSError& ret = hostSession_->RaiseToAppTop(); + return static_cast(ret); } bool WindowSceneSessionImpl::GetDebugPropForPC() diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 3cd33f1eb4a77512dcb87bd541f0429f74b14a38..4b5933b1a4ecfe4c827239b55c7d10850936361d 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -36,6 +36,7 @@ std::map>> WindowSessionImpl::lifec std::map>> WindowSessionImpl::windowChangeListeners_; std::recursive_mutex WindowSessionImpl::globalMutex_; std::map>> WindowSessionImpl::windowSessionMap_; +std::map>> WindowSessionImpl::subWindowSessionMap_; #define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, listeners) \ do { \ @@ -64,6 +65,7 @@ std::map>> WindowSessio WindowSessionImpl::WindowSessionImpl(const sptr& option) { + WLOGFD("WindowSessionImpl"); property_ = new (std::nothrow) WindowSessionProperty(); if (property_ == nullptr) { WLOGFE("Property is null"); @@ -76,6 +78,7 @@ WindowSessionImpl::WindowSessionImpl(const sptr& option) property_->SetTouchable(option->GetTouchable()); property_->SetDisplayId(option->GetDisplayId()); property_->SetWindowName(option->GetWindowName()); + property_->SetParentId(option->GetParentId()); surfaceNode_ = CreateSurfaceNode(property_->GetWindowName(), option->GetWindowType()); } @@ -101,14 +104,18 @@ RSSurfaceNode::SharedPtr WindowSessionImpl::CreateSurfaceNode(std::string name, WindowSessionImpl::~WindowSessionImpl() { - WLOGFD("~WindowSessionImpl"); + WLOGFD("~WindowSessionImpl, id: %{public}" PRIu64"", GetPersistentId()); Destroy(false); } uint32_t WindowSessionImpl::GetWindowId() const { - // for get window property - return static_cast((property_->GetPersistentId()) & 0xffffffff); // 0xffffffff: to get lower 32 bits + return static_cast(GetPersistentId()) & 0xffffffff; // 0xffffffff: to get low 32 bits +} + +uint32_t WindowSessionImpl::GetParentId() const +{ + return static_cast(property_->GetParentPersistentId()) & 0xffffffff; // 0xffffffff: to get low 32 bits } bool WindowSessionImpl::IsWindowSessionInvalid() const @@ -116,7 +123,7 @@ bool WindowSessionImpl::IsWindowSessionInvalid() const bool res = ((hostSession_ == nullptr) || (GetPersistentId() == INVALID_SESSION_ID) || (state_ == WindowState::STATE_DESTROYED)); if (res) { - WLOGW("already destroyed or not created! id: %{public}" PRIu64 " state_:%{public}u", GetPersistentId(), state_); + WLOGW("already destroyed or not created! id: %{public}" PRIu64" state_: %{public}u", GetPersistentId(), state_); } return res; } @@ -126,6 +133,16 @@ uint64_t WindowSessionImpl::GetPersistentId() const return property_->GetPersistentId(); } +sptr WindowSessionImpl::GetProperty() const +{ + return property_; +} + +sptr WindowSessionImpl::GetHostSession() const +{ + return hostSession_; +} + WMError WindowSessionImpl::WindowSessionCreateCheck() { const auto& name = property_->GetWindowName(); @@ -151,6 +168,7 @@ WMError WindowSessionImpl::WindowSessionCreateCheck() WMError WindowSessionImpl::Create(const std::shared_ptr& context, const sptr& iSession) { + WLOGFD("WindowSessionImpl::Create"); // allow iSession is nullptr when create from window manager if (!context || !hostSession_) { WLOGFE("context or hostSession is nullptr!"); @@ -244,7 +262,7 @@ WMError WindowSessionImpl::Hide(uint32_t reason, bool withAnimation, bool isFrom WMError WindowSessionImpl::Destroy(bool needClearListener) { - WLOGFI("id:%{public}" PRIu64 " Destroy, state_:%{public}u", property_->GetPersistentId(), state_); + WLOGFI("Id:%{public}" PRIu64 " Destroy, state_:%{public}u", property_->GetPersistentId(), state_); if (IsWindowSessionInvalid()) { WLOGFE("session is invalid"); return WMError::WM_ERROR_INVALID_WINDOW;