diff --git a/.gitee/CODEOWNERS b/.gitee/CODEOWNERS index 48a048c10a195f1ec2bcbbd52ebefd7527680710..0397b121316d6f9374fdafbe37c9e64ebb4df12a 100644 --- a/.gitee/CODEOWNERS +++ b/.gitee/CODEOWNERS @@ -114,6 +114,7 @@ adapter/ohos/osal/background_task_helper_ohos.cpp @arkuiframework adapter/ohos/osal/background_task_helper_ohos.h @arkuiframework adapter/ohos/osal/BUILD.gn @arkui_architecture adapter/ohos/osal/clipboard_impl.cpp @huawei_g_five +adapter/ohos/osal/input_compatible_manager.cpp @arkuievent adapter/ohos/osal/text_translation_adapter.cpp @huawei_g_five adapter/ohos/osal/text_translation_loader.cpp @huawei_g_five adapter/ohos/osal/text_translation_mgr.cpp @huawei_g_five @@ -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 @@ -3225,6 +3227,7 @@ test/unittest/core/common/sharedata/ @arkuiframework test/unittest/core/common/storage/ @arkuistatemgmt test/unittest/core/common/task/ @arkuiframework test/unittest/core/common/vibrator/ @arkuiframework +test/unittest/core/common/transform/ @arkuievent test/unittest/core/event/ @arkuievent test/unittest/core/gestures/ @arkuievent test/unittest/core/image_file_cache/ @arkui_image diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index 849c396b7ce371892e7663b813cc393d31989afc..22632ba7349862994399adcbb50d9d1775276e6e 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::GetInstance().LoadProductCompatiblePolicy(); }, + 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..2dda95c7e3105d89f4210a376b6fe313cc9764e9 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,8 @@ void AceViewOhos::ProcessMouseEvent(const std::shared_ptr& po markEnabled); }; - if (NG::EventInfoConvertor::IfNeedMouseTransform() && + if (InputCompatibleManager::GetInstance().IsCompatibleConvertingEnabledFor( + Kit::InputCompatibleSource::LEFT_PRESS) && ProcessMouseEventWithTouch(pointerEvent, event, node, markProcess)) { return; } @@ -449,12 +451,12 @@ bool AceViewOhos::ProcessMouseEventWithTouch(const std::shared_ptr& pointerEvent, const RefPtr& node, bool isInjected) { - if (NG::EventInfoConvertor::IfNeedMouseTransform()) { + if (InputCompatibleManager::GetInstance().IsCompatibleConvertingEnabledFor( + Kit::InputCompatibleSource::SCROLL_AXIS_EVENT)) { 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..b9075815102007a17af906356c02f29ae3d02e97 --- /dev/null +++ b/adapter/ohos/osal/input_compatible_manager.cpp @@ -0,0 +1,123 @@ +/* + * 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" +#include "frameworks/core/common/ace_application_info.h" +#include "frameworks/core/event/event_info_convertor.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 + +InputCompatibleManager& InputCompatibleManager::GetInstance() +{ + static InputCompatibleManager instance; + return instance; +} + +InputCompatibleManager::~InputCompatibleManager() +{ + UnloadProductCompatiblePolicy(); +} + +void InputCompatibleManager::LoadProductCompatiblePolicy() +{ + if (transformSoLoaded_ && libraryHandle_ != nullptr && productPolicy_ != nullptr) { + return; + } + 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; + } + auto getInputCompatiblePolicyInstance = + (Kit::InputCompatiblePolicy* (*)()) dlsym(libraryHandle_, "GetInputCompatiblePolicyInstance"); + if (getInputCompatiblePolicyInstance == nullptr) { + const char* error = dlerror(); + TAG_LOGE(AceLogTag::ACE_UIEVENT, "AceTransform load failed: %{public}s", error); + Close(); + return; + } + productPolicy_ = getInputCompatiblePolicyInstance(); + transformSoLoaded_ = true; + Close(); + return; +} + +void InputCompatibleManager::UnloadProductCompatiblePolicy() +{ + Close(); + libraryHandle_ = nullptr; + productPolicy_ = nullptr; + transformSoLoaded_ = false; +} + +void InputCompatibleManager::Close() +{ + if (libraryHandle_ != nullptr) { + dlclose(libraryHandle_); + } +} + +bool InputCompatibleManager::IsCompatibleConvertingEnabledFor(Kit::InputCompatibleSource source) +{ + static std::unordered_map convertingEnabledResult; + static bool transformEnable = SystemProperties::GetTransformEnabled(); + static bool mouseTransEnabled = SystemProperties::GetCompatibleInputTransEnabled(); + static int64_t lastLogTimeStamp = GetSysTimestamp(); + + if (convertingEnabledResult.find(source) != convertingEnabledResult.end()) { + auto currentTime = GetSysTimestamp(); + if ((currentTime - lastLogTimeStamp) >= LOG_DURATION * TRANSLATE_NS_TO_MS) { + TAG_LOGI(AceLogTag::ACE_UIEVENT, + "IsCompatibleConvertingEnabledFor get result successfully \n " + "transformEnable is %{public}d, mousetransEnable is %{public}d \n" + "result is %{public}d.", + transformEnable, mouseTransEnabled, convertingEnabledResult[source]); + lastLogTimeStamp = currentTime; + } + return convertingEnabledResult[source]; + } + + if (!transformEnable || !mouseTransEnabled) { + convertingEnabledResult[source] = false; + AceApplicationInfo::GetInstance().SetMouseTransformEnable(convertingEnabledResult[source]); + return convertingEnabledResult[source]; + } + if (productPolicy_) { + TAG_LOGD(AceLogTag::ACE_UIEVENT, "Load So successfully"); + convertingEnabledResult[source] = productPolicy_->IsInputCompatibleConvertingNeeded(source); + AceApplicationInfo::GetInstance().SetMouseTransformEnable(convertingEnabledResult[source]); + return convertingEnabledResult[source]; + } + + convertingEnabledResult[source] = NG::EventInfoConvertor::IfNeedMouseTransform(); + AceApplicationInfo::GetInstance().SetMouseTransformEnable(convertingEnabledResult[source]); + return convertingEnabledResult[source]; +} +} // namespace OHOS::Ace diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 708ad528ca83125e7db8c09ed5a90018427cf573..20fcc0ffc98dace04b6a1e014745e0a7cc751afa 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"); @@ -703,6 +708,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(); @@ -882,6 +888,7 @@ void SystemProperties::InitDeviceInfo( needAvoidWindow_ = system::GetBoolParameter(PROPERTY_NEED_AVOID_WINDOW, false); debugEnabled_ = IsDebugEnabled(); transformEnabled_ = IsMouseTransformEnable(); + compatibleInputTransEnabled_ = IsCompatibleInputTransEnabled(); debugFlags_ = GetDebugFlags(); layoutDetectEnabled_ = IsLayoutDetectEnabled(); multiInstanceEnabled_ = IsMultiInstanceEnabled(); @@ -1362,6 +1369,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 2405a5bf22e75bfa9cd0d89d5545b74801bdb68b..d61324f153424142a3bcbfade9aff4f66f6e9149 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() @@ -870,6 +872,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..cdb2ac7d6a8d52e359dbb17ca4fe374b238ba5dd --- /dev/null +++ b/frameworks/core/common/transform/input_compatible_manager.h @@ -0,0 +1,40 @@ +/* + * 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 "ui/event/input_compatible_policy.h" +#include "base/utils/noncopyable.h" + +namespace OHOS::Ace { +class InputCompatibleManager final : public std::enable_shared_from_this, + public NonCopyable, + public AceType { +public: + static InputCompatibleManager& GetInstance(); + void LoadProductCompatiblePolicy(); + void UnloadProductCompatiblePolicy(); + virtual ~InputCompatibleManager(); + bool IsCompatibleConvertingEnabledFor(Kit::InputCompatibleSource source); + +private: + void Close(); + Kit::InputCompatiblePolicy* productPolicy_ = nullptr; + void* libraryHandle_ = nullptr; + bool transformSoLoaded_ = false; +}; +} // 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..563450940080feda7b31694957819729f2830970 --- /dev/null +++ b/interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h @@ -0,0 +1,38 @@ +/* + * 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 "ui/base/ace_type.h" +#include "ui/base/macros.h" + +namespace OHOS::Ace::Kit { +enum class InputCompatibleSource : int8_t { + LEFT_PRESS, + SCROLL_AXIS_EVENT, +}; + +class ACE_EXPORT InputCompatiblePolicy : public AceType { +public: + static InputCompatiblePolicy* GetInputCompatiblePolicyInstance(); + virtual bool IsInputCompatibleConvertingNeeded(InputCompatibleSource source) = 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 67226059db059561985b6637f6604b8fc2553cdd..a9b9404b46823b8ca50b2f21973606635f383ae1 100644 --- a/test/mock/base/mock_system_properties.cpp +++ b/test/mock/base/mock_system_properties.cpp @@ -22,6 +22,8 @@ namespace OHOS::Ace { namespace MockSystemProperties { bool g_isSuperFoldDisplayDevice = false; +bool g_isCompatibleInputTransEnabled = false; +bool g_isTransformEnabled = false; } namespace { constexpr int32_t ORIENTATION_PORTRAIT = 0; @@ -389,4 +391,19 @@ std::string SystemProperties::GetMapSearchPrefix() { return ""; } + +bool SystemProperties::GetCompatibleInputTransEnabled() +{ + return MockSystemProperties::g_isTransformEnabled; +} + +float SystemProperties::GetScrollCoefficients() +{ + return 3.0f; +} + +bool SystemProperties::GetTransformEnabled() +{ + return MockSystemProperties::g_isCompatibleInputTransEnabled; +} } // namespace OHOS::Ace diff --git a/test/mock/base/mock_system_properties.h b/test/mock/base/mock_system_properties.h index 1de7d7f45602503eb947b8d301f837b180758723..d7537a044098c65b9f75cfb872aaa446263b5b47 100644 --- a/test/mock/base/mock_system_properties.h +++ b/test/mock/base/mock_system_properties.h @@ -18,6 +18,8 @@ namespace OHOS::Ace { namespace MockSystemProperties { extern bool g_isSuperFoldDisplayDevice; +extern bool g_isCompatibleInputTransEnabled; +extern bool g_isTransformEnabled; } // unit test globals extern bool g_segmentedWaterflow; diff --git a/test/unittest/core/common/BUILD.gn b/test/unittest/core/common/BUILD.gn index 2aa26494eee86f5a3b4bd1ce0dde55651c0e5560..ae956c02a249b7ac57bdf386ba7ea7230ceaa0cc 100644 --- a/test/unittest/core/common/BUILD.gn +++ b/test/unittest/core/common/BUILD.gn @@ -18,6 +18,7 @@ ace_unittest("common_test") { module_output = "common" sources = [ "$ace_root/adapter/ohos/entrance/file_asset_provider_impl.cpp", + "$ace_root/adapter/ohos/osal/input_compatible_manager.cpp", "$ace_root/frameworks/core/common/asset_manager_impl.cpp", "$ace_root/frameworks/core/common/environment/environment_proxy.cpp", "$ace_root/frameworks/core/common/rosen/rosen_asset_manager.cpp", @@ -36,6 +37,7 @@ ace_unittest("common_test") { "rosen/rosen_test.cpp", "sharedata/sharedata_test.cpp", "storage/storage_test.cpp", + "transform/input_compatible_manager_test_ng.cpp", "vibrator/vibrator_test.cpp", ] } diff --git a/test/unittest/core/common/transform/input_compatible_manager_test_ng.cpp b/test/unittest/core/common/transform/input_compatible_manager_test_ng.cpp new file mode 100644 index 0000000000000000000000000000000000000000..75900bb383a9cd6a7ab7c66bf2f0297d1ca9bf6f --- /dev/null +++ b/test/unittest/core/common/transform/input_compatible_manager_test_ng.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2025 iSoftStone Information Technology (Group) 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 "gmock/gmock.h" +#include "gtest/gtest.h" +#define private public +#define protected public +#include "interfaces/inner_api/ace_kit/include/ui/event/input_compatible_policy.h" +#include "test/mock/base/mock_system_properties.h" + +#include "frameworks/core/common/transform/input_compatible_manager.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Ace { +class MockInputCompatiblePolicy : public Kit::InputCompatiblePolicy { +public: + MOCK_METHOD1(IsInputCompatibleConvertingNeeded, bool(Kit::InputCompatibleSource source)); + static MockInputCompatiblePolicy* GetInputCompatiblePolicyInstance() + { + static MockInputCompatiblePolicy instance; + return &instance; + } +}; + +extern "C" { +void* dlopen(const char* filename, int flag) +{ + return reinterpret_cast(1); +} + +void* dlsym(void* handle, const char* symbol) +{ + return reinterpret_cast(MockInputCompatiblePolicy::GetInputCompatiblePolicyInstance); +} +} + +class InputCompatibleManagerTest : public testing::Test { +public: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + void SetUp() + { + OHOS::Ace::InputCompatibleManager::GetInstance().UnloadProductCompatiblePolicy(); + MockSystemProperties::g_isCompatibleInputTransEnabled = false; + MockSystemProperties::g_isTransformEnabled = false; + } + void TearDown() {} +}; + +/** + * @tc.name: InputCompatibleManagerTest001 + * @tc.desc: Test LoadProductCompatiblePolicy function. + * @tc.type: FUNC + */ +HWTEST_F(InputCompatibleManagerTest, LoadProductCompatiblePolicy001, TestSize.Level1) +{ + OHOS::Ace::InputCompatibleManager& manager = OHOS::Ace::InputCompatibleManager::GetInstance(); + manager.LoadProductCompatiblePolicy(); + EXPECT_NE(manager.productPolicy_, nullptr); + EXPECT_TRUE(manager.transformSoLoaded_); + + manager.libraryHandle_ = nullptr; + manager.LoadProductCompatiblePolicy(); + EXPECT_NE(manager.libraryHandle_, nullptr); + + manager.productPolicy_ = nullptr; + manager.LoadProductCompatiblePolicy(); + EXPECT_NE(manager.productPolicy_, nullptr); +} + +/** + * @tc.name: InputCompatibleManagerTest002 + * @tc.desc: Test UnloadProductCompatiblePolicy function. + * @tc.type: FUNC + */ +HWTEST_F(InputCompatibleManagerTest, UnloadProductCompatiblePolicy001, TestSize.Level1) +{ + OHOS::Ace::InputCompatibleManager& manager = OHOS::Ace::InputCompatibleManager::GetInstance(); + manager.LoadProductCompatiblePolicy(); + EXPECT_NE(manager.productPolicy_, nullptr); + EXPECT_TRUE(manager.transformSoLoaded_); + + manager.UnloadProductCompatiblePolicy(); + EXPECT_EQ(manager.productPolicy_, nullptr); + EXPECT_FALSE(manager.transformSoLoaded_); +} + +/** + * @tc.name: InputCompatibleManagerTest003 + * @tc.desc: Test IsCompatibleConvertingEnabledFor function. + * @tc.type: FUNC + */ +HWTEST_F(InputCompatibleManagerTest, IsCompatibleConvertingEnabledFor001, TestSize.Level1) +{ + OHOS::Ace::InputCompatibleManager& manager = OHOS::Ace::InputCompatibleManager::GetInstance(); + MockInputCompatiblePolicy* instance = MockInputCompatiblePolicy::GetInputCompatiblePolicyInstance(); + EXPECT_CALL(*instance, IsInputCompatibleConvertingNeeded(_)).Times(1).WillOnce(Return(true)); + manager.LoadProductCompatiblePolicy(); + MockSystemProperties::g_isCompatibleInputTransEnabled = true; + MockSystemProperties::g_isTransformEnabled = true; + EXPECT_TRUE(manager.IsCompatibleConvertingEnabledFor(Kit::InputCompatibleSource::LEFT_PRESS)); + manager.UnloadProductCompatiblePolicy(); + MockSystemProperties::g_isCompatibleInputTransEnabled = true; + MockSystemProperties::g_isTransformEnabled = false; + EXPECT_FALSE(manager.IsCompatibleConvertingEnabledFor(Kit::InputCompatibleSource::SCROLL_AXIS_EVENT)); +} + +/** + * @tc.name: InputCompatibleManagerTest004 + * @tc.desc: Test Close function. + * @tc.type: FUNC + */ +HWTEST_F(InputCompatibleManagerTest, Close001, TestSize.Level1) +{ + OHOS::Ace::InputCompatibleManager& manager = OHOS::Ace::InputCompatibleManager::GetInstance(); + manager.LoadProductCompatiblePolicy(); + manager.Close(); + manager.libraryHandle_ = nullptr; + manager.Close(); + ASSERT_EQ(manager.libraryHandle_, nullptr); +} +}; // namespace OHOS::Ace diff --git a/test/unittest/core/pattern/window_scene/BUILD.gn b/test/unittest/core/pattern/window_scene/BUILD.gn index b9b1443d60a2834be18fb0abb6969912db701b29..869df92de23c5c31792fbf0549b45cda363c791d 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",