From ecba674c4dcb3924d4a96d029d705a89d7830f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B0=B8=E5=87=AF?= Date: Thu, 14 Aug 2025 16:04:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BA=A7=E5=93=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=BC=A0=E6=A0=87=E8=BD=AC=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘永凯 --- .gitee/CODEOWNERS | 2 + adapter/ohos/entrance/ace_container.cpp | 8 + adapter/ohos/entrance/ace_view_ohos.cpp | 18 ++- adapter/ohos/osal/BUILD.gn | 1 + .../ohos/osal/input_compatible_manager.cpp | 138 ++++++++++++++++++ adapter/ohos/osal/system_properties.cpp | 12 ++ frameworks/base/utils/system_properties.h | 3 + .../transform/input_compatible_manager.h | 46 ++++++ .../ui/event/input_compatible_policy.h | 32 ++++ test/mock/base/mock_system_properties.cpp | 15 ++ .../core/pattern/window_scene/BUILD.gn | 1 + 11 files changed, 273 insertions(+), 3 deletions(-) create mode 100644 adapter/ohos/osal/input_compatible_manager.cpp create mode 100644 frameworks/core/common/transform/input_compatible_manager.h create mode 100644 interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index 04bbe2a29f5..fe6f907a52d 100644 --- a/.gitee/CODEOWNERS +++ b/.gitee/CODEOWNERS @@ -144,6 +144,7 @@ adapter/ohos/osal/image_packer_ohos.h @arkui_image adapter/ohos/osal/image_source_ohos.cpp @arkui_image adapter/ohos/osal/image_source_ohos.h @arkui_image adapter/ohos/osal/input_manager.cpp @arkuievent +adapter/ohos/osal/input_compatible_manager.cpp @arkuievent adapter/ohos/osal/input_method_manager_ohos.cpp @huawei_g_five adapter/ohos/osal/js_accessibility_manager.cpp @arkuiabilitygroup adapter/ohos/osal/js_accessibility_manager.h @arkuiabilitygroup @@ -1937,6 +1938,7 @@ frameworks/core/common/thread_container.cpp @arkuiframework frameworks/core/common/thread_container.h @arkuiframework frameworks/core/common/thread_model_impl.cpp @arkuiframework frameworks/core/common/thread_model_impl.h @arkuiframework +frameworks/core/common/transform/input_compatible_manager.h @arkuievent frameworks/core/common/udmf/ @arkuievent frameworks/core/common/update_config_manager.h @arkuiframework frameworks/core/common/vibrator/ @arkuiscroll diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index ad4fe89fddc..28dce66a19f 100644 --- a/adapter/ohos/entrance/ace_container.cpp +++ b/adapter/ohos/entrance/ace_container.cpp @@ -61,6 +61,7 @@ #include "core/common/resource/resource_wrapper.h" #include "core/common/task_executor_impl.h" #include "core/common/text_field_manager.h" +#include "core/common/transform/input_compatible_manager.h" #include "core/components_ng/base/inspector.h" #include "core/components_ng/image_provider/image_decoder.h" #include "core/components_ng/pattern/text_field/text_field_manager.h" @@ -2817,6 +2818,13 @@ void AceContainer::AttachView(std::shared_ptr window, const RefPtrPostTask( + [] { InputCompatibleManager::Load(); }, TaskExecutor::TaskType::UI, "ArkUITransformInit"); + } + // Load custom style at UI thread before frontend attach, for loading style before building tree. auto initThemeManagerTask = [pipelineContext = pipelineContext_, assetManager = assetManager_, colorScheme = colorScheme_, resourceInfo = resourceInfo_, diff --git a/adapter/ohos/entrance/ace_view_ohos.cpp b/adapter/ohos/entrance/ace_view_ohos.cpp index 4490a5d876c..3754ef7d6c9 100644 --- a/adapter/ohos/entrance/ace_view_ohos.cpp +++ b/adapter/ohos/entrance/ace_view_ohos.cpp @@ -18,6 +18,7 @@ #include "adapter/ohos/entrance/ace_container.h" #include "adapter/ohos/entrance/mmi_event_convertor.h" #include "base/log/dump_log.h" +#include "core/common/transform/input_compatible_manager.h" #include "core/event/event_info_convertor.h" namespace OHOS::Ace::Platform { @@ -414,7 +415,13 @@ void AceViewOhos::ProcessMouseEvent(const std::shared_ptr& po markEnabled); }; - if (NG::EventInfoConvertor::IfNeedMouseTransform() && + auto manager = InputCompatibleManager::Load(); + if (manager && manager->IfNeedInputCompatibleTransform()) { + if (ProcessMouseEventWithTouch(pointerEvent, event, node, markProcess)) { + return; + } + } + if (!manager && NG::EventInfoConvertor::IfNeedMouseTransform() && ProcessMouseEventWithTouch(pointerEvent, event, node, markProcess)) { return; } @@ -449,12 +456,17 @@ bool AceViewOhos::ProcessMouseEventWithTouch(const std::shared_ptr& pointerEvent, const RefPtr& node, bool isInjected) { - if (NG::EventInfoConvertor::IfNeedMouseTransform()) { + auto manager = InputCompatibleManager::Load(); + if (manager && manager->IfNeedInputCompatibleTransform()) { + if (ProcessAxisEventWithTouch(pointerEvent, node, isInjected)) { + return; + } + } + if (!manager && NG::EventInfoConvertor::IfNeedMouseTransform()) { if (ProcessAxisEventWithTouch(pointerEvent, node, isInjected)) { return; } } - CHECK_NULL_VOID(axisEventCallback_); AxisEvent event; event.isInjected = isInjected; diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index f64806f7081..26e44d4070d 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -77,6 +77,7 @@ template("ace_osal_ohos_source_set") { "image_analyzer_manager.cpp", "image_analyzer_mgr.cpp", "image_perf_ohos.cpp", + "input_compatible_manager.cpp", "input_method_manager_ohos.cpp", "layout_inspector.cpp", "log_wrapper.cpp", diff --git a/adapter/ohos/osal/input_compatible_manager.cpp b/adapter/ohos/osal/input_compatible_manager.cpp new file mode 100644 index 00000000000..f0a201b3518 --- /dev/null +++ b/adapter/ohos/osal/input_compatible_manager.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/common/transform/input_compatible_manager.h" + +#include + +#include "base/log/log.h" +#include "base/utils/time_util.h" + +namespace OHOS::Ace { +namespace { +#if (defined(__aarch64__) || defined(__x86_64__)) +const std::string TRANSFORM_SO_PATH = "/system/lib64/libtransform_interaction_ext.z.so"; +#else +const std::string TRANSFORM_SO_PATH = "/system/lib/libtransform_interaction_ext.z.so"; +#endif +constexpr int64_t LOG_DURATION = 5000; +constexpr int64_t TRANSLATE_NS_TO_MS = 1000000; +} // namespace + +std::shared_ptr InputCompatibleManager::Load() +{ + static std::shared_ptr instance = nullptr; + if (!instance) { + instance = std::make_shared(); + if (!instance->Init()) { + instance = nullptr; + return nullptr; + } + } + return instance; +} + +InputCompatibleManager::~InputCompatibleManager() +{ + Close(); +} + +bool InputCompatibleManager::Init() +{ + if (transformSoLoaded_ && libraryHandle_ != nullptr && createInputCompatibleInstance_ != nullptr && + destroyInputCompatibleInstance_ != nullptr) { + return true; + } + libraryHandle_ = dlopen(TRANSFORM_SO_PATH.c_str(), RTLD_LAZY); + if (libraryHandle_ == nullptr) { + const char* error = dlerror(); + TAG_LOGE(AceLogTag::ACE_UIEVENT, "AceTransform load failed: %{public}s", error); + return false; + } + createInputCompatibleInstance_ = + (Kit::InputCompatiblePolicy* (*)()) dlsym(libraryHandle_, "CreateInputCompatibleInstance"); + destroyInputCompatibleInstance_ = + (void (*)(Kit::InputCompatiblePolicy*))dlsym(libraryHandle_, "DestroyInputCompatibleInstance"); + if (createInputCompatibleInstance_ == nullptr || destroyInputCompatibleInstance_ == nullptr) { + TAG_LOGE(AceLogTag::ACE_UIEVENT, "CreateInputCompatibleInstance function load failed"); + Close(); + return false; + } + transformSoLoaded_ = true; + return true; +} + +void InputCompatibleManager::Close() +{ + if (libraryHandle_ != nullptr) { + dlclose(libraryHandle_); + } + transformSoLoaded_ = false; + createInputCompatibleInstance_ = nullptr; + destroyInputCompatibleInstance_ = nullptr; +} + +InputCompatibleInstance InputCompatibleManager::CreateTransformInstance() +{ + if (!transformSoLoaded_ || !createInputCompatibleInstance_ || !destroyInputCompatibleInstance_) { + return nullptr; + } + return { createInputCompatibleInstance_(), [lib = shared_from_this(), destroy = destroyInputCompatibleInstance_]( + Kit::InputCompatiblePolicy* e) { destroy(e); } }; +} + +bool InputCompatibleManager::IfNeedInputCompatibleTransform() +{ + static bool result = false; + static bool init = false; + static bool transfromEnable = SystemProperties::GetTransformEnabled(); + static bool mouseTransEnabled = SystemProperties::GetCompatibleInputTransEnabled(); + static int64_t lastLogTimeStamp = GetSysTimestamp(); + + if (init) { + auto currentTime = GetSysTimestamp(); + if ((currentTime - lastLogTimeStamp) >= LOG_DURATION * TRANSLATE_NS_TO_MS) { + TAG_LOGI(AceLogTag::ACE_INPUTTRACKING, + "IfNeedMouseTransform get result successfully \n " + "transformEnable is %{public}d, mousetransEnable is %{public}d \n" + "result is %{public}d.", + transfromEnable, mouseTransEnabled, result); + lastLogTimeStamp = currentTime; + } + return result; + } + + if (!transfromEnable || !mouseTransEnabled) { + result = false; + init = true; + AceApplicationInfo::GetInstance().SetMouseTransformEnable(result); + return result; + } + + InputCompatibleInstance instance = CreateTransformInstance(); + + if (!instance) { + result = false; + init = true; + AceApplicationInfo::GetInstance().SetMouseTransformEnable(result); + return result; + } + result = instance->LoadRawEventCompatibleConvertingProtocol(); + init = true; + AceApplicationInfo::GetInstance().SetMouseTransformEnable(result); + return result; +} + +} // namespace OHOS::Ace diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index c66167646e8..dae24671247 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -266,6 +266,11 @@ bool IsMouseTransformEnable() return (system::GetParameter("persist.ace.event.transform.enable", "1") == "1"); } +bool IsCompatibleInputTransEnabled() +{ + return (system::GetParameter("persist.ace.event.compatible.enable", "0") == "1"); +} + float ReadScrollCoefficients() { auto ret = system::GetParameter("persist.ace.scroll.coefficeient", "2.0"); @@ -698,6 +703,7 @@ ACE_WEAK_SYM bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationE ACE_WEAK_SYM bool SystemProperties::debugEnabled_ = IsDebugEnabled(); std::string SystemProperties::configDeviceType_ = ""; ACE_WEAK_SYM bool SystemProperties::transformEnabled_ = IsMouseTransformEnable(); +ACE_WEAK_SYM bool SystemProperties::compatibleInputTransEnabled_ = IsCompatibleInputTransEnabled(); float SystemProperties::scrollCoefficients_ = ReadScrollCoefficients(); ACE_WEAK_SYM DebugFlags SystemProperties::debugFlags_ = GetDebugFlags(); ACE_WEAK_SYM bool SystemProperties::containerDeleteFlag_ = IsContainerDeleteFlag(); @@ -876,6 +882,7 @@ void SystemProperties::InitDeviceInfo( needAvoidWindow_ = system::GetBoolParameter(PROPERTY_NEED_AVOID_WINDOW, false); debugEnabled_ = IsDebugEnabled(); transformEnabled_ = IsMouseTransformEnable(); + compatibleInputTransEnabled_ = IsCompatibleInputTransEnabled(); debugFlags_ = GetDebugFlags(); layoutDetectEnabled_ = IsLayoutDetectEnabled(); multiInstanceEnabled_ = IsMultiInstanceEnabled(); @@ -1356,6 +1363,11 @@ ACE_WEAK_SYM bool SystemProperties::GetTransformEnabled() return transformEnabled_; } +ACE_WEAK_SYM bool SystemProperties::GetCompatibleInputTransEnabled() +{ + return compatibleInputTransEnabled_; +} + bool SystemProperties::GetWebDebugMaximizeResizeOptimize() { return system::GetBoolParameter("web.debug.maximize_resize_optimize", true); diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index 15a8b1489d2..7e9893f7de5 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -562,6 +562,8 @@ public: static bool GetTransformEnabled(); + static bool GetCompatibleInputTransEnabled(); + static void InitMccMnc(int32_t mcc, int32_t mnc); static ScreenShape GetScreenShape() @@ -865,6 +867,7 @@ private: static bool debugEnabled_; static std::string configDeviceType_; static bool transformEnabled_; + static bool compatibleInputTransEnabled_; static float scrollCoefficients_; static DebugFlags debugFlags_; static bool containerDeleteFlag_; diff --git a/frameworks/core/common/transform/input_compatible_manager.h b/frameworks/core/common/transform/input_compatible_manager.h new file mode 100644 index 00000000000..b2902e11871 --- /dev/null +++ b/frameworks/core/common/transform/input_compatible_manager.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_INPUT_COMPATIBLE_MANAGER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_INPUT_COMPATIBLE_MANAGER_H + +#include "interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h" + +#include "adapter/ohos/entrance/ace_application_info.h" +#include "base/utils/noncopyable.h" + +namespace OHOS::Ace { +using InputCompatibleInstance = + std::unique_ptr>; + +class InputCompatibleManager final : public std::enable_shared_from_this, public NonCopyable { +public: + static std::shared_ptr Load(); + InputCompatibleManager() = default; + virtual ~InputCompatibleManager(); + InputCompatibleInstance CreateTransformInstance(); + bool IfNeedInputCompatibleTransform(); + +private: + bool Init(); + void Close(); + + void* libraryHandle_ = nullptr; + bool transformSoLoaded_ = false; + Kit::InputCompatiblePolicy* (*createInputCompatibleInstance_)() = nullptr; + void (*destroyInputCompatibleInstance_)(Kit::InputCompatiblePolicy*) = nullptr; +}; +} // namespace OHOS::Ace +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_INPUT_COMPATIBLE_MANAGER_H diff --git a/interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h b/interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h new file mode 100644 index 00000000000..146784bc26e --- /dev/null +++ b/interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_EVENT_INPUT_COMPATIBLE_POLICY_H +#define FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_EVENT_INPUT_COMPATIBLE_POLICY_H +#include +#include +#include + +#include "base/utils/macros.h" + +namespace OHOS::Ace::Kit { + +class ACE_EXPORT InputCompatiblePolicy { +public: + virtual bool LoadRawEventCompatibleConvertingProtocol() = 0; + virtual ~InputCompatiblePolicy() {} +}; +} // namespace OHOS::Ace::Kit +#endif // FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_BASE_EVENT_INPUT_COMPATIBLE_POLICY_H \ No newline at end of file diff --git a/test/mock/base/mock_system_properties.cpp b/test/mock/base/mock_system_properties.cpp index 7102c7cf555..0dc1efa5de4 100644 --- a/test/mock/base/mock_system_properties.cpp +++ b/test/mock/base/mock_system_properties.cpp @@ -388,4 +388,19 @@ std::string SystemProperties::GetMapSearchPrefix() { return ""; } + +bool SystemProperties::GetCompatibleInputTransEnabled() +{ + return false; +} + +float SystemProperties::GetScrollCoefficients() +{ + return 3.0f; +} + +bool SystemProperties::GetTransformEnabled() +{ + return false; +} } // namespace OHOS::Ace diff --git a/test/unittest/core/pattern/window_scene/BUILD.gn b/test/unittest/core/pattern/window_scene/BUILD.gn index 27094572277..8fbaaa4e3ea 100644 --- a/test/unittest/core/pattern/window_scene/BUILD.gn +++ b/test/unittest/core/pattern/window_scene/BUILD.gn @@ -27,6 +27,7 @@ ace_unittest("window_scene_test") { "$ace_root/test/unittest/core/pattern/window_scene/mock/mock_rosen_render_context.cpp", # self + "$ace_root/adapter/ohos/osal/input_compatible_manager.cpp", "$ace_root/frameworks/core/components_ng/pattern/window_scene/helper/starting_window_layout_helper.cpp", "$ace_root/frameworks/core/components_ng/pattern/window_scene/helper/window_scene_helper.cpp", "$ace_root/frameworks/core/components_ng/pattern/window_scene/scene/input_scene.cpp", -- Gitee