diff --git a/frameworks/core/components_ng/pattern/ui_extension/security_session_wrapper_impl.cpp b/frameworks/core/components_ng/pattern/ui_extension/security_session_wrapper_impl.cpp index 3ebdf08d4fa..c68e0cc1b1d 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/security_session_wrapper_impl.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/security_session_wrapper_impl.cpp @@ -366,7 +366,7 @@ bool SecuritySessionWrapperImpl::NotifyBackPressedSync() CHECK_NULL_RETURN(session_, false); bool isConsumed = false; session_->TransferBackPressedEventForConsumed(isConsumed); - PLATFORM_LOGI("BackPressed, persistentid = %{public}d and %{public}s consumed.", + PLATFORM_LOGI("BackPress, persistentid = %{public}d and %{public}s consumed.", GetSessionId(), isConsumed ? "is" : "is not"); return isConsumed; } diff --git a/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.cpp b/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.cpp index 9ddf63eb77d..f24398530cc 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.cpp @@ -273,11 +273,6 @@ void SecurityUIExtensionPattern::OnDisconnect(bool isAbnormal) host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } -void SecurityUIExtensionPattern::OnAreaChangedInner() -{ - DispatchDisplayArea(); -} - void SecurityUIExtensionPattern::FireBindModalCallback() {} @@ -347,7 +342,18 @@ void SecurityUIExtensionPattern::OnAttachToFrameNode() CHECK_NULL_VOID(pipeline); auto host = GetHost(); CHECK_NULL_VOID(host); - + auto eventHub = host->GetEventHub(); + CHECK_NULL_VOID(eventHub); + OnAreaChangedFunc onAreaChangedFunc = [weak = WeakClaim(this)]( + const RectF& oldRect, + const OffsetF& oldOrigin, + const RectF& rect, + const OffsetF& origin) { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->DispatchDisplayArea(); + }; + eventHub->AddInnerOnAreaChangedCallback(host->GetId(), std::move(onAreaChangedFunc)); pipeline->AddOnAreaChangeNode(host->GetId()); callbackId_ = pipeline->RegisterSurfacePositionChangedCallback( [weak = WeakClaim(this)](int32_t, int32_t) { @@ -356,6 +362,7 @@ void SecurityUIExtensionPattern::OnAttachToFrameNode() pattern->DispatchDisplayArea(true); } }); + PLATFORM_LOGI("OnAttachToFrameNode"); } void SecurityUIExtensionPattern::OnDetachFromFrameNode(FrameNode* frameNode) @@ -473,21 +480,24 @@ void SecurityUIExtensionPattern::FireOnTerminatedCallback( return; } + state_ = AbilityState::DESTRUCTION; + if (sessionWrapper_ && sessionWrapper_->IsSessionValid()) { + PLATFORM_LOGI("DestroySession."); + sessionWrapper_->DestroySession(); + } + ContainerScope scope(instanceId_); auto host = GetHost(); CHECK_NULL_VOID(host); auto eventHub = host->GetEventHub(); CHECK_NULL_VOID(eventHub); eventHub->FireOnTerminatedCallback(code, wantWrap); - state_ = AbilityState::DESTRUCTION; - if (sessionWrapper_ && sessionWrapper_->IsSessionValid()) { - sessionWrapper_->DestroySession(); - } } void SecurityUIExtensionPattern::FireOnErrorCallback( int32_t code, const std::string& name, const std::string& message) { + state_ = AbilityState::NONE; PlatformPattern::FireOnErrorCallback(code, name, message); if (sessionWrapper_ && sessionWrapper_->IsSessionValid()) { sessionWrapper_->DestroySession(); @@ -584,7 +594,7 @@ void SecurityUIExtensionPattern::OnMountToParentDone() return; } - PLATFORM_LOGI("OnMountToParentDone"); + PLATFORM_LOGI("OnMountToParentDone."); auto wantWrap = GetWantWrap(); CHECK_NULL_VOID(wantWrap); UpdateWant(wantWrap); diff --git a/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.h b/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.h index 5aea9dd425d..18db9d371dd 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.h +++ b/frameworks/core/components_ng/pattern/ui_extension/security_ui_extension_pattern.h @@ -63,7 +63,6 @@ public: int32_t GetNodeId(); int32_t GetInstanceId(); - void OnAreaChangedInner() override; void OnSyncGeometryNode(const DirtySwapConfig& config) override; void OnWindowShow() override; void OnWindowHide() override; 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 cbbe8aad2e9..ceb7985a47c 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 @@ -312,6 +312,7 @@ void SessionWrapperImpl::UpdateSessionConfig() void SessionWrapperImpl::DestroySession() { CHECK_NULL_VOID(session_); + UIEXT_LOGI("DestroySession, persistentid = %{public}d.", session_->GetPersistentId()); session_->UnregisterLifecycleListener(lifecycleListener_); session_ = nullptr; } @@ -442,6 +443,7 @@ void SessionWrapperImpl::NotifyForeground() auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto hostWindowId = pipeline->GetFocusWindowId(); + UIEXT_LOGI("NotifyForeground, persistentid = %{public}d.", session_->GetPersistentId()); Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionActivation( session_, hostWindowId, std::move(foregroundCallback_)); } @@ -449,12 +451,14 @@ void SessionWrapperImpl::NotifyForeground() void SessionWrapperImpl::NotifyBackground() { CHECK_NULL_VOID(session_); + UIEXT_LOGI("NotifyBackground, persistentid = %{public}d.", session_->GetPersistentId()); Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionBackground( session_, std::move(backgroundCallback_)); } void SessionWrapperImpl::NotifyDestroy() { CHECK_NULL_VOID(session_); + UIEXT_LOGI("NotifyDestroy, persistentid = %{public}d.", session_->GetPersistentId()); Rosen::ExtensionSessionManager::GetInstance().RequestExtensionSessionDestruction( session_, std::move(destructionCallback_)); } @@ -465,10 +469,16 @@ void SessionWrapperImpl::NotifyConfigurationUpdate() {} /************************************************ Begin: The interface for responsing provider ************************/ void SessionWrapperImpl::OnConnect() { + int32_t callSessionId = GetSessionId(); taskExecutor_->PostTask( - [weak = hostPattern_, wrapperWeak = WeakClaim(this)]() { + [weak = hostPattern_, wrapperWeak = WeakClaim(this), callSessionId]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); + if (callSessionId != pattern->GetSessionId()) { + TAG_LOGW(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "OnConnect: The callSessionId(%{public}d)" + " is inconsistent with the curSession(%{public}d)", + callSessionId, pattern->GetSessionId()); + } pattern->OnConnect(); auto wrapper = wrapperWeak.Upgrade(); CHECK_NULL_VOID(wrapper && wrapper->session_); @@ -492,7 +502,7 @@ void SessionWrapperImpl::OnDisconnect(bool isAbnormal) auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); if (callSessionId != pattern->GetSessionId()) { - LOGW("[AceUiExtensionComponent]OnDisconnect: The callSessionId(%{public}d)" + TAG_LOGW(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "OnDisconnect: The callSessionId(%{public}d)" " is inconsistent with the curSession(%{public}d)", callSessionId, pattern->GetSessionId()); return; @@ -514,10 +524,16 @@ void SessionWrapperImpl::OnDisconnect(bool isAbnormal) void SessionWrapperImpl::OnExtensionTimeout(int32_t /* errorCode */) { + int32_t callSessionId = GetSessionId(); taskExecutor_->PostTask( - [weak = hostPattern_]() { + [weak = hostPattern_, callSessionId]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); + if (callSessionId != pattern->GetSessionId()) { + TAG_LOGW(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "OnExtensionTimeout: The callSessionId(%{public}d)" + " is inconsistent with the curSession(%{public}d)", + callSessionId, pattern->GetSessionId()); + } pattern->FireOnErrorCallback( ERROR_CODE_UIEXTENSION_LIFECYCLE_TIMEOUT, LIFECYCLE_TIMEOUT_NAME, LIFECYCLE_TIMEOUT_MESSAGE); }, @@ -526,10 +542,16 @@ void SessionWrapperImpl::OnExtensionTimeout(int32_t /* errorCode */) void SessionWrapperImpl::OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, int64_t offset) { + int32_t callSessionId = GetSessionId(); taskExecutor_->PostTask( - [weak = hostPattern_, info, offset]() { + [weak = hostPattern_, info, offset, callSessionId]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); + if (callSessionId != pattern->GetSessionId()) { + TAG_LOGW(AceLogTag::ACE_UIEXTENSIONCOMPONENT, "OnAccessibilityEvent: The callSessionId(%{public}d)" + " is inconsistent with the curSession(%{public}d)", + callSessionId, pattern->GetSessionId()); + } pattern->OnAccessibilityEvent(info, offset); }, TaskExecutor::TaskType::UI, "ArkUIUIExtensionAccessibilityEvent"); @@ -632,8 +654,11 @@ bool SessionWrapperImpl::NotifyOccupiedAreaChangeInfo(sptrGetCurrentWindowRect(); + UIEXT_LOGD("keyboardHeight = %{public}d, CurWindow = %{public}s, displayArea_ = %{public}s.", + keyboardHeight, curWindow.ToString().c_str(), displayArea_.ToString().c_str()); if (curWindow.Bottom() >= displayArea_.Bottom()) { - keyboardHeight = keyboardHeight - (curWindow.Bottom() - displayArea_.Bottom()); + int32_t spaceWindow = std::max(curWindow.Bottom() - displayArea_.Bottom(), 0.0); + keyboardHeight = static_cast(std::max(keyboardHeight - spaceWindow, 0)); } else { keyboardHeight = keyboardHeight + (displayArea_.Bottom() - curWindow.Bottom()); } 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 1b9c27b58c6..95e3b09e19b 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 @@ -172,8 +172,8 @@ bool UIExtensionManager::NotifyOccupiedAreaChangeInfo(const sptr& rsTransaction) +void UIExtensionManager::NotifySizeChangeReason( + WindowSizeChangeReason type, const std::shared_ptr& rsTransaction) { for (const auto& it : aliveUIExtensions_) { auto uiExtension = it.second.Upgrade(); 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 b567453c4db..39accaa910a 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 @@ -144,7 +144,7 @@ void UIExtensionModelNG::Create(const UIExtensionConfig& config) void UIExtensionModelNG::CreateSecurityUIExtension(const UIExtensionConfig& config) { - LOGI("CreateSecurityUIExtension"); + LOGI("CreateSecurityUIExtension."); auto* stack = ViewStackProcessor::GetInstance(); auto nodeId = stack->ClaimNodeId(); auto frameNode = FrameNode::GetOrCreateFrameNode(V2::UI_EXTENSION_COMPONENT_ETS_TAG, nodeId, 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 ec1ea81bc1a..ac2cde158a2 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 @@ -46,6 +46,8 @@ public: const std::string& abcPath, const std::string& entryPoint, void* runtime) override; void InitializeIsolatedComponent(const RefPtr& frameNode, const RefPtr& wantWrap, void* runtime) override; + void SetPlatformOnError(std::function&& onError) override; void SetAdaptiveWidth(bool state) override; void SetAdaptiveHeight(bool state) override; @@ -61,8 +63,6 @@ public: void SetOnError( std::function&& onError, NG::SessionType sessionType = NG::SessionType::UI_EXTENSION_ABILITY) override; - void SetPlatformOnError(std::function&& onError) override; private: void CreateSecurityUIExtension(const UIExtensionConfig& config); 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 f95e0b6c597..47beb7a0a44 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 @@ -137,7 +137,6 @@ private: WeakPtr weakPattern_; }; } - UIExtensionPattern::UIExtensionPattern( bool isTransferringCaller, bool isModal, bool isAsyncModalBinding, SessionType sessionType) : isTransferringCaller_(isTransferringCaller), isModal_(isModal), @@ -149,7 +148,7 @@ UIExtensionPattern::UIExtensionPattern( CHECK_NULL_VOID(uiExtensionManager); uiExtensionId_ = uiExtensionManager->ApplyExtensionId(); sessionWrapper_ = SessionWrapperFactory::CreateSessionWrapper( - sessionType, WeakClaim(this), instanceId_, isTransferringCaller_); + sessionType, AceType::WeakClaim(this), instanceId_, isTransferringCaller_); accessibilitySessionAdapter_ = AceType::MakeRefPtr(sessionWrapper_); UIEXT_LOGI("The %{public}smodal UIExtension is created.", isModal_ ? "" : "non"); @@ -613,10 +612,16 @@ bool UIExtensionPattern::HandleKeyEvent(const KeyEvent& event) void UIExtensionPattern::HandleFocusEvent() { auto pipeline = PipelineContext::GetCurrentContext(); - if (pipeline->GetIsFocusActive()) { - DispatchFocusActiveEvent(true); + CHECK_NULL_VOID(pipeline); + if (canFocusSendToUIExtension_) { + if (pipeline->GetIsFocusActive()) { + DispatchFocusActiveEvent(true); + } + + DispatchFocusState(true); } - DispatchFocusState(true); + + canFocusSendToUIExtension_ = true; auto uiExtensionManager = pipeline->GetUIExtensionManager(); uiExtensionManager->RegisterUIExtensionInFocus(WeakClaim(this), sessionWrapper_); } @@ -662,10 +667,20 @@ void UIExtensionPattern::HandleTouchEvent(const TouchEventInfo& info) AceExtraInputData::InsertInterpolatePoints(info); auto focusHub = host->GetFocusHub(); CHECK_NULL_VOID(focusHub); - if (pipeline->IsWindowFocused()) { - focusHub->RequestFocusImmediately(); + bool ret = true; + if (pipeline->IsWindowFocused() && !focusHub->IsCurrentFocus()) { + canFocusSendToUIExtension_ = false; + ret = focusHub->RequestFocusImmediately(); + if (!ret) { + canFocusSendToUIExtension_ = true; + UIEXT_LOGW("RequestFocusImmediately failed when HandleTouchEvent."); + } } DispatchPointerEvent(pointerEvent); + if (pipeline->IsWindowFocused() && ret && + pointerEvent->GetPointerAction() == MMI::PointerEvent::POINTER_ACTION_UP) { + HandleFocusEvent(); + } } void UIExtensionPattern::HandleMouseEvent(const MouseInfo& info) @@ -873,7 +888,7 @@ void UIExtensionPattern::SetOnResultCallback(const std::function&& callback); - virtual void FireOnErrorCallback(int32_t code, const std::string& name, const std::string& message); + void FireOnErrorCallback(int32_t code, const std::string& name, const std::string& message); void SetSyncCallbacks(const std::list&)>>&& callbackList); void FireSyncCallbacks(); void SetAsyncCallbacks(const std::list&)>>&& callbackList); @@ -167,7 +167,6 @@ protected: int32_t uiExtensionId_ = 0; int32_t instanceId_ = Container::CurrentId(); - std::function onErrorCallback_; private: enum class AbilityState { @@ -190,7 +189,6 @@ private: void OnColorConfigurationUpdate() override; void OnModifyDone() override; bool CheckConstraint(); - void LogoutModalUIExtension(); void InitKeyEvent(const RefPtr& focusHub); void InitTouchEvent(const RefPtr& gestureHub); @@ -207,6 +205,7 @@ private: void DispatchFocusActiveEvent(bool isFocusActive); void DispatchFocusState(bool focusState); void DispatchDisplayArea(bool isForce = false); + void LogoutModalUIExtension(); void RegisterVisibleAreaChange(); void MountPlaceholderNode(); @@ -226,6 +225,7 @@ private: std::function onResultCallback_; std::function&)> onTerminatedCallback_; std::function onReceiveCallback_; + std::function onErrorCallback_; std::list&)>> onSyncOnCallbackList_; std::list&)>> onAsyncOnCallbackList_; std::function bindModalCallback_; @@ -243,6 +243,9 @@ private: bool isAsyncModalBinding_ = false; bool isShowPlaceholder_ = false; bool densityDpi_ = false; + // Whether to send the focus to the UIExtension + // No multi-threading problem due to run js thread + bool canFocusSendToUIExtension_ = true; int32_t callbackId_ = 0; RectF displayArea_; bool isKeyAsync_ = false; diff --git a/test/mock/adapter/mock_modal_ui_extension.cpp b/test/mock/adapter/mock_modal_ui_extension.cpp index 7c40af40c0e..095739db008 100644 --- a/test/mock/adapter/mock_modal_ui_extension.cpp +++ b/test/mock/adapter/mock_modal_ui_extension.cpp @@ -28,8 +28,8 @@ int32_t ModalUIExtension::GetSessionId(const RefPtr& /* uiExtNode return 0; } -void ModalUIExtension::SetBindModalCallback(const RefPtr& uiExtNode, - std::function&& bindModalCallback) +void ModalUIExtension::SetBindModalCallback( + const RefPtr& uiExtNode, std::function&& bindModalCallback) { } } // namespace OHOS::Ace 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 13929b41bc7..a728a48445d 100644 --- a/test/mock/core/pattern/mock_ui_extension_model_ng.cpp +++ b/test/mock/core/pattern/mock_ui_extension_model_ng.cpp @@ -53,4 +53,8 @@ void UIExtensionModelNG::SetOnRemoteReady(std::function&& onError) {} + +void UIExtensionModelNG::SetPlatformOnError( + std::function&& onError) +{} } // namespace OHOS::Ace::NG