From d031e62b31329b83de80aabe1347093bc4b0b2f5 Mon Sep 17 00:00:00 2001 From: ZhangYu Date: Mon, 11 Mar 2024 06:42:39 +0000 Subject: [PATCH] EmbeddedComponent onTerminated. Signed-off-by: ZhangYu Change-Id: I4127e44ff47e40fb15f27e38714698c491287ee0 --- adapter/ohos/osal/want_wrap_ohos.cpp | 2 + adapter/ohos/osal/want_wrap_ohos.h | 9 +- frameworks/base/error/error_code.h | 4 +- frameworks/base/want/want_wrap.h | 1 + .../jsview/js_embedded_component.cpp | 91 +++--- .../pattern/ui_extension/session_wrapper.h | 24 +- .../ui_extension/session_wrapper_factory.cpp | 6 +- .../ui_extension/session_wrapper_factory.h | 5 +- .../ui_extension/session_wrapper_impl.cpp | 287 ++++++++++-------- .../ui_extension/session_wrapper_impl.h | 31 +- .../ui_extension/ui_extension_manager.cpp | 4 +- .../ui_extension/ui_extension_manager.h | 9 +- .../pattern/ui_extension/ui_extension_model.h | 4 +- .../ui_extension/ui_extension_model_ng.cpp | 22 +- .../ui_extension/ui_extension_model_ng.h | 7 +- .../ui_extension/ui_extension_pattern.cpp | 138 ++++----- .../ui_extension/ui_extension_pattern.h | 40 ++- .../core/pipeline_ng/pipeline_context.cpp | 2 +- .../pattern/mock_ui_extension_model_ng.cpp | 3 +- 19 files changed, 392 insertions(+), 297 deletions(-) diff --git a/adapter/ohos/osal/want_wrap_ohos.cpp b/adapter/ohos/osal/want_wrap_ohos.cpp index 5b18d9b6a83..66dad5327ad 100644 --- a/adapter/ohos/osal/want_wrap_ohos.cpp +++ b/adapter/ohos/osal/want_wrap_ohos.cpp @@ -55,6 +55,8 @@ RefPtr WantWrap::CreateWantWrap(const std::string& bundleName, const s return AceType::MakeRefPtr(bundleName, abilityName); } +WantWrapOhos::WantWrapOhos(const AAFwk::Want& want) : want_(want) {} + WantWrapOhos::WantWrapOhos(napi_env env, napi_value value) { OHOS::AppExecFwk::UnwrapWant(env, value, want_); diff --git a/adapter/ohos/osal/want_wrap_ohos.h b/adapter/ohos/osal/want_wrap_ohos.h index be4d21a4a0f..23e6de1b7d1 100644 --- a/adapter/ohos/osal/want_wrap_ohos.h +++ b/adapter/ohos/osal/want_wrap_ohos.h @@ -16,17 +16,18 @@ #ifndef FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WANT_WRAP_OHOS_H #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WANT_WRAP_OHOS_H -#include "base/want/want_wrap.h" - #include #include "napi/native_api.h" #include "native_engine/native_engine.h" #include "want.h" +#include "base/want/want_wrap.h" + namespace OHOS::Ace { class WantParamsWrapOhos : public WantParamsWrap { DECLARE_ACE_TYPE(WantParamsWrapOhos, WantParamsWrap); + public: WantParamsWrapOhos(napi_env env, napi_value value); ~WantParamsWrapOhos() = default; @@ -34,6 +35,7 @@ public: { return params_; } + private: AAFwk::WantParams params_; }; @@ -42,6 +44,7 @@ class WantWrapOhos : public WantWrap { DECLARE_ACE_TYPE(WantWrapOhos, WantWrap) public: + explicit WantWrapOhos(const AAFwk::Want& want); WantWrapOhos(napi_env env, napi_value value); WantWrapOhos(const std::string& bundleName, const std::string& abilityName); ~WantWrapOhos() = default; @@ -49,7 +52,7 @@ public: std::string ToString() const override; void SetWantParam(const std::map& params) override; - const AAFwk::Want& GetWant() const + const AAFwk::Want& GetWant() const override { return want_; } diff --git a/frameworks/base/error/error_code.h b/frameworks/base/error/error_code.h index 5fc840573ea..81d0ef943da 100644 --- a/frameworks/base/error/error_code.h +++ b/frameworks/base/error/error_code.h @@ -43,6 +43,8 @@ constexpr int32_t ERROR_CODE_UIEXTENSION_NOT_REGISTER_SYNC_CALLBACK = 100011; constexpr int32_t ERROR_CODE_UIEXTENSION_TRANSFER_DATA_FAILED = 100012; // Forbid cascade uiextension constexpr int32_t ERROR_CODE_UIEXTENSION_FORBID_CASCADE = 100013; +// The uiextension provider exited abnormally. +constexpr int32_t ERROR_CODE_UIEXTENSION_EXITED_ABNORMALLY = 100014; // C-API errors constexpr int32_t ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND = 106101; @@ -52,4 +54,4 @@ constexpr int32_t ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED = 106102; constexpr int32_t ERROR_CODE_DRAG_DATA_NOT_FOUND = 190001; // GetData failed, data not found. constexpr int32_t ERROR_CODE_DRAG_DATA_ERROR = 190002; // GetData failed, data error. -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/frameworks/base/want/want_wrap.h b/frameworks/base/want/want_wrap.h index f157de690c3..d0ea0b08977 100644 --- a/frameworks/base/want/want_wrap.h +++ b/frameworks/base/want/want_wrap.h @@ -47,6 +47,7 @@ public: virtual void SetWantParamsFromWantWrap(void* want) = 0; virtual void SetWantParam(const std::map& params) = 0; virtual std::string ToString() const = 0; + virtual const OHOS::AAFwk::Want& GetWant() const = 0; }; } // namespace OHOS::Ace diff --git a/frameworks/bridge/declarative_frontend/jsview/js_embedded_component.cpp b/frameworks/bridge/declarative_frontend/jsview/js_embedded_component.cpp index 1bf637e6c3a..b190b41df38 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_embedded_component.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_embedded_component.cpp @@ -30,11 +30,12 @@ #include "bridge/declarative_frontend/engine/js_types.h" #include "bridge/declarative_frontend/engine/jsi/jsi_ref.h" #include "bridge/declarative_frontend/engine/jsi/jsi_types.h" -#include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_ui_extension.h" +#include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/js_frontend/engine/jsi/js_value.h" #include "core/common/container.h" #include "core/common/container_scope.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" #include "core/components_ng/pattern/ui_extension/ui_extension_model.h" #include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h" #include "frameworks/core/components_ng/base/view_abstract_model.h" @@ -62,22 +63,17 @@ void JSEmbeddedComponent::JSBind(BindingTarget globalObj) void JSEmbeddedComponent::Create(const JSCallbackInfo& info) { if (info.Length() < 1 || !info[0]->IsObject()) { - TAG_LOGW(AceLogTag::ACE_EMBEDDED_COMPONENT, "EmbeddedComponent argument is invalid."); return; } auto wantObj = JSRef::Cast(info[0]); RefPtr want = CreateWantWrapFromNapiValue(wantObj); - int32_t embeddedType = OHOS::Ace::NG::EmbeddedType::DEFAULT_TYPE; + NG::SessionType sessionType = NG::SessionType::EMBEDDED_UI_EXTENSION; if (info.Length() > 1 && info[1]->IsNumber()) { - int32_t type = info[1]->ToNumber(); - if (type >= OHOS::Ace::NG::EmbeddedType::DEFAULT_TYPE && - type <= OHOS::Ace::NG::EmbeddedType::UI_EXTENSION) { - embeddedType = type; - } + sessionType = static_cast(info[1]->ToNumber()); } - UIExtensionModel::GetInstance()->Create(want, embeddedType); + UIExtensionModel::GetInstance()->Create(want, sessionType); ViewAbstractModel::GetInstance()->SetWidth(EMBEDDED_COMPONENT_MIN_WIDTH); ViewAbstractModel::GetInstance()->SetHeight(EMBEDDED_COMPONENT_MIN_HEIGHT); ViewAbstractModel::GetInstance()->SetMinWidth(EMBEDDED_COMPONENT_MIN_WIDTH); @@ -87,59 +83,64 @@ void JSEmbeddedComponent::Create(const JSCallbackInfo& info) void JSEmbeddedComponent::OnTerminated(const JSCallbackInfo& info) { if (!info[0]->IsFunction()) { - TAG_LOGW(AceLogTag::ACE_EMBEDDED_COMPONENT, "OnTerminated argument is invalid."); return; } WeakPtr frameNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto instanceId = ContainerScope::CurrentId(); - auto onResult = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode] - (int32_t code, const AAFwk::Want& want) { - ContainerScope scope(instanceId); - JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - ACE_SCORING_EVENT("EmbeddedComponent.onTerminated"); - auto pipelineContext = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipelineContext); - pipelineContext->UpdateCurrentActiveNode(node); - auto engine = EngineHelper::GetCurrentEngine(); - CHECK_NULL_VOID(engine); - NativeEngine* nativeEngine = engine->GetNativeEngine(); - CHECK_NULL_VOID(nativeEngine); - auto nativeWant = WantWrap::ConvertToNativeValue(want, reinterpret_cast(nativeEngine)); + auto onTerminated = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( + std::optional code, const RefPtr& wantWrap) { + ContainerScope scope(instanceId); + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("EmbeddedComponent.onTerminated"); + auto pipelineContext = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->UpdateCurrentActiveNode(node); + auto engine = EngineHelper::GetCurrentEngine(); + CHECK_NULL_VOID(engine); + NativeEngine* nativeEngine = engine->GetNativeEngine(); + CHECK_NULL_VOID(nativeEngine); + if (!code.has_value()) { + func->ExecuteJS(); + return; + } + JSRef obj = JSRef::New(); + obj->SetProperty("code", code.value()); + if (wantWrap) { + auto nativeWant = + WantWrap::ConvertToNativeValue(wantWrap->GetWant(), reinterpret_cast(nativeEngine)); auto wantJSVal = JsConverter::ConvertNapiValueToJsVal(nativeWant); - JSRef obj = JSRef::New(); - obj->SetProperty("code", code); obj->SetPropertyObject("want", wantJSVal); - auto returnValue = JSRef::Cast(obj); - func->ExecuteJS(1, &returnValue); - }; - UIExtensionModel::GetInstance()->SetOnResult(std::move(onResult)); + } + auto returnValue = JSRef::Cast(obj); + func->ExecuteJS(1, &returnValue); + }; + UIExtensionModel::GetInstance()->SetOnTerminated(std::move(onTerminated)); } void JSEmbeddedComponent::OnError(const JSCallbackInfo& info) { if (!info[0]->IsFunction()) { - TAG_LOGW(AceLogTag::ACE_EMBEDDED_COMPONENT, "OnError argument is invalid."); return; } WeakPtr frameNode = NG::ViewStackProcessor::GetInstance()->GetMainFrameNode(); auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); auto instanceId = ContainerScope::CurrentId(); - auto onError = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode] - (int32_t code, const std::string& name, const std::string& message) { - ContainerScope scope(instanceId); - JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - ACE_SCORING_EVENT("EmbeddedComponent.onError"); - auto pipelineContext = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipelineContext); - pipelineContext->UpdateCurrentActiveNode(node); - JSRef obj = JSRef::New(); - obj->SetProperty("code", code); - obj->SetProperty("name", name); - obj->SetProperty("message", message); - auto returnValue = JSRef::Cast(obj); - func->ExecuteJS(FUNC_ARGC_1, &returnValue); - }; + auto onError = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc), instanceId, node = frameNode]( + int32_t code, const std::string& name, const std::string& message) { + ContainerScope scope(instanceId); + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("EmbeddedComponent.onError"); + auto pipelineContext = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + pipelineContext->UpdateCurrentActiveNode(node); + JSRef obj = JSRef::New(); + obj->SetProperty("code", code); + obj->SetProperty("name", name); + obj->SetProperty("message", message); + auto returnValue = JSRef::Cast(obj); + func->ExecuteJS(FUNC_ARGC_1, &returnValue); + }; UIExtensionModel::GetInstance()->SetOnError(std::move(onError)); } } // namespace OHOS::Ace::Framework diff --git a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper.h b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper.h index 65cfe73dfaa..66078a9ad02 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper.h +++ b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper.h @@ -55,6 +55,11 @@ class AccessibilityEventInfo; } // namespace OHOS namespace OHOS::Ace::NG { +enum class SessionType : int32_t { + EMBEDDED_UI_EXTENSION = 0, + UI_EXTENSION_ABILITY = 1, + CLOUD_CARD = 2, +}; class SessionWrapper : public AceType { DECLARE_ACE_TYPE(SessionWrapper, AceType); @@ -91,6 +96,11 @@ public: virtual void NotifyDestroy() = 0; virtual void NotifyConfigurationUpdate() = 0; + // The interface for responsing provider + virtual void OnConnect() = 0; + virtual void OnDisconnect(bool isAbnormal) = 0; + virtual void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) = 0; + // The interface about the accessibility virtual bool TransferExecuteAction(int64_t elementId, const std::map& actionArguments, int32_t action, int64_t offset) = 0; @@ -103,19 +113,17 @@ public: virtual void FocusMoveSearch( int64_t elementId, int32_t direction, int64_t baseParent, Accessibility::AccessibilityElementInfo& output) = 0; - // The interface to control the display area + // The interface to control the display area and the avoid area virtual std::shared_ptr GetSurfaceNode() const = 0; - virtual void RefreshDisplayArea(const RectF& displayArea) = 0; - virtual void OnSizeChanged(WindowSizeChangeReason type, - const std::shared_ptr& rsTransaction) = 0; + virtual void NotifyDisplayArea(const RectF& displayArea) = 0; + virtual void NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) = 0; + virtual void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const = 0; + virtual bool NotifyOccupiedAreaChangeInfo(sptr info) const = 0; // The interface to send the data for ArkTS virtual void SendDataAsync(const AAFwk::WantParams& params) const = 0; virtual int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const = 0; - - // The interface to control the avoid area - virtual void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const = 0; - virtual bool NotifyOccupiedAreaChangeInfo(sptr info) const = 0; }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_SESSION_WRAPPER_H diff --git a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.cpp b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.cpp index fa0f7ddf991..336f7963641 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.cpp @@ -20,11 +20,11 @@ #include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h" namespace OHOS::Ace::NG { -RefPtr SessionWrapperFactory::CreateSessionWrapper(SessionTye sessionType, +RefPtr SessionWrapperFactory::CreateSessionWrapper(SessionType sessionType, const WeakPtr& hostPattern, int32_t instanceId, bool isTransferringCaller) { - if (sessionType == SessionTye::UI_EXTENSION_ABILITY) { - return AceType::MakeRefPtr(hostPattern, instanceId, isTransferringCaller); + if (sessionType == SessionType::UI_EXTENSION_ABILITY || sessionType == SessionType::EMBEDDED_UI_EXTENSION) { + return AceType::MakeRefPtr(hostPattern, instanceId, isTransferringCaller, sessionType); } return nullptr; } diff --git a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.h b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.h index f3e7b0573ce..79acc1d0519 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.h +++ b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_factory.h @@ -21,12 +21,9 @@ #include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h" namespace OHOS::Ace::NG { - -enum class SessionTye { UI_EXTENSION_ABILITY, UNKNOWN }; - class SessionWrapperFactory { public: - static RefPtr CreateSessionWrapper(SessionTye sessionType, + static RefPtr CreateSessionWrapper(SessionType sessionType, const WeakPtr& hostPattern, int32_t instanceId, bool isTransferringCaller); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.cpp b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.cpp index 135bd1fa5f9..66af4c68f4b 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.cpp @@ -21,27 +21,48 @@ #include "accessibility_event_info.h" #include "refbase.h" #include "session_manager/include/extension_session_manager.h" +#include "transaction/rs_sync_transaction_controller.h" #include "ui/rs_surface_node.h" +#include "want_params.h" #include "wm/wm_common.h" #include "adapter/ohos/entrance/ace_container.h" #include "adapter/ohos/osal/want_wrap_ohos.h" +#include "base/error/error_code.h" #include "base/utils/utils.h" #include "core/common/container.h" #include "core/common/container_scope.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" #include "core/pipeline_ng/pipeline_context.h" -#include "transaction/rs_sync_transaction_controller.h" #ifdef ENABLE_ROSEN_BACKEND #include "render_service_client/core/transaction/rs_transaction.h" #endif namespace OHOS::Ace::NG { +namespace { +// Defines all error names and messages. +constexpr char START_FAIL_NAME[] = "start_ability_fail"; +constexpr char START_FAIL_MESSAGE[] = "Start ui extension ability failed, please check the want of UIextensionAbility."; +constexpr char BACKGROUND_FAIL_NAME[] = "background_fail"; +constexpr char BACKGROUND_FAIL_MESSAGE[] = "background ui extension ability failed, please check AMS log."; +constexpr char TERMINATE_FAIL_NAME[] = "terminate_fail"; +constexpr char TERMINATE_FAIL_MESSAGE[] = "terminate ui extension ability failed, please check AMS log."; +constexpr char PULL_FAIL_NAME[] = "extension_pulling_up_fail"; +constexpr char PULL_FAIL_MESSAGE[] = "pulling another embedded component failed, not allowed to cascade."; +constexpr char EXIT_ABNORMALLY_NAME[] = "extension_exit_abnormally"; +constexpr char EXIT_ABNORMALLY_MESSAGE[] = "the extension ability exited abnormally, please check AMS log."; +// Defines the want parameter to control the soft-keyboard area change of the provider. +constexpr char OCCUPIED_AREA_CHANGE_KEY[] = "ability.want.params.IsNotifyOccupiedAreaChange"; +// Set the UIExtension type of the EmbeddedComponent. +constexpr char UI_EXTENSION_TYPE_KEY[] = "ability.want.params.uiExtensionType"; +const std::string EMBEDDED_UI("embeddedUI"); +} // namespace class UIExtensionLifecycleListener : public Rosen::ILifecycleListener { public: - UIExtensionLifecycleListener(int32_t instanceId, const WeakPtr& hostPattern) - : instanceId_(instanceId), hostPattern_(hostPattern) + explicit UIExtensionLifecycleListener(const WeakPtr& sessionWrapper) + : sessionWrapper_(sessionWrapper) {} virtual ~UIExtensionLifecycleListener() = default; @@ -51,141 +72,105 @@ public: void OnConnect() override { - ContainerScope scope(instanceId_); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto taskExecutor = pipeline->GetTaskExecutor(); - CHECK_NULL_VOID(taskExecutor); - taskExecutor->PostTask( - [weak = hostPattern_]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->OnConnect(); - }, - TaskExecutor::TaskType::UI); + auto sessionWrapper = sessionWrapper_.Upgrade(); + CHECK_NULL_VOID(sessionWrapper); + sessionWrapper->OnConnect(); } void OnDisconnect() override { - ContainerScope scope(instanceId_); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto taskExecutor = pipeline->GetTaskExecutor(); - CHECK_NULL_VOID(taskExecutor); - taskExecutor->PostTask( - [weak = hostPattern_]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->OnDisconnect(); - }, - TaskExecutor::TaskType::UI); + auto sessionWrapper = sessionWrapper_.Upgrade(); + CHECK_NULL_VOID(sessionWrapper); + sessionWrapper->OnDisconnect(false); } void OnExtensionDied() override { - ContainerScope scope(instanceId_); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto taskExecutor = pipeline->GetTaskExecutor(); - CHECK_NULL_VOID(taskExecutor); - taskExecutor->PostTask( - [weak = hostPattern_]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->OnExtensionDied(); - }, - TaskExecutor::TaskType::UI); + auto sessionWrapper = sessionWrapper_.Upgrade(); + CHECK_NULL_VOID(sessionWrapper); + sessionWrapper->OnDisconnect(true); } void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t uiExtensionOffset) override { - ContainerScope scope(instanceId_); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto taskExecutor = pipeline->GetTaskExecutor(); - CHECK_NULL_VOID(taskExecutor); - taskExecutor->PostTask( - [weak = hostPattern_, info, uiExtensionOffset]() { - auto pattern = weak.Upgrade(); - CHECK_NULL_VOID(pattern); - pattern->OnAccessibilityEvent(info, uiExtensionOffset); - }, - TaskExecutor::TaskType::UI); + auto sessionWrapper = sessionWrapper_.Upgrade(); + CHECK_NULL_VOID(sessionWrapper); + sessionWrapper->OnAccessibilityEvent(info, uiExtensionOffset); } private: - int32_t instanceId_; - WeakPtr hostPattern_; + WeakPtr sessionWrapper_; }; /************************************************ Begin: Initialization ***********************************************/ -SessionWrapperImpl::SessionWrapperImpl( - const WeakPtr& hostPattern, int32_t instanceId, bool isTransferringCaller) - : hostPattern_(hostPattern), instanceId_(instanceId), isTransferringCaller_(isTransferringCaller) -{} +SessionWrapperImpl::SessionWrapperImpl(const WeakPtr& hostPattern, int32_t instanceId, + bool isTransferringCaller, SessionType sessionType) + : hostPattern_(hostPattern), instanceId_(instanceId), isTransferringCaller_(isTransferringCaller), + sessionType_(sessionType) +{ + auto pattern = hostPattern.Upgrade(); + uiExtensionId_ = pattern ? pattern->GetUiExtensionId() : 0; + taskExecutor_ = Container::CurrentTaskExecutor(); +} SessionWrapperImpl::~SessionWrapperImpl() {} void SessionWrapperImpl::InitAllCallback() { CHECK_NULL_VOID(session_); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto taskExecutor = pipeline->GetTaskExecutor(); - CHECK_NULL_VOID(taskExecutor); auto sessionCallbacks = session_->GetExtensionSessionEventCallback(); - foregroundCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) { + foregroundCallback_ = [weak = hostPattern_, taskExecutor = taskExecutor_](OHOS::Rosen::WSError errcode) { if (errcode != OHOS::Rosen::WSError::WS_OK) { taskExecutor->PostTask( [weak, errcode] { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - std::string name = "start_ability_fail"; - std::string message = - "Start ui extension ability failed, please check the want of UIextensionAbility."; - pattern->FireOnErrorCallback(static_cast(errcode), name, message); + pattern->FireOnErrorCallback(static_cast(errcode), START_FAIL_NAME, START_FAIL_MESSAGE); }, TaskExecutor::TaskType::UI); } }; - backgroundCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) { + backgroundCallback_ = [weak = hostPattern_, taskExecutor = taskExecutor_](OHOS::Rosen::WSError errcode) { if (errcode != OHOS::Rosen::WSError::WS_OK) { taskExecutor->PostTask( [weak, errcode] { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - std::string name = "background_fail"; - std::string message = "background ui extension ability failed, please check AMS log."; - pattern->FireOnErrorCallback(static_cast(errcode), name, message); + pattern->FireOnErrorCallback( + static_cast(errcode), BACKGROUND_FAIL_NAME, BACKGROUND_FAIL_MESSAGE); }, TaskExecutor::TaskType::UI); } }; - destructionCallback_ = [weak = hostPattern_, taskExecutor](OHOS::Rosen::WSError errcode) { + destructionCallback_ = [weak = hostPattern_, taskExecutor = taskExecutor_](OHOS::Rosen::WSError errcode) { if (errcode != OHOS::Rosen::WSError::WS_OK) { taskExecutor->PostTask( [weak, errcode] { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - std::string name = "terminate_fail"; - std::string message = "terminate ui extension ability failed, please check AMS log."; - pattern->FireOnErrorCallback(static_cast(errcode), name, message); + pattern->FireOnErrorCallback( + static_cast(errcode), TERMINATE_FAIL_NAME, TERMINATE_FAIL_MESSAGE); }, TaskExecutor::TaskType::UI); } }; - sessionCallbacks->transferAbilityResultFunc_ = [weak = hostPattern_, taskExecutor]( + sessionCallbacks->transferAbilityResultFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_, + sessionType = sessionType_]( int32_t code, const AAFwk::Want& want) { taskExecutor->PostTask( - [weak, code, want]() { + [weak, code, want, sessionType]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - pattern->FireOnResultCallback(code, want); + if (sessionType == SessionType::UI_EXTENSION_ABILITY) { + pattern->FireOnResultCallback(code, want); + } else { + pattern->FireOnTerminatedCallback(code, MakeRefPtr(want)); + } }, TaskExecutor::TaskType::UI); }; - sessionCallbacks->transferExtensionDataFunc_ = [weak = hostPattern_, taskExecutor]( + sessionCallbacks->transferExtensionDataFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_]( const AAFwk::WantParams& params) { taskExecutor->PostTask( [weak, params]() { @@ -195,7 +180,7 @@ void SessionWrapperImpl::InitAllCallback() }, TaskExecutor::TaskType::UI); }; - sessionCallbacks->notifyRemoteReadyFunc_ = [weak = hostPattern_, taskExecutor]() { + sessionCallbacks->notifyRemoteReadyFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_]() { taskExecutor->PostTask( [weak]() { auto pattern = weak.Upgrade(); @@ -204,7 +189,7 @@ void SessionWrapperImpl::InitAllCallback() }, TaskExecutor::TaskType::UI); }; - sessionCallbacks->notifySyncOnFunc_ = [weak = hostPattern_, taskExecutor]() { + sessionCallbacks->notifySyncOnFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_]() { taskExecutor->PostTask( [weak]() { auto pattern = weak.Upgrade(); @@ -213,7 +198,7 @@ void SessionWrapperImpl::InitAllCallback() }, TaskExecutor::TaskType::UI); }; - sessionCallbacks->notifyAsyncOnFunc_ = [weak = hostPattern_, taskExecutor]() { + sessionCallbacks->notifyAsyncOnFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_]() { taskExecutor->PostTask( [weak]() { auto pattern = weak.Upgrade(); @@ -222,7 +207,7 @@ void SessionWrapperImpl::InitAllCallback() }, TaskExecutor::TaskType::UI); }; - sessionCallbacks->notifyBindModalFunc_ = [weak = hostPattern_, taskExecutor]() { + sessionCallbacks->notifyBindModalFunc_ = [weak = hostPattern_, taskExecutor = taskExecutor_]() { taskExecutor->PostSyncTask( [weak]() { auto pattern = weak.Upgrade(); @@ -245,11 +230,27 @@ void SessionWrapperImpl::InitAllCallback() /************************************************ Begin: About session ************************************************/ void SessionWrapperImpl::CreateSession(const AAFwk::Want& want, bool isAsyncModalBinding) { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Create session: %{private}s", want.ToString().c_str()); - const std::string occupiedAreaChangeKey("ability.want.params.IsNotifyOccupiedAreaChange"); - isNotifyOccupiedAreaChange_ = want.GetBoolParam(occupiedAreaChangeKey, false); - auto container = AceType::DynamicCast(Container::Current()); + UIEXT_LOGI("The session is created with want = %{private}s", want.ToString().c_str()); + auto container = Platform::AceContainer::GetContainer(instanceId_); CHECK_NULL_VOID(container); + auto wantPtr = std::make_shared(want); + if (sessionType_ == SessionType::UI_EXTENSION_ABILITY && + wantPtr->GetStringParam(UI_EXTENSION_TYPE_KEY) == EMBEDDED_UI) { + UIEXT_LOGE("The UIExtensionComponent is not allowed to start the EmbeddedUIExtensionAbility."); + return; + } + if (sessionType_ == SessionType::EMBEDDED_UI_EXTENSION) { + if (container->IsUIExtensionWindow()) { + UIEXT_LOGE("The EmbeddedComponent does not allow nested pulling of another."); + auto pattern = hostPattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->FireOnErrorCallback(ERROR_CODE_UIEXTENSION_FORBID_CASCADE, PULL_FAIL_NAME, PULL_FAIL_MESSAGE); + return; + } + WantParams wantParams; + wantPtr->SetParam(UI_EXTENSION_TYPE_KEY, EMBEDDED_UI); + } + isNotifyOccupiedAreaChange_ = want.GetBoolParam(OCCUPIED_AREA_CHANGE_KEY, false); auto callerToken = container->GetToken(); auto parentToken = container->GetParentToken(); Rosen::SessionInfo extensionSessionInfo = { @@ -257,12 +258,12 @@ void SessionWrapperImpl::CreateSession(const AAFwk::Want& want, bool isAsyncModa .abilityName_ = want.GetElement().GetAbilityName(), .callerToken_ = callerToken, .rootToken_ = (isTransferringCaller_ && parentToken) ? parentToken : callerToken, - .want = std::make_shared(want), + .want = wantPtr, .isAsyncModalBinding_ = isAsyncModalBinding, }; session_ = Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSession(extensionSessionInfo); CHECK_NULL_VOID(session_); - lifecycleListener_ = std::make_shared(instanceId_, hostPattern_); + lifecycleListener_ = std::make_shared(AceType::WeakClaim(this)); session_->RegisterLifecycleListener(lifecycleListener_); InitAllCallback(); } @@ -305,6 +306,7 @@ bool SessionWrapperImpl::NotifyBackPressedSync() CHECK_NULL_RETURN(session_, false); bool isConsumed = false; session_->TransferBackPressedEventForConsumed(isConsumed); + UIEXT_LOGD("The back evnet is notified to the provider and %{public}s consumed.", isConsumed ? "is" : "is not"); return isConsumed; } @@ -318,6 +320,7 @@ bool SessionWrapperImpl::NotifyKeyEventSync(const std::shared_ptrTransferKeyEventForConsumed(keyEvent, isConsumed); + UIEXT_LOGD("The key evnet is notified to the provider and %{public}s consumed.", isConsumed ? "is" : "is not"); return isConsumed; } @@ -331,6 +334,7 @@ bool SessionWrapperImpl::NotifyAxisEventSync(const std::shared_ptrTransferFocusActiveEvent(isFocus); return true; } @@ -338,6 +342,7 @@ bool SessionWrapperImpl::NotifyFocusEventAsync(bool isFocus) bool SessionWrapperImpl::NotifyFocusStateAsync(bool focusState) { CHECK_NULL_RETURN(session_, false); + UIEXT_LOGD("The %{public}s state is notified to the provider.", focusState ? "focused" : "unfocused"); session_->TransferFocusStateEvent(focusState); return true; } @@ -349,6 +354,7 @@ bool SessionWrapperImpl::NotifyBackPressedAsync() bool SessionWrapperImpl::NotifyPointerEventAsync(const std::shared_ptr& pointerEvent) { if (session_ && pointerEvent) { + UIEXT_LOGD("Transfer the pointer event with 'id = %{public}d' to the provider.", pointerEvent->GetId()); session_->TransferPointerEvent(pointerEvent); } return false; @@ -356,6 +362,7 @@ bool SessionWrapperImpl::NotifyPointerEventAsync(const std::shared_ptr& keyEvent) { if (session_ && keyEvent) { + UIEXT_LOGD("Transfer the key event with 'id = %{public}d' to the provider.", keyEvent->GetId()); session_->TransferKeyEvent(keyEvent); } return false; @@ -371,7 +378,6 @@ void SessionWrapperImpl::NotifyCreate() {} void SessionWrapperImpl::NotifyForeground() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Foreground: session is %{public}s", session_ ? "valid" : "invalid"); CHECK_NULL_VOID(session_); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); @@ -382,14 +388,12 @@ void SessionWrapperImpl::NotifyForeground() void SessionWrapperImpl::NotifyBackground() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Background: session is %{public}s", session_ ? "valid" : "invalid"); CHECK_NULL_VOID(session_); Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionBackground( session_, std::move(backgroundCallback_)); } void SessionWrapperImpl::NotifyDestroy() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Destroy: session is %{public}s", session_ ? "valid" : "invalid"); CHECK_NULL_VOID(session_); Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionDestruction( session_, std::move(destructionCallback_)); @@ -398,6 +402,51 @@ void SessionWrapperImpl::NotifyDestroy() void SessionWrapperImpl::NotifyConfigurationUpdate() {} /************************************************ End: The lifecycle interface ****************************************/ +/************************* Begin: The interface to control the display area and the avoid area ************************/ +void SessionWrapperImpl::OnConnect() +{ + taskExecutor_->PostTask( + [weak = hostPattern_]() { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->OnConnect(); + }, + TaskExecutor::TaskType::UI); +} + +void SessionWrapperImpl::OnDisconnect(bool isAbnormal) +{ + taskExecutor_->PostTask( + [weak = hostPattern_, sessionType = sessionType_, isAbnormal]() { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->OnDisconnect(isAbnormal); + if (sessionType == SessionType::UI_EXTENSION_ABILITY) { + pattern->FireOnReleaseCallback(static_cast(isAbnormal)); + return; + } + if (isAbnormal) { + pattern->FireOnErrorCallback( + ERROR_CODE_UIEXTENSION_EXITED_ABNORMALLY, EXIT_ABNORMALLY_NAME, EXIT_ABNORMALLY_MESSAGE); + } else { + pattern->FireOnTerminatedCallback(std::nullopt, nullptr); + } + }, + TaskExecutor::TaskType::UI); +} + +void SessionWrapperImpl::OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) +{ + taskExecutor_->PostTask( + [weak = hostPattern_, info, offset]() { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->OnAccessibilityEvent(info, offset); + }, + TaskExecutor::TaskType::UI); +} +/*************************** End: The interface to control the display area and the avoid area ************************/ + /************************************************ Begin: The interface about the accessibility ************************/ bool SessionWrapperImpl::TransferExecuteAction( int64_t elementId, const std::map& actionArguments, int32_t action, int64_t offset) @@ -435,13 +484,13 @@ void SessionWrapperImpl::FocusMoveSearch( } /************************************************ Begin: The interface about the accessibility ************************/ -/************************************************ Begin: The interface to control the display area ********************/ +/***************************** Begin: The interface to control the display area and the avoid area ********************/ std::shared_ptr SessionWrapperImpl::GetSurfaceNode() const { return session_ ? session_->GetSurfaceNode() : nullptr; } -void SessionWrapperImpl::RefreshDisplayArea(const RectF& displayArea) +void SessionWrapperImpl::NotifyDisplayArea(const RectF& displayArea) { CHECK_NULL_VOID(session_); ContainerScope scope(instanceId_); @@ -449,6 +498,7 @@ void SessionWrapperImpl::RefreshDisplayArea(const RectF& displayArea) CHECK_NULL_VOID(pipeline); auto curWindow = pipeline->GetCurrentWindowRect(); displayArea_ = displayArea + OffsetF(curWindow.Left(), curWindow.Top()); + UIEXT_LOGD("The display area with '%{public}s' is notified to the provider.", displayArea_.ToString().c_str()); std::shared_ptr transaction; if (auto transactionController = Rosen::RSSyncTransactionController::GetInstance()) { transaction = transactionController->GetRSTransaction(); @@ -459,12 +509,12 @@ void SessionWrapperImpl::RefreshDisplayArea(const RectF& displayArea) #endif } session_->UpdateRect({ std::round(displayArea_.Left()), std::round(displayArea_.Top()), - std::round(displayArea_.Width()), std::round(displayArea_.Height()) }, + std::round(displayArea_.Width()), std::round(displayArea_.Height()) }, session_->GetSizeChangeReason(), transaction); } -void SessionWrapperImpl::OnSizeChanged(WindowSizeChangeReason type, - const std::shared_ptr& rsTransaction) +void SessionWrapperImpl::NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) { CHECK_NULL_VOID(session_); auto reason = static_cast(type); @@ -473,32 +523,11 @@ void SessionWrapperImpl::OnSizeChanged(WindowSizeChangeReason type, session_->UpdateRect(session_->GetSessionRect(), reason, rsTransaction); } } -/************************************************ End: The interface to control the display area **********************/ - -/************************************************ Begin: The interface to send the data for ArkTS *********************/ -void SessionWrapperImpl::SendDataAsync(const AAFwk::WantParams& params) const -{ - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Async: session is %{public}s", session_ ? "valid" : "invalid"); - CHECK_NULL_VOID(session_); - session_->TransferComponentData(params); -} - -int32_t SessionWrapperImpl::SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const -{ - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Sync: session is %{public}s", session_ ? "valid" : "invalid"); - Rosen::WSErrorCode transferCode = Rosen::WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED; - if (session_) { - transferCode = session_->TransferComponentDataSync(wantParams, reWantParams); - } - return static_cast(transferCode); -} -/************************************************ End: The interface to send the data for ArkTS ***********************/ -/************************************************ Begin: The interface to control the avoid area **********************/ void SessionWrapperImpl::NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "AvoidArea: session is %{public}s", session_ ? "valid" : "invalid"); CHECK_NULL_VOID(session_); + UIEXT_LOGD("The avoid area is notified to the provider."); session_->UpdateAvoidArea(sptr::MakeSptr(avoidArea), static_cast(type)); } @@ -517,8 +546,28 @@ bool SessionWrapperImpl::NotifyOccupiedAreaChangeInfo(sptr(std::max(keyboardHeight - spaceWindow, 0)); } info->rect_.height_ = static_cast(keyboardHeight); + UIEXT_LOGD("The occcupied area with 'keyboardHeight = %{public}d' is notified to the provider.", keyboardHeight); session_->NotifyOccupiedAreaChangeInfo(info); return true; } -/************************************************ End: The interface to control the avoid area ************************/ +/***************************** End: The interface to control the display area and the avoid area **********************/ + +/************************************************ Begin: The interface to send the data for ArkTS *********************/ +void SessionWrapperImpl::SendDataAsync(const AAFwk::WantParams& params) const +{ + UIEXT_LOGD("The data is asynchronously send and the session is %{public}s", session_ ? "valid" : "invalid"); + CHECK_NULL_VOID(session_); + session_->TransferComponentData(params); +} + +int32_t SessionWrapperImpl::SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const +{ + UIEXT_LOGD("The data is synchronously send and the session is %{public}s", session_ ? "valid" : "invalid"); + Rosen::WSErrorCode transferCode = Rosen::WSErrorCode::WS_ERROR_TRANSFER_DATA_FAILED; + if (session_) { + transferCode = session_->TransferComponentDataSync(wantParams, reWantParams); + } + return static_cast(transferCode); +} +/************************************************ End: The interface to send the data for ArkTS ***********************/ } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.h b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.h index 1a41e614d9b..2609475dc6f 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.h +++ b/frameworks/core/components_ng/pattern/ui_extension/session_wrapper_impl.h @@ -31,7 +31,8 @@ class SessionWrapperImpl : public SessionWrapper { DECLARE_ACE_TYPE(SessionWrapperImpl, SessionWrapper); public: - SessionWrapperImpl(const WeakPtr& hostPattern, int32_t instanceId, bool isTransferringCaller); + SessionWrapperImpl(const WeakPtr& hostPattern, int32_t instanceId, bool isTransferringCaller, + SessionType sessionType); ~SessionWrapperImpl() override; // About session @@ -64,6 +65,11 @@ public: void NotifyDestroy() override; void NotifyConfigurationUpdate() override; + // Notify the Host + void OnConnect() override; + void OnDisconnect(bool isAbnormal) override; + void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) override; + // The interface about the accessibility bool TransferExecuteAction(int64_t elementId, const std::map& actionArguments, int32_t action, int64_t offset) override; @@ -76,28 +82,29 @@ public: void FocusMoveSearch(int64_t elementId, int32_t direction, int64_t baseParent, Accessibility::AccessibilityElementInfo& output) override; - // The interface to control the display area + // The interface to control the display area and the avoid area std::shared_ptr GetSurfaceNode() const override; - void RefreshDisplayArea(const RectF& displayArea) override; - void OnSizeChanged(WindowSizeChangeReason type, - const std::shared_ptr& rsTransaction) override; + void NotifyDisplayArea(const RectF& displayArea) override; + void NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) override; + void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const override; + bool NotifyOccupiedAreaChangeInfo(sptr info) const override; // The interface to send the data for ArkTS void SendDataAsync(const AAFwk::WantParams& params) const override; int32_t SendDataSync(const AAFwk::WantParams& wantParams, AAFwk::WantParams& reWantParams) const override; - // The interface to control the avoid area - void NotifyOriginAvoidArea(const Rosen::AvoidArea& avoidArea, uint32_t type) const override; - bool NotifyOccupiedAreaChangeInfo(sptr info) const override; - private: void InitAllCallback(); - sptr session_; WeakPtr hostPattern_; - RectF displayArea_; - bool isNotifyOccupiedAreaChange_ = false; + RefPtr taskExecutor_; int32_t instanceId_; bool isTransferringCaller_; + SessionType sessionType_ = SessionType::UI_EXTENSION_ABILITY; + int32_t uiExtensionId_ = 0; + sptr session_; + bool isNotifyOccupiedAreaChange_ = false; + RectF displayArea_; std::shared_ptr lifecycleListener_; std::function foregroundCallback_; std::function backgroundCallback_; diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.cpp b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.cpp index f901aa0c81c..2822aeb5be4 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.cpp @@ -128,13 +128,13 @@ bool UIExtensionManager::NotifyOccupiedAreaChangeInfo(const sptrNotifyOccupiedAreaChangeInfo(info); } -void UIExtensionManager::OnSizeChanged(WindowSizeChangeReason type, +void UIExtensionManager::NotifySizeChangeReason(WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) { for (const auto& it : aliveUIExtensions_) { auto uiExtension = it.second.Upgrade(); if (uiExtension) { - uiExtension->OnSizeChanged(type, rsTransaction); + uiExtension->NotifySizeChangeReason(type, rsTransaction); } } } diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.h b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.h index 47a0e6bb286..64a96ab9f5b 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.h +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_manager.h @@ -33,7 +33,7 @@ namespace Rosen { class AvoidArea; enum class WSError; class OccupiedAreaChangeInfo; -} // namespace OHOS::Rosen +} // namespace Rosen } // namespace OHOS namespace OHOS::Ace::NG { @@ -61,8 +61,8 @@ public: bool OnBackPressed(); const RefPtr GetFocusUiExtensionNode(); bool IsWrapExtensionAbilityId(int64_t elementId); - bool SendAccessibilityEventInfo(const Accessibility::AccessibilityEventInfo& eventInfo, - int64_t uiExtensionOffset, const RefPtr& pipeline); + bool SendAccessibilityEventInfo(const Accessibility::AccessibilityEventInfo& eventInfo, int64_t uiExtensionOffset, + const RefPtr& pipeline); std::pair UnWrapExtensionAbilityId(int64_t extensionOffset, int64_t elementId); int32_t ApplyExtensionId(); void RecycleExtensionId(int32_t id); @@ -91,7 +91,8 @@ public: bool NotifyOccupiedAreaChangeInfo(const sptr& info); - void OnSizeChanged(WindowSizeChangeReason type, const std::shared_ptr& rsTransaction); + void NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction); private: class UIExtensionIdUtility { diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model.h b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model.h index 193fd7a8e91..e737971b760 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model.h +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model.h @@ -23,6 +23,7 @@ #include "base/utils/macros.h" #include "base/want/want_wrap.h" #include "core/components_ng/base/frame_node.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" namespace OHOS::AAFwk { class Want; @@ -41,7 +42,7 @@ public: virtual void Create(const RefPtr& wantWrap, bool transferringCaller = false); // for Embedded Component - virtual void Create(const RefPtr& wantWrap, int32_t embeddedType); + virtual void Create(const RefPtr& wantWrap, NG::SessionType sessionType); // for DynamicComponent virtual void Create(); virtual void InitializeDynamicComponent(const RefPtr& frameNode, const std::string& hapPath, @@ -51,6 +52,7 @@ public: virtual void SetOnRemoteReady(std::function&)>&& onRemoteReady); virtual void SetOnRelease(std::function&& onRelease); virtual void SetOnResult(std::function&& onResult); + virtual void SetOnTerminated(std::function, const RefPtr&)>&& onTerminated); virtual void SetOnReceive(std::function&& onReceive); virtual void SetOnError( std::function&& onError); diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.cpp b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.cpp index 53381c3c545..b6b4d654551 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.cpp @@ -20,6 +20,7 @@ #include "core/components/common/layout/constants.h" #include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" #include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/pipeline_ng/pipeline_context.h" @@ -43,8 +44,8 @@ RefPtr UIExtensionModelNG::Create(const std::string& bundleName, cons return frameNode; } -RefPtr UIExtensionModelNG::Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks, - bool isAsyncModalBinding) +RefPtr UIExtensionModelNG::Create( + const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks, bool isAsyncModalBinding) { auto nodeId = ElementRegister::GetInstance()->MakeUniqueId(); auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, @@ -83,12 +84,12 @@ void UIExtensionModelNG::Create(const RefPtr& wantWrap, boo } // for EmbeddedComponent -void UIExtensionModelNG::Create(const RefPtr& wantWrap, int32_t embeddedType) +void UIExtensionModelNG::Create(const RefPtr& wantWrap, SessionType sessionType) { auto* stack = ViewStackProcessor::GetInstance(); auto nodeId = stack->ClaimNodeId(); auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, - [embeddedType]() { return AceType::MakeRefPtr(false, false, false, embeddedType); }); + [sessionType]() { return AceType::MakeRefPtr(false, false, false, sessionType); }); auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); pattern->SetWantWrap(wantWrap); @@ -106,8 +107,8 @@ void UIExtensionModelNG::Create() { auto* stack = ViewStackProcessor::GetInstance(); auto nodeId = stack->ClaimNodeId(); - auto frameNode = FrameNode::GetOrCreateFrameNode(V2::DYNAMIC_COMPONENT_ETS_TAG, nodeId, - []() { return AceType::MakeRefPtr(); }); + auto frameNode = FrameNode::GetOrCreateFrameNode( + V2::DYNAMIC_COMPONENT_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); auto pattern = frameNode->GetPattern(); CHECK_NULL_VOID(pattern); stack->Push(frameNode); @@ -158,6 +159,15 @@ void UIExtensionModelNG::SetOnResult(std::functionSetOnResultCallback(std::move(onResult)); } +void UIExtensionModelNG::SetOnTerminated( + std::function, const RefPtr&)>&& onTerminated) +{ + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto pattern = frameNode->GetPattern(); + pattern->SetOnTerminatedCallback(std::move(onTerminated)); +} + void UIExtensionModelNG::SetOnReceive(std::function&& onReceive) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.h b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.h index a9a4f553528..f6432815b9d 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.h +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_model_ng.h @@ -32,12 +32,12 @@ public: static RefPtr Create(const std::string& bundleName, const std::string& abilityName, const std::map& params, std::function&& onRelease, std::function&& onError); - static RefPtr Create(const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks, - bool isAsyncModalBinding = false); + static RefPtr Create( + const AAFwk::Want& want, const ModalUIExtensionCallbacks& callbacks, bool isAsyncModalBinding = false); void Create(const RefPtr& wantWrap, bool transferringCaller = false) override; // for Embedded Component - void Create(const RefPtr& wantWrap, int32_t embeddedType) override; + void Create(const RefPtr& wantWrap, SessionType sessionType) override; // for dynamic component void Create() override; void InitializeDynamicComponent(const RefPtr& frameNode, const std::string& hapPath, @@ -47,6 +47,7 @@ public: void SetOnRemoteReady(std::function&)>&& onRemoteReady) override; void SetOnRelease(std::function&& onRelease) override; void SetOnResult(std::function&& onResult) override; + void SetOnTerminated(std::function, const RefPtr&)>&& onTerminated) override; void SetOnReceive(std::function&& onReceive) override; void SetOnError( std::function&& onError) override; diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp index 30448812dc3..5f28b3b59c3 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp @@ -15,6 +15,8 @@ #include "core/components_ng/pattern/ui_extension/ui_extension_pattern.h" +#include + #include "key_event.h" #include "pointer_event.h" #include "session/host/include/extension_session.h" @@ -25,7 +27,6 @@ #include "adapter/ohos/entrance/ace_extra_input_data.h" #include "adapter/ohos/entrance/mmi_event_convertor.h" #include "adapter/ohos/osal/want_wrap_ohos.h" -#include "base/error/error_code.h" #include "base/geometry/offset.h" #include "base/utils/utils.h" #include "core/common/container.h" @@ -33,6 +34,7 @@ #include "core/components_ng/pattern/pattern.h" #include "core/components_ng/pattern/text_field/text_field_manager.h" #include "core/components_ng/pattern/ui_extension/modal_ui_extension_proxy_impl.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" #include "core/components_ng/pattern/ui_extension/session_wrapper_factory.h" #include "core/components_ng/pattern/ui_extension/session_wrapper_impl.h" #include "core/components_ng/pattern/ui_extension/ui_extension_layout_algorithm.h" @@ -47,24 +49,23 @@ #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { -UIExtensionPattern::UIExtensionPattern(bool isTransferringCaller, bool isModal, bool isAsyncModalBinding, - int32_t embeddedType) : isTransferringCaller_(isTransferringCaller), isModal_(isModal), - isAsyncModalBinding_(isAsyncModalBinding), embeddedType_(embeddedType) +UIExtensionPattern::UIExtensionPattern( + bool isTransferringCaller, bool isModal, bool isAsyncModalBinding, SessionType sessionType) + : isTransferringCaller_(isTransferringCaller), isModal_(isModal), isAsyncModalBinding_(isAsyncModalBinding) { - sessionWrapper_ = SessionWrapperFactory::CreateSessionWrapper( - SessionTye::UI_EXTENSION_ABILITY, AceType::WeakClaim(this), instanceId_, isTransferringCaller_); auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto uiExtensionManager = pipeline->GetUIExtensionManager(); CHECK_NULL_VOID(uiExtensionManager); uiExtensionId_ = uiExtensionManager->ApplyExtensionId(); - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Id = %{public}d, TransferrCaller = %{public}d, isModal = %{public}d", - uiExtensionId_, isTransferringCaller_, isModal_); + sessionWrapper_ = SessionWrapperFactory::CreateSessionWrapper( + sessionType, AceType::WeakClaim(this), instanceId_, isTransferringCaller_); + UIEXT_LOGI("The %{public}smodal UIExtension is created.", isModal_ ? "" : "non"); } UIExtensionPattern::~UIExtensionPattern() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "UIExtension with id = %{public}d is destroyed.", uiExtensionId_); + UIEXT_LOGI("The %{public}smodal UIExtension is destroyed.", isModal_ ? "" : "non"); NotifyDestroy(); FireModalOnDestroy(); auto pipeline = PipelineContext::GetCurrentContext(); @@ -107,21 +108,12 @@ void UIExtensionPattern::UpdateWant(const RefPtr& wantWrap) void UIExtensionPattern::UpdateWant(const AAFwk::Want& want) { CHECK_NULL_VOID(sessionWrapper_); - auto container = Container::GetContainer(instanceId_); - if (container && container->IsUIExtensionWindow() && embeddedType_ == EmbeddedType::UI_EXTENSION) { - TAG_LOGE(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "This is embedded component, not allowed to pull up another."); - std::string name = "extension_pulling_up_fail"; - std::string message = "pulling another embedded component failed, not allowed to cascade."; - FireOnErrorCallback(ERROR_CODE_UIEXTENSION_FORBID_CASCADE, name, message); - return; - } // Prohibit rebuilding the session unless the Want is updated. if (sessionWrapper_->IsSessionValid()) { if (sessionWrapper_->GetWant()->IsEquals(want)) { return; } - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "The old want is %{private}s, id = %{public}d", - sessionWrapper_->GetWant()->ToString().c_str(), uiExtensionId_); + UIEXT_LOGI("The old want is %{private}s.", sessionWrapper_->GetWant()->ToString().c_str()); auto host = GetHost(); CHECK_NULL_VOID(host); host->RemoveChild(contentNode_); @@ -136,6 +128,7 @@ void UIExtensionPattern::OnConnect() { CHECK_RUN_ON(UI); CHECK_NULL_VOID(sessionWrapper_); + UIEXT_LOGI("The session is connected and the current state is '%{public}s'.", ToString(state_)); ContainerScope scope(instanceId_); contentNode_ = FrameNode::CreateFrameNode( V2::UI_EXTENSION_SURFACE_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); @@ -172,15 +165,12 @@ void UIExtensionPattern::OnConnect() if (isFocused || isModal_) { uiExtensionManager->RegisterUIExtensionInFocus(WeakClaim(this), sessionWrapper_); } - TAG_LOGI( - AceLogTag::ACE_UIEXTENSIONCOMPONENT, "The UIExtensionComponent is connected, id = %{public}d.", uiExtensionId_); } void UIExtensionPattern::OnAccessibilityEvent( const Accessibility::AccessibilityEventInfo& info, int64_t uiExtensionOffset) { - TAG_LOGI( - AceLogTag::ACE_UIEXTENSIONCOMPONENT, "The accessibility event is reported, id = %{public}d.", uiExtensionId_); + UIEXT_LOGI("The accessibility event is reported and the current state is '%{public}s'.", ToString(state_)); ContainerScope scope(instanceId_); auto ngPipeline = NG::PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(ngPipeline); @@ -192,24 +182,14 @@ void UIExtensionPattern::OnAccessibilityEvent( accessibilityManager->SendExtensionAccessibilityEvent(info, uiExtensionOffset); } -void UIExtensionPattern::OnDisconnect() +void UIExtensionPattern::OnDisconnect(bool isAbnormal) { CHECK_RUN_ON(UI); - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "The session is disconnected and state = %{public}d, id = %{public}d.", state_, uiExtensionId_); - FireOnReleaseCallback(static_cast(ReleaseCode::DESTROY_NORMAL)); -} - -void UIExtensionPattern::OnExtensionDied() -{ - CHECK_RUN_ON(UI); - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "The session is died and state = %{public}d, id = %{public}d.", - state_, uiExtensionId_); + UIEXT_LOGI("The session is disconnected and the current state is '%{public}s'.", ToString(state_)); auto host = GetHost(); CHECK_NULL_VOID(host); host->RemoveChild(contentNode_); host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); - FireOnReleaseCallback(static_cast(ReleaseCode::CONNECT_BROKEN)); } void UIExtensionPattern::OnAreaChangedInner() @@ -231,7 +211,7 @@ bool UIExtensionPattern::OnDirtyLayoutWrapperSwap(const RefPtr& d CHECK_NULL_RETURN(geometryNode, false); auto displaySize = geometryNode->GetFrameSize(); displayArea_ = RectF(displayOffset, displaySize); - sessionWrapper_->RefreshDisplayArea(displayArea_); + sessionWrapper_->NotifyDisplayArea(displayArea_); return false; } @@ -263,8 +243,7 @@ bool UIExtensionPattern::OnDirtyLayoutWrapperSwapForDynamicComponent( void UIExtensionPattern::OnWindowShow() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "Show window, state = %{public}d, visible = %{public}d, id = %{public}d.", state_, isVisible_, uiExtensionId_); + UIEXT_LOGI("The window is being shown and the component is %{public}s.", isVisible_ ? "visible" : "invisible"); if (isVisible_) { NotifyForeground(); } @@ -272,23 +251,23 @@ void UIExtensionPattern::OnWindowShow() void UIExtensionPattern::OnWindowHide() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "Hide window, state = %{public}d, visible = %{public}d, id = %{public}d.", state_, isVisible_, uiExtensionId_); + UIEXT_LOGI("The window is being hidden and the component is %{public}s.", isVisible_ ? "visible" : "invisible"); if (isVisible_) { NotifyBackground(); } } -void UIExtensionPattern::OnSizeChanged(WindowSizeChangeReason type, - const std::shared_ptr& rsTransaction) +void UIExtensionPattern::NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) { CHECK_NULL_VOID(sessionWrapper_); - sessionWrapper_->OnSizeChanged(type, rsTransaction); + sessionWrapper_->NotifySizeChangeReason(type, rsTransaction); } void UIExtensionPattern::NotifyForeground() { if (sessionWrapper_ && sessionWrapper_->IsSessionValid() && state_ != AbilityState::FOREGROUND) { + UIEXT_LOGI("The state is changing from '%{public}s' to 'FOREGROUND'.", ToString(state_)); state_ = AbilityState::FOREGROUND; sessionWrapper_->NotifyForeground(); } @@ -297,6 +276,7 @@ void UIExtensionPattern::NotifyForeground() void UIExtensionPattern::NotifyBackground() { if (sessionWrapper_ && sessionWrapper_->IsSessionValid() && state_ == AbilityState::FOREGROUND) { + UIEXT_LOGI("The state is changing from '%{public}s' to 'BACKGROUND'.", ToString(state_)); state_ = AbilityState::BACKGROUND; sessionWrapper_->NotifyBackground(); } @@ -306,6 +286,7 @@ void UIExtensionPattern::NotifyDestroy() { if (sessionWrapper_ && sessionWrapper_->IsSessionValid() && state_ != AbilityState::DESTRUCTION && state_ != AbilityState::NONE) { + UIEXT_LOGI("The state is changing from '%{public}s' to 'DESTRUCTION'.", ToString(state_)); state_ = AbilityState::DESTRUCTION; sessionWrapper_->NotifyDestroy(); sessionWrapper_->DestroySession(); @@ -595,7 +576,7 @@ void UIExtensionPattern::DispatchDisplayArea(bool isForce) auto displayArea = RectF(displayOffset, displaySize); if (displayArea_ != displayArea || isForce) { displayArea_ = displayArea; - sessionWrapper_->RefreshDisplayArea(displayArea_); + sessionWrapper_->NotifyDisplayArea(displayArea_); } } @@ -634,8 +615,7 @@ void UIExtensionPattern::SetModalOnRemoteReadyCallback( void UIExtensionPattern::FireOnRemoteReadyCallback() { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "The onRemoteReady is called and state = %{public}d, id = %{public}d.", state_, uiExtensionId_); + UIEXT_LOGD("The current state is '%{public}s'.", ToString(state_)); ContainerScope scope(instanceId_); // These two callbacks will be unified in the future. if (onRemoteReadyCallback_) { @@ -653,10 +633,9 @@ void UIExtensionPattern::SetModalOnDestroy(const std::function&& callbac void UIExtensionPattern::FireModalOnDestroy() { + UIEXT_LOGD("The current state is '%{public}s'.", ToString(state_)); // Native modal page destroy callback if (onModalDestroy_) { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "The onModalDestroy is called and state = %{public}d, id = %{public}d.", state_, uiExtensionId_); ContainerScope scope(instanceId_); onModalDestroy_(); } @@ -669,10 +648,10 @@ void UIExtensionPattern::SetOnReleaseCallback(const std::function void UIExtensionPattern::FireOnReleaseCallback(int32_t releaseCode) { + UIEXT_LOGD("The state is changing from '%{public}s' to 'DESTRUCTION' and releaseCode = %{public}d.", + ToString(state_), releaseCode); state_ = AbilityState::DESTRUCTION; if (onReleaseCallback_) { - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "The onRelease is called and state = %{public}d, id = %{public}d.", state_, uiExtensionId_); onReleaseCallback_(releaseCode); } // Release the session. @@ -695,9 +674,7 @@ void UIExtensionPattern::SetOnErrorCallback( void UIExtensionPattern::FireOnErrorCallback(int32_t code, const std::string& name, const std::string& message) { // 1. As long as the error occurs, the host believes that UIExtensionAbility has been killed. - TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, - "Error: Id = %{public}d, state = %{public}d, code=%{public}d, name=%{public}s", uiExtensionId_, state_, code, - name.c_str()); + UIEXT_LOGD("The state is changing from '%{public}s' to 'NONE'.", ToString(state_)); state_ = AbilityState::NONE; if (onErrorCallback_) { ContainerScope scope(instanceId_); @@ -714,15 +691,30 @@ void UIExtensionPattern::SetOnResultCallback(const std::function, const RefPtr& wantWrap)>&& callback) +{ + onTerminatedCallback_ = std::move(callback); +} + +void UIExtensionPattern::FireOnTerminatedCallback(std::optional code, const RefPtr& wantWrap) +{ + UIEXT_LOGD("The state is changing from '%{public}s' to 'DESTRUCTION'.", ToString(state_)); + if (onTerminatedCallback_ && (state_ != AbilityState::DESTRUCTION)) { + ContainerScope scope(instanceId_); + onTerminatedCallback_(code, wantWrap); + } + state_ = AbilityState::DESTRUCTION; +} + void UIExtensionPattern::SetOnReceiveCallback(const std::function&& callback) { onReceiveCallback_ = std::move(callback); @@ -730,9 +722,8 @@ void UIExtensionPattern::SetOnReceiveCallback(const std::functionGetNodeStatus() == NodeStatus::NORMAL_NODE) { - TAG_LOGD(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Frame node status is normal."); + UIEXT_LOGD("Frame node status is normal."); return; } auto wantWrap = GetWantWrap(); CHECK_NULL_VOID(wantWrap); UpdateWant(wantWrap); SetWantWrap(nullptr); - TAG_LOGD(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "Current node mount down."); } void UIExtensionPattern::RegisterVisibleAreaChange() @@ -827,7 +812,7 @@ void UIExtensionPattern::RegisterVisibleAreaChange() }; auto host = GetHost(); CHECK_NULL_VOID(host); - std::vector ratioList = {0.0}; + std::vector ratioList = { 0.0 }; pipeline->AddVisibleAreaChangeNode(host, ratioList, callback, false); } @@ -885,6 +870,21 @@ int64_t UIExtensionPattern::WrapExtensionAbilityId(int64_t extensionOffset, int6 return uiExtensionId_ * extensionOffset + abilityId; } +const char* UIExtensionPattern::ToString(AbilityState state) +{ + switch (state) { + case AbilityState::FOREGROUND: + return "FOREGROUND"; + case AbilityState::BACKGROUND: + return "BACKGROUND"; + case AbilityState::DESTRUCTION: + return "DESTRUCTION"; + case AbilityState::NONE: + default: + return "NONE"; + } +} + void UIExtensionPattern::SearchExtensionElementInfoByAccessibilityId( int64_t elementId, int32_t mode, int64_t baseParent, std::list& output) { diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.h b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.h index c6a84744c52..1c4877c7ccc 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.h +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,22 @@ #include "core/event/mouse_event.h" #include "core/event/touch_event.h" +#define UIEXT_LOGD(fmt, ...) \ + TAG_LOGD(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, uiExtensionId_, \ + ##__VA_ARGS__) +#define UIEXT_LOGI(fmt, ...) \ + TAG_LOGI(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, uiExtensionId_, \ + ##__VA_ARGS__) +#define UIEXT_LOGW(fmt, ...) \ + TAG_LOGW(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, uiExtensionId_, \ + ##__VA_ARGS__) +#define UIEXT_LOGE(fmt, ...) \ + TAG_LOGE(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, uiExtensionId_, \ + ##__VA_ARGS__) +#define UIEXT_LOGF(fmt, ...) \ + TAG_LOGF(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, uiExtensionId_, \ + ##__VA_ARGS__) + namespace OHOS::Accessibility { class AccessibilityElementInfo; class AccessibilityEventInfo; @@ -53,17 +70,13 @@ class RSTransaction; } // namespace OHOS::Rosen namespace OHOS::Ace::NG { -enum EmbeddedType : int32_t { - DEFAULT_TYPE = -1, - UI_EXTENSION = 0 -}; class UIExtensionProxy; class UIExtensionPattern : public Pattern { DECLARE_ACE_TYPE(UIExtensionPattern, Pattern); public: explicit UIExtensionPattern(bool isTransferringCaller = false, bool isModal = false, - bool isAsyncModalBinding = false, int32_t embeddedType = EmbeddedType::DEFAULT_TYPE); + bool isAsyncModalBinding = false, SessionType sessionType = SessionType::UI_EXTENSION_ABILITY); ~UIExtensionPattern() override; RefPtr CreateLayoutAlgorithm() override; @@ -97,8 +110,7 @@ public: } void OnConnect(); - void OnDisconnect(); - void OnExtensionDied(); + void OnDisconnect(bool isAbnormal); void HandleDragEvent(const PointerEvent& info) override; void SetModalOnDestroy(const std::function&& callback); @@ -111,6 +123,8 @@ public: void FireOnReleaseCallback(int32_t releaseCode); void SetOnResultCallback(const std::function&& callback); void FireOnResultCallback(int32_t code, const AAFwk::Want& want); + void SetOnTerminatedCallback(const std::function, const RefPtr&)>&& callback); + void FireOnTerminatedCallback(std::optional code, const RefPtr& wantWrap); void SetOnReceiveCallback(const std::function&& callback); void FireOnReceiveCallback(const AAFwk::WantParams& params); void SetOnErrorCallback( @@ -123,8 +137,8 @@ public: void SetBindModalCallback(const std::function&& callback); void FireBindModalCallback(); - void OnSizeChanged(WindowSizeChangeReason type, - const std::shared_ptr& rsTransaction); + void NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction); void NotifyForeground(); void NotifyBackground(); void NotifyDestroy(); @@ -150,11 +164,6 @@ public: void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t uiExtensionOffset); private: - enum class ReleaseCode { - DESTROY_NORMAL = 0, - CONNECT_BROKEN, - }; - enum class AbilityState { NONE = 0, FOREGROUND, @@ -170,6 +179,7 @@ private: enum class ComponentType { DYNAMIC, UI_EXTENSION }; + const char* ToString(AbilityState state); void OnAttachToFrameNode() override; void OnDetachFromFrameNode(FrameNode* frameNode) override; void OnLanguageConfigurationUpdate() override; @@ -205,6 +215,7 @@ private: std::function&)> onRemoteReadyCallback_; std::function onReleaseCallback_; std::function onResultCallback_; + std::function, const RefPtr&)> onTerminatedCallback_; std::function onReceiveCallback_; std::function onErrorCallback_; std::list&)>> onSyncOnCallbackList_; @@ -224,7 +235,6 @@ private: int32_t uiExtensionId_ = 0; int32_t callbackId_ = 0; RectF displayArea_; - int32_t embeddedType_ = EmbeddedType::DEFAULT_TYPE; // for DynamicComponent ComponentType componentType_ = ComponentType::UI_EXTENSION; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 327c7c8af3f..aedce09a40c 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -1321,7 +1321,7 @@ void PipelineContext::UpdateSizeChangeReason( { #ifdef WINDOW_SCENE_SUPPORTED CHECK_NULL_VOID(uiExtensionManager_); - uiExtensionManager_->OnSizeChanged(type, rsTransaction); + uiExtensionManager_->NotifySizeChangeReason(type, rsTransaction); #endif } diff --git a/test/mock/core/pattern/mock_ui_extension_model_ng.cpp b/test/mock/core/pattern/mock_ui_extension_model_ng.cpp index d72d1867aa8..be27d91da62 100644 --- a/test/mock/core/pattern/mock_ui_extension_model_ng.cpp +++ b/test/mock/core/pattern/mock_ui_extension_model_ng.cpp @@ -15,6 +15,7 @@ #include "base/want/want_wrap.h" #include "core/components_ng/base/frame_node.h" +#include "core/components_ng/pattern/ui_extension/session_wrapper.h" #include "core/components_ng/pattern/ui_extension/ui_extension_model_ng.h" namespace OHOS::Ace::NG { @@ -27,7 +28,7 @@ RefPtr UIExtensionModelNG::Create(const std::string& bundleName, cons void UIExtensionModelNG::Create(const RefPtr& wantWrap, bool transferringCaller) {} -void UIExtensionModelNG::Create(const RefPtr& wantWrap, int32_t embeddedType) {} +void UIExtensionModelNG::Create(const RefPtr& wantWrap, SessionType sessionType) {} void UIExtensionModelNG::Create() {} -- Gitee