diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index 04bbe2a29f5a938666c9cd7f96de3e31d844fc15..fe6f907a52dd5f25b9bbfeec6332ab1f5f760c6f 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 ad4fe89fddc5e8a067e9860f1860e5ef14972219..28dce66a19f1310b58f397aacce851387da05bb1 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 4490a5d876cda8fb86073e54a90c23a43f3edbcd..3754ef7d6c9dc5eeb6e4887d916218132f343fa7 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 f64806f708122386b3dca164c0446faea94e29c5..26e44d4070d560129089c2dca3e8f0a4e1594083 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 0000000000000000000000000000000000000000..f0a201b3518eb90ed8aa66b2dc6b00ab3dd42d80 --- /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 c66167646e8668be58037395a81d8880ddacf551..dae2467124717b68575fa0e871a999325f2f60aa 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 15a8b1489d2a1ae18c44283d60fdf759841fd614..7e9893f7de556fb6656d4e436e720b49b006a19e 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 0000000000000000000000000000000000000000..b2902e1187137181aa490ff6b5897459f3f76792 --- /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 0000000000000000000000000000000000000000..146784bc26e7abcde63c164ef5cc85334aab1369 --- /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 7102c7cf555a7ac4428f9a04409a8ecbce7c58ff..0dc1efa5de447923836191582ea76d168d043892 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 27094572277a1fa4304799c4822d9da0301f6e1d..8fbaaa4e3eaf24948f783a35b6a89aa5bc09c170 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",