diff options
author | Siarhei Vishniakou <svv@google.com> | 2022-01-27 16:01:46 -0800 |
---|---|---|
committer | Siarhei Vishniakou <svv@google.com> | 2022-01-28 13:34:22 -0800 |
commit | b97dd69ec7d8255fdecc2abce9b0c0d4c5f73218 (patch) | |
tree | 355e21cf4d7fcfda35325201a7e9e2cf1b43e675 | |
parent | a579128c15ae83460f22c87c4762f26e0d66387b (diff) | |
download | libpalmrejection-b97dd69ec7d8255fdecc2abce9b0c0d4c5f73218.tar.gz |
Build libpalmrejection and tests
These changes allow us to build libpalmrejection on Android. These are
the changes to the original chromium source.
Bug: 198472780
Test: atest libpalmrejection_test
Change-Id: I4b01d033a27539fd677105918f540a24604e0de0
17 files changed, 413 insertions, 2 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..495b9af --- /dev/null +++ b/.clang-format @@ -0,0 +1,39 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium +# This defaults to 'Auto'. Explicitly set it for a while, so that +# 'vector<vector<int> >' in existing files gets formatted to +# 'vector<vector<int>>'. ('Auto' means that clang-format will only use +# 'int>>' if the file already contains at least one such instance.) +Standard: Cpp11 + +# Make sure code like: +# IPC_BEGIN_MESSAGE_MAP() +# IPC_MESSAGE_HANDLER(WidgetHostViewHost_Update, OnUpdate) +# IPC_END_MESSAGE_MAP() +# gets correctly indented. +MacroBlockBegin: "^\ +BEGIN_MSG_MAP|\ +BEGIN_MSG_MAP_EX|\ +BEGIN_SAFE_MSG_MAP_EX|\ +CR_BEGIN_MSG_MAP_EX|\ +IPC_BEGIN_MESSAGE_MAP|\ +IPC_BEGIN_MESSAGE_MAP_WITH_PARAM|\ +IPC_PROTOBUF_MESSAGE_TRAITS_BEGIN|\ +IPC_STRUCT_BEGIN|\ +IPC_STRUCT_BEGIN_WITH_PARENT|\ +IPC_STRUCT_TRAITS_BEGIN|\ +POLPARAMS_BEGIN|\ +PPAPI_BEGIN_MESSAGE_MAP$" +MacroBlockEnd: "^\ +CR_END_MSG_MAP|\ +END_MSG_MAP|\ +IPC_END_MESSAGE_MAP|\ +IPC_PROTOBUF_MESSAGE_TRAITS_END|\ +IPC_STRUCT_END|\ +IPC_STRUCT_TRAITS_END|\ +POLPARAMS_END|\ +PPAPI_END_MESSAGE_MAP$" + +# TODO: Remove this once clang-format r357700 is rolled in. +JavaImportGroups: ['android', 'androidx', 'com', 'dalvik', 'junit', 'org', 'com.google.android.apps.chrome', 'org.chromium', 'java', 'javax']
\ No newline at end of file diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..73c6a92 --- /dev/null +++ b/Android.bp @@ -0,0 +1,84 @@ +package { + default_applicable_licenses: ["external_libpalmrejection_license"], +} + +license { + name: "external_libpalmrejection_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-BSD", + ], + license_text: [ + "LICENSE", + ], +} + +cc_library_static { + name: "libpalmrejection", + local_include_dirs: ["."], + export_include_dirs: ["."], + srcs: [ + "ui/events/ozone/evdev/touch_evdev_types.cc", + "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc", + "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.cc", + "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc", + "ui/events/ozone/evdev/touch_filter/palm_detection_filter.cc", + "ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_model.cc", + "ui/events/ozone/evdev/touch_filter/palm_model/onedevice_train_palm_detection_filter_inference.cc", + ], + visibility: [ + "//frameworks/native/services/inputflinger:__subpackages__", + ], + shared_libs: [ + "libchrome", + ], + cpp_std: "c++20", + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + "-Wthread-safety", + "-Wshadow", + "-Wshadow-field-in-constructor-modified", + "-Wshadow-uncaptured-local", + "-Wno-unused-parameter", + "-Wno-unneeded-internal-declaration", + ], + sanitize: { + misc_undefined: ["bounds"], + }, +} + +cc_test { + name: "libpalmrejection_test", + srcs: [ + "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc", + "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc", + "chrome_to_android_compatibility_test_support.cc", + ], + shared_libs: [ + "libbase", + "libchrome", + ], + + static_libs: [ + "libc++fs", + "libgmock", + "liblog", + "libpalmrejection", + ], + cpp_std: "c++20", + cflags: [ + "-Wall", + "-Wextra", + "-Werror", + "-Wthread-safety", + "-Wshadow", + "-Wshadow-field-in-constructor-modified", + "-Wshadow-uncaptured-local", + ], + sanitize: { + misc_undefined: ["bounds"], + }, + test_suites: ["device-tests"], +} diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg new file mode 100644 index 0000000..4a52520 --- /dev/null +++ b/PREUPLOAD.cfg @@ -0,0 +1,8 @@ +[Builtin Hooks] +bpfmt = true +clang_format = true + +[Builtin Hooks Options] +clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp + +bpfmt = -d
\ No newline at end of file diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..28459b6 --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,10 @@ +{ + "presubmit": [ + { + "name": "inputflinger_tests" + }, + { + "name": "libpalmrejector_test" + } + ] +}
\ No newline at end of file diff --git a/chrome_to_android_compatibility.h b/chrome_to_android_compatibility.h new file mode 100644 index 0000000..f51ea36 --- /dev/null +++ b/chrome_to_android_compatibility.h @@ -0,0 +1,47 @@ +// Copyright 2022 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "base/time/time.h" + +// Android's external/libchrome directory is out of date. +// Add missing templates here as a temporary solution +namespace base { + +namespace time_internal { + +// clang-format off +template <typename T> +using EnableIfIntegral = typename std:: + enable_if<std::is_integral<T>::value || std::is_enum<T>::value, int>::type; +template <typename T> +using EnableIfFloat = + typename std::enable_if<std::is_floating_point<T>::value, int>::type; + +} // namespace time_internal + + +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr TimeDelta Seconds(T n) { + return TimeDelta::FromInternalValue( + ClampMul(static_cast<int64_t>(n), Time::kMicrosecondsPerSecond)); +} +template <typename T, time_internal::EnableIfIntegral<T> = 0> +constexpr TimeDelta Milliseconds(T n) { + return TimeDelta::FromInternalValue( + ClampMul(static_cast<int64_t>(n), Time::kMicrosecondsPerMillisecond)); +} +template <typename T, time_internal::EnableIfFloat<T> = 0> +constexpr TimeDelta Seconds(T n) { + return TimeDelta::FromInternalValue( + saturated_cast<int64_t>(n * Time::kMicrosecondsPerSecond)); +} +template <typename T, time_internal::EnableIfFloat<T> = 0> +constexpr TimeDelta Milliseconds(T n) { + return TimeDelta::FromInternalValue( + saturated_cast<int64_t>(n * Time::kMicrosecondsPerMillisecond)); +} + +} // namespace base diff --git a/chrome_to_android_compatibility_test_support.cc b/chrome_to_android_compatibility_test_support.cc new file mode 100644 index 0000000..5aa94b9 --- /dev/null +++ b/chrome_to_android_compatibility_test_support.cc @@ -0,0 +1,22 @@ +// Copyright 2022 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/geometry/point_f.h" + +#include "base/time/time.h" + +namespace base { +bool operator==(const TimeTicks& t1, const TimeTicks& t2) { + return t1.since_origin() == t2.since_origin(); +} +} // namespace base + +namespace gfx { + +// clang-format off +void PrintTo(const PointF& point, ::std::ostream* os) { + *os << point.ToString(); +} +// clang-format on +} // namespace gfx diff --git a/chrome_to_android_compatibility_test_support.h b/chrome_to_android_compatibility_test_support.h new file mode 100644 index 0000000..c2e4c90 --- /dev/null +++ b/chrome_to_android_compatibility_test_support.h @@ -0,0 +1,19 @@ +// Copyright 2022 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "base/time/time.h" + +namespace base { + +/** + * Workaround for the error in unit tests: ISO C++20 considers use of overloaded + * operator '==' (with operand types 'const base::TimeTicks' + * and 'const base::TimeTicks') to be ambiguous despite there being a unique + * best viable function [-Werror,-Wambiguous-reversed-operator] + */ +bool operator==(const TimeTicks& t1, const TimeTicks& t2); + +} // namespace base diff --git a/copy.bara.sky b/copy.bara.sky index b26a346..da06812 100644 --- a/copy.bara.sky +++ b/copy.bara.sky @@ -6,6 +6,7 @@ core.workflow( ), origin_files = glob( [ + ".clang-format", "ui/events/event_constants.h", "ui/events/ozone/evdev/touch_evdev_types.cc", "ui/events/ozone/evdev/touch_evdev_types.h", @@ -41,6 +42,7 @@ core.workflow( ), destination_files = glob( [ + ".clang-format", "ui/events/event_constants.h", "ui/events/ozone/evdev/touch_evdev_types.cc", "ui/events/ozone/evdev/touch_evdev_types.h", @@ -67,10 +69,16 @@ core.workflow( "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h", ], exclude = [ + "**/Android.bp", "LICENSE", "METADATA", "MODULE_LICENSE_BSD", "OWNERS", + "PREUPLOAD.cfg", + "TEST_MAPPING", + "chrome_to_android_compatibility.h", + "chrome_to_android_compatibility_test_support.cc", + "chrome_to_android_compatibility_test_support.h", "copy.bara.sky", ], ), diff --git a/ui/events/ozone/evdev/touch_evdev_types.h b/ui/events/ozone/evdev/touch_evdev_types.h index fd8db66..26106bb 100644 --- a/ui/events/ozone/evdev/touch_evdev_types.h +++ b/ui/events/ozone/evdev/touch_evdev_types.h @@ -5,6 +5,9 @@ #ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_EVDEV_TYPES_H_ #define UI_EVENTS_OZONE_EVDEV_TOUCH_EVDEV_TYPES_H_ +#if defined(__ANDROID__) +#include <compare> +#endif #include <stddef.h> #include "base/component_export.h" @@ -22,6 +25,10 @@ struct COMPONENT_EXPORT(EVDEV) InProgressTouchEvdev { InProgressTouchEvdev(const InProgressTouchEvdev& other); ~InProgressTouchEvdev(); +#if defined(__ANDROID__) + auto operator<=>(const InProgressTouchEvdev&) const = default; +#endif + // Current touch major of this slot. int major = 0; diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc index 2c43486..74c22cb 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.cc @@ -18,10 +18,16 @@ #include "base/json/json_reader.h" #include "base/logging.h" #include "base/values.h" +#if !defined(__ANDROID__) #include "ui/events/ozone/evdev/event_device_info.h" +#endif #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h" #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h" +#if !defined(__ANDROID__) #include "ui/events/ozone/features.h" +#else +#include <linux/input-event-codes.h> +#endif namespace ui { namespace { @@ -33,15 +39,25 @@ float EuclideanDistance(const gfx::PointF& a, const gfx::PointF& b) { } // namespace NeuralStylusPalmDetectionFilter::NeuralStylusPalmDetectionFilter( +#if !defined(__ANDROID__) const EventDeviceInfo& devinfo, +#else + PalmFilterDeviceInfo palm_filter_device_info, +#endif std::unique_ptr<NeuralStylusPalmDetectionFilterModel> palm_model, SharedPalmDetectionFilterState* shared_palm_state) : PalmDetectionFilter(shared_palm_state), tracking_ids_count_within_session_(0), +#if !defined(__ANDROID__) palm_filter_dev_info_(CreatePalmFilterDeviceInfo(devinfo)), +#else + palm_filter_dev_info_(palm_filter_device_info), +#endif model_(std::move(palm_model)) { +#if !defined(__ANDROID__) DCHECK(CompatibleWithNeuralStylusPalmDetectionFilter(devinfo)) << "One should run compatible check before instantiation."; +#endif } NeuralStylusPalmDetectionFilter::~NeuralStylusPalmDetectionFilter() {} @@ -407,6 +423,7 @@ std::string NeuralStylusPalmDetectionFilter::FilterNameForTesting() const { return kFilterName; } +#if !defined(__ANDROID__) bool NeuralStylusPalmDetectionFilter:: CompatibleWithNeuralStylusPalmDetectionFilter( const EventDeviceInfo& devinfo) { @@ -482,6 +499,7 @@ bool NeuralStylusPalmDetectionFilter:: } return true; } +#endif void NeuralStylusPalmDetectionFilter::EraseOldStrokes(base::TimeTicks time) { const base::TimeDelta max_age = model_->config().max_dead_neighbor_time; diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h index 96d3c1b..87c2bf4 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h @@ -15,7 +15,9 @@ #include <vector> #include "base/time/time.h" +#if !defined(__ANDROID__) #include "ui/events/ozone/evdev/event_device_info.h" +#endif #include "ui/events/ozone/evdev/touch_evdev_types.h" #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h" #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h" @@ -33,7 +35,11 @@ class COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilter public: // Takes ownership of the model. NeuralStylusPalmDetectionFilter( +#if !defined(__ANDROID__) const EventDeviceInfo& devinfo, +#else + PalmFilterDeviceInfo palm_filter_device_info, +#endif std::unique_ptr<NeuralStylusPalmDetectionFilterModel> palm_model, SharedPalmDetectionFilterState* shared_palm_state); @@ -47,14 +53,14 @@ class COMPONENT_EXPORT(EVDEV) NeuralStylusPalmDetectionFilter base::TimeTicks time, std::bitset<kNumTouchEvdevSlots>* slots_to_hold, std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override; - +#if !defined(__ANDROID__) static bool CompatibleWithNeuralStylusPalmDetectionFilter( const EventDeviceInfo& devinfo); static bool CompatibleWithNeuralStylusPalmDetectionFilter( const EventDeviceInfo& devinfo, const std::string& ozone_params_switch_string); - +#endif static const int kFeaturesPerSample; static const int kExtraFeaturesForNeighbor; diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h index 83ab9b0..eb07af9 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h @@ -5,6 +5,10 @@ #ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_ #define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_ +#if defined(__ANDROID__) +#include "chrome_to_android_compatibility.h" +#endif + #include <cstdint> #include <vector> diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc index 60eac8c..f3e834d 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc @@ -11,7 +11,11 @@ #include "base/test/gtest_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +#if !defined(__ANDROID__) #include "ui/events/ozone/evdev/event_device_test_util.h" +#else +#include "chrome_to_android_compatibility_test_support.h" +#endif #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h" #include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h" #include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h" @@ -47,10 +51,24 @@ class NeuralStylusPalmDetectionFilterTest : public testing::Test { EXPECT_CALL(*model_, config()) .Times(testing::AnyNumber()) .WillRepeatedly(testing::ReturnRef(model_config_)); +#if !defined(__ANDROID__) EXPECT_TRUE( CapabilitiesToDeviceInfo(kNocturneTouchScreen, &nocturne_touchscreen_)); palm_detection_filter_ = std::make_unique<NeuralStylusPalmDetectionFilter>( nocturne_touchscreen_, +#else + PalmFilterDeviceInfo nocturne_info{ + .max_x = 10404, + .max_y = 6936, + .x_res = 40, + .y_res = 40, + .major_radius_res = 1, + .minor_radius_res = 1, + .minor_radius_supported = true, + }; + palm_detection_filter_ = std::make_unique<NeuralStylusPalmDetectionFilter>( + nocturne_info, +#endif std::unique_ptr<NeuralStylusPalmDetectionFilterModel>(model_), shared_palm_state.get()); touch_.resize(kNumTouchEvdevSlots); @@ -62,7 +80,9 @@ class NeuralStylusPalmDetectionFilterTest : public testing::Test { protected: std::vector<InProgressTouchEvdev> touch_; std::unique_ptr<SharedPalmDetectionFilterState> shared_palm_state; +#if !defined(__ANDROID__) EventDeviceInfo nocturne_touchscreen_; +#endif // Owned by the filter. MockNeuralModel* model_; NeuralStylusPalmDetectionFilterModelConfig model_config_; @@ -72,6 +92,7 @@ class NeuralStylusPalmDetectionFilterTest : public testing::Test { class NeuralStylusPalmDetectionFilterDeathTest : public NeuralStylusPalmDetectionFilterTest {}; +#if !defined(__ANDROID__) TEST_F(NeuralStylusPalmDetectionFilterTest, EventDeviceSimpleTest) { EventDeviceInfo devinfo; std::vector<std::pair<DeviceCapabilities, bool>> devices = { @@ -112,6 +133,7 @@ TEST_F(NeuralStylusPalmDetectionFilterDeathTest, EventDeviceConstructionDeath) { shared_palm_state.get()); }); } +#endif TEST_F(NeuralStylusPalmDetectionFilterTest, NameTest) { EXPECT_EQ("NeuralStylusPalmDetectionFilter", diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc index 7663442..975adee 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc @@ -8,6 +8,7 @@ namespace ui { +#if !defined(__ANDROID__) PalmFilterDeviceInfo CreatePalmFilterDeviceInfo( const EventDeviceInfo& devinfo) { PalmFilterDeviceInfo info; @@ -42,6 +43,7 @@ PalmFilterDeviceInfo CreatePalmFilterDeviceInfo( return info; } +#endif namespace { float ScaledRadius( diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h index c523ad9..115a443 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h @@ -9,8 +9,14 @@ #include <deque> #include <vector> +#if defined(__ANDROID__) +#undef LOG_INFO +#undef LOG_WARNING +#endif #include "base/time/time.h" +#if !defined(__ANDROID__) #include "ui/events/ozone/evdev/event_device_info.h" +#endif #include "ui/events/ozone/evdev/touch_evdev_types.h" #include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h" #include "ui/gfx/geometry/point_f.h" @@ -25,10 +31,15 @@ struct COMPONENT_EXPORT(EVDEV) PalmFilterDeviceInfo { float major_radius_res = 1.f; float minor_radius_res = 1.f; bool minor_radius_supported = false; +#if defined(__ANDROID__) + auto operator<=>(const PalmFilterDeviceInfo&) const = default; +#endif }; +#if !defined(__ANDROID__) COMPONENT_EXPORT(EVDEV) PalmFilterDeviceInfo CreatePalmFilterDeviceInfo(const EventDeviceInfo& devinfo); +#endif // Data for a single touch event. struct COMPONENT_EXPORT(EVDEV) PalmFilterSample { diff --git a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc index 5a8725e..fc5d367 100644 --- a/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc +++ b/ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc @@ -10,13 +10,79 @@ #include <vector> #include "testing/gtest/include/gtest/gtest.h" +#if defined(__ANDROID__) +#include <linux/input-event-codes.h> +#include "chrome_to_android_compatibility_test_support.h" +#else #include "ui/events/ozone/evdev/event_device_test_util.h" +#endif #include "ui/events/ozone/evdev/touch_evdev_types.h" #include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h" #include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h" namespace ui { +#if defined(__ANDROID__) +/** + * The tests that require an actual device (something that responds to ioctls) + * have been removed. The rest of the tests were simplified by modifying the + * 'CreatePalmFilterDeviceInfo' method. + */ +enum DeviceType { + kNocturneTouchScreen, + kLinkTouchscreen, + kKohakuTouchscreen, +}; + +static PalmFilterDeviceInfo CreatePalmFilterDeviceInfo(DeviceType deviceType) { + // Default value for resolution is 1 if it's not specified (or set to 0). See + // https://source.chromium.org/chromium/chromium/src/+/main:ui/events/ozone/evdev/touch_filter/ + // neural_stylus_palm_detection_filter_util.cc;l=11;drc=7f74e1d22e2d0b91856ea6b3619098cd05ef6158 + + switch (deviceType) { + case kNocturneTouchScreen: + return PalmFilterDeviceInfo{ + .max_x = 10404, + .max_y = 6936, + .x_res = 40, + .y_res = 40, + .major_radius_res = 1, + .minor_radius_res = 1, + .minor_radius_supported = true, + }; + case kLinkTouchscreen: + return PalmFilterDeviceInfo{ + .max_x = 2559, + .max_y = 1699, + .x_res = 20, + .y_res = 20, + .major_radius_res = 1, + .minor_radius_res = 1, + .minor_radius_supported = false, + }; + case kKohakuTouchscreen: + return PalmFilterDeviceInfo{ + .max_x = 2559, + .max_y = 1699, + .x_res = 1, + .y_res = 1, + .major_radius_res = 1, + .minor_radius_res = 1, + .minor_radius_supported = false, + }; + } +} + +class EventDeviceInfo { + public: + float GetAbsResolution(int /*axis*/) { return 20; } +}; + +bool CapabilitiesToDeviceInfo(DeviceType, EventDeviceInfo*) { + return true; +} +#endif + class NeuralStylusPalmDetectionFilterUtilTest : public testing::Test { public: NeuralStylusPalmDetectionFilterUtilTest() = default; @@ -43,6 +109,7 @@ class NeuralStylusPalmDetectionFilterUtilTest : public testing::Test { NeuralStylusPalmDetectionFilterModelConfig model_config_; }; +#if !defined(__ANDROID__) TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistilledNocturneTest) { const PalmFilterDeviceInfo nocturne_distilled = CreatePalmFilterDeviceInfo(nocturne_touchscreen_); @@ -72,13 +139,18 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, NoMinorResTest) { EXPECT_EQ(1, nocturne_distilled.minor_radius_res); EXPECT_EQ(1, nocturne_distilled.major_radius_res); } +#endif TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistillerKohakuTest) { EventDeviceInfo kohaku_touchscreen; ASSERT_TRUE( CapabilitiesToDeviceInfo(kKohakuTouchscreen, &kohaku_touchscreen)); const PalmFilterDeviceInfo kohaku_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(kohaku_touchscreen); +#else + CreatePalmFilterDeviceInfo(kKohakuTouchscreen); +#endif EXPECT_FALSE(kohaku_distilled.minor_radius_supported); EXPECT_EQ(1, kohaku_distilled.x_res); EXPECT_EQ(1, kohaku_distilled.y_res); @@ -88,7 +160,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistilledLinkTest) { EventDeviceInfo link_touchscreen; ASSERT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &link_touchscreen)); const PalmFilterDeviceInfo link_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(link_touchscreen); +#else + CreatePalmFilterDeviceInfo(kLinkTouchscreen); +#endif EXPECT_FALSE(link_distilled.minor_radius_supported); EXPECT_FLOAT_EQ(1.f, link_distilled.major_radius_res); EXPECT_FLOAT_EQ(link_distilled.major_radius_res, @@ -98,7 +174,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, DistilledLinkTest) { TEST_F(NeuralStylusPalmDetectionFilterUtilTest, PalmFilterSampleTest) { base::TimeTicks time = base::TimeTicks() + base::Seconds(30); const PalmFilterDeviceInfo nocturne_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(nocturne_touchscreen_); +#else + CreatePalmFilterDeviceInfo(kNocturneTouchScreen); +#endif const PalmFilterSample sample = CreatePalmFilterSample(touch_, time, model_config_, nocturne_distilled); EXPECT_EQ(time, sample.time); @@ -115,7 +195,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, LinkTouchscreenSampleTest) { base::TimeTicks time = base::TimeTicks() + base::Seconds(30); ASSERT_TRUE(CapabilitiesToDeviceInfo(kLinkTouchscreen, &link_touchscreen)); const PalmFilterDeviceInfo link_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(link_touchscreen); +#else + CreatePalmFilterDeviceInfo(kLinkTouchscreen); +#endif touch_.minor = 0; // no minor from link. // use 40 as a base since model is trained on that kind of device. model_config_.radius_polynomial_resize = { @@ -134,7 +218,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, PalmFilterStrokeTest) { base::TimeTicks time = base::TimeTicks() + base::Seconds(30); const PalmFilterDeviceInfo nocturne_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(nocturne_touchscreen_); +#else + CreatePalmFilterDeviceInfo(kNocturneTouchScreen); +#endif // Deliberately long test to ensure floating point continued accuracy. for (int i = 0; i < 500000; ++i) { touch_.x = 15 + i; @@ -172,7 +260,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, base::TimeTicks time = base::TimeTicks() + base::Seconds(30); const PalmFilterDeviceInfo nocturne_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(nocturne_touchscreen_); +#else + CreatePalmFilterDeviceInfo(kNocturneTouchScreen); +#endif for (int i = 0; i < 500; ++i) { touch_.major = 2 + i; touch_.minor = 1 + i; @@ -196,7 +288,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeGetMaxMajorTest) { EXPECT_FLOAT_EQ(0, stroke.MaxMajorRadius()); base::TimeTicks time = base::TimeTicks::UnixEpoch() + base::Seconds(30); const PalmFilterDeviceInfo nocturne_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(nocturne_touchscreen_); +#else + CreatePalmFilterDeviceInfo(kNocturneTouchScreen); +#endif for (int i = 1; i < 50; ++i) { touch_.major = i; touch_.minor = i - 1; @@ -214,7 +310,11 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, SampleRadiusConversion) { model_config_.radius_polynomial_resize = {71.3}; base::TimeTicks time = base::TimeTicks::UnixEpoch() + base::Seconds(30); const PalmFilterDeviceInfo nocturne_distilled = +#if !defined(__ANDROID__) CreatePalmFilterDeviceInfo(nocturne_touchscreen_); +#else + CreatePalmFilterDeviceInfo(kNocturneTouchScreen); +#endif PalmFilterSample sample = CreatePalmFilterSample(touch_, time, model_config_, nocturne_distilled); EXPECT_FLOAT_EQ(71.3, sample.major_radius); diff --git a/ui/events/ozone/evdev/touch_filter/palm_detection_filter.h b/ui/events/ozone/evdev/touch_filter/palm_detection_filter.h index 5f0dcad..6e72dc1 100644 --- a/ui/events/ozone/evdev/touch_filter/palm_detection_filter.h +++ b/ui/events/ozone/evdev/touch_filter/palm_detection_filter.h @@ -5,6 +5,10 @@ #ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_ #define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_PALM_DETECTION_FILTER_H_ +#if defined(__ANDROID__) +#include "chrome_to_android_compatibility.h" +#endif + #include <bitset> #include <vector> |