From 2800fb0c6b56711c6daf70491270dbea89fbf660 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Thu, 15 Sep 2022 13:49:23 +0000 Subject: Use TWO_FINGER_SWIPE classification for touchpad scroll events This allows apps to distinguish the fake finger created for touchpad scrolling from an actual finger. Bug: 246758376 Test: add classification to InputDispatcher's outbound event logs and check the new value is used when scrolling Change-Id: Ia90f9984e75ad6fde2d0e42628ab42eab371b7a5 --- libs/input/Input.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 2b7483d27d..579b28e588 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -87,6 +87,8 @@ const char* motionClassificationToString(MotionClassification classification) { return "AMBIGUOUS_GESTURE"; case MotionClassification::DEEP_PRESS: return "DEEP_PRESS"; + case MotionClassification::TWO_FINGER_SWIPE: + return "TWO_FINGER_SWIPE"; } } -- cgit v1.2.3-59-g8ed1b From 31977184520e99110e1deadceb6197636f76450a Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 30 Sep 2022 08:51:23 -0700 Subject: Run some inputflinger_tests on host Sometimes, it's convenient to execute the input tests without having a connected device. This is especially useful when doing cherry-picks of patch on a cloud device. Allow input code to build for host, and enable the tests for running on host. Bug: 249591924 Test: atest --host --no-bazel-mode -c -m inputflinger_tests Change-Id: Ib9be6a5fb6c35ffc450e41cb2a5688bfb2c8d01a --- libs/attestation/Android.bp | 1 + libs/input/Input.cpp | 36 +++++++++-------- services/batteryservice/Android.bp | 1 + services/inputflinger/Android.bp | 46 +++++++++++++++++----- services/inputflinger/InputThread.cpp | 6 +++ services/inputflinger/benchmarks/Android.bp | 1 - services/inputflinger/dispatcher/Android.bp | 27 ++++++++++--- .../inputflinger/dispatcher/InputDispatcher.cpp | 5 ++- services/inputflinger/reader/Android.bp | 37 +++++++++++++---- services/inputflinger/reader/EventHub.cpp | 1 - .../reader/mapper/MultiTouchInputMapper.cpp | 8 +++- services/inputflinger/reporter/Android.bp | 3 +- services/inputflinger/tests/Android.bp | 27 +++++++++++++ services/inputflinger/tests/EventHub_test.cpp | 6 +++ .../inputflinger/tests/InputDispatcher_test.cpp | 2 +- services/inputflinger/tests/InputReader_test.cpp | 9 +++++ services/inputflinger/tests/UinputDevice.cpp | 1 + 17 files changed, 172 insertions(+), 45 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/libs/attestation/Android.bp b/libs/attestation/Android.bp index 2bf15d45eb..fddecc0ceb 100644 --- a/libs/attestation/Android.bp +++ b/libs/attestation/Android.bp @@ -22,6 +22,7 @@ package { cc_library_static { name: "libattestation", + host_supported: true, cflags: [ "-Wall", "-Wextra", diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 579b28e588..a6f6b14bae 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -34,9 +35,6 @@ #ifdef __linux__ #include #endif -#ifdef __ANDROID__ -#include -#endif using android::base::StringPrintf; @@ -112,28 +110,34 @@ const char* motionToolTypeToString(int32_t toolType) { } // --- IdGenerator --- + +static status_t getRandomBytes(uint8_t* data, size_t size) { + int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW)); + if (ret == -1) { + return -errno; + } + + base::unique_fd fd(ret); + if (!base::ReadFully(fd, data, size)) { + return -errno; + } + return OK; +} + IdGenerator::IdGenerator(Source source) : mSource(source) {} int32_t IdGenerator::nextId() const { constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; int32_t id = 0; -// Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't -// use sequence number so just always return mSource. -#ifdef __ANDROID__ - constexpr size_t BUF_LEN = sizeof(id); - size_t totalBytes = 0; - while (totalBytes < BUF_LEN) { - ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); - if (CC_UNLIKELY(bytes < 0)) { - ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); - id = 0; +#if defined(__linux__) + while (true) { + status_t result = getRandomBytes(reinterpret_cast(&id), sizeof(id)); + if (result == OK) { break; } - totalBytes += bytes; } -#endif // __ANDROID__ - +#endif // __linux__ return (id & SEQUENCE_NUMBER_MASK) | static_cast(mSource); } diff --git a/services/batteryservice/Android.bp b/services/batteryservice/Android.bp index 1e3799185e..9b783916d3 100644 --- a/services/batteryservice/Android.bp +++ b/services/batteryservice/Android.bp @@ -9,6 +9,7 @@ package { cc_library_headers { name: "libbatteryservice_headers", + host_supported: true, vendor_available: true, recovery_available: true, export_include_dirs: ["include"], diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index ddcd51f357..4dcbba2c43 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -41,7 +41,9 @@ cc_defaults { "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION", ], sanitize: { - misc_undefined: ["bounds"], + misc_undefined: [ + "bounds", + ], }, tidy: true, tidy_checks: [ @@ -57,11 +59,11 @@ cc_defaults { filegroup { name: "libinputflinger_sources", srcs: [ - "InputProcessor.cpp", "InputCommonConverter.cpp", + "InputManager.cpp", + "InputProcessor.cpp", "PreferStylusOverTouchBlocker.cpp", "UnwantedInteractionBlocker.cpp", - "InputManager.cpp", ], } @@ -77,13 +79,10 @@ cc_defaults { "libcrypto", "libcutils", "libhidlbase", - "libinput", "libkll", "liblog", "libprotobuf-cpp-lite", "libstatslog", - "libstatspull", - "libstatssocket", "libutils", "server_configurable_flags", ], @@ -92,6 +91,23 @@ cc_defaults { "libpalmrejection", "libui-types", ], + target: { + android: { + shared_libs: [ + "libgui", + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + host: { + static_libs: [ + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + }, } cc_library_shared { @@ -108,9 +124,8 @@ cc_library_shared { // This should consist only of dependencies from inputflinger. Other dependencies should be // in cc_defaults so that they are included in the tests. "libinputflinger_base", - "libinputreporter", "libinputreader", - "libgui", + "libinputreporter", ], static_libs: [ "libinputdispatcher", @@ -130,6 +145,7 @@ cc_library_shared { cc_library_headers { name: "libinputflinger_headers", + host_supported: true, export_include_dirs: ["include"], } @@ -151,17 +167,29 @@ cc_defaults { "libbase", "libbinder", "libcutils", - "libinput", "liblog", "libutils", ], header_libs: [ "libinputflinger_headers", ], + target: { + android: { + shared_libs: [ + "libinput", + ], + }, + host: { + static_libs: [ + "libinput", + ], + }, + }, } cc_library_shared { name: "libinputflinger_base", + host_supported: true, defaults: [ "inputflinger_defaults", "libinputflinger_base_defaults", diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index e2e64f992f..e74f258168 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -54,7 +54,13 @@ InputThread::~InputThread() { } bool InputThread::isCallingThread() { +#if defined(__ANDROID__) return gettid() == mThread->getTid(); +#else + // Assume that the caller is doing everything correctly, + // since thread information is not available on host + return false; +#endif } } // namespace android \ No newline at end of file diff --git a/services/inputflinger/benchmarks/Android.bp b/services/inputflinger/benchmarks/Android.bp index e5c19afead..4e2a6fbf87 100644 --- a/services/inputflinger/benchmarks/Android.bp +++ b/services/inputflinger/benchmarks/Android.bp @@ -21,7 +21,6 @@ cc_benchmark { "libbinder", "libcrypto", "libcutils", - "libinput", "libinputflinger_base", "libinputreporter", "liblog", diff --git a/services/inputflinger/dispatcher/Android.bp b/services/inputflinger/dispatcher/Android.bp index eb79b76b28..99c4936f32 100644 --- a/services/inputflinger/dispatcher/Android.bp +++ b/services/inputflinger/dispatcher/Android.bp @@ -23,6 +23,7 @@ package { cc_library_headers { name: "libinputdispatcher_headers", + host_supported: true, export_include_dirs: [ "include", ], @@ -33,6 +34,7 @@ filegroup { srcs: [ "AnrTracker.cpp", "Connection.cpp", + "DragState.cpp", "Entry.cpp", "FocusResolver.cpp", "InjectionState.cpp", @@ -45,7 +47,6 @@ filegroup { "LatencyTracker.cpp", "Monitor.cpp", "TouchState.cpp", - "DragState.cpp", ], } @@ -56,20 +57,34 @@ cc_defaults { "libbase", "libcrypto", "libcutils", - "libinput", "libkll", "liblog", "libprotobuf-cpp-lite", "libstatslog", - "libstatspull", - "libstatssocket", - "libgui", "libutils", "server_configurable_flags", ], static_libs: [ "libattestation", + "libgui_window_info_static", ], + target: { + android: { + shared_libs: [ + "libgui", + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + host: { + static_libs: [ + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + }, header_libs: [ "libinputdispatcher_headers", ], @@ -84,8 +99,8 @@ cc_library_static { shared_libs: [ // This should consist only of dependencies from inputflinger. Other dependencies should be // in cc_defaults so that they are included in the tests. - "libinputreporter", "libinputflinger_base", + "libinputreporter", ], export_header_lib_headers: [ "libinputdispatcher_headers", diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index a793f57ade..5587a8f5d0 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -25,7 +25,9 @@ #include #include #include +#if defined(__ANDROID__) #include +#endif #include #include #include @@ -569,8 +571,9 @@ InputDispatcher::InputDispatcher(const sp& polic mReporter = createInputReporter(); mWindowInfoListener = sp::make(*this); +#if defined(__ANDROID__) SurfaceComposerClient::getDefault()->addWindowInfosListener(mWindowInfoListener); - +#endif mKeyRepeatState.lastKeyEntry = nullptr; policy->getDispatcherConfiguration(&mConfig); } diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp index 0f87201caf..43259c0c5f 100644 --- a/services/inputflinger/reader/Android.bp +++ b/services/inputflinger/reader/Android.bp @@ -23,6 +23,7 @@ package { cc_library_headers { name: "libinputreader_headers", + host_supported: true, export_include_dirs: [ "controller", "include", @@ -36,11 +37,9 @@ filegroup { srcs: [ "EventHub.cpp", "InputDevice.cpp", + "InputReader.cpp", + "TouchVideoDevice.cpp", "controller/PeripheralController.cpp", - "mapper/accumulator/CursorButtonAccumulator.cpp", - "mapper/accumulator/CursorScrollAccumulator.cpp", - "mapper/accumulator/SingleTouchMotionAccumulator.cpp", - "mapper/accumulator/TouchButtonAccumulator.cpp", "mapper/CursorInputMapper.cpp", "mapper/ExternalStylusInputMapper.cpp", "mapper/InputMapper.cpp", @@ -53,8 +52,10 @@ filegroup { "mapper/SwitchInputMapper.cpp", "mapper/TouchInputMapper.cpp", "mapper/VibratorInputMapper.cpp", - "InputReader.cpp", - "TouchVideoDevice.cpp", + "mapper/accumulator/CursorButtonAccumulator.cpp", + "mapper/accumulator/CursorScrollAccumulator.cpp", + "mapper/accumulator/SingleTouchMotionAccumulator.cpp", + "mapper/accumulator/TouchButtonAccumulator.cpp", ], } @@ -66,11 +67,9 @@ cc_defaults { "libcap", "libcrypto", "libcutils", - "libinput", "liblog", "libstatslog", "libutils", - "libPlatformProperties", ], static_libs: [ "libc++fs", @@ -80,10 +79,24 @@ cc_defaults { "libbatteryservice_headers", "libinputreader_headers", ], + target: { + android: { + shared_libs: [ + "libPlatformProperties", + "libinput", + ], + }, + host: { + static_libs: [ + "libinput", + ], + }, + }, } cc_library_shared { name: "libinputreader", + host_supported: true, defaults: [ "inputflinger_defaults", "libinputreader_defaults", @@ -99,6 +112,14 @@ cc_library_shared { export_header_lib_headers: [ "libinputreader_headers", ], + target: { + host: { + include_dirs: [ + "bionic/libc/kernel/android/uapi/", + "bionic/libc/kernel/uapi", + ], + }, + }, static_libs: [ "libc++fs", ], diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index ca7e426fdf..956746d7d2 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp index 1d53eaba6e..acba4f6513 100644 --- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp @@ -17,8 +17,9 @@ #include "../Macros.h" #include "MultiTouchInputMapper.h" - +#if defined(__ANDROID__) #include +#endif namespace android { @@ -362,7 +363,12 @@ bool MultiTouchInputMapper::hasStylus() const { bool MultiTouchInputMapper::shouldSimulateStylusWithTouch() const { static const bool SIMULATE_STYLUS_WITH_TOUCH = +#if defined(__ANDROID__) sysprop::InputProperties::simulate_stylus_with_touch().value_or(false); +#else + // Disable this developer feature where sysproperties are not available + false; +#endif return SIMULATE_STYLUS_WITH_TOUCH && mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN; } diff --git a/services/inputflinger/reporter/Android.bp b/services/inputflinger/reporter/Android.bp index 74307310c5..693ff063b1 100644 --- a/services/inputflinger/reporter/Android.bp +++ b/services/inputflinger/reporter/Android.bp @@ -23,13 +23,14 @@ package { cc_library_headers { name: "libinputreporter_headers", + host_supported: true, export_include_dirs: ["."], } filegroup { name: "libinputreporter_sources", srcs: [ - "InputReporter.cpp", + "InputReporter.cpp", ], } diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index fcbb98fce8..b6d0709af0 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -23,6 +23,7 @@ package { cc_test { name: "inputflinger_tests", + host_supported: true, defaults: [ "inputflinger_defaults", // For all targets inside inputflinger, these tests build all of their sources using their @@ -56,10 +57,36 @@ cc_test { "frameworks/native/libs/input", ], }, + target: { + android: { + shared_libs: [ + "libinput", + "libvintf", + ], + }, + host: { + include_dirs: [ + "bionic/libc/kernel/android/uapi/", + "bionic/libc/kernel/uapi", + ], + cflags: [ + "-D__ANDROID_HOST__", + ], + static_libs: [ + "libinput", + ], + }, + }, static_libs: [ "libc++fs", "libgmock", ], + shared_libs: [ + "libinputreader", + ], require_root: true, + test_options: { + unit_test: true, + }, test_suites: ["device-tests"], } diff --git a/services/inputflinger/tests/EventHub_test.cpp b/services/inputflinger/tests/EventHub_test.cpp index 9380c7142f..2e296daa22 100644 --- a/services/inputflinger/tests/EventHub_test.cpp +++ b/services/inputflinger/tests/EventHub_test.cpp @@ -68,12 +68,18 @@ protected: int32_t mDeviceId; virtual void SetUp() override { +#if !defined(__ANDROID__) + GTEST_SKIP() << "It's only possible to interact with uinput on device"; +#endif mEventHub = std::make_unique(); consumeInitialDeviceAddedEvents(); mKeyboard = createUinputDevice(); ASSERT_NO_FATAL_FAILURE(mDeviceId = waitForDeviceCreation()); } virtual void TearDown() override { +#if !defined(__ANDROID__) + return; +#endif mKeyboard.reset(); waitForDeviceClose(mDeviceId); assertNoMoreEvents(); diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 985c9c570c..a1ccfc7d16 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -7028,7 +7028,7 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesInputInOrder) { } for (int i = 0; i < nFds; i++) { ASSERT_EQ(EPOLLIN, events[i].events); - eventOrder.push_back(events[i].data.u64); + eventOrder.push_back(static_cast(events[i].data.u64)); channels[i]->consumeMotionDown(); } } diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 8ac8dfc3ac..3cc8e94030 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2300,6 +2300,9 @@ protected: std::shared_ptr mFakePointerController; void SetUp() override { +#if !defined(__ANDROID__) + GTEST_SKIP(); +#endif mFakePolicy = sp::make(); mFakePointerController = std::make_shared(); mFakePolicy->setPointerController(mFakePointerController); @@ -2318,6 +2321,9 @@ protected: } void TearDown() override { +#if !defined(__ANDROID__) + return; +#endif ASSERT_EQ(mReader->stop(), OK); mReader.reset(); mTestListener.reset(); @@ -2432,6 +2438,9 @@ protected: const std::string UNIQUE_ID = "local:0"; void SetUp() override { +#if !defined(__ANDROID__) + GTEST_SKIP(); +#endif InputReaderIntegrationTest::SetUp(); // At least add an internal display. setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp index 9c939198f3..7862b5839c 100644 --- a/services/inputflinger/tests/UinputDevice.cpp +++ b/services/inputflinger/tests/UinputDevice.cpp @@ -17,6 +17,7 @@ #include "UinputDevice.h" #include +#include #include namespace android { -- cgit v1.2.3-59-g8ed1b From 63740b961ea0aceb7153c374f9761c44506e6b1a Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 20 Oct 2022 10:28:08 -0700 Subject: Use getrandom for device input event ID generation On device, let's go back to using 'getrandom' for the generation of random input event ids. This should be faster than reading from /dev/urandom. This is a partial revert of the previous patch. After this patch, we will only use '/dev/urandom' on host. We may be able to switch to 'getrandom' for both if we ever switch to musl for host. We can revisit it then. Bug: 254215895 Test: m && atest --host libinput_tests Change-Id: Idc6241facbd93f3f71ae90567db831d96a5fc98b --- libs/input/Input.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index a6f6b14bae..c1eb8e2a12 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -35,6 +35,9 @@ #ifdef __linux__ #include #endif +#if defined(__ANDROID__) +#include +#endif using android::base::StringPrintf; @@ -110,8 +113,11 @@ const char* motionToolTypeToString(int32_t toolType) { } // --- IdGenerator --- - -static status_t getRandomBytes(uint8_t* data, size_t size) { +#if defined(__ANDROID__) +[[maybe_unused]] +#endif +static status_t +getRandomBytes(uint8_t* data, size_t size) { int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW)); if (ret == -1) { return -errno; @@ -130,7 +136,22 @@ int32_t IdGenerator::nextId() const { constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; int32_t id = 0; +#if defined(__ANDROID__) + // On device, prefer 'getrandom' to '/dev/urandom' because it's faster. + constexpr size_t BUF_LEN = sizeof(id); + size_t totalBytes = 0; + while (totalBytes < BUF_LEN) { + ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); + if (CC_UNLIKELY(bytes < 0)) { + ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); + id = 0; + break; + } + totalBytes += bytes; + } +#else #if defined(__linux__) + // On host, / GRND_NONBLOCK is not available while (true) { status_t result = getRandomBytes(reinterpret_cast(&id), sizeof(id)); if (result == OK) { @@ -138,6 +159,7 @@ int32_t IdGenerator::nextId() const { } } #endif // __linux__ +#endif // __ANDROID__ return (id & SEQUENCE_NUMBER_MASK) | static_cast(mSource); } -- cgit v1.2.3-59-g8ed1b From ae4d05384bebad96510969e859dc2af1bd6b81c4 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Mon, 31 Oct 2022 17:50:04 +0000 Subject: Use std::array and default copy assignment for PointerCoords Bug: 245989146 Test: atest inputflinger_tests Change-Id: I5e008d03184204a2f34f369e2d5958f6cd4de952 --- include/input/Input.h | 5 +++-- libs/input/Input.cpp | 8 -------- services/inputflinger/InputCommonConverter.cpp | 4 ++-- 3 files changed, 5 insertions(+), 12 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 172e5b46d8..dd74a51e5e 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -366,7 +366,7 @@ struct PointerCoords { // Values of axes that are stored in this structure packed in order by axis id // for each axis that is present in the structure according to 'bits'. - float values[MAX_AXES]; + std::array values; inline void clear() { BitSet64::clear(bits); @@ -406,7 +406,8 @@ struct PointerCoords { return !(*this == other); } - void copyFrom(const PointerCoords& other); + inline void copyFrom(const PointerCoords& other) { *this = other; } + PointerCoords& operator=(const PointerCoords&) = default; private: void tooManyAxes(int axis); diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c1eb8e2a12..cf5a7e7b05 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -438,14 +438,6 @@ bool PointerCoords::operator==(const PointerCoords& other) const { return true; } -void PointerCoords::copyFrom(const PointerCoords& other) { - bits = other.bits; - uint32_t count = BitSet64::count(bits); - for (uint32_t i = 0; i < count; i++) { - values[i] = other.values[i]; - } -} - void PointerCoords::transform(const ui::Transform& transform) { const vec2 xy = transform.transform(getXYValue()); setAxisValue(AMOTION_EVENT_AXIS_X, xy.x); diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index 6db89d4759..628ce6fc9a 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -304,8 +304,8 @@ static void getHalPropertiesAndCoords(const NotifyMotionArgs& args, common::PointerCoords coords; // OK to copy bits because we have static_assert for pointerCoords axes coords.bits = args.pointerCoords[i].bits; - coords.values = std::vector(args.pointerCoords[i].values, - args.pointerCoords[i].values + + coords.values = std::vector(args.pointerCoords[i].values.cbegin(), + args.pointerCoords[i].values.cbegin() + BitSet64::count(args.pointerCoords[i].bits)); outPointerCoords.push_back(coords); } -- cgit v1.2.3-59-g8ed1b From e562696c7658102f63558be034a2fb7ab158840f Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 27 Oct 2022 20:30:53 +0000 Subject: Input: Add isStylusToolType() utility function Using this utility function will ensure we don't forget to check for both TOOL_TYPE_STYLUS and TOOL_TYPE_ERASER when we are looking to identify a stylus. This will cause a behavior change in UnwantedInteractionBlocker, where TOOL_TYPE_ERASER was not previously considered a stylus tool. Bug: None Test: atest inputflinger_tests Change-Id: I3dae9b5037d7ac08a5672c6e4d6e3b62ee2bd352 --- include/input/Input.h | 2 ++ libs/input/Input.cpp | 4 ++++ .../inputflinger/PreferStylusOverTouchBlocker.cpp | 3 +-- services/inputflinger/UnwantedInteractionBlocker.cpp | 19 +++++++++++-------- services/inputflinger/dispatcher/InputDispatcher.cpp | 3 +-- services/inputflinger/reader/InputReader.cpp | 3 +-- .../inputflinger/reader/mapper/TouchInputMapper.cpp | 6 ++---- 7 files changed, 22 insertions(+), 18 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index dd74a51e5e..d298d817f5 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -209,6 +209,8 @@ std::string inputEventSourceToString(int32_t source); bool isFromSource(uint32_t source, uint32_t test); +bool isStylusToolType(uint32_t toolType); + /* * Flags that flow alongside events in the input dispatch system to help with certain * policy decisions such as waking from device sleep. diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index cf5a7e7b05..3685f54a53 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -238,6 +238,10 @@ bool isFromSource(uint32_t source, uint32_t test) { return (source & test) == test; } +bool isStylusToolType(uint32_t toolType) { + return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; +} + VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(), event.getSource(), event.getDisplayId()}, diff --git a/services/inputflinger/PreferStylusOverTouchBlocker.cpp b/services/inputflinger/PreferStylusOverTouchBlocker.cpp index beec2e162e..ddd514676b 100644 --- a/services/inputflinger/PreferStylusOverTouchBlocker.cpp +++ b/services/inputflinger/PreferStylusOverTouchBlocker.cpp @@ -25,8 +25,7 @@ static std::pair checkToolType(const NotifyMotionArgs& args) { for (size_t i = 0; i < args.pointerCount; i++) { // Make sure we are canceling stylus pointers const int32_t toolType = args.pointerProperties[i].toolType; - if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(toolType)) { hasStylus = true; } if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index ec41025e9d..c170b81475 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -99,14 +99,17 @@ static bool isPalmRejectionEnabled() { } static int getLinuxToolCode(int toolType) { - if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) { - return BTN_TOOL_PEN; + switch (toolType) { + case AMOTION_EVENT_TOOL_TYPE_STYLUS: + return BTN_TOOL_PEN; + case AMOTION_EVENT_TOOL_TYPE_ERASER: + return BTN_TOOL_RUBBER; + case AMOTION_EVENT_TOOL_TYPE_FINGER: + return BTN_TOOL_FINGER; + default: + ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); + return BTN_TOOL_FINGER; } - if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { - return BTN_TOOL_FINGER; - } - ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); - return BTN_TOOL_FINGER; } static int32_t getActionUpForPointerId(const NotifyMotionArgs& args, int32_t pointerId) { @@ -195,7 +198,7 @@ NotifyMotionArgs removePointerIds(const NotifyMotionArgs& args, static std::optional removeStylusPointerIds(const NotifyMotionArgs& args) { std::set stylusPointerIds; for (uint32_t i = 0; i < args.pointerCount; i++) { - if (args.pointerProperties[i].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) { + if (isStylusToolType(args.pointerProperties[i].toolType)) { stylusPointerIds.insert(args.pointerProperties[i].id); } } diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index f6982173af..4091310193 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -479,8 +479,7 @@ bool windowAcceptsTouchAt(const WindowInfo& windowInfo, int32_t displayId, int32 bool isPointerFromStylus(const MotionEntry& entry, int32_t pointerIndex) { return isFromSource(entry.source, AINPUT_SOURCE_STYLUS) && - (entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - entry.pointerProperties[pointerIndex].toolType == AMOTION_EVENT_TOOL_TYPE_ERASER); + isStylusToolType(entry.pointerProperties[pointerIndex].toolType); } // Determines if the given window can be targeted as InputTarget::FLAG_FOREGROUND. diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index f8b1b3fa6e..f04a6469ea 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -66,8 +66,7 @@ static bool isStylusPointerGestureStart(const NotifyMotionArgs& motionArgs) { return false; } const auto actionIndex = MotionEvent::getActionIndex(motionArgs.action); - return motionArgs.pointerProperties[actionIndex].toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - motionArgs.pointerProperties[actionIndex].toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; + return isStylusToolType(motionArgs.pointerProperties[actionIndex].toolType); } // --- InputReader --- diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index f8d6cf9e7f..7db73dbb9e 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -1595,8 +1595,7 @@ std::list TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { @@ -1609,8 +1608,7 @@ std::list TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re uint32_t id = idBits.clearFirstMarkedBit(); const RawPointerData::Pointer& pointer = mCurrentRawState.rawPointerData.pointerForId(id); - if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) { + if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); } } -- cgit v1.2.3-59-g8ed1b From a9cf419caeebb019a6ca39fd43aab69f0956ae85 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Dec 2022 23:46:39 +0000 Subject: Convert orientation values in input to ui::Rotation. ui::Rotation both provides better typesafety as well as some convenience functions (e.g. operator+, operator-). Test: atest TouchVideoFrame_test.cpp InputReader_test.cpp Change-Id: Ib423457c742ed3d41f2e3fc269ddf86809cbf247 --- include/input/DisplayViewport.h | 14 +- include/input/Input.h | 2 +- include/input/TouchVideoFrame.h | 4 +- libs/input/Input.cpp | 10 +- libs/input/TouchVideoFrame.cpp | 11 +- libs/input/tests/TouchVideoFrame_test.cpp | 46 +-- libs/ui/include/ui/Rotation.h | 9 +- services/inputflinger/include/InputReaderBase.h | 3 +- .../reader/mapper/CursorInputMapper.cpp | 2 +- .../inputflinger/reader/mapper/CursorInputMapper.h | 3 +- .../reader/mapper/KeyboardInputMapper.cpp | 15 +- .../reader/mapper/KeyboardInputMapper.h | 2 +- .../reader/mapper/RotaryEncoderInputMapper.cpp | 6 +- .../reader/mapper/RotaryEncoderInputMapper.h | 4 +- .../reader/mapper/TouchCursorInputMapperCommon.h | 19 +- .../reader/mapper/TouchInputMapper.cpp | 50 ++- .../inputflinger/reader/mapper/TouchInputMapper.h | 13 +- .../inputflinger/tests/FakeInputReaderPolicy.cpp | 8 +- .../inputflinger/tests/FakeInputReaderPolicy.h | 6 +- services/inputflinger/tests/InputReader_test.cpp | 345 ++++++++++----------- .../inputflinger/tests/fuzzers/MapperHelpers.h | 2 +- 21 files changed, 282 insertions(+), 292 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/DisplayViewport.h b/include/input/DisplayViewport.h index 98a18c9560..7457496784 100644 --- a/include/input/DisplayViewport.h +++ b/include/input/DisplayViewport.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -29,13 +30,6 @@ using android::base::StringPrintf; namespace android { -enum { - DISPLAY_ORIENTATION_0 = 0, - DISPLAY_ORIENTATION_90 = 1, - DISPLAY_ORIENTATION_180 = 2, - DISPLAY_ORIENTATION_270 = 3 -}; - /** * Describes the different type of viewports supported by input flinger. * Keep in sync with values in InputManagerService.java. @@ -54,7 +48,7 @@ enum class ViewportType : int32_t { */ struct DisplayViewport { int32_t displayId; // -1 if invalid - int32_t orientation; + ui::Rotation orientation; int32_t logicalLeft; int32_t logicalTop; int32_t logicalRight; @@ -74,7 +68,7 @@ struct DisplayViewport { DisplayViewport() : displayId(ADISPLAY_ID_NONE), - orientation(DISPLAY_ORIENTATION_0), + orientation(ui::ROTATION_0), logicalLeft(0), logicalTop(0), logicalRight(0), @@ -111,7 +105,7 @@ struct DisplayViewport { void setNonDisplayViewport(int32_t width, int32_t height) { displayId = ADISPLAY_ID_NONE; - orientation = DISPLAY_ORIENTATION_0; + orientation = ui::ROTATION_0; logicalLeft = 0; logicalTop = 0; logicalRight = width; diff --git a/include/input/Input.h b/include/input/Input.h index d298d817f5..07a566a63c 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -577,7 +577,7 @@ public: inline const ui::Transform& getTransform() const { return mTransform; } - int getSurfaceRotation() const; + int32_t getSurfaceRotation() const; inline float getXPrecision() const { return mXPrecision; } diff --git a/include/input/TouchVideoFrame.h b/include/input/TouchVideoFrame.h index a616a95ab1..1e4f6e7a4c 100644 --- a/include/input/TouchVideoFrame.h +++ b/include/input/TouchVideoFrame.h @@ -16,6 +16,8 @@ #pragma once +#include + #include #include #include @@ -58,7 +60,7 @@ public: * Rotate the video frame. * The rotation value is an enum from ui/Rotation.h */ - void rotate(int32_t orientation); + void rotate(ui::Rotation orientation); private: uint32_t mHeight; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 3685f54a53..162b757743 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -552,19 +552,19 @@ void MotionEvent::addSample( &pointerCoords[getPointerCount()]); } -int MotionEvent::getSurfaceRotation() const { +int32_t MotionEvent::getSurfaceRotation() const { // The surface rotation is the rotation from the window's coordinate space to that of the // display. Since the event's transform takes display space coordinates to window space, the // returned surface rotation is the inverse of the rotation for the surface. switch (mTransform.getOrientation()) { case ui::Transform::ROT_0: - return DISPLAY_ORIENTATION_0; + return static_cast(ui::ROTATION_0); case ui::Transform::ROT_90: - return DISPLAY_ORIENTATION_270; + return static_cast(ui::ROTATION_270); case ui::Transform::ROT_180: - return DISPLAY_ORIENTATION_180; + return static_cast(ui::ROTATION_180); case ui::Transform::ROT_270: - return DISPLAY_ORIENTATION_90; + return static_cast(ui::ROTATION_90); default: return -1; } diff --git a/libs/input/TouchVideoFrame.cpp b/libs/input/TouchVideoFrame.cpp index c62e0985f1..c9393f4451 100644 --- a/libs/input/TouchVideoFrame.cpp +++ b/libs/input/TouchVideoFrame.cpp @@ -40,17 +40,20 @@ const std::vector& TouchVideoFrame::getData() const { return mData; } const struct timeval& TouchVideoFrame::getTimestamp() const { return mTimestamp; } -void TouchVideoFrame::rotate(int32_t orientation) { +void TouchVideoFrame::rotate(ui::Rotation orientation) { switch (orientation) { - case DISPLAY_ORIENTATION_90: + case ui::ROTATION_90: rotateQuarterTurn(false /*clockwise*/); break; - case DISPLAY_ORIENTATION_180: + case ui::ROTATION_180: rotate180(); break; - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_270: rotateQuarterTurn(true /*clockwise*/); break; + case ui::ROTATION_0: + // No need to rotate if there's no rotation. + break; } } diff --git a/libs/input/tests/TouchVideoFrame_test.cpp b/libs/input/tests/TouchVideoFrame_test.cpp index 654b236bda..081a995a6f 100644 --- a/libs/input/tests/TouchVideoFrame_test.cpp +++ b/libs/input/tests/TouchVideoFrame_test.cpp @@ -73,38 +73,38 @@ TEST(TouchVideoFrame, Equality) { TEST(TouchVideoFrame, Rotate90_0x0) { TouchVideoFrame frame(0, 0, {}, TIMESTAMP); TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_90); + frame.rotate(ui::ROTATION_90); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate90_1x1) { TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_90); + frame.rotate(ui::ROTATION_90); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate90_2x2) { TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); TouchVideoFrame frameRotated(2, 2, {2, 4, 1, 3}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_90); + frame.rotate(ui::ROTATION_90); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate90_3x2) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameRotated(2, 3, {2, 4, 6, 1, 3, 5}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_90); + frame.rotate(ui::ROTATION_90); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate90_3x2_4times) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_90); - frame.rotate(DISPLAY_ORIENTATION_90); - frame.rotate(DISPLAY_ORIENTATION_90); - frame.rotate(DISPLAY_ORIENTATION_90); + frame.rotate(ui::ROTATION_90); + frame.rotate(ui::ROTATION_90); + frame.rotate(ui::ROTATION_90); + frame.rotate(ui::ROTATION_90); ASSERT_EQ(frame, frameOriginal); } @@ -113,43 +113,43 @@ TEST(TouchVideoFrame, Rotate90_3x2_4times) { TEST(TouchVideoFrame, Rotate180_0x0) { TouchVideoFrame frame(0, 0, {}, TIMESTAMP); TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate180_1x1) { TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate180_2x2) { TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); TouchVideoFrame frameRotated(2, 2, {4, 3, 2, 1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate180_3x2) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameRotated(3, 2, {6, 5, 4, 3, 2, 1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate180_3x2_2times) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameOriginal); } TEST(TouchVideoFrame, Rotate180_3x3) { TouchVideoFrame frame(3, 3, {1, 2, 3, 4, 5, 6, 7, 8, 9}, TIMESTAMP); TouchVideoFrame frameRotated(3, 3, {9, 8, 7, 6, 5, 4, 3, 2, 1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_180); + frame.rotate(ui::ROTATION_180); ASSERT_EQ(frame, frameRotated); } @@ -158,38 +158,38 @@ TEST(TouchVideoFrame, Rotate180_3x3) { TEST(TouchVideoFrame, Rotate270_0x0) { TouchVideoFrame frame(0, 0, {}, TIMESTAMP); TouchVideoFrame frameRotated(0, 0, {}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_270); + frame.rotate(ui::ROTATION_270); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate270_1x1) { TouchVideoFrame frame(1, 1, {1}, TIMESTAMP); TouchVideoFrame frameRotated(1, 1, {1}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_270); + frame.rotate(ui::ROTATION_270); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate270_2x2) { TouchVideoFrame frame(2, 2, {1, 2, 3, 4}, TIMESTAMP); TouchVideoFrame frameRotated(2, 2, {3, 1, 4, 2}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_270); + frame.rotate(ui::ROTATION_270); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate270_3x2) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameRotated(2, 3, {5, 3, 1, 6, 4, 2}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_270); + frame.rotate(ui::ROTATION_270); ASSERT_EQ(frame, frameRotated); } TEST(TouchVideoFrame, Rotate270_3x2_4times) { TouchVideoFrame frame(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); TouchVideoFrame frameOriginal(3, 2, {1, 2, 3, 4, 5, 6}, TIMESTAMP); - frame.rotate(DISPLAY_ORIENTATION_270); - frame.rotate(DISPLAY_ORIENTATION_270); - frame.rotate(DISPLAY_ORIENTATION_270); - frame.rotate(DISPLAY_ORIENTATION_270); + frame.rotate(ui::ROTATION_270); + frame.rotate(ui::ROTATION_270); + frame.rotate(ui::ROTATION_270); + frame.rotate(ui::ROTATION_270); ASSERT_EQ(frame, frameOriginal); } diff --git a/libs/ui/include/ui/Rotation.h b/libs/ui/include/ui/Rotation.h index 83d431dea3..c1d60f4f6c 100644 --- a/libs/ui/include/ui/Rotation.h +++ b/libs/ui/include/ui/Rotation.h @@ -20,7 +20,14 @@ namespace android::ui { -enum class Rotation { Rotation0 = 0, Rotation90 = 1, Rotation180 = 2, Rotation270 = 3 }; +enum class Rotation { + Rotation0 = 0, + Rotation90 = 1, + Rotation180 = 2, + Rotation270 = 3, + + ftl_last = Rotation270 +}; // Equivalent to Surface.java constants. constexpr auto ROTATION_0 = Rotation::Rotation0; diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index 3b0f2ac5a2..6d6cefb0c0 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -395,7 +396,7 @@ public: /* Gets the affine calibration associated with the specified device. */ virtual TouchAffineTransformation getTouchAffineTransformation( - const std::string& inputDeviceDescriptor, int32_t surfaceRotation) = 0; + const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) = 0; /* Notifies the input reader policy that a stylus gesture has started. */ virtual void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) = 0; }; diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index a1a2af9500..13e4d0cfbe 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -227,7 +227,7 @@ std::list CursorInputMapper::configure(nsecs_t when, mDisplayId = mPointerController->getDisplayId(); } - mOrientation = DISPLAY_ORIENTATION_0; + mOrientation = ui::ROTATION_0; const bool isOrientedDevice = (mParameters.orientationAware && mParameters.hasAssociatedDisplay); // InputReader works in the un-rotated display coordinate space, so we don't need to do diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h index 20746e5bb0..939cceb6b0 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.h +++ b/services/inputflinger/reader/mapper/CursorInputMapper.h @@ -22,6 +22,7 @@ #include #include +#include namespace android { @@ -115,7 +116,7 @@ private: // ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e. // std::nullopt), all events will be ignored. std::optional mDisplayId; - int32_t mOrientation; + ui::Rotation mOrientation; std::shared_ptr mPointerController; diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index da9413e4ca..44f0dfe3b6 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -20,11 +20,13 @@ #include "KeyboardInputMapper.h" +#include + namespace android { // --- Static Definitions --- -static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { +static int32_t rotateKeyCode(int32_t keyCode, ui::Rotation orientation) { static constexpr int32_t KEYCODE_ROTATION_MAP[][4] = { // key codes enumerated counter-clockwise with the original (unrotated) key first // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation @@ -42,11 +44,10 @@ static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { AKEYCODE_SYSTEM_NAVIGATION_RIGHT, AKEYCODE_SYSTEM_NAVIGATION_UP}, }; - LOG_ALWAYS_FATAL_IF(orientation < 0 || orientation > 3, "Invalid orientation: %d", orientation); - if (orientation != DISPLAY_ORIENTATION_0) { + if (orientation != ui::ROTATION_0) { for (const auto& rotation : KEYCODE_ROTATION_MAP) { - if (rotation[DISPLAY_ORIENTATION_0] == keyCode) { - return rotation[orientation]; + if (rotation[static_cast(ui::ROTATION_0)] == keyCode) { + return rotation[static_cast(orientation)]; } } } @@ -100,11 +101,11 @@ uint32_t KeyboardInputMapper::getSources() const { return mSource; } -int32_t KeyboardInputMapper::getOrientation() { +ui::Rotation KeyboardInputMapper::getOrientation() { if (mViewport) { return mViewport->orientation; } - return DISPLAY_ORIENTATION_0; + return ui::ROTATION_0; } int32_t KeyboardInputMapper::getDisplayId() { diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h index 11d5ad26e8..0526fd89de 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h @@ -82,7 +82,7 @@ private: void configureParameters(); void dumpParameters(std::string& dump) const; - int32_t getOrientation(); + ui::Rotation getOrientation(); int32_t getDisplayId(); [[nodiscard]] std::list processKey(nsecs_t when, nsecs_t readTime, bool down, diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index 06d4dc342d..19a79d7751 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -25,7 +25,7 @@ namespace android { RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDeviceContext& deviceContext) - : InputMapper(deviceContext), mOrientation(DISPLAY_ORIENTATION_0) { + : InputMapper(deviceContext), mOrientation(ui::ROTATION_0) { mSource = AINPUT_SOURCE_ROTARY_ENCODER; } @@ -73,7 +73,7 @@ std::list RotaryEncoderInputMapper::configure(nsecs_t when, if (internalViewport) { mOrientation = internalViewport->orientation; } else { - mOrientation = DISPLAY_ORIENTATION_0; + mOrientation = ui::ROTATION_0; } } return out; @@ -107,7 +107,7 @@ std::list RotaryEncoderInputMapper::sync(nsecs_t when, nsecs_t readT // This is not a pointer, so it's not associated with a display. int32_t displayId = ADISPLAY_ID_NONE; - if (mOrientation == DISPLAY_ORIENTATION_180) { + if (mOrientation == ui::ROTATION_180) { scroll = -scroll; } diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h index f4352e76a0..cb5fd88209 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h @@ -16,6 +16,8 @@ #pragma once +#include + #include "CursorScrollAccumulator.h" #include "InputMapper.h" @@ -40,7 +42,7 @@ private: int32_t mSource; float mScalingFactor; - int32_t mOrientation; + ui::Rotation mOrientation; [[nodiscard]] std::list sync(nsecs_t when, nsecs_t readTime); }; diff --git a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h index d8a4d34d20..1c3ca975ac 100644 --- a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h +++ b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h @@ -18,6 +18,7 @@ #include #include +#include #include "EventHub.h" #include "InputListener.h" @@ -27,32 +28,32 @@ namespace android { // --- Static Definitions --- -static int32_t getInverseRotation(int32_t orientation) { +static ui::Rotation getInverseRotation(ui::Rotation orientation) { switch (orientation) { - case DISPLAY_ORIENTATION_90: - return DISPLAY_ORIENTATION_270; - case DISPLAY_ORIENTATION_270: - return DISPLAY_ORIENTATION_90; + case ui::ROTATION_90: + return ui::ROTATION_270; + case ui::ROTATION_270: + return ui::ROTATION_90; default: return orientation; } } -static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { +static void rotateDelta(ui::Rotation orientation, float* deltaX, float* deltaY) { float temp; switch (orientation) { - case DISPLAY_ORIENTATION_90: + case ui::ROTATION_90: temp = *deltaX; *deltaX = *deltaY; *deltaY = -temp; break; - case DISPLAY_ORIENTATION_180: + case ui::ROTATION_180: *deltaX = -*deltaX; *deltaY = -*deltaY; break; - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_270: temp = *deltaX; *deltaX = -*deltaY; *deltaY = temp; diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 5631a10253..cefc44ef7a 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -27,6 +27,7 @@ #include "CursorScrollAccumulator.h" #include "TouchButtonAccumulator.h" #include "TouchCursorInputMapperCommon.h" +#include "ui/Rotation.h" namespace android { @@ -81,16 +82,14 @@ inline static int32_t signExtendNybble(int32_t value) { } static std::tuple getNaturalDisplayInfo( - const DisplayViewport& viewport, int32_t naturalOrientation) { - const auto rotation = ui::toRotation(naturalOrientation); - + const DisplayViewport& viewport, ui::Rotation naturalOrientation) { ui::Size rotatedDisplaySize{viewport.deviceWidth, viewport.deviceHeight}; - if (rotation == ui::ROTATION_90 || rotation == ui::ROTATION_270) { + if (naturalOrientation == ui::ROTATION_90 || naturalOrientation == ui::ROTATION_270) { std::swap(rotatedDisplaySize.width, rotatedDisplaySize.height); } - ui::Transform rotate(ui::Transform::toRotationFlags(rotation), rotatedDisplaySize.width, - rotatedDisplaySize.height); + ui::Transform rotate(ui::Transform::toRotationFlags(naturalOrientation), + rotatedDisplaySize.width, rotatedDisplaySize.height); Rect physicalFrame{viewport.physicalLeft, viewport.physicalTop, viewport.physicalRight, viewport.physicalBottom}; @@ -133,7 +132,7 @@ TouchInputMapper::TouchInputMapper(InputDeviceContext& deviceContext) mTouchButtonAccumulator(deviceContext), mSource(0), mDeviceMode(DeviceMode::DISABLED), - mInputDeviceOrientation(DISPLAY_ORIENTATION_0) {} + mInputDeviceOrientation(ui::ROTATION_0) {} TouchInputMapper::~TouchInputMapper() {} @@ -424,18 +423,18 @@ void TouchInputMapper::configureParameters() { getDeviceContext().getConfiguration().tryGetProperty("touch.orientationAware", mParameters.orientationAware); - mParameters.orientation = Parameters::Orientation::ORIENTATION_0; + mParameters.orientation = ui::ROTATION_0; std::string orientationString; if (getDeviceContext().getConfiguration().tryGetProperty("touch.orientation", orientationString)) { if (mParameters.deviceType != Parameters::DeviceType::TOUCH_SCREEN) { ALOGW("The configuration 'touch.orientation' is only supported for touchscreens."); } else if (orientationString == "ORIENTATION_90") { - mParameters.orientation = Parameters::Orientation::ORIENTATION_90; + mParameters.orientation = ui::ROTATION_90; } else if (orientationString == "ORIENTATION_180") { - mParameters.orientation = Parameters::Orientation::ORIENTATION_180; + mParameters.orientation = ui::ROTATION_180; } else if (orientationString == "ORIENTATION_270") { - mParameters.orientation = Parameters::Orientation::ORIENTATION_270; + mParameters.orientation = ui::ROTATION_270; } else if (orientationString != "ORIENTATION_0") { ALOGW("Invalid value for touch.orientation: '%s'", orientationString.c_str()); } @@ -812,8 +811,8 @@ void TouchInputMapper::initializeOrientedRanges() { // Note that the maximum value reported is an inclusive maximum value so it is one // unit less than the total width or height of the display. switch (mInputDeviceOrientation) { - case DISPLAY_ORIENTATION_90: - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_90: + case ui::ROTATION_270: mOrientedXPrecision = mYPrecision; mOrientedYPrecision = mXPrecision; @@ -923,8 +922,8 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) // Apply the inverse of the input device orientation so that the input device is // configured in the same orientation as the viewport. The input device orientation will // be re-applied by mInputDeviceOrientation. - const int32_t naturalDeviceOrientation = - (mViewport.orientation - static_cast(mParameters.orientation) + 4) % 4; + const ui::Rotation naturalDeviceOrientation = + mViewport.orientation - mParameters.orientation; std::tie(mDisplayBounds, mPhysicalFrameInDisplay) = getNaturalDisplayInfo(mViewport, naturalDeviceOrientation); @@ -935,7 +934,7 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) // when the display rotation is applied later as a part of the per-window transform, we // get the expected screen coordinates. mInputDeviceOrientation = mParameters.orientationAware - ? DISPLAY_ORIENTATION_0 + ? ui::ROTATION_0 : getInverseRotation(mViewport.orientation); // For orientation-aware devices that work in the un-rotated coordinate space, the // viewport update should be skipped if it is only a change in the orientation. @@ -943,12 +942,11 @@ void TouchInputMapper::configureInputDevice(nsecs_t when, bool* outResetNeeded) mDisplayBounds == oldDisplayBounds && viewportOrientationChanged; // Apply the input device orientation for the device. - mInputDeviceOrientation = - (mInputDeviceOrientation + static_cast(mParameters.orientation)) % 4; + mInputDeviceOrientation = mInputDeviceOrientation + mParameters.orientation; } else { mDisplayBounds = rawSize; mPhysicalFrameInDisplay = Rect{mDisplayBounds}; - mInputDeviceOrientation = DISPLAY_ORIENTATION_0; + mInputDeviceOrientation = ui::ROTATION_0; } } @@ -2349,7 +2347,7 @@ void TouchInputMapper::cookPointerData() { float left, top, right, bottom; switch (mInputDeviceOrientation) { - case DISPLAY_ORIENTATION_90: + case ui::ROTATION_90: left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale; right = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale; bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; @@ -2360,7 +2358,7 @@ void TouchInputMapper::cookPointerData() { (mOrientedRanges.orientation->max - mOrientedRanges.orientation->min); } break; - case DISPLAY_ORIENTATION_180: + case ui::ROTATION_180: left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale; right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; @@ -2371,7 +2369,7 @@ void TouchInputMapper::cookPointerData() { (mOrientedRanges.orientation->max - mOrientedRanges.orientation->min); } break; - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_270: left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale; right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale; @@ -3805,19 +3803,19 @@ void TouchInputMapper::rotateAndScale(float& x, float& y) const { // 180 - reverse x, y. // 270 - swap x/y and reverse x. switch (mInputDeviceOrientation) { - case DISPLAY_ORIENTATION_0: + case ui::ROTATION_0: x = xScaled; y = yScaled; break; - case DISPLAY_ORIENTATION_90: + case ui::ROTATION_90: y = xScaledMax; x = yScaled; break; - case DISPLAY_ORIENTATION_180: + case ui::ROTATION_180: x = xScaledMax; y = yScaledMax; break; - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_270: y = xScaled; x = yScaledMax; break; diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 3962b2a2fc..34ba62515f 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include "CursorButtonAccumulator.h" #include "CursorScrollAccumulator.h" @@ -218,15 +219,7 @@ protected: bool associatedDisplayIsExternal; bool orientationAware; - enum class Orientation : int32_t { - ORIENTATION_0 = DISPLAY_ORIENTATION_0, - ORIENTATION_90 = DISPLAY_ORIENTATION_90, - ORIENTATION_180 = DISPLAY_ORIENTATION_180, - ORIENTATION_270 = DISPLAY_ORIENTATION_270, - - ftl_last = ORIENTATION_270 - }; - Orientation orientation; + ui::Rotation orientation; bool hasButtonUnderPad; std::string uniqueDisplayId; @@ -424,7 +417,7 @@ private: // The orientation of the input device relative to that of the display panel. It specifies // the rotation of the input device coordinates required to produce the display panel // orientation, so it will depend on whether the device is orientation aware. - int32_t mInputDeviceOrientation; + ui::Rotation mInputDeviceOrientation; // Translation and scaling factors, orientation-independent. float mXScale; diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp index 5c6a1b8f6d..3af4298434 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp +++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp @@ -20,6 +20,7 @@ #include #include "TestConstants.h" +#include "ui/Rotation.h" namespace android { @@ -76,12 +77,11 @@ void FakeInputReaderPolicy::addDisplayViewport(DisplayViewport viewport) { } void FakeInputReaderPolicy::addDisplayViewport(int32_t displayId, int32_t width, int32_t height, - int32_t orientation, bool isActive, + ui::Rotation orientation, bool isActive, const std::string& uniqueId, std::optional physicalPort, ViewportType type) { - const bool isRotated = - (orientation == DISPLAY_ORIENTATION_90 || orientation == DISPLAY_ORIENTATION_270); + const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270; DisplayViewport v; v.displayId = displayId; v.orientation = orientation; @@ -153,7 +153,7 @@ const std::vector& FakeInputReaderPolicy::getInputDevices() con } TouchAffineTransformation FakeInputReaderPolicy::getTouchAffineTransformation( - const std::string& inputDeviceDescriptor, int32_t surfaceRotation) { + const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) { return transform; } diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.h b/services/inputflinger/tests/FakeInputReaderPolicy.h index 65fe08f87b..c16cda404e 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.h +++ b/services/inputflinger/tests/FakeInputReaderPolicy.h @@ -49,8 +49,8 @@ public: std::optional getDisplayViewportByType(ViewportType type) const; std::optional getDisplayViewportByPort(uint8_t displayPort) const; void addDisplayViewport(DisplayViewport viewport); - void addDisplayViewport(int32_t displayId, int32_t width, int32_t height, int32_t orientation, - bool isActive, const std::string& uniqueId, + void addDisplayViewport(int32_t displayId, int32_t width, int32_t height, + ui::Rotation orientation, bool isActive, const std::string& uniqueId, std::optional physicalPort, ViewportType type); bool updateViewport(const DisplayViewport& viewport); void addExcludedDeviceName(const std::string& deviceName); @@ -63,7 +63,7 @@ public: const InputReaderConfiguration* getReaderConfiguration() const; const std::vector& getInputDevices() const; TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor, - int32_t surfaceRotation); + ui::Rotation surfaceRotation); void setTouchAffineTransformation(const TouchAffineTransformation t); PointerCaptureRequest setPointerCapture(bool enabled); void setShowTouches(bool enabled); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index c72d01fad8..01539671d8 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -36,8 +36,10 @@ #include #include #include +#include #include #include +#include #include #include "FakeEventHub.h" @@ -111,12 +113,12 @@ const std::unordered_map LIGHT_COLORS = {{"red", LightC {"green", LightColor::GREEN}, {"blue", LightColor::BLUE}}; -static int32_t getInverseRotation(int32_t orientation) { +static ui::Rotation getInverseRotation(ui::Rotation orientation) { switch (orientation) { - case DISPLAY_ORIENTATION_90: - return DISPLAY_ORIENTATION_270; - case DISPLAY_ORIENTATION_270: - return DISPLAY_ORIENTATION_90; + case ui::ROTATION_90: + return ui::ROTATION_270; + case ui::ROTATION_270: + return ui::ROTATION_90; default: return orientation; } @@ -479,9 +481,8 @@ TEST_F(InputReaderPolicyTest, Viewports_GetCleared) { ASSERT_FALSE(internalViewport); // Add an internal viewport, then clear it - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId, NO_PORT, - ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, uniqueId, NO_PORT, ViewportType::INTERNAL); // Check matching by uniqueId internalViewport = mFakePolicy->getDisplayViewportByUniqueId(uniqueId); @@ -510,21 +511,21 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByType) { constexpr int32_t virtualDisplayId2 = 3; // Add an internal viewport - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, internalUniqueId, - NO_PORT, ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, internalUniqueId, NO_PORT, + ViewportType::INTERNAL); // Add an external viewport - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, externalUniqueId, - NO_PORT, ViewportType::EXTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, externalUniqueId, NO_PORT, + ViewportType::EXTERNAL); // Add an virtual viewport mFakePolicy->addDisplayViewport(virtualDisplayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, virtualUniqueId1, - NO_PORT, ViewportType::VIRTUAL); + ui::ROTATION_0, true /*isActive*/, virtualUniqueId1, NO_PORT, + ViewportType::VIRTUAL); // Add another virtual viewport mFakePolicy->addDisplayViewport(virtualDisplayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, virtualUniqueId2, - NO_PORT, ViewportType::VIRTUAL); + ui::ROTATION_0, true /*isActive*/, virtualUniqueId2, NO_PORT, + ViewportType::VIRTUAL); // Check matching by type for internal std::optional internalViewport = @@ -572,13 +573,11 @@ TEST_F(InputReaderPolicyTest, Viewports_TwoOfSameType) { for (const ViewportType& type : types) { mFakePolicy->clearViewports(); // Add a viewport - mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, - NO_PORT, type); + mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, uniqueId1, NO_PORT, type); // Add another viewport - mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, - NO_PORT, type); + mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, uniqueId2, NO_PORT, type); // Check that correct display viewport was returned by comparing the display IDs. std::optional viewport1 = @@ -618,10 +617,10 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { // Add the default display first and ensure it gets returned. mFakePolicy->clearViewports(); mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, NO_PORT, + ui::ROTATION_0, true /*isActive*/, uniqueId1, NO_PORT, ViewportType::INTERNAL); mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, NO_PORT, + ui::ROTATION_0, true /*isActive*/, uniqueId2, NO_PORT, ViewportType::INTERNAL); std::optional viewport = @@ -633,10 +632,10 @@ TEST_F(InputReaderPolicyTest, Viewports_ByTypeReturnsDefaultForInternal) { // Add the default display second to make sure order doesn't matter. mFakePolicy->clearViewports(); mFakePolicy->addDisplayViewport(nonDefaultDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, NO_PORT, + ui::ROTATION_0, true /*isActive*/, uniqueId2, NO_PORT, ViewportType::INTERNAL); mFakePolicy->addDisplayViewport(ADISPLAY_ID_DEFAULT, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, NO_PORT, + ui::ROTATION_0, true /*isActive*/, uniqueId1, NO_PORT, ViewportType::INTERNAL); viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL); @@ -660,13 +659,11 @@ TEST_F(InputReaderPolicyTest, Viewports_GetByPort) { mFakePolicy->clearViewports(); // Add a viewport that's associated with some display port that's not of interest. - mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId1, hdmi3, - type); + mFakePolicy->addDisplayViewport(displayId1, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, uniqueId1, hdmi3, type); // Add another viewport, connected to HDMI1 port - mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, uniqueId2, hdmi1, - type); + mFakePolicy->addDisplayViewport(displayId2, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, uniqueId2, hdmi1, type); // Check that correct display viewport was returned by comparing the display ports. std::optional hdmi1Viewport = mFakePolicy->getDisplayViewportByPort(hdmi1); @@ -1119,11 +1116,10 @@ TEST_F(InputReaderTest, Device_CanDispatchToDisplay) { // Add default and second display. mFakePolicy->clearViewports(); - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, "local:0", NO_PORT, - ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, "local:0", NO_PORT, ViewportType::INTERNAL); mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, "local:1", hdmi1, + ui::ROTATION_0, true /*isActive*/, "local:1", hdmi1, ViewportType::EXTERNAL); mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO); mReader->loopOnce(); @@ -1582,9 +1578,8 @@ protected: #endif InputReaderIntegrationTest::SetUp(); // At least add an internal display. - setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, UNIQUE_ID, NO_PORT, - ViewportType::INTERNAL); + setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); mDevice = createUinputDevice(Rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT)); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged()); @@ -1595,7 +1590,7 @@ protected: } void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, - int32_t orientation, const std::string& uniqueId, + ui::Rotation orientation, const std::string& uniqueId, std::optional physicalPort, ViewportType viewportType) { mFakePolicy->addDisplayViewport(displayId, width, height, orientation, true /*isActive*/, @@ -2533,7 +2528,7 @@ TEST_F(InputDeviceTest, Configure_AssignsDisplayPort) { // Prepare displays. mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, UNIQUE_ID, hdmi, + ui::ROTATION_0, true /*isActive*/, UNIQUE_ID, hdmi, ViewportType::INTERNAL); unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), InputReaderConfiguration::CHANGE_DISPLAY_INFO); @@ -2568,7 +2563,7 @@ TEST_F(InputDeviceTest, Configure_AssignsDisplayUniqueId) { // Device should be enabled when a display is found. mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, + ui::ROTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), InputReaderConfiguration::CHANGE_DISPLAY_INFO); @@ -2594,7 +2589,7 @@ TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) { mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, DISPLAY_UNIQUE_ID); mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, + ui::ROTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), InputReaderConfiguration::CHANGE_DISPLAY_INFO); @@ -2713,8 +2708,9 @@ protected: } void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height, - int32_t orientation, const std::string& uniqueId, - std::optional physicalPort, ViewportType viewportType) { + ui::Rotation orientation, const std::string& uniqueId, + std::optional physicalPort, + ViewportType viewportType) { mFakePolicy->addDisplayViewport(displayId, width, height, orientation, true /*isActive*/, uniqueId, physicalPort, viewportType); configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); @@ -2744,7 +2740,7 @@ protected: void resetMapper(InputMapper& mapper, nsecs_t when) { const auto resetArgs = mapper.reset(when); - for (const auto args : resetArgs) { + for (const auto& args : resetArgs) { mFakeListener->notify(args); } // Loop the reader to flush the input listener queue. @@ -3069,7 +3065,7 @@ class KeyboardInputMapperTest : public InputMapperTest { protected: const std::string UNIQUE_ID = "local:0"; - void prepareDisplay(int32_t orientation); + void prepareDisplay(ui::Rotation orientation); void testDPadKeyRotation(KeyboardInputMapper& mapper, int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode, @@ -3079,7 +3075,7 @@ protected: /* Similar to setDisplayInfoAndReconfigure, but pre-populates all parameters except for the * orientation. */ -void KeyboardInputMapperTest::prepareDisplay(int32_t orientation) { +void KeyboardInputMapperTest::prepareDisplay(ui::Rotation orientation) { setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); } @@ -3291,7 +3287,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateD addMapperAndConfigure(AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP)); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, @@ -3313,7 +3309,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { addMapperAndConfigure(AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); ASSERT_NO_FATAL_FAILURE( testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP, DISPLAY_ID)); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT, @@ -3324,7 +3320,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { AKEYCODE_DPAD_LEFT, DISPLAY_ID)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); ASSERT_NO_FATAL_FAILURE( testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, DISPLAY_ID)); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT, @@ -3335,7 +3331,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { AKEYCODE_DPAD_DOWN, DISPLAY_ID)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_180); + prepareDisplay(ui::ROTATION_180); ASSERT_NO_FATAL_FAILURE( testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN, DISPLAY_ID)); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT, @@ -3346,7 +3342,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { AKEYCODE_DPAD_RIGHT, DISPLAY_ID)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_270); + prepareDisplay(ui::ROTATION_270); ASSERT_NO_FATAL_FAILURE( testDPadKeyRotation(mapper, KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT, DISPLAY_ID)); ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper, KEY_RIGHT, AKEYCODE_DPAD_RIGHT, @@ -3360,7 +3356,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { // in the key up as we did in the key down. NotifyKeyArgs args; clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_270); + prepareDisplay(ui::ROTATION_270); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action); @@ -3368,7 +3364,7 @@ TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) { ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_180); + prepareDisplay(ui::ROTATION_180); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action); @@ -3393,7 +3389,7 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_NotOrientationAware ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); ASSERT_EQ(ADISPLAY_ID_NONE, args.displayId); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 0); @@ -3415,7 +3411,7 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { // Display id should be ADISPLAY_ID_NONE without any display configuration. // ^--- already checked by the previous test - setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0, + setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); @@ -3425,7 +3421,7 @@ TEST_F(KeyboardInputMapperTest, DisplayIdConfigurationChange_OrientationAware) { constexpr int32_t newDisplayId = 2; clearViewports(); - setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0, + setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, KEY_UP, 1); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args)); @@ -3635,9 +3631,9 @@ TEST_F(KeyboardInputMapperTest, Configure_AssignsDisplayPort) { // Prepare second display. constexpr int32_t newDisplayId = 2; - setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0, + setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, UNIQUE_ID, hdmi1, ViewportType::INTERNAL); - setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0, + setDisplayInfoAndReconfigure(newDisplayId, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, SECONDARY_UNIQUE_ID, hdmi2, ViewportType::EXTERNAL); // Default device will reconfigure above, need additional reconfiguration for another device. unused += device2->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), @@ -3968,14 +3964,14 @@ protected: void testMotionRotation(CursorInputMapper& mapper, int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY); - void prepareDisplay(int32_t orientation) { + void prepareDisplay(ui::Rotation orientation) { setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation, DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); } void prepareSecondaryDisplay() { setDisplayInfoAndReconfigure(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, SECONDARY_DISPLAY_UNIQUE_ID, NO_PORT, + ui::ROTATION_0, SECONDARY_DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::EXTERNAL); } @@ -4260,7 +4256,7 @@ TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldNotRotateMotion addConfigurationProperty("cursor.orientationAware", "1"); CursorInputMapper& mapper = addMapperAndConfigure(); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); @@ -4279,7 +4275,7 @@ TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldRotateMotion CursorInputMapper& mapper = addMapperAndConfigure(); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, 1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, 1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 1, 0)); @@ -4290,7 +4286,7 @@ TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldRotateMotion ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, 1)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, -1, 0)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, 1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, 1)); @@ -4301,7 +4297,7 @@ TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldRotateMotion ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, -1, -1)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_180); + prepareDisplay(ui::ROTATION_180); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 0, -1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, -1, -1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, -1, 0)); @@ -4312,7 +4308,7 @@ TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldRotateMotion ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, 1, 1, -1)); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_270); + prepareDisplay(ui::ROTATION_270); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 0, 1, 1, 0)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 1, 1, -1)); ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, 1, 0, 0, -1)); @@ -4776,7 +4772,7 @@ TEST_F(CursorInputMapperTest, PointerCaptureDisablesOrientationChanges) { ASSERT_EQ(DEVICE_ID, resetArgs.deviceId); // Ensure the display is rotated. - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); NotifyMotionArgs args; @@ -4812,7 +4808,7 @@ TEST_F(CursorInputMapperTest, ConfigureDisplayId_NoAssociatedViewport) { CursorInputMapper& mapper = addMapperAndConfigure(); // Set up the default display. - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); // Set up the secondary display as the display on which the pointer should be shown. // The InputDevice is not associated with any display. @@ -4839,7 +4835,7 @@ TEST_F(CursorInputMapperTest, ConfigureDisplayId_WithAssociatedViewport) { CursorInputMapper& mapper = addMapperAndConfigure(); // Set up the default display. - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); // Set up the secondary display as the display on which the pointer should be shown, // and associate the InputDevice with the secondary display. @@ -4866,7 +4862,7 @@ TEST_F(CursorInputMapperTest, ConfigureDisplayId_IgnoresEventsForMismatchedPoint CursorInputMapper& mapper = addMapperAndConfigure(); // Set up the default display as the display on which the pointer should be shown. - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); mFakePolicy->setDefaultPointerDisplayId(DISPLAY_ID); // Associate the InputDevice with the secondary display. @@ -5033,9 +5029,9 @@ protected: TOOL_TYPE = 1 << 10, }; - void prepareDisplay(int32_t orientation, std::optional port = NO_PORT); + void prepareDisplay(ui::Rotation orientation, std::optional port = NO_PORT); void prepareSecondaryDisplay(ViewportType type, std::optional port = NO_PORT); - void prepareVirtualDisplay(int32_t orientation); + void prepareVirtualDisplay(ui::Rotation orientation); void prepareVirtualKeys(); void prepareLocationCalibration(); int32_t toRawX(float displayX); @@ -5089,17 +5085,17 @@ const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = { { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 }, }; -void TouchInputMapperTest::prepareDisplay(int32_t orientation, std::optional port) { +void TouchInputMapperTest::prepareDisplay(ui::Rotation orientation, std::optional port) { setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation, UNIQUE_ID, port, ViewportType::INTERNAL); } void TouchInputMapperTest::prepareSecondaryDisplay(ViewportType type, std::optional port) { setDisplayInfoAndReconfigure(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, SECONDARY_UNIQUE_ID, port, type); + ui::ROTATION_0, SECONDARY_UNIQUE_ID, port, type); } -void TouchInputMapperTest::prepareVirtualDisplay(int32_t orientation) { +void TouchInputMapperTest::prepareVirtualDisplay(ui::Rotation orientation) { setDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH, VIRTUAL_DISPLAY_HEIGHT, orientation, VIRTUAL_DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::VIRTUAL); @@ -5266,7 +5262,7 @@ TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_Return TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5294,7 +5290,7 @@ TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) { TEST_F(SingleTouchInputMapperTest, GetScanCodeState) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5322,7 +5318,7 @@ TEST_F(SingleTouchInputMapperTest, GetScanCodeState) { TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5337,7 +5333,7 @@ TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) { TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5387,7 +5383,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNor TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5508,7 +5504,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5583,7 +5579,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl addConfigurationProperty("touch.deviceType", "touchScreen"); addConfigurationProperty("touch.displayId", VIRTUAL_DISPLAY_UNIQUE_ID); - prepareVirtualDisplay(DISPLAY_ORIENTATION_0); + prepareVirtualDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5679,7 +5675,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); prepareVirtualKeys(); @@ -5778,7 +5774,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_DoesNotRotateMot NotifyMotionArgs args; // Rotation 90. - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); processDown(mapper, toRawX(50), toRawY(75)); processSync(mapper); @@ -5804,7 +5800,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_RotatesMotion // Rotation 0. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); processDown(mapper, toRawX(50), toRawY(75)); processSync(mapper); @@ -5818,7 +5814,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_RotatesMotion // Rotation 90. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN); processSync(mapper); @@ -5832,7 +5828,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_RotatesMotion // Rotation 180. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_180); + prepareDisplay(ui::ROTATION_180); processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN); processSync(mapper); @@ -5846,7 +5842,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_RotatesMotion // Rotation 270. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_270); + prepareDisplay(ui::ROTATION_270); processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50)); processSync(mapper); @@ -5866,7 +5862,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientation0_RotatesMotions) { addConfigurationProperty("touch.orientationAware", "1"); addConfigurationProperty("touch.orientation", "ORIENTATION_0"); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); auto& mapper = addMapperAndConfigure(); NotifyMotionArgs args; @@ -5890,7 +5886,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientation90_RotatesMotions) { addConfigurationProperty("touch.orientationAware", "1"); addConfigurationProperty("touch.orientation", "ORIENTATION_90"); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); auto& mapper = addMapperAndConfigure(); NotifyMotionArgs args; @@ -5914,7 +5910,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientation180_RotatesMotions) { addConfigurationProperty("touch.orientationAware", "1"); addConfigurationProperty("touch.orientation", "ORIENTATION_180"); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); auto& mapper = addMapperAndConfigure(); NotifyMotionArgs args; @@ -5938,7 +5934,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientation270_RotatesMotions) { addConfigurationProperty("touch.orientationAware", "1"); addConfigurationProperty("touch.orientation", "ORIENTATION_270"); clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); auto& mapper = addMapperAndConfigure(); NotifyMotionArgs args; @@ -5969,7 +5965,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationSpecified_RotatesMotio // Orientation 90, Rotation 0. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); processDown(mapper, RAW_X_MAX - toRotatedRawX(75) + RAW_X_MIN, toRotatedRawY(50)); processSync(mapper); @@ -5983,7 +5979,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationSpecified_RotatesMotio // Orientation 90, Rotation 90. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); processDown(mapper, toRotatedRawX(50), toRotatedRawY(75)); processSync(mapper); @@ -5997,7 +5993,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationSpecified_RotatesMotio // Orientation 90, Rotation 180. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_180); + prepareDisplay(ui::ROTATION_180); processDown(mapper, toRotatedRawX(75), RAW_Y_MAX - toRotatedRawY(50) + RAW_Y_MIN); processSync(mapper); @@ -6011,7 +6007,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationSpecified_RotatesMotio // Orientation 90, Rotation 270. clearViewports(); - prepareDisplay(DISPLAY_ORIENTATION_270); + prepareDisplay(ui::ROTATION_270); processDown(mapper, RAW_X_MAX - toRotatedRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRotatedRawY(75) + RAW_Y_MIN); processSync(mapper); @@ -6027,7 +6023,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationSpecified_RotatesMotio TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6071,7 +6067,7 @@ TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) { TEST_F(SingleTouchInputMapperTest, Process_XYAxes_AffineCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareLocationCalibration(); prepareButtons(); prepareAxes(POSITION); @@ -6094,7 +6090,7 @@ TEST_F(SingleTouchInputMapperTest, Process_XYAxes_AffineCalibration) { TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6337,7 +6333,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) { TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6472,7 +6468,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOOL_FINGER, 0, AKEYCODE_UNKNOWN, 0); @@ -6544,7 +6540,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueI TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION | PRESSURE); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6615,7 +6611,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsV TEST_F(SingleTouchInputMapperTest, Reset_CancelsOngoingGesture) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION | PRESSURE); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6637,7 +6633,7 @@ TEST_F(SingleTouchInputMapperTest, Reset_CancelsOngoingGesture) { TEST_F(SingleTouchInputMapperTest, Reset_RecreatesTouchState) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION | PRESSURE); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6665,7 +6661,7 @@ TEST_F(SingleTouchInputMapperTest, Reset_RecreatesTouchState) { TEST_F(SingleTouchInputMapperTest, Process_WhenViewportDisplayIdChanged_TouchIsCanceledAndDeviceIsReset) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6693,7 +6689,7 @@ TEST_F(SingleTouchInputMapperTest, TEST_F(SingleTouchInputMapperTest, Process_WhenViewportActiveStatusChanged_TouchIsCanceledAndDeviceIsReset) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6753,7 +6749,7 @@ TEST_F(SingleTouchInputMapperTest, TEST_F(SingleTouchInputMapperTest, ButtonIsReleasedOnTouchUp) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); SingleTouchInputMapper& mapper = addMapperAndConfigure(); @@ -6796,27 +6792,25 @@ public: // The values inside DisplayViewport are expected to be pre-rotated. This updates the current // DisplayViewport to pre-rotate the values. The viewport's physical display will be set to the // rotated equivalent of the given un-rotated physical display bounds. - void configurePhysicalDisplay(int32_t orientation, Rect naturalPhysicalDisplay) { + void configurePhysicalDisplay(ui::Rotation orientation, Rect naturalPhysicalDisplay) { uint32_t inverseRotationFlags; auto width = DISPLAY_WIDTH; auto height = DISPLAY_HEIGHT; switch (orientation) { - case DISPLAY_ORIENTATION_90: + case ui::ROTATION_90: inverseRotationFlags = ui::Transform::ROT_270; std::swap(width, height); break; - case DISPLAY_ORIENTATION_180: + case ui::ROTATION_180: inverseRotationFlags = ui::Transform::ROT_180; break; - case DISPLAY_ORIENTATION_270: + case ui::ROTATION_270: inverseRotationFlags = ui::Transform::ROT_90; std::swap(width, height); break; - case DISPLAY_ORIENTATION_0: + case ui::ROTATION_0: inverseRotationFlags = ui::Transform::ROT_0; break; - default: - FAIL() << "Invalid orientation: " << orientation; } const ui::Transform rotation(inverseRotationFlags, width, height); @@ -6860,7 +6854,7 @@ public: TEST_F(TouchDisplayProjectionTest, IgnoresTouchesOutsidePhysicalDisplay) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); @@ -6875,8 +6869,7 @@ TEST_F(TouchDisplayProjectionTest, IgnoresTouchesOutsidePhysicalDisplay) { static const std::array kPointsOutsidePhysicalDisplay{ {{-10, -10}, {0, 0}, {5, 100}, {50, 15}, {75, 100}, {50, 165}}}; - for (auto orientation : {DISPLAY_ORIENTATION_0, DISPLAY_ORIENTATION_90, DISPLAY_ORIENTATION_180, - DISPLAY_ORIENTATION_270}) { + for (auto orientation : {ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180, ui::ROTATION_270}) { configurePhysicalDisplay(orientation, kPhysicalDisplay); // Touches outside the physical display should be ignored, and should not generate any @@ -6896,7 +6889,7 @@ TEST_F(TouchDisplayProjectionTest, IgnoresTouchesOutsidePhysicalDisplay) { TEST_F(TouchDisplayProjectionTest, EmitsTouchDownAfterEnteringPhysicalDisplay) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); @@ -6909,8 +6902,7 @@ TEST_F(TouchDisplayProjectionTest, EmitsTouchDownAfterEnteringPhysicalDisplay) { // points (10, 20) and (70, 160) inside the display space, which is of the size 400 x 800. static const Rect kPhysicalDisplay{10, 20, 70, 160}; - for (auto orientation : {DISPLAY_ORIENTATION_0, DISPLAY_ORIENTATION_90, DISPLAY_ORIENTATION_180, - DISPLAY_ORIENTATION_270}) { + for (auto orientation : {ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180, ui::ROTATION_270}) { configurePhysicalDisplay(orientation, kPhysicalDisplay); // Touches that start outside the physical display should be ignored until it enters the @@ -6961,7 +6953,7 @@ class ExternalStylusFusionTest : public SingleTouchInputMapperTest { public: SingleTouchInputMapper& initializeInputMapperWithExternalStylus() { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareButtons(); prepareAxes(POSITION); auto& mapper = addMapperAndConfigure(); @@ -7450,7 +7442,7 @@ void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper& mapper, nsecs TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION); prepareVirtualKeys(); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -7722,7 +7714,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin TEST_F(MultiTouchInputMapperTest, AxisResolution_IsPopulated) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, RAW_X_MIN, RAW_X_MAX, /*flat*/ 0, /*fuzz*/ 0, /*resolution*/ 10); @@ -7752,7 +7744,7 @@ TEST_F(MultiTouchInputMapperTest, AxisResolution_IsPopulated) { TEST_F(MultiTouchInputMapperTest, TouchMajorAndMinorAxes_DoNotAppearIfNotSupported) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, RAW_X_MIN, RAW_X_MAX, /*flat*/ 0, /*fuzz*/ 0, /*resolution*/ 10); @@ -7773,7 +7765,7 @@ TEST_F(MultiTouchInputMapperTest, TouchMajorAndMinorAxes_DoNotAppearIfNotSupport TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID); prepareVirtualKeys(); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -7944,7 +7936,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); prepareVirtualKeys(); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8110,7 +8102,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR | DISTANCE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8159,7 +8151,7 @@ TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) { TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | TOUCH | TOOL | MINOR); addConfigurationProperty("touch.size.calibration", "geometric"); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8196,7 +8188,7 @@ TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | TOUCH | TOOL); addConfigurationProperty("touch.size.calibration", "diameter"); addConfigurationProperty("touch.size.scale", "10"); @@ -8247,7 +8239,7 @@ TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibrati TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | TOUCH | TOOL); addConfigurationProperty("touch.size.calibration", "area"); addConfigurationProperty("touch.size.scale", "43"); @@ -8280,7 +8272,7 @@ TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) { TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | PRESSURE); addConfigurationProperty("touch.pressure.calibration", "amplitude"); addConfigurationProperty("touch.pressure.scale", "0.01"); @@ -8314,7 +8306,7 @@ TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) { TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8557,7 +8549,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) { TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleMappedStylusButtons) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8614,7 +8606,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleMappedStylusButtons) { TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8764,7 +8756,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8835,7 +8827,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIs TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -8935,7 +8927,7 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayPort) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); // Add viewport for display 1 on hdmi1 - prepareDisplay(DISPLAY_ORIENTATION_0, hdmi1); + prepareDisplay(ui::ROTATION_0, hdmi1); // Send a touch event again processPosition(mapper, 100, 100); processSync(mapper); @@ -8952,8 +8944,8 @@ TEST_F(MultiTouchInputMapperTest, Configure_AssignsDisplayUniqueId) { mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, VIRTUAL_DISPLAY_UNIQUE_ID); - prepareDisplay(DISPLAY_ORIENTATION_0); - prepareVirtualDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); + prepareVirtualDisplay(ui::ROTATION_0); // Send a touch event processPosition(mapper, 100, 100); @@ -8976,7 +8968,7 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) { mFakePolicy->setDefaultPointerDisplayId(SECONDARY_DISPLAY_ID); prepareSecondaryDisplay(ViewportType::EXTERNAL); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9000,7 +8992,7 @@ TEST_F(MultiTouchInputMapperTest, Process_SendsReadTime) { prepareAxes(POSITION); MultiTouchInputMapper& mapper = addMapperAndConfigure(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); process(mapper, 10, 11 /*readTime*/, EV_ABS, ABS_MT_TRACKING_ID, 1); process(mapper, 15, 16 /*readTime*/, EV_ABS, ABS_MT_POSITION_X, 100); process(mapper, 20, 21 /*readTime*/, EV_ABS, ABS_MT_POSITION_Y, 100); @@ -9025,9 +9017,8 @@ TEST_F(MultiTouchInputMapperTest, Process_SendsReadTime) { TEST_F(MultiTouchInputMapperTest, WhenViewportIsNotActive_TouchesAreDropped) { addConfigurationProperty("touch.deviceType", "touchScreen"); // Don't set touch.enableForInactiveViewport to verify the default behavior. - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, false /*isActive*/, UNIQUE_ID, NO_PORT, - ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + false /*isActive*/, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); prepareAxes(POSITION); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9046,9 +9037,8 @@ TEST_F(MultiTouchInputMapperTest, WhenViewportIsNotActive_TouchesAreDropped) { TEST_F(MultiTouchInputMapperTest, WhenViewportIsNotActive_TouchesAreProcessed) { addConfigurationProperty("touch.deviceType", "touchScreen"); addConfigurationProperty("touch.enableForInactiveViewport", "1"); - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, false /*isActive*/, UNIQUE_ID, NO_PORT, - ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + false /*isActive*/, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO); prepareAxes(POSITION); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9064,9 +9054,8 @@ TEST_F(MultiTouchInputMapperTest, WhenViewportIsNotActive_TouchesAreProcessed) { TEST_F(MultiTouchInputMapperTest, Process_DeactivateViewport_AbortTouches) { addConfigurationProperty("touch.deviceType", "touchScreen"); addConfigurationProperty("touch.enableForInactiveViewport", "0"); - mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, - DISPLAY_ORIENTATION_0, true /*isActive*/, UNIQUE_ID, NO_PORT, - ViewportType::INTERNAL); + mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, + true /*isActive*/, UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); std::optional optionalDisplayViewport = mFakePolicy->getDisplayViewportByUniqueId(UNIQUE_ID); ASSERT_TRUE(optionalDisplayViewport.has_value()); @@ -9160,7 +9149,7 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) { mFakePolicy->setShowTouches(true); // Create displays. - prepareDisplay(DISPLAY_ORIENTATION_0, hdmi1); + prepareDisplay(ui::ROTATION_0, hdmi1); prepareSecondaryDisplay(ViewportType::EXTERNAL, hdmi2); // Default device will reconfigure above, need additional reconfiguration for another device. @@ -9205,7 +9194,7 @@ TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShowTouches) { TEST_F(MultiTouchInputMapperTest, VideoFrames_ReceivedByListener) { prepareAxes(POSITION); addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); MultiTouchInputMapper& mapper = addMapperAndConfigure(); NotifyMotionArgs motionArgs; @@ -9236,8 +9225,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_AreNotRotated) { NotifyMotionArgs motionArgs; // Test all 4 orientations - for (int32_t orientation : {DISPLAY_ORIENTATION_0, DISPLAY_ORIENTATION_90, - DISPLAY_ORIENTATION_180, DISPLAY_ORIENTATION_270}) { + for (ui::Rotation orientation : ftl::enum_range()) { SCOPED_TRACE("Orientation " + StringPrintf("%i", orientation)); clearViewports(); prepareDisplay(orientation); @@ -9262,8 +9250,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_WhenNotOrientationAware_AreRotated NotifyMotionArgs motionArgs; // Test all 4 orientations - for (int32_t orientation : {DISPLAY_ORIENTATION_0, DISPLAY_ORIENTATION_90, - DISPLAY_ORIENTATION_180, DISPLAY_ORIENTATION_270}) { + for (ui::Rotation orientation : ftl::enum_range()) { SCOPED_TRACE("Orientation " + StringPrintf("%i", orientation)); clearViewports(); prepareDisplay(orientation); @@ -9297,7 +9284,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_MultipleFramesAreNotRotated) { std::vector frames{frame1, frame2, frame3}; NotifyMotionArgs motionArgs; - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); mFakeEventHub->setVideoFrames({{EVENTHUB_ID, frames}}); processPosition(mapper, 100, 200); processSync(mapper); @@ -9320,7 +9307,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_WhenNotOrientationAware_MultipleFr std::vector frames{frame1, frame2, frame3}; NotifyMotionArgs motionArgs; - prepareDisplay(DISPLAY_ORIENTATION_90); + prepareDisplay(ui::ROTATION_90); mFakeEventHub->setVideoFrames({{EVENTHUB_ID, frames}}); processPosition(mapper, 100, 200); processSync(mapper); @@ -9330,7 +9317,7 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_WhenNotOrientationAware_MultipleFr // compared to the display. This is so that when the window transform (which contains the // display rotation) is applied later by InputDispatcher, the coordinates end up in the // window's coordinate space. - frame.rotate(getInverseRotation(DISPLAY_ORIENTATION_90)); + frame.rotate(getInverseRotation(ui::ROTATION_90)); }); ASSERT_EQ(frames, motionArgs.videoFrames); } @@ -9367,7 +9354,7 @@ TEST_F(MultiTouchInputMapperTest, Configure_EnabledForAssociatedDisplay) { TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9412,7 +9399,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { */ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9460,7 +9447,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer */ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9535,7 +9522,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) */ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelWhenAllTouchIsPalm) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9633,7 +9620,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW */ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPointer) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9705,7 +9692,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPoin */ TEST_F(MultiTouchInputMapperTest, Process_MultiTouch_WithInvalidTrackingId) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9762,7 +9749,7 @@ TEST_F(MultiTouchInputMapperTest, Process_MultiTouch_WithInvalidTrackingId) { TEST_F(MultiTouchInputMapperTest, Reset_PreservesLastTouchState) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9803,7 +9790,7 @@ TEST_F(MultiTouchInputMapperTest, Reset_PreservesLastTouchState) { TEST_F(MultiTouchInputMapperTest, Reset_PreservesLastTouchState_NoPointersDown) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -9831,7 +9818,7 @@ TEST_F(MultiTouchInputMapperTest, Reset_PreservesLastTouchState_NoPointersDown) TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE | TOOL_TYPE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled()); @@ -9890,7 +9877,7 @@ protected: TEST_F(MultiTouchInputMapperTest_ExternalDevice, Viewports_Fallback) { prepareAxes(POSITION); addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); MultiTouchInputMapper& mapper = addMapperAndConfigure(); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper.getSources()); @@ -9921,7 +9908,7 @@ TEST_F(MultiTouchInputMapperTest, Process_TouchpadCapture) { fakePointerController->setButtonState(0); // prepare device and capture - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0); mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); @@ -10071,7 +10058,7 @@ TEST_F(MultiTouchInputMapperTest, Process_UnCapturedTouchpadPointer) { fakePointerController->setButtonState(0); // prepare device and capture - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0); mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0); @@ -10112,7 +10099,7 @@ TEST_F(MultiTouchInputMapperTest, WhenCapturedAndNotCaptured_GetSources) { std::shared_ptr fakePointerController = std::make_shared(); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT); mFakeEventHub->addKey(EVENTHUB_ID, BTN_LEFT, 0, AKEYCODE_UNKNOWN, 0); mFakePolicy->setPointerController(fakePointerController); @@ -10139,7 +10126,7 @@ protected: TEST_F(BluetoothMultiTouchInputMapperTest, TimestampSmoothening) { addConfigurationProperty("touch.deviceType", "touchScreen"); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION | ID | SLOT | PRESSURE); MultiTouchInputMapper& mapper = addMapperAndConfigure(); @@ -10189,7 +10176,7 @@ protected: fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1); fakePointerController->setPosition(0, 0); fakePointerController->setButtonState(0); - prepareDisplay(DISPLAY_ORIENTATION_0); + prepareDisplay(ui::ROTATION_0); prepareAxes(POSITION); prepareAbsoluteAxisResolution(xAxisResolution, yAxisResolution); @@ -10549,7 +10536,7 @@ protected: process(mapper, ARBITRARY_TIME, READ_TIME, EV_SYN, SYN_REPORT, 0); } - void prepareVirtualDisplay(int32_t orientation) { + void prepareVirtualDisplay(ui::Rotation orientation) { setDisplayInfoAndReconfigure(VIRTUAL_DISPLAY_ID, VIRTUAL_DISPLAY_WIDTH, VIRTUAL_DISPLAY_HEIGHT, orientation, VIRTUAL_DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::VIRTUAL); @@ -10567,7 +10554,7 @@ TEST_F(JoystickInputMapperTest, Configure_AssignsDisplayUniqueId) { mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, VIRTUAL_DISPLAY_UNIQUE_ID); - prepareVirtualDisplay(DISPLAY_ORIENTATION_0); + prepareVirtualDisplay(ui::ROTATION_0); // Send an axis event processAxis(mapper, ABS_X, 100); diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h index 64316baa3a..445ed182fe 100644 --- a/services/inputflinger/tests/fuzzers/MapperHelpers.h +++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h @@ -311,7 +311,7 @@ public: return mFdp->ConsumeRandomLengthString(32); } TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor, - int32_t surfaceRotation) override { + ui::Rotation surfaceRotation) override { return mTransform; } void setTouchAffineTransformation(const TouchAffineTransformation t) { mTransform = t; } -- cgit v1.2.3-59-g8ed1b From 635422be3e0e02b7221633b2eb1b112fc18bb65e Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 2 Dec 2022 00:43:56 +0000 Subject: Convert MotionEvent#getSurfaceRotation to ui::Rotation Because it might have an invalid rotation it needs to return std::optional, but at least we're using the types effectively here. Test: compiles Change-Id: I27076edcc6ce33594552863caa8ee643027a81e7 --- include/input/Input.h | 2 +- libs/input/Input.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 07a566a63c..015efdd064 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -577,7 +577,7 @@ public: inline const ui::Transform& getTransform() const { return mTransform; } - int32_t getSurfaceRotation() const; + std::optional getSurfaceRotation() const; inline float getXPrecision() const { return mXPrecision; } diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 162b757743..9e8ebf30c5 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -552,21 +553,21 @@ void MotionEvent::addSample( &pointerCoords[getPointerCount()]); } -int32_t MotionEvent::getSurfaceRotation() const { +std::optional MotionEvent::getSurfaceRotation() const { // The surface rotation is the rotation from the window's coordinate space to that of the // display. Since the event's transform takes display space coordinates to window space, the // returned surface rotation is the inverse of the rotation for the surface. switch (mTransform.getOrientation()) { case ui::Transform::ROT_0: - return static_cast(ui::ROTATION_0); + return ui::ROTATION_0; case ui::Transform::ROT_90: - return static_cast(ui::ROTATION_270); + return ui::ROTATION_270; case ui::Transform::ROT_180: - return static_cast(ui::ROTATION_180); + return ui::ROTATION_180; case ui::Transform::ROT_270: - return static_cast(ui::ROTATION_90); + return ui::ROTATION_90; default: - return -1; + return std::nullopt; } } -- cgit v1.2.3-59-g8ed1b From e2e10b4a0143b4a90be2d6a52b8cc2757d18d4bf Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 17 Nov 2022 20:59:36 +0000 Subject: TouchInputMapper: Use ui::Transform to calculate orientation angles Rather than manually re-orienting the calculated angles for orientation and tilt, we use the transform to compute the oriented values for these non-planar axes. This approach is both less error-prone and less verbose. In this CL, we also transform the coverage rect from raw to display space using the computed transform. Bug: 236798672 Test: atest inputflinger_tests Change-Id: Ibfb6d2ab43e6fd7a63736ee7d9610c42be44affd --- include/input/Input.h | 7 ++ libs/input/Input.cpp | 38 +++---- .../reader/mapper/TouchInputMapper.cpp | 114 ++++++--------------- .../inputflinger/reader/mapper/TouchInputMapper.h | 8 +- 4 files changed, 58 insertions(+), 109 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 015efdd064..1a35196036 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -203,6 +203,13 @@ class Parcel; */ vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy); +/* + * Transform an angle on the x-y plane. An angle of 0 radians corresponds to "north" or + * pointing upwards in the negative Y direction, a positive angle points towards the right, and a + * negative angle points towards the left. + */ +float transformAngle(const ui::Transform& transform, float angleRadians); + const char* inputEventTypeToString(int32_t type); std::string inputEventSourceToString(int32_t source); diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 9e8ebf30c5..d893cb99ba 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -46,25 +46,6 @@ namespace android { namespace { -float transformAngle(const ui::Transform& transform, float angleRadians) { - // Construct and transform a vector oriented at the specified clockwise angle from vertical. - // Coordinate system: down is increasing Y, right is increasing X. - float x = sinf(angleRadians); - float y = -cosf(angleRadians); - vec2 transformedPoint = transform.transform(x, y); - - // Determine how the origin is transformed by the matrix so that we - // can transform orientation vectors. - const vec2 origin = transform.transform(0, 0); - - transformedPoint.x -= origin.x; - transformedPoint.y -= origin.y; - - // Derive the transformed vector's clockwise angle from vertical. - // The return value of atan2f is in range [-pi, pi] which conforms to the orientation API. - return atan2f(transformedPoint.x, -transformedPoint.y); -} - bool shouldDisregardTransformation(uint32_t source) { // Do not apply any transformations to axes from joysticks, touchpads, or relative mice. return isFromSource(source, AINPUT_SOURCE_CLASS_JOYSTICK) || @@ -172,6 +153,25 @@ vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) return transformedXy - transformedOrigin; } +float transformAngle(const ui::Transform& transform, float angleRadians) { + // Construct and transform a vector oriented at the specified clockwise angle from vertical. + // Coordinate system: down is increasing Y, right is increasing X. + float x = sinf(angleRadians); + float y = -cosf(angleRadians); + vec2 transformedPoint = transform.transform(x, y); + + // Determine how the origin is transformed by the matrix so that we + // can transform orientation vectors. + const vec2 origin = transform.transform(0, 0); + + transformedPoint.x -= origin.x; + transformedPoint.y -= origin.y; + + // Derive the transformed vector's clockwise angle from vertical. + // The return value of atan2f is in range [-pi, pi] which conforms to the orientation API. + return atan2f(transformedPoint.x, -transformedPoint.y); +} + const char* inputEventTypeToString(int32_t type) { switch (type) { case AINPUT_EVENT_TYPE_KEY: { diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index 66691f83c0..80e1a8900a 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -207,10 +207,9 @@ void TouchInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "Translation and Scaling Factors:\n"); mRawToDisplay.dump(dump, "RawToDisplay Transform:", INDENT4); - dump += StringPrintf(INDENT4 "XScale: %0.3f\n", mXScale); - dump += StringPrintf(INDENT4 "YScale: %0.3f\n", mYScale); - dump += StringPrintf(INDENT4 "XPrecision: %0.3f\n", mXPrecision); - dump += StringPrintf(INDENT4 "YPrecision: %0.3f\n", mYPrecision); + mRawRotation.dump(dump, "RawRotation Transform:", INDENT4); + dump += StringPrintf(INDENT4 "OrientedXPrecision: %0.3f\n", mOrientedXPrecision); + dump += StringPrintf(INDENT4 "OrientedYPrecision: %0.3f\n", mOrientedYPrecision); dump += StringPrintf(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale); dump += StringPrintf(INDENT4 "PressureScale: %0.3f\n", mPressureScale); dump += StringPrintf(INDENT4 "SizeScale: %0.3f\n", mSizeScale); @@ -670,10 +669,10 @@ void TouchInputMapper::initializeSizeRanges() { void TouchInputMapper::initializeOrientedRanges() { // Configure X and Y factors. - mXScale = float(mDisplayBounds.width) / mRawPointerAxes.getRawWidth(); - mYScale = float(mDisplayBounds.height) / mRawPointerAxes.getRawHeight(); - mXPrecision = 1.0f / mXScale; - mYPrecision = 1.0f / mYScale; + const float orientedScaleX = mRawToDisplay.getScaleX(); + const float orientedScaleY = mRawToDisplay.getScaleY(); + mOrientedXPrecision = 1.0f / orientedScaleX; + mOrientedYPrecision = 1.0f / orientedScaleY; mOrientedRanges.x.axis = AMOTION_EVENT_AXIS_X; mOrientedRanges.x.source = mSource; @@ -683,7 +682,7 @@ void TouchInputMapper::initializeOrientedRanges() { // Scale factor for terms that are not oriented in a particular axis. // If the pixels are square then xScale == yScale otherwise we fake it // by choosing an average. - mGeometricScale = avg(mXScale, mYScale); + mGeometricScale = avg(orientedScaleX, orientedScaleY); initializeSizeRanges(); @@ -800,40 +799,35 @@ void TouchInputMapper::initializeOrientedRanges() { // Compute oriented precision, scales and ranges. // Note that the maximum value reported is an inclusive maximum value so it is one // unit less than the total width or height of the display. + // TODO(b/20508709): Calculate the oriented ranges using the input device's raw frame. switch (mInputDeviceOrientation) { case ui::ROTATION_90: case ui::ROTATION_270: - mOrientedXPrecision = mYPrecision; - mOrientedYPrecision = mXPrecision; - mOrientedRanges.x.min = 0; mOrientedRanges.x.max = mDisplayBounds.height - 1; mOrientedRanges.x.flat = 0; mOrientedRanges.x.fuzz = 0; - mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mYScale; + mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mRawToDisplay.getScaleY(); mOrientedRanges.y.min = 0; mOrientedRanges.y.max = mDisplayBounds.width - 1; mOrientedRanges.y.flat = 0; mOrientedRanges.y.fuzz = 0; - mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mXScale; + mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mRawToDisplay.getScaleX(); break; default: - mOrientedXPrecision = mXPrecision; - mOrientedYPrecision = mYPrecision; - mOrientedRanges.x.min = 0; mOrientedRanges.x.max = mDisplayBounds.width - 1; mOrientedRanges.x.flat = 0; mOrientedRanges.x.fuzz = 0; - mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mXScale; + mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mRawToDisplay.getScaleX(); mOrientedRanges.y.min = 0; mOrientedRanges.y.max = mDisplayBounds.height - 1; mOrientedRanges.y.flat = 0; mOrientedRanges.y.fuzz = 0; - mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mYScale; + mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mRawToDisplay.getScaleY(); break; } } @@ -845,6 +839,8 @@ void TouchInputMapper::computeInputTransforms() { if (mInputDeviceOrientation == ui::ROTATION_270 || mInputDeviceOrientation == ui::ROTATION_90) { std::swap(rotatedRawSize.width, rotatedRawSize.height); } + const auto rotationFlags = ui::Transform::toRotationFlags(-mInputDeviceOrientation); + mRawRotation = ui::Transform{rotationFlags}; // Step 1: Undo the raw offset so that the raw coordinate space now starts at (0, 0). ui::Transform undoRawOffset; @@ -854,8 +850,7 @@ void TouchInputMapper::computeInputTransforms() { ui::Transform rotate; // When rotating raw coordinates, the raw size will be used as an offset. // Account for the extra unit added to the raw range when the raw size was calculated. - rotate.set(ui::Transform::toRotationFlags(-mInputDeviceOrientation), rotatedRawSize.width - 1, - rotatedRawSize.height - 1); + rotate.set(rotationFlags, rotatedRawSize.width - 1, rotatedRawSize.height - 1); // Step 3: Scale the raw coordinates to the display space. ui::Transform scaleToDisplay; @@ -2307,20 +2302,20 @@ void TouchInputMapper::cookPointerData() { if (mHaveTilt) { float tiltXAngle = (in.tiltX - mTiltXCenter) * mTiltXScale; float tiltYAngle = (in.tiltY - mTiltYCenter) * mTiltYScale; - orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle)); + orientation = transformAngle(mRawRotation, atan2f(-sinf(tiltXAngle), sinf(tiltYAngle))); tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle)); } else { tilt = 0; switch (mCalibration.orientationCalibration) { case Calibration::OrientationCalibration::INTERPOLATED: - orientation = in.orientation * mOrientationScale; + orientation = transformAngle(mRawRotation, in.orientation * mOrientationScale); break; case Calibration::OrientationCalibration::VECTOR: { int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4); int32_t c2 = signExtendNybble(in.orientation & 0x0f); if (c1 != 0 || c2 != 0) { - orientation = atan2f(c1, c2) * 0.5f; + orientation = transformAngle(mRawRotation, atan2f(c1, c2) * 0.5f); float confidence = hypotf(c1, c2); float scale = 1.0f + confidence / 16.0f; touchMajor *= scale; @@ -2348,18 +2343,14 @@ void TouchInputMapper::cookPointerData() { } // Coverage - int32_t rawLeft, rawTop, rawRight, rawBottom; - switch (mCalibration.coverageCalibration) { - case Calibration::CoverageCalibration::BOX: - rawLeft = (in.toolMinor & 0xffff0000) >> 16; - rawRight = in.toolMinor & 0x0000ffff; - rawBottom = in.toolMajor & 0x0000ffff; - rawTop = (in.toolMajor & 0xffff0000) >> 16; - break; - default: - rawLeft = rawTop = rawRight = rawBottom = 0; - break; + Rect rawCoverage{0, 0}; + if (mCalibration.coverageCalibration == Calibration::CoverageCalibration::BOX) { + rawCoverage.left = (in.toolMinor & 0xffff0000) >> 16; + rawCoverage.right = in.toolMinor & 0x0000ffff; + rawCoverage.bottom = in.toolMajor & 0x0000ffff; + rawCoverage.top = (in.toolMajor & 0xffff0000) >> 16; } + const auto coverage = mRawToDisplay.transform(rawCoverage); // Adjust X,Y coords for device calibration and convert to the natural display coordinates. vec2 transformed = {in.x, in.y}; @@ -2367,51 +2358,6 @@ void TouchInputMapper::cookPointerData() { mAffineTransform.applyTo(transformed.x /*byRef*/, transformed.y /*byRef*/); transformed = mRawToDisplay.transform(transformed); - // Adjust X, Y, and coverage coords for input device orientation. - float left, top, right, bottom; - - switch (mInputDeviceOrientation) { - case ui::ROTATION_90: - left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale; - right = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale; - bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; - top = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale; - orientation -= M_PI_2; - if (mOrientedRanges.orientation && orientation < mOrientedRanges.orientation->min) { - orientation += - (mOrientedRanges.orientation->max - mOrientedRanges.orientation->min); - } - break; - case ui::ROTATION_180: - left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale; - right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale; - bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; - top = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale; - orientation -= M_PI; - if (mOrientedRanges.orientation && orientation < mOrientedRanges.orientation->min) { - orientation += - (mOrientedRanges.orientation->max - mOrientedRanges.orientation->min); - } - break; - case ui::ROTATION_270: - left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale; - right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale; - bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale; - top = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale; - orientation += M_PI_2; - if (mOrientedRanges.orientation && orientation > mOrientedRanges.orientation->max) { - orientation -= - (mOrientedRanges.orientation->max - mOrientedRanges.orientation->min); - } - break; - default: - left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale; - right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale; - bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale; - top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale; - break; - } - // Write output coords. PointerCoords& out = mCurrentCookedState.cookedPointerData.pointerCoords[i]; out.clear(); @@ -2425,10 +2371,10 @@ void TouchInputMapper::cookPointerData() { out.setAxisValue(AMOTION_EVENT_AXIS_TILT, tilt); out.setAxisValue(AMOTION_EVENT_AXIS_DISTANCE, distance); if (mCalibration.coverageCalibration == Calibration::CoverageCalibration::BOX) { - out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_1, left); - out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_2, top); - out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_3, right); - out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_4, bottom); + out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_1, coverage.left); + out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_2, coverage.top); + out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_3, coverage.right); + out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_4, coverage.bottom); } else { out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, toolMajor); out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, toolMinor); diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index 1a583c0dda..29b850ffd3 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -428,12 +428,8 @@ private: // the rotated coordinate space. See mPhysicalFrameInRotatedDisplay. ui::Transform mRawToRotatedDisplay; - // Translation and scaling factors, orientation-independent. - float mXScale; - float mXPrecision; - - float mYScale; - float mYPrecision; + // The transform used for non-planar raw axes, such as orientation and tilt. + ui::Transform mRawRotation; float mGeometricScale; -- cgit v1.2.3-59-g8ed1b From c5748d198b4ee9819ba35bf4c5c4eecf817fee7a Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Fri, 2 Dec 2022 17:30:18 +0000 Subject: Report three- and four-finger swipes The dispatcher still needs to be modified to only dispatch these to SysUI windows. Bug: 251196347 Test: check events received by a custom tester app, and touches shown by pointer location overlay Test: atest inputflinger_tests Change-Id: I3a7211d4a67e6388231bef158d3748c2e72e128d --- include/android/input.h | 8 + include/input/Input.h | 6 + libs/input/Input.cpp | 2 + .../reader/mapper/TouchpadInputMapper.cpp | 2 +- .../reader/mapper/gestures/GestureConverter.cpp | 142 ++++++++++-- .../reader/mapper/gestures/GestureConverter.h | 26 ++- .../inputflinger/tests/GestureConverter_test.cpp | 256 ++++++++++++++++++++- .../inputflinger/tests/TestInputListenerMatchers.h | 25 ++ 8 files changed, 438 insertions(+), 29 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/android/input.h b/include/android/input.h index 5d19c5cb13..a0b46de260 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -870,6 +870,14 @@ enum AMotionClassification : uint32_t { * The current event stream represents the user swiping with two fingers on a touchpad. */ AMOTION_EVENT_CLASSIFICATION_TWO_FINGER_SWIPE = 3, + /** + * Classification constant: multi-finger swipe. + * + * The current event stream represents the user swiping with three or more fingers on a + * touchpad. Unlike two-finger swipes, these are only to be handled by the system UI, which is + * why they have a separate constant from two-finger swipes. + */ + AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE = 4, }; /** diff --git a/include/input/Input.h b/include/input/Input.h index 1a35196036..7e62ac005e 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -302,6 +302,12 @@ enum class MotionClassification : uint8_t { * The current gesture represents the user swiping with two fingers on a touchpad. */ TWO_FINGER_SWIPE = AMOTION_EVENT_CLASSIFICATION_TWO_FINGER_SWIPE, + /** + * The current gesture represents the user swiping with three or more fingers on a touchpad. + * Unlike two-finger swipes, these are only to be handled by the system UI, which is why they + * have a separate constant from two-finger swipes. + */ + MULTI_FINGER_SWIPE = AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE, }; /** diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index d893cb99ba..000775b42a 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -72,6 +72,8 @@ const char* motionClassificationToString(MotionClassification classification) { return "DEEP_PRESS"; case MotionClassification::TWO_FINGER_SWIPE: return "TWO_FINGER_SWIPE"; + case MotionClassification::MULTI_FINGER_SWIPE: + return "MULTI_FINGER_SWIPE"; } } diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index 23d7fdf91d..3b51be83ab 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -92,7 +92,7 @@ TouchpadInputMapper::TouchpadInputMapper(InputDeviceContext& deviceContext) mGestureInterpreter(NewGestureInterpreter(), DeleteGestureInterpreter), mPointerController(getContext()->getPointerController(getDeviceId())), mStateConverter(deviceContext), - mGestureConverter(*getContext(), getDeviceId()) { + mGestureConverter(*getContext(), deviceContext, getDeviceId()) { mGestureInterpreter->Initialize(GESTURES_DEVCLASS_TOUCHPAD); mGestureInterpreter->SetHardwareProperties(createHardwareProperties(deviceContext)); // Even though we don't explicitly delete copy/move semantics, it's safe to diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp index 8600065395..ffc0523e97 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp @@ -17,6 +17,7 @@ #include "gestures/GestureConverter.h" #include +#include #include "TouchCursorInputMapperCommon.h" #include "input/Input.h" @@ -44,10 +45,14 @@ uint32_t gesturesButtonToMotionEventButton(uint32_t gesturesButton) { } // namespace -GestureConverter::GestureConverter(InputReaderContext& readerContext, int32_t deviceId) +GestureConverter::GestureConverter(InputReaderContext& readerContext, + const InputDeviceContext& deviceContext, int32_t deviceId) : mDeviceId(deviceId), mReaderContext(readerContext), - mPointerController(readerContext.getPointerController(deviceId)) {} + mPointerController(readerContext.getPointerController(deviceId)) { + deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mXAxisInfo); + deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mYAxisInfo); +} void GestureConverter::reset() { mButtonState = 0; @@ -60,6 +65,15 @@ std::list GestureConverter::handleGesture(nsecs_t when, nsecs_t read return {handleMove(when, readTime, gesture)}; case kGestureTypeButtonsChange: return handleButtonsChange(when, readTime, gesture); + case kGestureTypeSwipe: + return handleMultiFingerSwipe(when, readTime, 3, gesture.details.swipe.dx, + gesture.details.swipe.dy); + case kGestureTypeFourFingerSwipe: + return handleMultiFingerSwipe(when, readTime, 4, gesture.details.four_finger_swipe.dx, + gesture.details.four_finger_swipe.dy); + case kGestureTypeSwipeLift: + case kGestureTypeFourFingerSwipeLift: + return handleMultiFingerSwipeLift(when, readTime); default: // TODO(b/251196347): handle more gesture types. return {}; @@ -67,11 +81,6 @@ std::list GestureConverter::handleGesture(nsecs_t when, nsecs_t read } NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Gesture& gesture) { - PointerProperties props; - props.clear(); - props.id = 0; - props.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; - float deltaX = gesture.details.move.dx; float deltaY = gesture.details.move.dy; rotateDelta(mOrientation, &deltaX, &deltaY); @@ -93,7 +102,8 @@ NotifyArgs GestureConverter::handleMove(nsecs_t when, nsecs_t readTime, const Ge const int32_t action = down ? AMOTION_EVENT_ACTION_MOVE : AMOTION_EVENT_ACTION_HOVER_MOVE; return makeMotionArgs(when, readTime, action, /* actionButton= */ 0, mButtonState, - /* pointerCount= */ 1, &props, &coords, xCursorPosition, yCursorPosition); + /* pointerCount= */ 1, mFingerProps.data(), &coords, xCursorPosition, + yCursorPosition); } std::list GestureConverter::handleButtonsChange(nsecs_t when, nsecs_t readTime, @@ -103,11 +113,6 @@ std::list GestureConverter::handleButtonsChange(nsecs_t when, nsecs_ mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER); mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE); - PointerProperties props; - props.clear(); - props.id = 0; - props.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; - float xCursorPosition, yCursorPosition; mPointerController->getPosition(&xCursorPosition, &yCursorPosition); @@ -131,15 +136,16 @@ std::list GestureConverter::handleButtonsChange(nsecs_t when, nsecs_ newButtonState |= actionButton; pressEvents.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, newButtonState, - /* pointerCount= */ 1, &props, &coords, - xCursorPosition, yCursorPosition)); + /* pointerCount= */ 1, mFingerProps.data(), + &coords, xCursorPosition, yCursorPosition)); } } if (!isPointerDown(mButtonState) && isPointerDown(newButtonState)) { mDownTime = when; out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN, /* actionButton= */ 0, newButtonState, /* pointerCount= */ 1, - &props, &coords, xCursorPosition, yCursorPosition)); + mFingerProps.data(), &coords, xCursorPosition, + yCursorPosition)); } out.splice(out.end(), pressEvents); @@ -155,19 +161,109 @@ std::list GestureConverter::handleButtonsChange(nsecs_t when, nsecs_ newButtonState &= ~actionButton; out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, newButtonState, /* pointerCount= */ 1, - &props, &coords, xCursorPosition, yCursorPosition)); + mFingerProps.data(), &coords, xCursorPosition, + yCursorPosition)); } } if (isPointerDown(mButtonState) && !isPointerDown(newButtonState)) { coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.0f); out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP, /* actionButton= */ 0, - newButtonState, /* pointerCount= */ 1, &props, &coords, - xCursorPosition, yCursorPosition)); + newButtonState, /* pointerCount= */ 1, mFingerProps.data(), + &coords, xCursorPosition, yCursorPosition)); } mButtonState = newButtonState; return out; } +[[nodiscard]] std::list GestureConverter::handleMultiFingerSwipe(nsecs_t when, + nsecs_t readTime, + uint32_t fingerCount, + float dx, float dy) { + std::list out = {}; + float xCursorPosition, yCursorPosition; + mPointerController->getPosition(&xCursorPosition, &yCursorPosition); + if (mCurrentClassification != MotionClassification::MULTI_FINGER_SWIPE) { + // If the user changes the number of fingers mid-way through a swipe (e.g. they start with + // three and then put a fourth finger down), the gesture library will treat it as two + // separate swipes with an appropriate lift event between them, so we don't have to worry + // about the finger count changing mid-swipe. + mCurrentClassification = MotionClassification::MULTI_FINGER_SWIPE; + mSwipeFingerCount = fingerCount; + + constexpr float FAKE_FINGER_SPACING = 100; + float xCoord = xCursorPosition - FAKE_FINGER_SPACING * (mSwipeFingerCount - 1) / 2; + for (size_t i = 0; i < mSwipeFingerCount; i++) { + PointerCoords& coords = mFakeFingerCoords[i]; + coords.clear(); + coords.setAxisValue(AMOTION_EVENT_AXIS_X, xCoord); + coords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); + coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f); + xCoord += FAKE_FINGER_SPACING; + } + + mDownTime = when; + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN, + /* actionButton= */ 0, mButtonState, /* pointerCount= */ 1, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + for (size_t i = 1; i < mSwipeFingerCount; i++) { + out.push_back(makeMotionArgs(when, readTime, + AMOTION_EVENT_ACTION_POINTER_DOWN | + (i << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + /* actionButton= */ 0, mButtonState, + /* pointerCount= */ i + 1, mFingerProps.data(), + mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + } + } + for (size_t i = 0; i < mSwipeFingerCount; i++) { + PointerCoords& coords = mFakeFingerCoords[i]; + coords.setAxisValue(AMOTION_EVENT_AXIS_X, coords.getAxisValue(AMOTION_EVENT_AXIS_X) + dx); + // TODO(b/251196347): Set the gesture properties appropriately to avoid needing to negate + // the Y values. + coords.setAxisValue(AMOTION_EVENT_AXIS_Y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y) - dy); + } + float xOffset = dx / (mXAxisInfo.maxValue - mXAxisInfo.minValue); + // TODO(b/251196347): Set the gesture properties appropriately to avoid needing to negate the Y + // values. + float yOffset = -dy / (mYAxisInfo.maxValue - mYAxisInfo.minValue); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_X_OFFSET, xOffset); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET, yOffset); + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, /* actionButton= */ 0, + mButtonState, /* pointerCount= */ mSwipeFingerCount, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + return out; +} + +[[nodiscard]] std::list GestureConverter::handleMultiFingerSwipeLift(nsecs_t when, + nsecs_t readTime) { + std::list out = {}; + if (mCurrentClassification != MotionClassification::MULTI_FINGER_SWIPE) { + return out; + } + float xCursorPosition, yCursorPosition; + mPointerController->getPosition(&xCursorPosition, &yCursorPosition); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_X_OFFSET, 0); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET, 0); + + for (size_t i = mSwipeFingerCount; i > 1; i--) { + out.push_back(makeMotionArgs(when, readTime, + AMOTION_EVENT_ACTION_POINTER_UP | + ((i - 1) << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + /* actionButton= */ 0, mButtonState, /* pointerCount= */ i, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + } + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP, + /* actionButton= */ 0, mButtonState, /* pointerCount= */ 1, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + mCurrentClassification = MotionClassification::NONE; + mSwipeFingerCount = 0; + return out; +} + NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action, int32_t actionButton, int32_t buttonState, uint32_t pointerCount, @@ -181,10 +277,10 @@ NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime mPointerController->getDisplayId(), /* policyFlags= */ 0, action, /* actionButton= */ actionButton, /* flags= */ 0, mReaderContext.getGlobalMetaState(), buttonState, - MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, - pointerProperties, pointerCoords, - /* xPrecision= */ 1.0f, /* yPrecision= */ 1.0f, xCursorPosition, - yCursorPosition, /* downTime= */ mDownTime, /* videoFrames= */ {}); + mCurrentClassification, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount, + pointerProperties, pointerCoords, /* xPrecision= */ 1.0f, + /* yPrecision= */ 1.0f, xCursorPosition, yCursorPosition, + /* downTime= */ mDownTime, /* videoFrames= */ {}); } } // namespace android diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index d6a51d2da8..ae5581d3ec 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -16,12 +16,15 @@ #pragma once +#include #include #include #include #include +#include "EventHub.h" +#include "InputDevice.h" #include "InputReaderContext.h" #include "NotifyArgs.h" #include "ui/Rotation.h" @@ -34,7 +37,8 @@ namespace android { // PointerController calls. class GestureConverter { public: - GestureConverter(InputReaderContext& readerContext, int32_t deviceId); + GestureConverter(InputReaderContext& readerContext, const InputDeviceContext& deviceContext, + int32_t deviceId); void setOrientation(ui::Rotation orientation) { mOrientation = orientation; } void reset(); @@ -46,6 +50,10 @@ private: NotifyArgs handleMove(nsecs_t when, nsecs_t readTime, const Gesture& gesture); [[nodiscard]] std::list handleButtonsChange(nsecs_t when, nsecs_t readTime, const Gesture& gesture); + [[nodiscard]] std::list handleMultiFingerSwipe(nsecs_t when, nsecs_t readTime, + uint32_t fingerCount, float dx, + float dy); + [[nodiscard]] std::list handleMultiFingerSwipeLift(nsecs_t when, nsecs_t readTime); NotifyMotionArgs makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action, int32_t actionButton, int32_t buttonState, @@ -59,10 +67,26 @@ private: std::shared_ptr mPointerController; ui::Rotation mOrientation = ui::ROTATION_0; + RawAbsoluteAxisInfo mXAxisInfo; + RawAbsoluteAxisInfo mYAxisInfo; + // The current button state according to the gestures library, but converted into MotionEvent // button values (AMOTION_EVENT_BUTTON_...). uint32_t mButtonState = 0; nsecs_t mDownTime = 0; + + MotionClassification mCurrentClassification = MotionClassification::NONE; + uint32_t mSwipeFingerCount = 0; + static constexpr size_t MAX_FAKE_FINGERS = 4; + // We never need any PointerProperties other than the finger tool type, so we can just keep a + // const array of them. + const std::array mFingerProps = {{ + {.id = 0, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + {.id = 1, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + {.id = 2, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + {.id = 3, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + }}; + std::array mFakeFingerCoords = {}; }; } // namespace android diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 74c2028b6f..1c7ec7665a 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -38,6 +38,7 @@ using testing::AllOf; class GestureConverterTest : public testing::Test { protected: static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; + static constexpr int32_t EVENTHUB_ID = 1; static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; static constexpr float POINTER_X = 100; static constexpr float POINTER_Y = 200; @@ -48,6 +49,9 @@ protected: mFakeListener = std::make_unique(); mReader = std::make_unique(mFakeEventHub, mFakePolicy, *mFakeListener); + mDevice = newDevice(); + mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20); + mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20); mFakePointerController = std::make_shared(); mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1); @@ -55,15 +59,32 @@ protected: mFakePolicy->setPointerController(mFakePointerController); } + std::shared_ptr newDevice() { + InputDeviceIdentifier identifier; + identifier.name = "device"; + identifier.location = "USB1"; + identifier.bus = 0; + std::shared_ptr device = + std::make_shared(mReader->getContext(), DEVICE_ID, /* generation= */ 2, + identifier); + mReader->pushNextDevice(device); + mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, + identifier.bus); + mReader->loopOnce(); + return device; + } + std::shared_ptr mFakeEventHub; sp mFakePolicy; std::unique_ptr mFakeListener; std::unique_ptr mReader; + std::shared_ptr mDevice; std::shared_ptr mFakePointerController; }; TEST_F(GestureConverterTest, Move) { - GestureConverter converter(*mReader->getContext(), DEVICE_ID); + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); @@ -79,7 +100,8 @@ TEST_F(GestureConverterTest, Move) { } TEST_F(GestureConverterTest, Move_Rotated) { - GestureConverter converter(*mReader->getContext(), DEVICE_ID); + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); converter.setOrientation(ui::ROTATION_90); Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -96,7 +118,8 @@ TEST_F(GestureConverterTest, Move_Rotated) { } TEST_F(GestureConverterTest, ButtonsChange) { - GestureConverter converter(*mReader->getContext(), DEVICE_ID); + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); // Press left and right buttons at once Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -161,7 +184,8 @@ TEST_F(GestureConverterTest, ButtonsChange) { } TEST_F(GestureConverterTest, DragWithButton) { - GestureConverter converter(*mReader->getContext(), DEVICE_ID); + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); // Press the button Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -215,4 +239,228 @@ TEST_F(GestureConverterTest, DragWithButton) { WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); } +TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAndOffsetsAfterGesture) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, + /* dy= */ 0); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + + Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); + + Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ -5, + /* dy= */ 10); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); + ASSERT_EQ(1u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionClassification(MotionClassification::NONE), + WithGestureOffset(0, 0, EPSILON))); +} + +TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { + // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you + // start swiping up and then start moving left or right, it'll return gesture events with only Y + // deltas until you lift your fingers and start swiping again. That's why each of these tests + // only checks movement in one dimension. + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0, + /* dy= */ 10); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + ASSERT_EQ(4u, args.size()); + + // Three fake fingers should be created. We don't actually care where they are, so long as they + // move appropriately. + NotifyMotionArgs arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger0Start = arg.pointerCoords[0]; + args.pop_front(); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger1Start = arg.pointerCoords[1]; + args.pop_front(); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger2Start = arg.pointerCoords[2]; + args.pop_front(); + + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0, -0.01, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10); + + Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dx= */ 0, /* dy= */ 5); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); + ASSERT_EQ(1u, args.size()); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0, -0.005, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15); + + Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); + ASSERT_EQ(3u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); +} + +TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dx= */ 10, /* dy= */ 0); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + ASSERT_EQ(5u, args.size()); + + // Four fake fingers should be created. We don't actually care where they are, so long as they + // move appropriately. + NotifyMotionArgs arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger0Start = arg.pointerCoords[0]; + args.pop_front(); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger1Start = arg.pointerCoords[1]; + args.pop_front(); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger2Start = arg.pointerCoords[2]; + args.pop_front(); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + PointerCoords finger3Start = arg.pointerCoords[3]; + args.pop_front(); + + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0.01, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); + EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); + EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); + + Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dx= */ 5, /* dy= */ 0); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); + ASSERT_EQ(1u, args.size()); + arg = std::get(args.front()); + ASSERT_THAT(arg, + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithGestureOffset(0.005, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); + EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); + EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); + EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15); + EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY()); + EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY()); + EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY()); + EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY()); + + Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture); + ASSERT_EQ(4u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), + WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); +} + } // namespace android diff --git a/services/inputflinger/tests/TestInputListenerMatchers.h b/services/inputflinger/tests/TestInputListenerMatchers.h index e5a4b14f00..64c2c7511b 100644 --- a/services/inputflinger/tests/TestInputListenerMatchers.h +++ b/services/inputflinger/tests/TestInputListenerMatchers.h @@ -16,6 +16,8 @@ #pragma once +#include + #include #include #include @@ -66,6 +68,11 @@ MATCHER_P(WithKeyCode, keyCode, "KeyEvent with specified key code") { return arg.keyCode == keyCode; } +MATCHER_P(WithPointerCount, count, "MotionEvent with specified number of pointers") { + *result_listener << "expected " << count << " pointer(s), but got " << arg.pointerCount; + return arg.pointerCount == count; +} + MATCHER_P2(WithCoords, x, y, "InputEvent with specified coords") { const auto argX = arg.pointerCoords[0].getX(); const auto argY = arg.pointerCoords[0].getY(); @@ -82,6 +89,17 @@ MATCHER_P2(WithRelativeMotion, x, y, "InputEvent with specified relative motion" return argX == x && argY == y; } +MATCHER_P3(WithGestureOffset, dx, dy, epsilon, + "InputEvent with specified touchpad gesture offset") { + const auto argGestureX = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_X_OFFSET); + const auto argGestureY = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET); + const double xDiff = fabs(argGestureX - dx); + const double yDiff = fabs(argGestureY - dy); + *result_listener << "expected gesture offset (" << dx << ", " << dy << ") within " << epsilon + << ", but got (" << argGestureX << ", " << argGestureY << ")"; + return xDiff <= epsilon && yDiff <= epsilon; +} + MATCHER_P(WithPressure, pressure, "InputEvent with specified pressure") { const auto argPressure = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE); *result_listener << "expected pressure " << pressure << ", but got " << argPressure; @@ -100,6 +118,13 @@ MATCHER_P(WithFlags, flags, "InputEvent with specified flags") { return arg.flags == flags; } +MATCHER_P(WithMotionClassification, classification, + "InputEvent with specified MotionClassification") { + *result_listener << "expected classification " << motionClassificationToString(classification) + << ", but got " << motionClassificationToString(arg.classification); + return arg.classification == classification; +} + MATCHER_P(WithButtonState, buttons, "InputEvent with specified button state") { *result_listener << "expected button state " << buttons << ", but got " << arg.buttonState; return arg.buttonState == buttons; -- cgit v1.2.3-59-g8ed1b From afb312889849d435e59f8e1014e1385ac419c4ea Mon Sep 17 00:00:00 2001 From: Philip Quinn Date: Tue, 20 Dec 2022 18:17:55 -0800 Subject: Add isResampled field to PointerCoords. This field is set if a pointer's coordinate data were generated by input resampling and did not originate from the input device. Bug: 167946721 Test: atest libinput_tests Change-Id: I30d9aee85d462e6536fa33be5242365b52a11a6c --- include/input/Input.h | 13 +++++++++- libs/input/Input.cpp | 7 ++++++ libs/input/InputTransport.cpp | 6 +++++ libs/input/tests/InputEvent_test.cpp | 18 ++++++++++++++ libs/input/tests/StructLayout_test.cpp | 14 +++++------ libs/input/tests/TouchResampling_test.cpp | 41 +++++++++++++++++++++---------- 6 files changed, 78 insertions(+), 21 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 1a35196036..08d9019911 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -368,7 +368,7 @@ constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits values; + // Whether these coordinate data were generated by resampling. + bool isResampled; + + static_assert(sizeof(bool) == 1); // Ensure padding is correctly sized. + uint8_t empty[7]; + inline void clear() { BitSet64::clear(bits); + isResampled = false; } bool isEmpty() const { @@ -769,6 +776,10 @@ public: AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); } + inline bool isResampled(size_t pointerIndex, size_t historicalIndex) const { + return getHistoricalRawPointerCoords(pointerIndex, historicalIndex)->isResampled; + } + ssize_t findPointerIndex(int32_t pointerId) const; void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index d893cb99ba..cdc779dfd9 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -411,6 +411,8 @@ status_t PointerCoords::readFromParcel(Parcel* parcel) { for (uint32_t i = 0; i < count; i++) { values[i] = parcel->readFloat(); } + + isResampled = parcel->readBool(); return OK; } @@ -421,6 +423,8 @@ status_t PointerCoords::writeToParcel(Parcel* parcel) const { for (uint32_t i = 0; i < count; i++) { parcel->writeFloat(values[i]); } + + parcel->writeBool(isResampled); return OK; } #endif @@ -440,6 +444,9 @@ bool PointerCoords::operator==(const PointerCoords& other) const { return false; } } + if (isResampled != other.isResampled) { + return false; + } return true; } diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 8d8433b973..9f0a314041 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -267,6 +267,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const { memcpy(&msg->body.motion.pointers[i].coords.values[0], &body.motion.pointers[i].coords.values[0], count * (sizeof(body.motion.pointers[i].coords.values[0]))); + msg->body.motion.pointers[i].coords.isResampled = + body.motion.pointers[i].coords.isResampled; } break; } @@ -1079,6 +1081,7 @@ void InputConsumer::rewriteMessage(TouchState& state, InputMessage& msg) { #endif msgCoords.setAxisValue(AMOTION_EVENT_AXIS_X, resampleCoords.getX()); msgCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, resampleCoords.getY()); + msgCoords.isResampled = true; } else { state.lastResample.idBits.clearBit(id); } @@ -1191,6 +1194,8 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, // We maintain the previously resampled value for this pointer (stored in // oldLastResample) when the coordinates for this pointer haven't changed since then. // This way we don't introduce artificial jitter when pointers haven't actually moved. + // The isResampled flag isn't cleared as the values don't reflect what the device is + // actually reporting. // We know here that the coordinates for the pointer haven't changed because we // would've cleared the resampled bit in rewriteMessage if they had. We can't modify @@ -1209,6 +1214,7 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, lerp(currentCoords.getX(), otherCoords.getX(), alpha)); resampledCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, lerp(currentCoords.getY(), otherCoords.getY(), alpha)); + resampledCoords.isResampled = true; #if DEBUG_RESAMPLING ALOGD("[%d] - out (%0.3f, %0.3f), cur (%0.3f, %0.3f), " "other (%0.3f, %0.3f), alpha %0.3f", diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 4b3124636b..8a6e983bb5 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -46,6 +46,7 @@ TEST_F(PointerCoordsTest, ClearSetsBitsToZero) { coords.clear(); ASSERT_EQ(0ULL, coords.bits); + ASSERT_FALSE(coords.isResampled); } TEST_F(PointerCoordsTest, AxisValues) { @@ -158,11 +159,13 @@ TEST_F(PointerCoordsTest, Parcel) { outCoords.readFromParcel(&parcel); ASSERT_EQ(0ULL, outCoords.bits); + ASSERT_FALSE(outCoords.isResampled); // Round trip with some values. parcel.freeData(); inCoords.setAxisValue(2, 5); inCoords.setAxisValue(5, 8); + inCoords.isResampled = true; inCoords.writeToParcel(&parcel); parcel.setDataPosition(0); @@ -171,6 +174,7 @@ TEST_F(PointerCoordsTest, Parcel) { ASSERT_EQ(outCoords.bits, inCoords.bits); ASSERT_EQ(outCoords.values[0], inCoords.values[0]); ASSERT_EQ(outCoords.values[1], inCoords.values[1]); + ASSERT_TRUE(outCoords.isResampled); } @@ -263,6 +267,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 16); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 17); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 18); + pointerCoords[0].isResampled = true; pointerCoords[1].clear(); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 20); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 21); @@ -281,6 +286,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { mRawTransform, ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME, 2, pointerProperties, pointerCoords); + pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 110); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 111); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 112); @@ -290,6 +296,8 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 116); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 117); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 118); + pointerCoords[0].isResampled = true; + pointerCoords[1].clear(); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 120); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 121); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 122); @@ -299,8 +307,10 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 126); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 127); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 128); + pointerCoords[1].isResampled = true; event->addSample(ARBITRARY_EVENT_TIME + 1, pointerCoords); + pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 210); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 211); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 212); @@ -310,6 +320,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 216); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 217); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 218); + pointerCoords[1].clear(); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 220); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 221); pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 222); @@ -457,6 +468,13 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { ASSERT_EQ(toScaledOrientation(128), event->getHistoricalOrientation(1, 1)); ASSERT_EQ(toScaledOrientation(218), event->getOrientation(0)); ASSERT_EQ(toScaledOrientation(228), event->getOrientation(1)); + + ASSERT_TRUE(event->isResampled(0, 0)); + ASSERT_FALSE(event->isResampled(1, 0)); + ASSERT_TRUE(event->isResampled(0, 1)); + ASSERT_TRUE(event->isResampled(1, 1)); + ASSERT_FALSE(event->isResampled(0, 2)); + ASSERT_FALSE(event->isResampled(1, 2)); } TEST_F(MotionEventTest, Properties) { diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp index 1c8658b69a..024b6d3d43 100644 --- a/libs/input/tests/StructLayout_test.cpp +++ b/libs/input/tests/StructLayout_test.cpp @@ -117,7 +117,7 @@ void TestHeaderSize() { void TestBodySize() { static_assert(sizeof(InputMessage::Body::Key) == 96); - static_assert(sizeof(InputMessage::Body::Motion::Pointer) == 136); + static_assert(sizeof(InputMessage::Body::Motion::Pointer) == 144); static_assert(sizeof(InputMessage::Body::Motion) == offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS); @@ -137,8 +137,8 @@ void TestBodySize() { static_assert(sizeof(InputMessage::Body) == offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS); - static_assert(sizeof(InputMessage::Body) == 160 + 136 * 16); - static_assert(sizeof(InputMessage::Body) == 2336); + static_assert(sizeof(InputMessage::Body) == 160 + 144 * 16); + static_assert(sizeof(InputMessage::Body) == 2464); } /** @@ -148,8 +148,8 @@ void TestBodySize() { * still helpful to compute to get an idea of the sizes that are involved. */ void TestWorstCaseInputMessageSize() { - static_assert(sizeof(InputMessage) == /*header*/ 8 + /*body*/ 2336); - static_assert(sizeof(InputMessage) == 2344); + static_assert(sizeof(InputMessage) == /*header*/ 8 + /*body*/ 2464); + static_assert(sizeof(InputMessage) == 2472); } /** @@ -159,8 +159,8 @@ void CalculateSinglePointerInputMessageSize() { constexpr size_t pointerCount = 1; constexpr size_t bodySize = offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * pointerCount; - static_assert(bodySize == 160 + 136); - static_assert(bodySize == 296); // For the total message size, add the small header + static_assert(bodySize == 160 + 144); + static_assert(bodySize == 304); // For the total message size, add the small header } // --- VerifiedInputEvent --- diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index c09a8e9358..d01258c783 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -31,6 +31,7 @@ struct Pointer { int32_t id; float x; float y; + bool isResampled = false; }; struct InputEventEntry { @@ -190,6 +191,8 @@ void TouchResamplingTest::consumeInputEventEntries(const std::vectorgetHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, motionEventPointerIndex, i)); + ASSERT_EQ(entry.pointers[p].isResampled, + motionEvent->isResampled(motionEventPointerIndex, i)); } } @@ -244,7 +247,7 @@ TEST_F(TouchResamplingTest, EventIsResampled) { // id x y {10ms, {{0, 20, 30}}, AMOTION_EVENT_ACTION_MOVE}, {20ms, {{0, 30, 30}}, AMOTION_EVENT_ACTION_MOVE}, - {25ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {25ms, {{0, 35, 30, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); } @@ -283,7 +286,7 @@ TEST_F(TouchResamplingTest, EventIsResampledWithDifferentId) { // id x y {10ms, {{1, 20, 30}}, AMOTION_EVENT_ACTION_MOVE}, {20ms, {{1, 30, 30}}, AMOTION_EVENT_ACTION_MOVE}, - {25ms, {{1, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {25ms, {{1, 35, 30, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); } @@ -361,7 +364,7 @@ TEST_F(TouchResamplingTest, ResampledValueIsUsedForIdenticalCoordinates) { // id x y {10ms, {{0, 20, 30}}, AMOTION_EVENT_ACTION_MOVE}, {20ms, {{0, 30, 30}}, AMOTION_EVENT_ACTION_MOVE}, - {25ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {25ms, {{0, 35, 30, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); @@ -375,8 +378,12 @@ TEST_F(TouchResamplingTest, ResampledValueIsUsedForIdenticalCoordinates) { frameTime = 45ms + 5ms /*RESAMPLE_LATENCY*/; expectedEntries = { // id x y - {40ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // original event, rewritten - {45ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled event, rewritten + {40ms, + {{0, 35, 30, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, // original event, rewritten + {45ms, + {{0, 35, 30, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, // resampled event, rewritten }; consumeInputEventEntries(expectedEntries, frameTime); } @@ -411,7 +418,7 @@ TEST_F(TouchResamplingTest, OldEventReceivedAfterResampleOccurs) { // id x y {10ms, {{0, 20, 30}}, AMOTION_EVENT_ACTION_MOVE}, {20ms, {{0, 30, 30}}, AMOTION_EVENT_ACTION_MOVE}, - {25ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {25ms, {{0, 35, 30, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); // Above, the resampled event is at 25ms rather than at 30 ms = 35ms - RESAMPLE_LATENCY @@ -428,8 +435,12 @@ TEST_F(TouchResamplingTest, OldEventReceivedAfterResampleOccurs) { frameTime = 50ms; expectedEntries = { // id x y - {24ms, {{0, 35, 30}}, AMOTION_EVENT_ACTION_MOVE}, // original event, rewritten - {26ms, {{0, 45, 30}}, AMOTION_EVENT_ACTION_MOVE}, // resampled event, rewritten + {24ms, + {{0, 35, 30, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, // original event, rewritten + {26ms, + {{0, 45, 30, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, // resampled event, rewritten }; consumeInputEventEntries(expectedEntries, frameTime); } @@ -499,7 +510,9 @@ TEST_F(TouchResamplingTest, TwoPointersAreResampledIndependently) { // id x y {30ms, {{0, 100, 100}, {1, 500, 500}}, AMOTION_EVENT_ACTION_MOVE}, {40ms, {{0, 120, 120}, {1, 600, 600}}, AMOTION_EVENT_ACTION_MOVE}, - {45ms, {{0, 130, 130}, {1, 650, 650}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {45ms, + {{0, 130, 130, .isResampled = true}, {1, 650, 650, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); @@ -518,11 +531,13 @@ TEST_F(TouchResamplingTest, TwoPointersAreResampledIndependently) { */ expectedEntries = { {60ms, - {{0, 130, 130}, // not 120! because it matches previous real event - {1, 650, 650}}, + {{0, 130, 130, .isResampled = true}, // not 120! because it matches previous real event + {1, 650, 650, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, {70ms, {{0, 130, 130}, {1, 700, 700}}, AMOTION_EVENT_ACTION_MOVE}, - {75ms, {{0, 135, 135}, {1, 750, 750}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {75ms, + {{0, 135, 135, .isResampled = true}, {1, 750, 750, .isResampled = true}}, + AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); @@ -554,7 +569,7 @@ TEST_F(TouchResamplingTest, TwoPointersAreResampledIndependently) { * The latest event with ACTION_MOVE was at t = 70, coord = 700. * Use that value for resampling here: (600 - 700) / (90 - 70) * 5 + 600 */ - {95ms, {{1, 575, 575}}, AMOTION_EVENT_ACTION_MOVE}, // resampled value + {95ms, {{1, 575, 575, .isResampled = true}}, AMOTION_EVENT_ACTION_MOVE}, }; consumeInputEventEntries(expectedEntries, frameTime); } -- cgit v1.2.3-59-g8ed1b From b1e8355b5967159230b80b207396230c671f6280 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Tue, 20 Dec 2022 11:02:26 +0000 Subject: Report pinch gestures Bug: 251196347 Test: check events received by a custom tester app, and touches shown by pointer location overlay Test: atest inputflinger_tests Change-Id: I249ca6208091e3c4291c5be68c77339bf5f69a5b --- include/android/input.h | 27 +++- include/input/Input.h | 5 + libs/input/Input.cpp | 2 + libs/input/InputEventLabels.cpp | 3 +- services/inputflinger/InputCommonConverter.cpp | 5 +- .../reader/mapper/gestures/GestureConverter.cpp | 74 +++++++++++ .../reader/mapper/gestures/GestureConverter.h | 6 + .../inputflinger/tests/GestureConverter_test.cpp | 138 ++++++++++++++++++++- .../inputflinger/tests/TestInputListenerMatchers.h | 17 +++ 9 files changed, 269 insertions(+), 8 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/android/input.h b/include/android/input.h index e1aac65457..d6f9d633b6 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -778,6 +778,9 @@ enum { * proportion of the touch pad's size. For example, if a touch pad is 1000 units wide, and a * swipe gesture starts at X = 500 then moves to X = 400, this axis would have a value of * -0.1. + * + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. */ AMOTION_EVENT_AXIS_GESTURE_X_OFFSET = 48, /** @@ -791,6 +794,9 @@ enum { * * - For a touch pad, reports the distance that should be scrolled in the X axis as a result of * the user's two-finger scroll gesture, in display pixels. + * + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. */ AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE = 50, /** @@ -799,6 +805,18 @@ enum { * The same as {@link AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE}, but for the Y axis. */ AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE = 51, + /** + * Axis constant: pinch scale factor of a motion event. + * + * - For a touch pad, reports the change in distance between the fingers when the user is making + * a pinch gesture, as a proportion of that distance when the gesture was last reported. For + * example, if the fingers were 50 units apart and are now 52 units apart, the scale factor + * would be 1.04. + * + * These values are relative to the state from the last event, not accumulated, so developers + * should make sure to process this axis value for all batched historical events. + */ + AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR = 52, /** * Note: This is not an "Axis constant". It does not represent any axis, nor should it be used @@ -806,7 +824,7 @@ enum { * to make some computations (like iterating through all possible axes) cleaner. * Please update the value accordingly if you add a new axis. */ - AMOTION_EVENT_MAXIMUM_VALID_AXIS_VALUE = AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE, + AMOTION_EVENT_MAXIMUM_VALID_AXIS_VALUE = AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR, // NOTE: If you add a new axis here you must also add it to several other files. // Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list. @@ -891,6 +909,13 @@ enum AMotionClassification : uint32_t { * why they have a separate constant from two-finger swipes. */ AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE = 4, + /** + * Classification constant: pinch. + * + * The current event stream represents the user pinching with two fingers on a touchpad. The + * gesture is centered around the current cursor position. + */ + AMOTION_EVENT_CLASSIFICATION_PINCH = 5, }; /** diff --git a/include/input/Input.h b/include/input/Input.h index 7e62ac005e..cf5474c60d 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -308,6 +308,11 @@ enum class MotionClassification : uint8_t { * have a separate constant from two-finger swipes. */ MULTI_FINGER_SWIPE = AMOTION_EVENT_CLASSIFICATION_MULTI_FINGER_SWIPE, + /** + * The current gesture represents the user pinching with two fingers on a touchpad. The gesture + * is centered around the current cursor position. + */ + PINCH = AMOTION_EVENT_CLASSIFICATION_PINCH, }; /** diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 000775b42a..c247fdbe07 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -74,6 +74,8 @@ const char* motionClassificationToString(MotionClassification classification) { return "TWO_FINGER_SWIPE"; case MotionClassification::MULTI_FINGER_SWIPE: return "MULTI_FINGER_SWIPE"; + case MotionClassification::PINCH: + return "PINCH"; } } diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index 8ffd220ad8..7159e27b13 100644 --- a/libs/input/InputEventLabels.cpp +++ b/libs/input/InputEventLabels.cpp @@ -396,7 +396,8 @@ namespace android { DEFINE_AXIS(GESTURE_X_OFFSET), \ DEFINE_AXIS(GESTURE_Y_OFFSET), \ DEFINE_AXIS(GESTURE_SCROLL_X_DISTANCE), \ - DEFINE_AXIS(GESTURE_SCROLL_Y_DISTANCE) + DEFINE_AXIS(GESTURE_SCROLL_Y_DISTANCE), \ + DEFINE_AXIS(GESTURE_PINCH_SCALE_FACTOR) // NOTE: If you add new LEDs here, you must also add them to Input.h #define LEDS_SEQUENCE \ diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index ea0a429000..0c93f5ce40 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -263,11 +263,12 @@ static_assert(static_cast(AMOTION_EVENT_AXIS_GENERIC_13) == common static_assert(static_cast(AMOTION_EVENT_AXIS_GENERIC_14) == common::Axis::GENERIC_14); static_assert(static_cast(AMOTION_EVENT_AXIS_GENERIC_15) == common::Axis::GENERIC_15); static_assert(static_cast(AMOTION_EVENT_AXIS_GENERIC_16) == common::Axis::GENERIC_16); -// TODO(b/251196347): add GESTURE_{X,Y}_OFFSET and GESTURE_SCROLL_{X,Y}_DISTANCE. +// TODO(b/251196347): add GESTURE_{X,Y}_OFFSET, GESTURE_SCROLL_{X,Y}_DISTANCE, and +// GESTURE_PINCH_SCALE_FACTOR. // If you added a new axis, consider whether this should also be exposed as a HAL axis. Update the // static_assert below and add the new axis here, or leave a comment summarizing your decision. static_assert(static_cast(AMOTION_EVENT_MAXIMUM_VALID_AXIS_VALUE) == - static_cast(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE)); + static_cast(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR)); static common::VideoFrame getHalVideoFrame(const TouchVideoFrame& frame) { common::VideoFrame out; diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp index 575acb06b6..e8e05b7663 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp @@ -18,6 +18,7 @@ #include #include +#include #include "TouchCursorInputMapperCommon.h" #include "input/Input.h" @@ -78,6 +79,8 @@ std::list GestureConverter::handleGesture(nsecs_t when, nsecs_t read case kGestureTypeSwipeLift: case kGestureTypeFourFingerSwipeLift: return handleMultiFingerSwipeLift(when, readTime); + case kGestureTypePinch: + return handlePinch(when, readTime, gesture); default: // TODO(b/251196347): handle more gesture types. return {}; @@ -321,6 +324,77 @@ NotifyArgs GestureConverter::handleFling(nsecs_t when, nsecs_t readTime, const G return out; } +[[nodiscard]] std::list GestureConverter::handlePinch(nsecs_t when, nsecs_t readTime, + const Gesture& gesture) { + std::list out; + float xCursorPosition, yCursorPosition; + mPointerController->getPosition(&xCursorPosition, &yCursorPosition); + + // Pinch gesture phases are reported a little differently from others, in that the same details + // struct is used for all phases of the gesture, just with different zoom_state values. When + // zoom_state is START or END, dz will always be 1, so we don't need to move the pointers in + // those cases. + + if (mCurrentClassification != MotionClassification::PINCH) { + LOG_ALWAYS_FATAL_IF(gesture.details.pinch.zoom_state != GESTURES_ZOOM_START, + "First pinch gesture does not have the START zoom state (%d instead).", + gesture.details.pinch.zoom_state); + mCurrentClassification = MotionClassification::PINCH; + mPinchFingerSeparation = INITIAL_PINCH_SEPARATION_PX; + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR, 1.0); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, + xCursorPosition - mPinchFingerSeparation / 2); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f); + mFakeFingerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, + xCursorPosition + mPinchFingerSeparation / 2); + mFakeFingerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); + mFakeFingerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f); + mDownTime = when; + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_DOWN, + /* actionButton= */ 0, mButtonState, /* pointerCount= */ 1, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + out.push_back(makeMotionArgs(when, readTime, + AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT, + /* actionButton= */ 0, mButtonState, /* pointerCount= */ 2, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + return out; + } + + if (gesture.details.pinch.zoom_state == GESTURES_ZOOM_END) { + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR, 1.0); + out.push_back(makeMotionArgs(when, readTime, + AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT, + /* actionButton= */ 0, mButtonState, /* pointerCount= */ 2, + mFingerProps.data(), mFakeFingerCoords.data(), xCursorPosition, + yCursorPosition)); + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_UP, /* actionButton= */ 0, + mButtonState, /* pointerCount= */ 1, mFingerProps.data(), + mFakeFingerCoords.data(), xCursorPosition, yCursorPosition)); + mCurrentClassification = MotionClassification::NONE; + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR, 0); + return out; + } + + mPinchFingerSeparation *= gesture.details.pinch.dz; + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR, + gesture.details.pinch.dz); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, + xCursorPosition - mPinchFingerSeparation / 2); + mFakeFingerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); + mFakeFingerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, + xCursorPosition + mPinchFingerSeparation / 2); + mFakeFingerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); + out.push_back(makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, /* actionButton= */ 0, + mButtonState, /* pointerCount= */ 2, mFingerProps.data(), + mFakeFingerCoords.data(), xCursorPosition, yCursorPosition)); + return out; +} + NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action, int32_t actionButton, int32_t buttonState, uint32_t pointerCount, diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index 6bea2d922c..8e8e3d9de3 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -57,6 +57,8 @@ private: uint32_t fingerCount, float dx, float dy); [[nodiscard]] std::list handleMultiFingerSwipeLift(nsecs_t when, nsecs_t readTime); + [[nodiscard]] std::list handlePinch(nsecs_t when, nsecs_t readTime, + const Gesture& gesture); NotifyMotionArgs makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action, int32_t actionButton, int32_t buttonState, @@ -79,7 +81,11 @@ private: nsecs_t mDownTime = 0; MotionClassification mCurrentClassification = MotionClassification::NONE; + // Only used when mCurrentClassification is MULTI_FINGER_SWIPE. uint32_t mSwipeFingerCount = 0; + static constexpr float INITIAL_PINCH_SEPARATION_PX = 200.0; + // Only used when mCurrentClassification is PINCH. + float mPinchFingerSeparation; static constexpr size_t MAX_FAKE_FINGERS = 4; // We never need any PointerProperties other than the finger tool type, so we can just keep a // const array of them. diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 683e78e348..b22c741475 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -40,7 +40,7 @@ protected: static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; static constexpr int32_t EVENTHUB_ID = 1; static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2; - static constexpr float POINTER_X = 100; + static constexpr float POINTER_X = 500; static constexpr float POINTER_Y = 200; void SetUp() { @@ -96,7 +96,7 @@ TEST_F(GestureConverterTest, Move) { WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), WithPressure(0.0f))); - ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(95, 210)); + ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); } TEST_F(GestureConverterTest, Move_Rotated) { @@ -114,7 +114,7 @@ TEST_F(GestureConverterTest, Move_Rotated) { WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), WithPressure(0.0f))); - ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110, 205)); + ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); } TEST_F(GestureConverterTest, ButtonsChange) { @@ -218,7 +218,7 @@ TEST_F(GestureConverterTest, DragWithButton) { WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))); - ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(95, 210)); + ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); // Release the button Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -574,4 +574,134 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); } +TEST_F(GestureConverterTest, Pinch_Inwards) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_START); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + ASSERT_EQ(2u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + + Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); + ASSERT_EQ(1u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(0.8f, EPSILON), + WithPointerCoords(0, POINTER_X - 80, POINTER_Y), + WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + + Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_END); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); + ASSERT_EQ(2u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); +} + +TEST_F(GestureConverterTest, Pinch_Outwards) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_START); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + ASSERT_EQ(2u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + + Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); + ASSERT_EQ(1u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.2f, EPSILON), + WithPointerCoords(0, POINTER_X - 120, POINTER_Y), + WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + + Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_END); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); + ASSERT_EQ(2u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | + 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + args.pop_front(); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), + WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), + WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); +} + +TEST_F(GestureConverterTest, Pinch_ClearsClassificationAndScaleFactorAfterGesture) { + InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID); + GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID); + + Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_START); + std::list args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture); + + Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, + /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture); + + Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, + GESTURES_ZOOM_END); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture); + + Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); + args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture); + ASSERT_EQ(1u, args.size()); + ASSERT_THAT(std::get(args.front()), + AllOf(WithMotionClassification(MotionClassification::NONE), + WithGesturePinchScaleFactor(0, EPSILON))); +} + } // namespace android diff --git a/services/inputflinger/tests/TestInputListenerMatchers.h b/services/inputflinger/tests/TestInputListenerMatchers.h index 53e4066b20..b9d96076f1 100644 --- a/services/inputflinger/tests/TestInputListenerMatchers.h +++ b/services/inputflinger/tests/TestInputListenerMatchers.h @@ -81,6 +81,14 @@ MATCHER_P2(WithCoords, x, y, "InputEvent with specified coords") { return argX == x && argY == y; } +MATCHER_P3(WithPointerCoords, pointer, x, y, "InputEvent with specified coords for pointer") { + const auto argX = arg.pointerCoords[pointer].getX(); + const auto argY = arg.pointerCoords[pointer].getY(); + *result_listener << "expected pointer " << pointer << " to have coords (" << x << ", " << y + << "), but got (" << argX << ", " << argY << ")"; + return argX == x && argY == y; +} + MATCHER_P2(WithRelativeMotion, x, y, "InputEvent with specified relative motion") { const auto argX = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); const auto argY = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); @@ -113,6 +121,15 @@ MATCHER_P3(WithGestureScrollDistance, x, y, epsilon, return xDiff <= epsilon && yDiff <= epsilon; } +MATCHER_P2(WithGesturePinchScaleFactor, factor, epsilon, + "InputEvent with specified touchpad pinch gesture scale factor") { + const auto argScaleFactor = + arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR); + *result_listener << "expected gesture scale factor " << factor << " within " << epsilon + << " but got " << argScaleFactor; + return fabs(argScaleFactor - factor) <= epsilon; +} + MATCHER_P(WithPressure, pressure, "InputEvent with specified pressure") { const auto argPressure = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE); *result_listener << "expected pressure " << pressure << ", but got " << argPressure; -- cgit v1.2.3-59-g8ed1b From d010b014dc42f55b5973c8329ab10dd69da92c77 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 18 Jan 2023 15:00:53 -0800 Subject: Improve debug prints in InputDispatcher It's useful sometimes to print out the events produced by the dispatcher. In this CL: - Switch (partially) to the C++-style prints from android-base - Add a way to print keyevents, motionevent into a stream - Add InputEventInjectionResult print Also, improve the debug prints for outgoing events. When an entry is getting dispatched, the dispatcher may modify its action, among other variables. With this CL, this will be observable in the logs. Bug: 211379801 Test: atest AccessibilityEndToEndTest Change-Id: I221161af7903ae4da77733265c67a426a3e5b557 --- include/input/Input.h | 2 ++ libs/input/Input.cpp | 22 ++++++++++++++++++++ .../android/os/InputEventInjectionResult.aidl | 3 +++ services/inputflinger/dispatcher/Entry.cpp | 24 ++++++++++++++++++++++ services/inputflinger/dispatcher/Entry.h | 2 ++ .../inputflinger/dispatcher/InputDispatcher.cpp | 18 ++++++++++++++-- 6 files changed, 69 insertions(+), 2 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index e281675a33..30b0d6a67a 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -550,6 +550,8 @@ protected: nsecs_t mEventTime; }; +std::ostream& operator<<(std::ostream& out, const KeyEvent& event); + /* * Motion events. */ diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c7964393e0..c356c2e5e9 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -343,6 +343,28 @@ const char* KeyEvent::actionToString(int32_t action) { return "UNKNOWN"; } +std::ostream& operator<<(std::ostream& out, const KeyEvent& event) { + out << "KeyEvent { action=" << KeyEvent::actionToString(event.getAction()); + + out << ", keycode=" << event.getKeyCode() << "(" << KeyEvent::getLabel(event.getKeyCode()) + << ")"; + + if (event.getMetaState() != 0) { + out << ", metaState=" << event.getMetaState(); + } + + out << ", eventTime=" << event.getEventTime(); + out << ", downTime=" << event.getDownTime(); + out << ", flags=" << std::hex << event.getFlags() << std::dec; + out << ", repeatCount=" << event.getRepeatCount(); + out << ", deviceId=" << event.getDeviceId(); + out << ", source=" << inputEventSourceToString(event.getSource()); + out << ", displayId=" << event.getDisplayId(); + out << ", eventId=" << event.getId(); + out << "}"; + return out; +} + // --- PointerCoords --- float PointerCoords::getAxisValue(int32_t axis) const { diff --git a/libs/input/android/os/InputEventInjectionResult.aidl b/libs/input/android/os/InputEventInjectionResult.aidl index 3bc7068f3c..e80c2a52dc 100644 --- a/libs/input/android/os/InputEventInjectionResult.aidl +++ b/libs/input/android/os/InputEventInjectionResult.aidl @@ -37,4 +37,7 @@ enum InputEventInjectionResult { /* Injection failed due to a timeout. */ TIMED_OUT = 3, + + ftl_first=PENDING, + ftl_last=TIMED_OUT, } diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp index 7bbfb95b88..ce7c882f7d 100644 --- a/services/inputflinger/dispatcher/Entry.cpp +++ b/services/inputflinger/dispatcher/Entry.cpp @@ -331,4 +331,28 @@ uint32_t DispatchEntry::nextSeq() { return seq; } +std::ostream& operator<<(std::ostream& out, const DispatchEntry& entry) { + out << "DispatchEntry{resolvedAction="; + switch (entry.eventEntry->type) { + case EventEntry::Type::KEY: { + out << KeyEvent::actionToString(entry.resolvedAction); + break; + } + case EventEntry::Type::MOTION: { + out << MotionEvent::actionToString(entry.resolvedAction); + break; + } + default: { + out << ""; + break; + } + } + std::string transform; + entry.transform.dump(transform, "transform"); + out << ", resolvedFlags=" << entry.resolvedFlags + << ", targetFlags=" << entry.targetFlags.string() << ", transform=" << transform + << "} original =" << entry.eventEntry->getDescription(); + return out; +} + } // namespace android::inputdispatcher diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h index 3799814f67..8dc2a2a221 100644 --- a/services/inputflinger/dispatcher/Entry.h +++ b/services/inputflinger/dispatcher/Entry.h @@ -254,6 +254,8 @@ private: static uint32_t nextSeq(); }; +std::ostream& operator<<(std::ostream& out, const DispatchEntry& entry); + VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry); VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry, const ui::Transform& rawTransform); diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 37a451b3dd..204fff4566 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -20,6 +20,7 @@ #define LOG_NDEBUG 1 #include +#include #include #include #include @@ -3382,6 +3383,10 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, case EventEntry::Type::KEY: { const KeyEntry& keyEntry = static_cast(eventEntry); std::array hmac = getSignature(keyEntry, *dispatchEntry); + if (DEBUG_OUTBOUND_EVENT_DETAILS) { + LOG(DEBUG) << "Publishing " << *dispatchEntry << " to " + << connection->getInputChannelName(); + } // Publish the key event. status = connection->inputPublisher @@ -3397,6 +3402,10 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, } case EventEntry::Type::MOTION: { + if (DEBUG_OUTBOUND_EVENT_DETAILS) { + LOG(DEBUG) << "Publishing " << *dispatchEntry << " to " + << connection->getInputChannelName(); + } status = publishMotionEvent(*connection, *dispatchEntry); break; } @@ -4448,6 +4457,9 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev bool needWake = false; while (!injectedEntries.empty()) { + if (DEBUG_INJECTION) { + LOG(DEBUG) << "Injecting " << injectedEntries.front()->getDescription(); + } needWake |= enqueueInboundEventLocked(std::move(injectedEntries.front())); injectedEntries.pop(); } @@ -4510,7 +4522,8 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev } // release lock if (DEBUG_INJECTION) { - ALOGD("injectInputEvent - Finished with result %d.", injectionResult); + LOG(DEBUG) << "injectInputEvent - Finished with result " + << ftl::enum_string(injectionResult); } return injectionResult; @@ -4554,7 +4567,8 @@ void InputDispatcher::setInjectionResult(EventEntry& entry, InjectionState* injectionState = entry.injectionState; if (injectionState) { if (DEBUG_INJECTION) { - ALOGD("Setting input event injection result to %d.", injectionResult); + LOG(DEBUG) << "Setting input event injection result to " + << ftl::enum_string(injectionResult); } if (injectionState->injectionIsAsync && !(entry.policyFlags & POLICY_FLAG_FILTERED)) { -- cgit v1.2.3-59-g8ed1b From 5df3493d3cf633f8ac7447bc5474a0dfbc1a8359 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Mon, 23 Jan 2023 12:41:01 -0800 Subject: Validate axes and led labels correctly Before this CL, a number of checks for kl file validity were incorrect. Some of the APIs were supposed to return an invalid value, but instead were always returning a valid value, no matter what the input was. Correct these values by switching to std::optional. Bug: 266400536 Test: m libinput_tests && adb sync data && adb shell -t /data/nativetest64/libinput_tests/libinput_tests Change-Id: I4ef45f3249dca4f4f033fb85e9fecbc2ad1f1395 --- include/input/Input.h | 4 +- include/input/InputEventLabels.h | 12 ++-- libs/input/Input.cpp | 4 +- libs/input/InputEventLabels.cpp | 22 +++---- libs/input/KeyCharacterMap.cpp | 24 ++++---- libs/input/KeyLayoutMap.cpp | 106 +++++++++++++++++++------------- libs/input/tests/InputDevice_test.cpp | 14 +++++ libs/input/tests/data/bad_axis_label.kl | 17 +++++ libs/input/tests/data/bad_led_label.kl | 17 +++++ 9 files changed, 142 insertions(+), 78 deletions(-) create mode 100644 libs/input/tests/data/bad_axis_label.kl create mode 100644 libs/input/tests/data/bad_led_label.kl (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 30b0d6a67a..7573282fc1 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -529,7 +529,7 @@ public: inline nsecs_t getEventTime() const { return mEventTime; } static const char* getLabel(int32_t keyCode); - static int32_t getKeyCodeFromLabel(const char* label); + static std::optional getKeyCodeFromLabel(const char* label); void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, std::array hmac, int32_t action, int32_t flags, int32_t keyCode, @@ -842,7 +842,7 @@ public: } static const char* getLabel(int32_t axis); - static int32_t getAxisFromLabel(const char* label); + static std::optional getAxisFromLabel(const char* label); static std::string actionToString(int32_t action); diff --git a/include/input/InputEventLabels.h b/include/input/InputEventLabels.h index b4374acdcc..4668fce116 100644 --- a/include/input/InputEventLabels.h +++ b/include/input/InputEventLabels.h @@ -35,22 +35,22 @@ struct InputEventLabel { class InputEventLookup { public: - static int lookupValueByLabel(const std::unordered_map& map, - const char* literal); + static std::optional lookupValueByLabel(const std::unordered_map& map, + const char* literal); static const char* lookupLabelByValue(const std::vector& vec, int value); - static int32_t getKeyCodeByLabel(const char* label); + static std::optional getKeyCodeByLabel(const char* label); static const char* getLabelByKeyCode(int32_t keyCode); - static uint32_t getKeyFlagByLabel(const char* label); + static std::optional getKeyFlagByLabel(const char* label); - static int32_t getAxisByLabel(const char* label); + static std::optional getAxisByLabel(const char* label); static const char* getAxisLabel(int32_t axisId); - static int32_t getLedByLabel(const char* label); + static std::optional getLedByLabel(const char* label); private: static const std::unordered_map KEYCODES; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c356c2e5e9..133b260a61 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -299,7 +299,7 @@ const char* KeyEvent::getLabel(int32_t keyCode) { return InputEventLookup::getLabelByKeyCode(keyCode); } -int32_t KeyEvent::getKeyCodeFromLabel(const char* label) { +std::optional KeyEvent::getKeyCodeFromLabel(const char* label) { return InputEventLookup::getKeyCodeByLabel(label); } @@ -891,7 +891,7 @@ const char* MotionEvent::getLabel(int32_t axis) { return InputEventLookup::getAxisLabel(axis); } -int32_t MotionEvent::getAxisFromLabel(const char* label) { +std::optional MotionEvent::getAxisFromLabel(const char* label) { return InputEventLookup::getAxisByLabel(label); } diff --git a/libs/input/InputEventLabels.cpp b/libs/input/InputEventLabels.cpp index 7159e27b13..d97c1bb629 100644 --- a/libs/input/InputEventLabels.cpp +++ b/libs/input/InputEventLabels.cpp @@ -438,11 +438,11 @@ const std::unordered_map InputEventLookup::LEDS = {LEDS_SEQUEN const std::unordered_map InputEventLookup::FLAGS = {FLAGS_SEQUENCE}; -int InputEventLookup::lookupValueByLabel(const std::unordered_map& map, - const char* literal) { +std::optional InputEventLookup::lookupValueByLabel( + const std::unordered_map& map, const char* literal) { std::string str(literal); auto it = map.find(str); - return it != map.end() ? it->second : 0; + return it != map.end() ? std::make_optional(it->second) : std::nullopt; } const char* InputEventLookup::lookupLabelByValue(const std::vector& vec, @@ -453,8 +453,8 @@ const char* InputEventLookup::lookupLabelByValue(const std::vector InputEventLookup::getKeyCodeByLabel(const char* label) { + return lookupValueByLabel(KEYCODES, label); } const char* InputEventLookup::getLabelByKeyCode(int32_t keyCode) { @@ -464,20 +464,20 @@ const char* InputEventLookup::getLabelByKeyCode(int32_t keyCode) { return nullptr; } -uint32_t InputEventLookup::getKeyFlagByLabel(const char* label) { - return uint32_t(lookupValueByLabel(FLAGS, label)); +std::optional InputEventLookup::getKeyFlagByLabel(const char* label) { + return lookupValueByLabel(FLAGS, label); } -int32_t InputEventLookup::getAxisByLabel(const char* label) { - return int32_t(lookupValueByLabel(AXES, label)); +std::optional InputEventLookup::getAxisByLabel(const char* label) { + return lookupValueByLabel(AXES, label); } const char* InputEventLookup::getAxisLabel(int32_t axisId) { return lookupLabelByValue(AXES_NAMES, axisId); } -int32_t InputEventLookup::getLedByLabel(const char* label) { - return int32_t(lookupValueByLabel(LEDS, label)); +std::optional InputEventLookup::getLedByLabel(const char* label) { + return lookupValueByLabel(LEDS, label); } } // namespace android diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index 6bfac40932..737bd15901 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -999,7 +999,7 @@ status_t KeyCharacterMap::Parser::parseMapKey() { mTokenizer->skipDelimiters(WHITESPACE); String8 keyCodeToken = mTokenizer->nextToken(WHITESPACE); - int32_t keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); + std::optional keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); if (!keyCode) { ALOGE("%s: Expected key code label, got '%s'.", mTokenizer->getLocation().string(), keyCodeToken.string()); @@ -1010,19 +1010,19 @@ status_t KeyCharacterMap::Parser::parseMapKey() { ALOGD("Parsed map key %s: code=%d, keyCode=%d.", mapUsage ? "usage" : "scan code", code, keyCode); #endif - map.insert_or_assign(code, keyCode); + map.insert_or_assign(code, *keyCode); return NO_ERROR; } status_t KeyCharacterMap::Parser::parseKey() { String8 keyCodeToken = mTokenizer->nextToken(WHITESPACE); - int32_t keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); + std::optional keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); if (!keyCode) { ALOGE("%s: Expected key code label, got '%s'.", mTokenizer->getLocation().string(), keyCodeToken.string()); return BAD_VALUE; } - if (mMap->mKeys.indexOfKey(keyCode) >= 0) { + if (mMap->mKeys.indexOfKey(*keyCode) >= 0) { ALOGE("%s: Duplicate entry for key code '%s'.", mTokenizer->getLocation().string(), keyCodeToken.string()); return BAD_VALUE; @@ -1036,11 +1036,9 @@ status_t KeyCharacterMap::Parser::parseKey() { return BAD_VALUE; } -#if DEBUG_PARSER - ALOGD("Parsed beginning of key: keyCode=%d.", keyCode); -#endif - mKeyCode = keyCode; - mMap->mKeys.add(keyCode, new Key()); + ALOGD_IF(DEBUG_PARSER, "Parsed beginning of key: keyCode=%d.", *keyCode); + mKeyCode = *keyCode; + mMap->mKeys.add(*keyCode, new Key()); mState = STATE_KEY; return NO_ERROR; } @@ -1136,7 +1134,7 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { } else if (token == "fallback") { mTokenizer->skipDelimiters(WHITESPACE); token = mTokenizer->nextToken(WHITESPACE); - int32_t keyCode = InputEventLookup::getKeyCodeByLabel(token.string()); + std::optional keyCode = InputEventLookup::getKeyCodeByLabel(token.string()); if (!keyCode) { ALOGE("%s: Invalid key code label for fallback behavior, got '%s'.", mTokenizer->getLocation().string(), @@ -1148,12 +1146,12 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { mTokenizer->getLocation().string()); return BAD_VALUE; } - behavior.fallbackKeyCode = keyCode; + behavior.fallbackKeyCode = *keyCode; haveFallback = true; } else if (token == "replace") { mTokenizer->skipDelimiters(WHITESPACE); token = mTokenizer->nextToken(WHITESPACE); - int32_t keyCode = InputEventLookup::getKeyCodeByLabel(token.string()); + std::optional keyCode = InputEventLookup::getKeyCodeByLabel(token.string()); if (!keyCode) { ALOGE("%s: Invalid key code label for replace, got '%s'.", mTokenizer->getLocation().string(), @@ -1170,7 +1168,7 @@ status_t KeyCharacterMap::Parser::parseKeyProperty() { mTokenizer->getLocation().string()); return BAD_VALUE; } - behavior.replacementKeyCode = keyCode; + behavior.replacementKeyCode = *keyCode; haveReplacement = true; } else { diff --git a/libs/input/KeyLayoutMap.cpp b/libs/input/KeyLayoutMap.cpp index 73710330d0..a2649f6f11 100644 --- a/libs/input/KeyLayoutMap.cpp +++ b/libs/input/KeyLayoutMap.cpp @@ -16,6 +16,7 @@ #define LOG_TAG "KeyLayoutMap" +#include #include #include #include @@ -54,6 +55,21 @@ const bool DEBUG_MAPPING = namespace android { namespace { +std::optional parseInt(const char* str) { + char* end; + errno = 0; + const int value = strtol(str, &end, 0); + if (end == str) { + LOG(ERROR) << "Could not parse " << str; + return {}; + } + if (errno == ERANGE) { + LOG(ERROR) << "Out of bounds: " << str; + return {}; + } + return value; +} + constexpr const char* WHITESPACE = " \t\r"; template @@ -336,16 +352,15 @@ status_t KeyLayoutMap::Parser::parseKey() { codeToken = mTokenizer->nextToken(WHITESPACE); } - char* end; - int32_t code = int32_t(strtol(codeToken.string(), &end, 0)); - if (*end) { + std::optional code = parseInt(codeToken.string()); + if (!code) { ALOGE("%s: Expected key %s number, got '%s'.", mTokenizer->getLocation().string(), mapUsage ? "usage" : "scan code", codeToken.string()); return BAD_VALUE; } std::unordered_map& map = mapUsage ? mMap->mKeysByUsageCode : mMap->mKeysByScanCode; - if (map.find(code) != map.end()) { + if (map.find(*code) != map.end()) { ALOGE("%s: Duplicate entry for key %s '%s'.", mTokenizer->getLocation().string(), mapUsage ? "usage" : "scan code", codeToken.string()); return BAD_VALUE; @@ -353,7 +368,7 @@ status_t KeyLayoutMap::Parser::parseKey() { mTokenizer->skipDelimiters(WHITESPACE); String8 keyCodeToken = mTokenizer->nextToken(WHITESPACE); - int32_t keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); + std::optional keyCode = InputEventLookup::getKeyCodeByLabel(keyCodeToken.string()); if (!keyCode) { ALOGE("%s: Expected key code label, got '%s'.", mTokenizer->getLocation().string(), keyCodeToken.string()); @@ -366,40 +381,39 @@ status_t KeyLayoutMap::Parser::parseKey() { if (mTokenizer->isEol() || mTokenizer->peekChar() == '#') break; String8 flagToken = mTokenizer->nextToken(WHITESPACE); - uint32_t flag = InputEventLookup::getKeyFlagByLabel(flagToken.string()); + std::optional flag = InputEventLookup::getKeyFlagByLabel(flagToken.string()); if (!flag) { ALOGE("%s: Expected key flag label, got '%s'.", mTokenizer->getLocation().string(), flagToken.string()); return BAD_VALUE; } - if (flags & flag) { + if (flags & *flag) { ALOGE("%s: Duplicate key flag '%s'.", mTokenizer->getLocation().string(), flagToken.string()); return BAD_VALUE; } - flags |= flag; + flags |= *flag; } ALOGD_IF(DEBUG_PARSER, "Parsed key %s: code=%d, keyCode=%d, flags=0x%08x.", - mapUsage ? "usage" : "scan code", code, keyCode, flags); + mapUsage ? "usage" : "scan code", *code, *keyCode, flags); Key key; - key.keyCode = keyCode; + key.keyCode = *keyCode; key.flags = flags; - map.insert({code, key}); + map.insert({*code, key}); return NO_ERROR; } status_t KeyLayoutMap::Parser::parseAxis() { String8 scanCodeToken = mTokenizer->nextToken(WHITESPACE); - char* end; - int32_t scanCode = int32_t(strtol(scanCodeToken.string(), &end, 0)); - if (*end) { + std::optional scanCode = parseInt(scanCodeToken.string()); + if (!scanCode) { ALOGE("%s: Expected axis scan code number, got '%s'.", mTokenizer->getLocation().string(), scanCodeToken.string()); return BAD_VALUE; } - if (mMap->mAxes.find(scanCode) != mMap->mAxes.end()) { + if (mMap->mAxes.find(*scanCode) != mMap->mAxes.end()) { ALOGE("%s: Duplicate entry for axis scan code '%s'.", mTokenizer->getLocation().string(), scanCodeToken.string()); return BAD_VALUE; @@ -414,48 +428,53 @@ status_t KeyLayoutMap::Parser::parseAxis() { mTokenizer->skipDelimiters(WHITESPACE); String8 axisToken = mTokenizer->nextToken(WHITESPACE); - axisInfo.axis = InputEventLookup::getAxisByLabel(axisToken.string()); - if (axisInfo.axis < 0) { + std::optional axis = InputEventLookup::getAxisByLabel(axisToken.string()); + if (!axis) { ALOGE("%s: Expected inverted axis label, got '%s'.", mTokenizer->getLocation().string(), axisToken.string()); return BAD_VALUE; } + axisInfo.axis = *axis; } else if (token == "split") { axisInfo.mode = AxisInfo::MODE_SPLIT; mTokenizer->skipDelimiters(WHITESPACE); String8 splitToken = mTokenizer->nextToken(WHITESPACE); - axisInfo.splitValue = int32_t(strtol(splitToken.string(), &end, 0)); - if (*end) { + std::optional splitValue = parseInt(splitToken.string()); + if (!splitValue) { ALOGE("%s: Expected split value, got '%s'.", mTokenizer->getLocation().string(), splitToken.string()); return BAD_VALUE; } + axisInfo.splitValue = *splitValue; mTokenizer->skipDelimiters(WHITESPACE); String8 lowAxisToken = mTokenizer->nextToken(WHITESPACE); - axisInfo.axis = InputEventLookup::getAxisByLabel(lowAxisToken.string()); - if (axisInfo.axis < 0) { + std::optional axis = InputEventLookup::getAxisByLabel(lowAxisToken.string()); + if (!axis) { ALOGE("%s: Expected low axis label, got '%s'.", mTokenizer->getLocation().string(), lowAxisToken.string()); return BAD_VALUE; } + axisInfo.axis = *axis; mTokenizer->skipDelimiters(WHITESPACE); String8 highAxisToken = mTokenizer->nextToken(WHITESPACE); - axisInfo.highAxis = InputEventLookup::getAxisByLabel(highAxisToken.string()); - if (axisInfo.highAxis < 0) { + std::optional highAxis = InputEventLookup::getAxisByLabel(highAxisToken.string()); + if (!highAxis) { ALOGE("%s: Expected high axis label, got '%s'.", mTokenizer->getLocation().string(), highAxisToken.string()); return BAD_VALUE; } + axisInfo.highAxis = *highAxis; } else { - axisInfo.axis = InputEventLookup::getAxisByLabel(token.string()); - if (axisInfo.axis < 0) { + std::optional axis = InputEventLookup::getAxisByLabel(token.string()); + if (!axis) { ALOGE("%s: Expected axis label, 'split' or 'invert', got '%s'.", mTokenizer->getLocation().string(), token.string()); return BAD_VALUE; } + axisInfo.axis = *axis; } for (;;) { @@ -467,12 +486,13 @@ status_t KeyLayoutMap::Parser::parseAxis() { if (keywordToken == "flat") { mTokenizer->skipDelimiters(WHITESPACE); String8 flatToken = mTokenizer->nextToken(WHITESPACE); - axisInfo.flatOverride = int32_t(strtol(flatToken.string(), &end, 0)); - if (*end) { + std::optional flatOverride = parseInt(flatToken.string()); + if (!flatOverride) { ALOGE("%s: Expected flat value, got '%s'.", mTokenizer->getLocation().string(), flatToken.string()); return BAD_VALUE; } + axisInfo.flatOverride = *flatOverride; } else { ALOGE("%s: Expected keyword 'flat', got '%s'.", mTokenizer->getLocation().string(), keywordToken.string()); @@ -483,9 +503,9 @@ status_t KeyLayoutMap::Parser::parseAxis() { ALOGD_IF(DEBUG_PARSER, "Parsed axis: scanCode=%d, mode=%d, axis=%d, highAxis=%d, " "splitValue=%d, flatOverride=%d.", - scanCode, axisInfo.mode, axisInfo.axis, axisInfo.highAxis, axisInfo.splitValue, + *scanCode, axisInfo.mode, axisInfo.axis, axisInfo.highAxis, axisInfo.splitValue, axisInfo.flatOverride); - mMap->mAxes.insert({scanCode, axisInfo}); + mMap->mAxes.insert({*scanCode, axisInfo}); return NO_ERROR; } @@ -497,9 +517,8 @@ status_t KeyLayoutMap::Parser::parseLed() { mTokenizer->skipDelimiters(WHITESPACE); codeToken = mTokenizer->nextToken(WHITESPACE); } - char* end; - int32_t code = int32_t(strtol(codeToken.string(), &end, 0)); - if (*end) { + std::optional code = parseInt(codeToken.string()); + if (!code) { ALOGE("%s: Expected led %s number, got '%s'.", mTokenizer->getLocation().string(), mapUsage ? "usage" : "scan code", codeToken.string()); return BAD_VALUE; @@ -507,7 +526,7 @@ status_t KeyLayoutMap::Parser::parseLed() { std::unordered_map& map = mapUsage ? mMap->mLedsByUsageCode : mMap->mLedsByScanCode; - if (map.find(code) != map.end()) { + if (map.find(*code) != map.end()) { ALOGE("%s: Duplicate entry for led %s '%s'.", mTokenizer->getLocation().string(), mapUsage ? "usage" : "scan code", codeToken.string()); return BAD_VALUE; @@ -515,19 +534,19 @@ status_t KeyLayoutMap::Parser::parseLed() { mTokenizer->skipDelimiters(WHITESPACE); String8 ledCodeToken = mTokenizer->nextToken(WHITESPACE); - int32_t ledCode = InputEventLookup::getLedByLabel(ledCodeToken.string()); - if (ledCode < 0) { + std::optional ledCode = InputEventLookup::getLedByLabel(ledCodeToken.string()); + if (!ledCode) { ALOGE("%s: Expected LED code label, got '%s'.", mTokenizer->getLocation().string(), ledCodeToken.string()); return BAD_VALUE; } ALOGD_IF(DEBUG_PARSER, "Parsed led %s: code=%d, ledCode=%d.", mapUsage ? "usage" : "scan code", - code, ledCode); + *code, *ledCode); Led led; - led.ledCode = ledCode; - map.insert({code, led}); + led.ledCode = *ledCode; + map.insert({*code, led}); return NO_ERROR; } @@ -565,16 +584,15 @@ static std::optional getSensorDataIndex(String8 token) { // sensor 0x05 GYROSCOPE Z status_t KeyLayoutMap::Parser::parseSensor() { String8 codeToken = mTokenizer->nextToken(WHITESPACE); - char* end; - int32_t code = int32_t(strtol(codeToken.string(), &end, 0)); - if (*end) { + std::optional code = parseInt(codeToken.string()); + if (!code) { ALOGE("%s: Expected sensor %s number, got '%s'.", mTokenizer->getLocation().string(), "abs code", codeToken.string()); return BAD_VALUE; } std::unordered_map& map = mMap->mSensorsByAbsCode; - if (map.find(code) != map.end()) { + if (map.find(*code) != map.end()) { ALOGE("%s: Duplicate entry for sensor %s '%s'.", mTokenizer->getLocation().string(), "abs code", codeToken.string()); return BAD_VALUE; @@ -599,13 +617,13 @@ status_t KeyLayoutMap::Parser::parseSensor() { } int32_t sensorDataIndex = indexOpt.value(); - ALOGD_IF(DEBUG_PARSER, "Parsed sensor: abs code=%d, sensorType=%s, sensorDataIndex=%d.", code, + ALOGD_IF(DEBUG_PARSER, "Parsed sensor: abs code=%d, sensorType=%s, sensorDataIndex=%d.", *code, ftl::enum_string(sensorType).c_str(), sensorDataIndex); Sensor sensor; sensor.sensorType = sensorType; sensor.sensorDataIndex = sensorDataIndex; - map.emplace(code, sensor); + map.emplace(*code, sensor); return NO_ERROR; } diff --git a/libs/input/tests/InputDevice_test.cpp b/libs/input/tests/InputDevice_test.cpp index 2344463241..ee961f0ffc 100644 --- a/libs/input/tests/InputDevice_test.cpp +++ b/libs/input/tests/InputDevice_test.cpp @@ -133,6 +133,20 @@ TEST_F(InputDeviceKeyMapTest, keyCharacteMapApplyMultipleOverlaysTest) { ASSERT_EQ(*mKeyMap.keyCharacterMap, *frenchOverlaidKeyCharacterMap); } +TEST_F(InputDeviceKeyMapTest, keyCharacteMapBadAxisLabel) { + std::string klPath = base::GetExecutableDirectory() + "/data/bad_axis_label.kl"; + + base::Result> ret = KeyLayoutMap::load(klPath); + ASSERT_FALSE(ret.ok()) << "Should not be able to load KeyLayout at " << klPath; +} + +TEST_F(InputDeviceKeyMapTest, keyCharacteMapBadLedLabel) { + std::string klPath = base::GetExecutableDirectory() + "/data/bad_led_label.kl"; + + base::Result> ret = KeyLayoutMap::load(klPath); + ASSERT_FALSE(ret.ok()) << "Should not be able to load KeyLayout at " << klPath; +} + TEST(InputDeviceKeyLayoutTest, DoesNotLoadWhenRequiredKernelConfigIsMissing) { #if !defined(__ANDROID__) GTEST_SKIP() << "Can't check kernel configs on host"; diff --git a/libs/input/tests/data/bad_axis_label.kl b/libs/input/tests/data/bad_axis_label.kl new file mode 100644 index 0000000000..689738077c --- /dev/null +++ b/libs/input/tests/data/bad_axis_label.kl @@ -0,0 +1,17 @@ +# Copyright (C) 2023 The Android Open Source Project +# +# 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. + +# This KL should not be loaded because the axis label is not valid + +axis 0 DEFINITELY_NOT_AXIS_LABEL diff --git a/libs/input/tests/data/bad_led_label.kl b/libs/input/tests/data/bad_led_label.kl new file mode 100644 index 0000000000..293c0d2af4 --- /dev/null +++ b/libs/input/tests/data/bad_led_label.kl @@ -0,0 +1,17 @@ +# Copyright (C) 2023 The Android Open Source Project +# +# 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. + +# This KL should not be loaded because the led label is invalid + +led 0 ABSOLUTELY_NOT_LED_LABEL -- cgit v1.2.3-59-g8ed1b From 00e029d8cfd1e5487d8c8997ec852ffd54252a57 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 9 Mar 2023 20:11:09 +0000 Subject: MotionEvent: Round coordinates to a precision of 0.001 When tests inject input events at a location on the screen, the dispatched event is expected to have the same coordinates. However, on scaled devices, this may not always be the case due to precision losses incurred through floating point arithmetics. For example, it was possible for an injected event with a coordinate of 1.0 to end up with a value of 0.9997. To combat this issue, we will round transformed axis values that are leaving a MotionEvent to a precision of 0.001. After this CL, even if the injection process results in precision losses, they should be overcome by rounding, assuming injection does not require greater precision. This will solve the issue where input injected to an inclusive edge of the View bounds was not getting dispatched to the View due to precision losses. Bug: 264978231 Bug: 260965930 Test: atest libinput_tests Test: atest inputflinger_tests Test: atest HoverTest (with screen size override) Change-Id: I81062597058361a1218e6873d34b9b0d2fbfad96 --- include/input/Input.h | 2 + libs/input/Input.cpp | 21 +- libs/input/tests/InputEvent_test.cpp | 328 ++++++++++++--------- .../input/tests/InputPublisherAndConsumer_test.cpp | 20 +- .../inputflinger/tests/InputDispatcher_test.cpp | 8 +- 5 files changed, 230 insertions(+), 149 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index 608519b70e..e8af5f7d46 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -855,6 +855,8 @@ public: const PointerCoords&); static PointerCoords calculateTransformedCoords(uint32_t source, const ui::Transform&, const PointerCoords&); + // The rounding precision for transformed motion events. + static constexpr float ROUNDING_PRECISION = 0.001f; protected: int32_t mAction; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 133b260a61..53b22cb883 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -151,10 +151,23 @@ int32_t IdGenerator::nextId() const { // --- InputEvent --- +// Due to precision limitations when working with floating points, transforming - namely +// scaling - floating points can lead to minute errors. We round transformed values to approximately +// three decimal places so that values like 0.99997 show up as 1.0. +inline float roundTransformedCoords(float val) { + // Use a power to two to approximate three decimal places to potentially reduce some cycles. + // This should be at least as precise as MotionEvent::ROUNDING_PRECISION. + return std::round(val * 1024.f) / 1024.f; +} + +inline vec2 roundTransformedCoords(vec2 p) { + return {roundTransformedCoords(p.x), roundTransformedCoords(p.y)}; +} + vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) { const vec2 transformedXy = transform.transform(xy); const vec2 transformedOrigin = transform.transform(0, 0); - return transformedXy - transformedOrigin; + return roundTransformedCoords(transformedXy - transformedOrigin); } float transformAngle(const ui::Transform& transform, float angleRadians) { @@ -606,12 +619,12 @@ std::optional MotionEvent::getSurfaceRotation() const { float MotionEvent::getXCursorPosition() const { vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition()); - return vals.x; + return roundTransformedCoords(vals.x); } float MotionEvent::getYCursorPosition() const { vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition()); - return vals.y; + return roundTransformedCoords(vals.y); } void MotionEvent::setCursorPosition(float x, float y) { @@ -933,7 +946,7 @@ std::string MotionEvent::actionToString(int32_t action) { static inline vec2 calculateTransformedXYUnchecked(uint32_t source, const ui::Transform& transform, const vec2& xy) { return shouldDisregardOffset(source) ? transformWithoutTranslation(transform, xy) - : transform.transform(xy); + : roundTransformedCoords(transform.transform(xy)); } vec2 MotionEvent::calculateTransformedXY(uint32_t source, const ui::Transform& transform, diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 8a6e983bb5..81c23df97a 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -29,6 +29,8 @@ namespace android { // Default display id. static constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; +static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION; + class BaseTest : public testing::Test { protected: static constexpr std::array HMAC = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, @@ -235,102 +237,110 @@ protected: static constexpr float RAW_X_OFFSET = 12; static constexpr float RAW_Y_OFFSET = -41.1; + void SetUp() override; + int32_t mId; ui::Transform mTransform; ui::Transform mRawTransform; + PointerProperties mPointerProperties[2]; + struct Sample { + PointerCoords pointerCoords[2]; + }; + std::array mSamples{}; void initializeEventWithHistory(MotionEvent* event); void assertEqualsEventWithHistory(const MotionEvent* event); }; -void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { +void MotionEventTest::SetUp() { mId = InputEvent::nextId(); mTransform.set({X_SCALE, 0, X_OFFSET, 0, Y_SCALE, Y_OFFSET, 0, 0, 1}); mRawTransform.set({RAW_X_SCALE, 0, RAW_X_OFFSET, 0, RAW_Y_SCALE, RAW_Y_OFFSET, 0, 0, 1}); - PointerProperties pointerProperties[2]; - pointerProperties[0].clear(); - pointerProperties[0].id = 1; - pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; - pointerProperties[1].clear(); - pointerProperties[1].id = 2; - pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; - - PointerCoords pointerCoords[2]; - pointerCoords[0].clear(); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 10); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 11); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 12); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 13); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 14); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 15); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 16); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 17); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 18); - pointerCoords[0].isResampled = true; - pointerCoords[1].clear(); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 20); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 21); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 22); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 23); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 24); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 25); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 26); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 27); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 28); + mPointerProperties[0].clear(); + mPointerProperties[0].id = 1; + mPointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerProperties[1].clear(); + mPointerProperties[1].id = 2; + mPointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + + mSamples[0].pointerCoords[0].clear(); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 10); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 11); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 12); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 13); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 14); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 15); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 16); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 17); + mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 18); + mSamples[0].pointerCoords[0].isResampled = true; + mSamples[0].pointerCoords[1].clear(); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 20); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 21); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 22); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 23); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 24); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 25); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 26); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 27); + mSamples[0].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 28); + + mSamples[1].pointerCoords[0].clear(); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 110); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 111); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 112); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 113); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 114); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 115); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 116); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 117); + mSamples[1].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 118); + mSamples[1].pointerCoords[0].isResampled = true; + mSamples[1].pointerCoords[1].clear(); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 120); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 121); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 122); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 123); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 124); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 125); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 126); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 127); + mSamples[1].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 128); + mSamples[1].pointerCoords[1].isResampled = true; + + mSamples[2].pointerCoords[0].clear(); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 210); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 211); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 212); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 213); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 214); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 215); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 216); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 217); + mSamples[2].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 218); + mSamples[2].pointerCoords[1].clear(); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 220); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 221); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 222); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 223); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 224); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 225); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 226); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 227); + mSamples[2].pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 228); +} + +void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { event->initialize(mId, 2, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, HMAC, AMOTION_EVENT_ACTION_MOVE, 0, AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, AMOTION_EVENT_EDGE_FLAG_TOP, AMETA_ALT_ON, AMOTION_EVENT_BUTTON_PRIMARY, MotionClassification::NONE, mTransform, 2.0f, 2.1f, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, mRawTransform, ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME, 2, - pointerProperties, pointerCoords); - - pointerCoords[0].clear(); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 110); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 111); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 112); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 113); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 114); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 115); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 116); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 117); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 118); - pointerCoords[0].isResampled = true; - pointerCoords[1].clear(); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 120); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 121); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 122); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 123); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 124); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 125); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 126); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 127); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 128); - pointerCoords[1].isResampled = true; - event->addSample(ARBITRARY_EVENT_TIME + 1, pointerCoords); - - pointerCoords[0].clear(); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 210); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 211); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 212); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 213); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 214); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 215); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 216); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 217); - pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 218); - pointerCoords[1].clear(); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_X, 220); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_Y, 221); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 222); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 223); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 224); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 225); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 226); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 227); - pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 228); - event->addSample(ARBITRARY_EVENT_TIME + 2, pointerCoords); + mPointerProperties, mSamples[0].pointerCoords); + event->addSample(ARBITRARY_EVENT_TIME + 1, mSamples[1].pointerCoords); + event->addSample(ARBITRARY_EVENT_TIME + 2, mSamples[2].pointerCoords); } void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { @@ -367,51 +377,65 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { ASSERT_EQ(ARBITRARY_EVENT_TIME + 1, event->getHistoricalEventTime(1)); ASSERT_EQ(ARBITRARY_EVENT_TIME + 2, event->getEventTime()); - ASSERT_EQ(11, event->getHistoricalRawPointerCoords(0, 0)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - ASSERT_EQ(21, event->getHistoricalRawPointerCoords(1, 0)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - ASSERT_EQ(111, event->getHistoricalRawPointerCoords(0, 1)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - ASSERT_EQ(121, event->getHistoricalRawPointerCoords(1, 1)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - ASSERT_EQ(211, event->getRawPointerCoords(0)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - ASSERT_EQ(221, event->getRawPointerCoords(1)->getAxisValue(AMOTION_EVENT_AXIS_Y)); - - ASSERT_EQ(RAW_Y_OFFSET + 11 * RAW_Y_SCALE, - event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 0, 0)); - ASSERT_EQ(RAW_Y_OFFSET + 21 * RAW_Y_SCALE, - event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 1, 0)); - ASSERT_EQ(RAW_Y_OFFSET + 111 * RAW_Y_SCALE, - event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 0, 1)); - ASSERT_EQ(RAW_Y_OFFSET + 121 * RAW_Y_SCALE, - event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 1, 1)); - ASSERT_EQ(RAW_Y_OFFSET + 211 * RAW_Y_SCALE, event->getRawAxisValue(AMOTION_EVENT_AXIS_Y, 0)); - ASSERT_EQ(RAW_Y_OFFSET + 221 * RAW_Y_SCALE, event->getRawAxisValue(AMOTION_EVENT_AXIS_Y, 1)); - - ASSERT_EQ(RAW_X_OFFSET + 10 * RAW_X_SCALE, event->getHistoricalRawX(0, 0)); - ASSERT_EQ(RAW_X_OFFSET + 20 * RAW_X_SCALE, event->getHistoricalRawX(1, 0)); - ASSERT_EQ(RAW_X_OFFSET + 110 * RAW_X_SCALE, event->getHistoricalRawX(0, 1)); - ASSERT_EQ(RAW_X_OFFSET + 120 * RAW_X_SCALE, event->getHistoricalRawX(1, 1)); - ASSERT_EQ(RAW_X_OFFSET + 210 * RAW_X_SCALE, event->getRawX(0)); - ASSERT_EQ(RAW_X_OFFSET + 220 * RAW_X_SCALE, event->getRawX(1)); - - ASSERT_EQ(RAW_Y_OFFSET + 11 * RAW_Y_SCALE, event->getHistoricalRawY(0, 0)); - ASSERT_EQ(RAW_Y_OFFSET + 21 * RAW_Y_SCALE, event->getHistoricalRawY(1, 0)); - ASSERT_EQ(RAW_Y_OFFSET + 111 * RAW_Y_SCALE, event->getHistoricalRawY(0, 1)); - ASSERT_EQ(RAW_Y_OFFSET + 121 * RAW_Y_SCALE, event->getHistoricalRawY(1, 1)); - ASSERT_EQ(RAW_Y_OFFSET + 211 * RAW_Y_SCALE, event->getRawY(0)); - ASSERT_EQ(RAW_Y_OFFSET + 221 * RAW_Y_SCALE, event->getRawY(1)); - - ASSERT_EQ(X_OFFSET + 10 * X_SCALE, event->getHistoricalX(0, 0)); - ASSERT_EQ(X_OFFSET + 20 * X_SCALE, event->getHistoricalX(1, 0)); - ASSERT_EQ(X_OFFSET + 110 * X_SCALE, event->getHistoricalX(0, 1)); - ASSERT_EQ(X_OFFSET + 120 * X_SCALE, event->getHistoricalX(1, 1)); - ASSERT_EQ(X_OFFSET + 210 * X_SCALE, event->getX(0)); - ASSERT_EQ(X_OFFSET + 220 * X_SCALE, event->getX(1)); - - ASSERT_EQ(Y_OFFSET + 11 * Y_SCALE, event->getHistoricalY(0, 0)); - ASSERT_EQ(Y_OFFSET + 21 * Y_SCALE, event->getHistoricalY(1, 0)); - ASSERT_EQ(Y_OFFSET + 111 * Y_SCALE, event->getHistoricalY(0, 1)); - ASSERT_EQ(Y_OFFSET + 121 * Y_SCALE, event->getHistoricalY(1, 1)); - ASSERT_EQ(Y_OFFSET + 211 * Y_SCALE, event->getY(0)); - ASSERT_EQ(Y_OFFSET + 221 * Y_SCALE, event->getY(1)); + // Ensure the underlying PointerCoords are identical. + for (int sampleIdx = 0; sampleIdx < 3; sampleIdx++) { + for (int pointerIdx = 0; pointerIdx < 2; pointerIdx++) { + ASSERT_EQ(mSamples[sampleIdx].pointerCoords[pointerIdx], + event->getSamplePointerCoords()[sampleIdx * 2 + pointerIdx]); + } + } + + ASSERT_NEAR(11, event->getHistoricalRawPointerCoords(0, 0)->getAxisValue(AMOTION_EVENT_AXIS_Y), + EPSILON); + ASSERT_NEAR(21, event->getHistoricalRawPointerCoords(1, 0)->getAxisValue(AMOTION_EVENT_AXIS_Y), + EPSILON); + ASSERT_NEAR(111, event->getHistoricalRawPointerCoords(0, 1)->getAxisValue(AMOTION_EVENT_AXIS_Y), + EPSILON); + ASSERT_NEAR(121, event->getHistoricalRawPointerCoords(1, 1)->getAxisValue(AMOTION_EVENT_AXIS_Y), + EPSILON); + ASSERT_NEAR(211, event->getRawPointerCoords(0)->getAxisValue(AMOTION_EVENT_AXIS_Y), EPSILON); + ASSERT_NEAR(221, event->getRawPointerCoords(1)->getAxisValue(AMOTION_EVENT_AXIS_Y), EPSILON); + + ASSERT_NEAR(RAW_Y_OFFSET + 11 * RAW_Y_SCALE, + event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 0, 0), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 21 * RAW_Y_SCALE, + event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 1, 0), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 111 * RAW_Y_SCALE, + event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 0, 1), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 121 * RAW_Y_SCALE, + event->getHistoricalRawAxisValue(AMOTION_EVENT_AXIS_Y, 1, 1), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 211 * RAW_Y_SCALE, event->getRawAxisValue(AMOTION_EVENT_AXIS_Y, 0), + EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 221 * RAW_Y_SCALE, event->getRawAxisValue(AMOTION_EVENT_AXIS_Y, 1), + EPSILON); + + ASSERT_NEAR(RAW_X_OFFSET + 10 * RAW_X_SCALE, event->getHistoricalRawX(0, 0), EPSILON); + ASSERT_NEAR(RAW_X_OFFSET + 20 * RAW_X_SCALE, event->getHistoricalRawX(1, 0), EPSILON); + ASSERT_NEAR(RAW_X_OFFSET + 110 * RAW_X_SCALE, event->getHistoricalRawX(0, 1), EPSILON); + ASSERT_NEAR(RAW_X_OFFSET + 120 * RAW_X_SCALE, event->getHistoricalRawX(1, 1), EPSILON); + ASSERT_NEAR(RAW_X_OFFSET + 210 * RAW_X_SCALE, event->getRawX(0), EPSILON); + ASSERT_NEAR(RAW_X_OFFSET + 220 * RAW_X_SCALE, event->getRawX(1), EPSILON); + + ASSERT_NEAR(RAW_Y_OFFSET + 11 * RAW_Y_SCALE, event->getHistoricalRawY(0, 0), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 21 * RAW_Y_SCALE, event->getHistoricalRawY(1, 0), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 111 * RAW_Y_SCALE, event->getHistoricalRawY(0, 1), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 121 * RAW_Y_SCALE, event->getHistoricalRawY(1, 1), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 211 * RAW_Y_SCALE, event->getRawY(0), EPSILON); + ASSERT_NEAR(RAW_Y_OFFSET + 221 * RAW_Y_SCALE, event->getRawY(1), EPSILON); + + ASSERT_NEAR(X_OFFSET + 10 * X_SCALE, event->getHistoricalX(0, 0), EPSILON); + ASSERT_NEAR(X_OFFSET + 20 * X_SCALE, event->getHistoricalX(1, 0), EPSILON); + ASSERT_NEAR(X_OFFSET + 110 * X_SCALE, event->getHistoricalX(0, 1), EPSILON); + ASSERT_NEAR(X_OFFSET + 120 * X_SCALE, event->getHistoricalX(1, 1), EPSILON); + ASSERT_NEAR(X_OFFSET + 210 * X_SCALE, event->getX(0), EPSILON); + ASSERT_NEAR(X_OFFSET + 220 * X_SCALE, event->getX(1), EPSILON); + + ASSERT_NEAR(Y_OFFSET + 11 * Y_SCALE, event->getHistoricalY(0, 0), EPSILON); + ASSERT_NEAR(Y_OFFSET + 21 * Y_SCALE, event->getHistoricalY(1, 0), EPSILON); + ASSERT_NEAR(Y_OFFSET + 111 * Y_SCALE, event->getHistoricalY(0, 1), EPSILON); + ASSERT_NEAR(Y_OFFSET + 121 * Y_SCALE, event->getHistoricalY(1, 1), EPSILON); + ASSERT_NEAR(Y_OFFSET + 211 * Y_SCALE, event->getY(0), EPSILON); + ASSERT_NEAR(Y_OFFSET + 221 * Y_SCALE, event->getY(1), EPSILON); ASSERT_EQ(12, event->getHistoricalPressure(0, 0)); ASSERT_EQ(22, event->getHistoricalPressure(1, 0)); @@ -550,10 +574,10 @@ TEST_F(MotionEventTest, Scale) { ASSERT_EQ(X_OFFSET * 2, event.getXOffset()); ASSERT_EQ(Y_OFFSET * 2, event.getYOffset()); - ASSERT_EQ((RAW_X_OFFSET + 210 * RAW_X_SCALE) * 2, event.getRawX(0)); - ASSERT_EQ((RAW_Y_OFFSET + 211 * RAW_Y_SCALE) * 2, event.getRawY(0)); - ASSERT_EQ((X_OFFSET + 210 * X_SCALE) * 2, event.getX(0)); - ASSERT_EQ((Y_OFFSET + 211 * Y_SCALE) * 2, event.getY(0)); + ASSERT_NEAR((RAW_X_OFFSET + 210 * RAW_X_SCALE) * 2, event.getRawX(0), EPSILON); + ASSERT_NEAR((RAW_Y_OFFSET + 211 * RAW_Y_SCALE) * 2, event.getRawY(0), EPSILON); + ASSERT_NEAR((X_OFFSET + 210 * X_SCALE) * 2, event.getX(0), EPSILON); + ASSERT_NEAR((Y_OFFSET + 211 * Y_SCALE) * 2, event.getY(0), EPSILON); ASSERT_EQ(212, event.getPressure(0)); ASSERT_EQ(213, event.getSize(0)); ASSERT_EQ(214 * 2, event.getTouchMajor(0)); @@ -791,18 +815,18 @@ TEST_F(MotionEventTest, AxesAreCorrectlyTransformed) { // The x and y axes should have the window transform applied. const auto newPoint = transform.transform(60, 100); - ASSERT_EQ(newPoint.x, event.getX(0)); - ASSERT_EQ(newPoint.y, event.getY(0)); + ASSERT_NEAR(newPoint.x, event.getX(0), EPSILON); + ASSERT_NEAR(newPoint.y, event.getY(0), EPSILON); // The raw values should have the display transform applied. const auto raw = rawTransform.transform(60, 100); - ASSERT_EQ(raw.x, event.getRawX(0)); - ASSERT_EQ(raw.y, event.getRawY(0)); + ASSERT_NEAR(raw.x, event.getRawX(0), EPSILON); + ASSERT_NEAR(raw.y, event.getRawY(0), EPSILON); // Relative values should have the window transform applied without any translation. const auto rel = transformWithoutTranslation(transform, 42, 96); - ASSERT_EQ(rel.x, event.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, 0)); - ASSERT_EQ(rel.y, event.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, 0)); + ASSERT_NEAR(rel.x, event.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, 0), EPSILON); + ASSERT_NEAR(rel.y, event.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, 0), EPSILON); } TEST_F(MotionEventTest, Initialize_SetsClassification) { @@ -869,4 +893,42 @@ TEST_F(MotionEventTest, SetCursorPosition) { ASSERT_EQ(4, event.getYCursorPosition()); } +TEST_F(MotionEventTest, CoordinatesAreRoundedAppropriately) { + // These are specifically integral values, since we are testing for rounding. + const vec2 EXPECTED{400.f, 700.f}; + + // Pick a transform such that transforming the point with its inverse and bringing that + // back to the original coordinate space results in a non-zero error amount due to the + // nature of floating point arithmetics. This can happen when the display is scaled. + // For example, the 'adb shell wm size' command can be used to set an override for the + // logical display size, which could result in the display being scaled. + constexpr float scale = 720.f / 1080.f; + ui::Transform transform; + transform.set(scale, 0, 0, scale); + ASSERT_NE(EXPECTED, transform.transform(transform.inverse().transform(EXPECTED))); + + // Store the inverse-transformed values in the motion event. + const vec2 rawCoords = transform.inverse().transform(EXPECTED); + PointerCoords pc{}; + pc.setAxisValue(AMOTION_EVENT_AXIS_X, rawCoords.x); + pc.setAxisValue(AMOTION_EVENT_AXIS_Y, rawCoords.y); + PointerProperties pp{}; + MotionEvent event; + event.initialize(InputEvent::nextId(), 2, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, HMAC, + AMOTION_EVENT_ACTION_MOVE, 0, AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, + AMOTION_EVENT_EDGE_FLAG_TOP, AMETA_ALT_ON, AMOTION_EVENT_BUTTON_PRIMARY, + MotionClassification::NONE, transform, 2.0f, 2.1f, rawCoords.x, rawCoords.y, + transform, ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME, 1, &pp, &pc); + + // When using the getters from the MotionEvent to obtain the coordinates, the transformed + // values should be rounded by an appropriate amount so that they now precisely equal the + // original coordinates. + ASSERT_EQ(EXPECTED.x, event.getX(0)); + ASSERT_EQ(EXPECTED.y, event.getY(0)); + ASSERT_EQ(EXPECTED.x, event.getRawX(0)); + ASSERT_EQ(EXPECTED.y, event.getRawY(0)); + ASSERT_EQ(EXPECTED.x, event.getXCursorPosition()); + ASSERT_EQ(EXPECTED.y, event.getYCursorPosition()); +} + } // namespace android diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 70e4fda662..57606e8bdc 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -25,6 +25,8 @@ using android::base::Result; namespace android { +constexpr static float EPSILON = MotionEvent::ROUNDING_PRECISION; + class InputPublisherAndConsumerTest : public testing::Test { protected: std::shared_ptr mServerChannel, mClientChannel; @@ -226,10 +228,10 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { EXPECT_EQ(yOffset, motionEvent->getYOffset()); EXPECT_EQ(xPrecision, motionEvent->getXPrecision()); EXPECT_EQ(yPrecision, motionEvent->getYPrecision()); - EXPECT_EQ(xCursorPosition, motionEvent->getRawXCursorPosition()); - EXPECT_EQ(yCursorPosition, motionEvent->getRawYCursorPosition()); - EXPECT_EQ(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition()); - EXPECT_EQ(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition()); + EXPECT_NEAR(xCursorPosition, motionEvent->getRawXCursorPosition(), EPSILON); + EXPECT_NEAR(yCursorPosition, motionEvent->getRawYCursorPosition(), EPSILON); + EXPECT_NEAR(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition(), EPSILON); + EXPECT_NEAR(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition(), EPSILON); EXPECT_EQ(rawTransform, motionEvent->getRawTransform()); EXPECT_EQ(downTime, motionEvent->getDownTime()); EXPECT_EQ(eventTime, motionEvent->getEventTime()); @@ -242,10 +244,12 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i)); const auto& pc = pointerCoords[i]; - EXPECT_EQ(pc.getX() * rawXScale + rawXOffset, motionEvent->getRawX(i)); - EXPECT_EQ(pc.getY() * rawYScale + rawYOffset, motionEvent->getRawY(i)); - EXPECT_EQ(pc.getX() * xScale + xOffset, motionEvent->getX(i)); - EXPECT_EQ(pc.getY() * yScale + yOffset, motionEvent->getY(i)); + EXPECT_EQ(pc, motionEvent->getSamplePointerCoords()[i]); + + EXPECT_NEAR(pc.getX() * rawXScale + rawXOffset, motionEvent->getRawX(i), EPSILON); + EXPECT_NEAR(pc.getY() * rawYScale + rawYOffset, motionEvent->getRawY(i), EPSILON); + EXPECT_NEAR(pc.getX() * xScale + xOffset, motionEvent->getX(i), EPSILON); + EXPECT_NEAR(pc.getY() * yScale + yOffset, motionEvent->getY(i), EPSILON); EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), motionEvent->getPressure(i)); EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_SIZE), motionEvent->getSize(i)); EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), motionEvent->getTouchMajor(i)); diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index e4ba24153d..3586a5e3b1 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -230,10 +230,10 @@ public: const auto& motionEvent = static_cast(event); EXPECT_EQ(motionEvent.getEventTime(), args.eventTime); EXPECT_EQ(motionEvent.getAction(), args.action); - EXPECT_EQ(motionEvent.getX(0), point.x); - EXPECT_EQ(motionEvent.getY(0), point.y); - EXPECT_EQ(motionEvent.getRawX(0), point.x); - EXPECT_EQ(motionEvent.getRawY(0), point.y); + EXPECT_NEAR(motionEvent.getX(0), point.x, MotionEvent::ROUNDING_PRECISION); + EXPECT_NEAR(motionEvent.getY(0), point.y, MotionEvent::ROUNDING_PRECISION); + EXPECT_NEAR(motionEvent.getRawX(0), point.x, MotionEvent::ROUNDING_PRECISION); + EXPECT_NEAR(motionEvent.getRawY(0), point.y, MotionEvent::ROUNDING_PRECISION); }); } -- cgit v1.2.3-59-g8ed1b From 6d73f83c0a0ba15a7488916a435d0b2985d4f2a0 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 21 Jul 2022 17:27:03 -0700 Subject: Convert tool type to enum class For better type safety, use enum class when sending tool type. Bug: 198472780 Test: atest libinput_tests inputflinger_tests (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:09a8fe42ba1d218c2f445e4fd5bc387e260ae067) Merged-In: I371f08087b9513b6f75966c124de77bc12f8324e Change-Id: I371f08087b9513b6f75966c124de77bc12f8324e --- include/input/Input.h | 24 +- include/input/InputTransport.h | 1 - libs/input/Input.cpp | 33 +-- libs/input/InputTransport.cpp | 9 +- libs/input/MotionPredictor.cpp | 7 +- libs/input/tests/InputEvent_test.cpp | 10 +- .../input/tests/InputPublisherAndConsumer_test.cpp | 2 +- libs/input/tests/MotionPredictor_test.cpp | 2 +- libs/input/tests/TouchResampling_test.cpp | 2 +- libs/input/tests/VelocityTracker_test.cpp | 2 +- services/inputflinger/InputCommonConverter.cpp | 17 +- services/inputflinger/NotifyArgs.cpp | 6 +- .../inputflinger/PreferStylusOverTouchBlocker.cpp | 4 +- .../inputflinger/UnwantedInteractionBlocker.cpp | 18 +- .../benchmarks/InputDispatcher_benchmarks.cpp | 4 +- .../inputflinger/dispatcher/InputDispatcher.cpp | 7 +- services/inputflinger/reader/include/StylusState.h | 4 +- .../reader/mapper/CursorInputMapper.cpp | 2 +- .../reader/mapper/ExternalStylusInputMapper.cpp | 4 +- .../reader/mapper/JoystickInputMapper.cpp | 2 +- .../reader/mapper/MultiTouchInputMapper.cpp | 17 +- .../reader/mapper/RotaryEncoderInputMapper.cpp | 2 +- .../reader/mapper/SingleTouchInputMapper.cpp | 6 +- .../reader/mapper/TouchInputMapper.cpp | 40 +-- .../inputflinger/reader/mapper/TouchInputMapper.h | 4 +- .../accumulator/MultiTouchMotionAccumulator.cpp | 10 +- .../accumulator/MultiTouchMotionAccumulator.h | 2 +- .../mapper/accumulator/TouchButtonAccumulator.cpp | 12 +- .../mapper/accumulator/TouchButtonAccumulator.h | 2 +- .../reader/mapper/gestures/GestureConverter.h | 8 +- .../mapper/gestures/HardwareStateConverter.cpp | 2 +- .../inputflinger/tests/GestureConverter_test.cpp | 116 ++++---- .../inputflinger/tests/InputDispatcher_test.cpp | 328 +++++++++----------- .../tests/InputProcessorConverter_test.cpp | 2 +- .../inputflinger/tests/InputProcessor_test.cpp | 2 +- services/inputflinger/tests/InputReader_test.cpp | 330 ++++++++++----------- services/inputflinger/tests/NotifyArgs_test.cpp | 2 +- .../tests/PreferStylusOverTouch_test.cpp | 14 +- .../inputflinger/tests/TestInputListenerMatchers.h | 4 +- .../tests/UnwantedInteractionBlocker_test.cpp | 26 +- .../tests/fuzzers/InputClassifierFuzzer.cpp | 2 +- .../inputflinger/tests/fuzzers/MapperHelpers.h | 8 + .../tests/fuzzers/MultiTouchInputFuzzer.cpp | 2 +- 43 files changed, 534 insertions(+), 567 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index e8af5f7d46..a033535f4b 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -216,7 +216,21 @@ std::string inputEventSourceToString(int32_t source); bool isFromSource(uint32_t source, uint32_t test); -bool isStylusToolType(uint32_t toolType); +/** + * The pointer tool type. + */ +enum class ToolType { + UNKNOWN = AMOTION_EVENT_TOOL_TYPE_UNKNOWN, + FINGER = AMOTION_EVENT_TOOL_TYPE_FINGER, + STYLUS = AMOTION_EVENT_TOOL_TYPE_STYLUS, + MOUSE = AMOTION_EVENT_TOOL_TYPE_MOUSE, + ERASER = AMOTION_EVENT_TOOL_TYPE_ERASER, + PALM = AMOTION_EVENT_TOOL_TYPE_PALM, + ftl_first = UNKNOWN, + ftl_last = PALM, +}; + +bool isStylusToolType(ToolType toolType); /* * Flags that flow alongside events in the input dispatch system to help with certain @@ -320,8 +334,6 @@ enum class MotionClassification : uint8_t { */ const char* motionClassificationToString(MotionClassification classification); -const char* motionToolTypeToString(int32_t toolType); - /** * Portion of FrameMetrics timeline of interest to input code. */ @@ -448,11 +460,11 @@ struct PointerProperties { int32_t id; // The pointer tool type. - int32_t toolType; + ToolType toolType; inline void clear() { id = -1; - toolType = 0; + toolType = ToolType::UNKNOWN; } bool operator==(const PointerProperties& other) const; @@ -638,7 +650,7 @@ public: return mPointerProperties[pointerIndex].id; } - inline int32_t getToolType(size_t pointerIndex) const { + inline ToolType getToolType(size_t pointerIndex) const { return mPointerProperties[pointerIndex].toolType; } diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index a1be542d7b..4f53c36d6f 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -669,7 +669,6 @@ private: static void addSample(MotionEvent* event, const InputMessage* msg); static bool canAddSample(const Batch& batch, const InputMessage* msg); static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time); - static bool shouldResampleTool(int32_t toolType); static bool isTouchResamplingEnabled(); }; diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 53b22cb883..4dbf575490 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -79,25 +79,6 @@ const char* motionClassificationToString(MotionClassification classification) { } } -const char* motionToolTypeToString(int32_t toolType) { - switch (toolType) { - case AMOTION_EVENT_TOOL_TYPE_UNKNOWN: - return "UNKNOWN"; - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return "FINGER"; - case AMOTION_EVENT_TOOL_TYPE_STYLUS: - return "STYLUS"; - case AMOTION_EVENT_TOOL_TYPE_MOUSE: - return "MOUSE"; - case AMOTION_EVENT_TOOL_TYPE_ERASER: - return "ERASER"; - case AMOTION_EVENT_TOOL_TYPE_PALM: - return "PALM"; - default: - return "INVALID"; - } -} - // --- IdGenerator --- #if defined(__ANDROID__) [[maybe_unused]] @@ -256,8 +237,8 @@ bool isFromSource(uint32_t source, uint32_t test) { return (source & test) == test; } -bool isStylusToolType(uint32_t toolType) { - return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER; +bool isStylusToolType(ToolType toolType) { + return toolType == ToolType::STYLUS || toolType == ToolType::ERASER; } VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { @@ -810,7 +791,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) { mPointerProperties.push_back({}); PointerProperties& properties = mPointerProperties.back(); properties.id = parcel->readInt32(); - properties.toolType = parcel->readInt32(); + properties.toolType = static_cast(parcel->readInt32()); } while (sampleCount > 0) { @@ -866,7 +847,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const { for (size_t i = 0; i < pointerCount; i++) { const PointerProperties& properties = mPointerProperties[i]; parcel->writeInt32(properties.id); - parcel->writeInt32(properties.toolType); + parcel->writeInt32(static_cast(properties.toolType)); } const PointerCoords* pc = mSamplePointerCoords.data(); @@ -1030,9 +1011,9 @@ std::ostream& operator<<(std::ostream& out, const MotionEvent& event) { out << ", x[" << i << "]=" << x; out << ", y[" << i << "]=" << y; } - int toolType = event.getToolType(i); - if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) { - out << ", toolType[" << i << "]=" << toolType; + ToolType toolType = event.getToolType(i); + if (toolType != ToolType::FINGER) { + out << ", toolType[" << i << "]=" << ftl::enum_string(toolType); } } if (event.getButtonState() != 0) { diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 311b2441a4..f6b4648d67 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -145,6 +145,10 @@ inline static const char* toString(bool value) { return value ? "true" : "false"; } +static bool shouldResampleTool(ToolType toolType) { + return toolType == ToolType::FINGER || toolType == ToolType::UNKNOWN; +} + // --- InputMessage --- bool InputMessage::isValid(size_t actualSize) const { @@ -1274,11 +1278,6 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, event->addSample(sampleTime, touchState.lastResample.pointers); } -bool InputConsumer::shouldResampleTool(int32_t toolType) { - return toolType == AMOTION_EVENT_TOOL_TYPE_FINGER - || toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN; -} - status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { ALOGD_IF(DEBUG_TRANSPORT_CONSUMER, "channel '%s' consumer ~ sendFinishedSignal: seq=%u, handled=%s", diff --git a/libs/input/MotionPredictor.cpp b/libs/input/MotionPredictor.cpp index b4151c6ea1..3037573538 100644 --- a/libs/input/MotionPredictor.cpp +++ b/libs/input/MotionPredictor.cpp @@ -30,6 +30,7 @@ #include #include +#include #include namespace android { @@ -108,10 +109,10 @@ android::base::Result MotionPredictor::record(const MotionEvent& event) { return {}; } - const int32_t toolType = event.getPointerProperties(0)->toolType; - if (toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS) { + const ToolType toolType = event.getPointerProperties(0)->toolType; + if (toolType != ToolType::STYLUS) { ALOGD_IF(isDebug(), "Prediction not supported for non-stylus tool: %s", - motionToolTypeToString(toolType)); + ftl::enum_string(toolType).c_str()); return {}; } diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 2132dc1bdf..59125dd428 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -259,10 +259,10 @@ void MotionEventTest::SetUp() { mPointerProperties[0].clear(); mPointerProperties[0].id = 1; - mPointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerProperties[0].toolType = ToolType::FINGER; mPointerProperties[1].clear(); mPointerProperties[1].id = 2; - mPointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mPointerProperties[1].toolType = ToolType::STYLUS; mSamples[0].pointerCoords[0].clear(); mSamples[0].pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 10); @@ -366,9 +366,9 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { ASSERT_EQ(2U, event->getPointerCount()); ASSERT_EQ(1, event->getPointerId(0)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, event->getToolType(0)); + ASSERT_EQ(ToolType::FINGER, event->getToolType(0)); ASSERT_EQ(2, event->getPointerId(1)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, event->getToolType(1)); + ASSERT_EQ(ToolType::STYLUS, event->getToolType(1)); ASSERT_EQ(2U, event->getHistorySize()); @@ -692,7 +692,7 @@ TEST_F(MotionEventTest, Transform) { MotionEvent createMotionEvent(int32_t source, uint32_t action, float x, float y, float dx, float dy, const ui::Transform& transform, const ui::Transform& rawTransform) { std::vector pointerProperties; - pointerProperties.push_back(PointerProperties{/* id */ 0, AMOTION_EVENT_TOOL_TYPE_FINGER}); + pointerProperties.push_back(PointerProperties{/*id=*/0, ToolType::FINGER}); std::vector pointerCoords; pointerCoords.emplace_back().clear(); pointerCoords.back().setAxisValue(AMOTION_EVENT_AXIS_X, x); diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 5d8b9700b3..965fda73b4 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -172,7 +172,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = (i + 2) % pointerCount; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i); diff --git a/libs/input/tests/MotionPredictor_test.cpp b/libs/input/tests/MotionPredictor_test.cpp index c61efbf9ed..7a62f5ec58 100644 --- a/libs/input/tests/MotionPredictor_test.cpp +++ b/libs/input/tests/MotionPredictor_test.cpp @@ -45,7 +45,7 @@ static MotionEvent getMotionEvent(int32_t action, float x, float y, PointerProperties properties; properties.clear(); properties.id = i; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + properties.toolType = ToolType::STYLUS; pointerProperties.push_back(properties); PointerCoords coords; coords.clear(); diff --git a/libs/input/tests/TouchResampling_test.cpp b/libs/input/tests/TouchResampling_test.cpp index 7cb9526af0..655de803ae 100644 --- a/libs/input/tests/TouchResampling_test.cpp +++ b/libs/input/tests/TouchResampling_test.cpp @@ -99,7 +99,7 @@ void TouchResamplingTest::publishSimpleMotionEvent(int32_t action, nsecs_t event properties.push_back({}); properties.back().clear(); properties.back().id = pointer.id; - properties.back().toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.back().toolType = ToolType::FINGER; coords.push_back({}); coords.back().clear(); diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index 027757973b..ae721093a0 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -212,7 +212,7 @@ static std::vector createTouchMotionEventStream( coords[pointerIndex].isResampled = position.isResampled; properties[pointerIndex].id = pointerId; - properties[pointerIndex].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties[pointerIndex].toolType = ToolType::FINGER; pointerIndex++; } EXPECT_EQ(pointerIndex, pointerCount); diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index 0c93f5ce40..2437d0fcfc 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -200,17 +200,12 @@ static common::Button getButtonState(int32_t buttonState) { return static_cast(buttonState); } -static common::ToolType getToolType(int32_t toolType) { - static_assert(static_cast(AMOTION_EVENT_TOOL_TYPE_UNKNOWN) == - common::ToolType::UNKNOWN); - static_assert(static_cast(AMOTION_EVENT_TOOL_TYPE_FINGER) == - common::ToolType::FINGER); - static_assert(static_cast(AMOTION_EVENT_TOOL_TYPE_STYLUS) == - common::ToolType::STYLUS); - static_assert(static_cast(AMOTION_EVENT_TOOL_TYPE_MOUSE) == - common::ToolType::MOUSE); - static_assert(static_cast(AMOTION_EVENT_TOOL_TYPE_ERASER) == - common::ToolType::ERASER); +static common::ToolType getToolType(ToolType toolType) { + static_assert(static_cast(ToolType::UNKNOWN) == common::ToolType::UNKNOWN); + static_assert(static_cast(ToolType::FINGER) == common::ToolType::FINGER); + static_assert(static_cast(ToolType::STYLUS) == common::ToolType::STYLUS); + static_assert(static_cast(ToolType::MOUSE) == common::ToolType::MOUSE); + static_assert(static_cast(ToolType::ERASER) == common::ToolType::ERASER); return static_cast(toolType); } diff --git a/services/inputflinger/NotifyArgs.cpp b/services/inputflinger/NotifyArgs.cpp index b192ad73c3..5f2a22f467 100644 --- a/services/inputflinger/NotifyArgs.cpp +++ b/services/inputflinger/NotifyArgs.cpp @@ -161,9 +161,9 @@ std::string NotifyMotionArgs::dump() const { StringPrintf("id=%" PRIu32 " x=%.1f y=%.1f pressure=%.1f", pointerProperties[i].id, pointerCoords[i].getX(), pointerCoords[i].getY(), pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); - const int32_t toolType = pointerProperties[i].toolType; - if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) { - coords += StringPrintf(" toolType=%s", motionToolTypeToString(toolType)); + const ToolType toolType = pointerProperties[i].toolType; + if (toolType != ToolType::FINGER) { + coords += StringPrintf(" toolType=%s", ftl::enum_string(toolType).c_str()); } const float major = pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR); const float minor = pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR); diff --git a/services/inputflinger/PreferStylusOverTouchBlocker.cpp b/services/inputflinger/PreferStylusOverTouchBlocker.cpp index ddd514676b..fbd296c131 100644 --- a/services/inputflinger/PreferStylusOverTouchBlocker.cpp +++ b/services/inputflinger/PreferStylusOverTouchBlocker.cpp @@ -24,11 +24,11 @@ static std::pair checkToolType(const NotifyMotionArgs& args) { bool hasTouch = false; for (size_t i = 0; i < args.pointerCount; i++) { // Make sure we are canceling stylus pointers - const int32_t toolType = args.pointerProperties[i].toolType; + const ToolType toolType = args.pointerProperties[i].toolType; if (isStylusToolType(toolType)) { hasStylus = true; } - if (toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { + if (toolType == ToolType::FINGER) { hasTouch = true; } } diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index c170b81475..ae20f862dc 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -18,6 +18,7 @@ #include "UnwantedInteractionBlocker.h" #include +#include #include #include #include @@ -98,18 +99,21 @@ static bool isPalmRejectionEnabled() { return false; } -static int getLinuxToolCode(int toolType) { +static int getLinuxToolCode(ToolType toolType) { switch (toolType) { - case AMOTION_EVENT_TOOL_TYPE_STYLUS: + case ToolType::STYLUS: return BTN_TOOL_PEN; - case AMOTION_EVENT_TOOL_TYPE_ERASER: + case ToolType::ERASER: return BTN_TOOL_RUBBER; - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return BTN_TOOL_FINGER; - default: - ALOGW("Got tool type %" PRId32 ", converting to BTN_TOOL_FINGER", toolType); + case ToolType::FINGER: return BTN_TOOL_FINGER; + case ToolType::UNKNOWN: + case ToolType::MOUSE: + case ToolType::PALM: + break; } + ALOGW("Got tool type %s, converting to BTN_TOOL_FINGER", ftl::enum_string(toolType).c_str()); + return BTN_TOOL_FINGER; } static int32_t getActionUpForPointerId(const NotifyMotionArgs& args, int32_t pointerId) { diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index f03c837f56..58324c4762 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -207,7 +207,7 @@ static MotionEvent generateMotionEvent() { pointerProperties[0].clear(); pointerProperties[0].id = 0; - pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[0].toolType = ToolType::FINGER; pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); @@ -235,7 +235,7 @@ static NotifyMotionArgs generateMotionArgs() { pointerProperties[0].clear(); pointerProperties[0].id = 0; - pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[0].toolType = ToolType::FINGER; pointerCoords[0].clear(); pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index cd427f03cf..0f7991ae09 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -1862,11 +1862,12 @@ void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionE entry.yPrecision, entry.downTime); for (uint32_t i = 0; i < entry.pointerCount; i++) { - ALOGD(" Pointer %d: id=%d, toolType=%d, " + ALOGD(" Pointer %d: id=%d, toolType=%s, " "x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " "orientation=%f", - i, entry.pointerProperties[i].id, entry.pointerProperties[i].toolType, + i, entry.pointerProperties[i].id, + ftl::enum_string(entry.pointerProperties[i].toolType).c_str(), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), entry.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), @@ -4178,7 +4179,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) { ALOGD(" Pointer %d: id=%d, toolType=%s, x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, orientation=%f", i, args->pointerProperties[i].id, - motionToolTypeToString(args->pointerProperties[i].toolType), + ftl::enum_string(args->pointerProperties[i].toolType).c_str(), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y), args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), diff --git a/services/inputflinger/reader/include/StylusState.h b/services/inputflinger/reader/include/StylusState.h index ff15e0c660..d042784c9e 100644 --- a/services/inputflinger/reader/include/StylusState.h +++ b/services/inputflinger/reader/include/StylusState.h @@ -33,8 +33,8 @@ struct StylusState { std::optional pressure{}; /* The state of the stylus buttons as a bitfield (e.g. AMOTION_EVENT_BUTTON_SECONDARY). */ uint32_t buttons{}; - /* Which tool type the stylus is currently using (e.g. AMOTION_EVENT_TOOL_TYPE_ERASER). */ - int32_t toolType{AMOTION_EVENT_TOOL_TYPE_UNKNOWN}; + /* Which tool type the stylus is currently using (e.g. ToolType::ERASER). */ + ToolType toolType{ToolType::UNKNOWN}; void clear() { *this = StylusState{}; } }; diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 83cf28798c..a3fdcdf19d 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -350,7 +350,7 @@ std::list CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) { PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE; + pointerProperties.toolType = ToolType::MOUSE; PointerCoords pointerCoords; pointerCoords.clear(); diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp index a44d15bcdf..99e6cf9a74 100644 --- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp +++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp @@ -77,8 +77,8 @@ std::list ExternalStylusInputMapper::sync(nsecs_t when) { mStylusState.when = when; mStylusState.toolType = mTouchButtonAccumulator.getToolType(); - if (mStylusState.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + if (mStylusState.toolType == ToolType::UNKNOWN) { + mStylusState.toolType = ToolType::STYLUS; } if (mRawPressureAxis.valid) { diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp index 7724cf7ed5..f65cdcb677 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp @@ -321,7 +321,7 @@ std::list JoystickInputMapper::sync(nsecs_t when, nsecs_t readTime, PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + pointerProperties.toolType = ToolType::UNKNOWN; PointerCoords pointerCoords; pointerCoords.clear(); diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp index 33e72c7c6f..e87128825d 100644 --- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp @@ -77,7 +77,7 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { continue; } - if (inSlot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { + if (inSlot.getToolType() == ToolType::PALM) { std::optional id = getActiveBitId(inSlot); if (id) { outState->rawPointerData.canceledIdBits.markBit(id.value()); @@ -112,12 +112,12 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outPointer.tiltY = 0; outPointer.toolType = inSlot.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + if (outPointer.toolType == ToolType::UNKNOWN) { outPointer.toolType = mTouchButtonAccumulator.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + if (outPointer.toolType == ToolType::UNKNOWN) { + outPointer.toolType = ToolType::FINGER; } - } else if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS && !mStylusMtToolSeen) { + } else if (outPointer.toolType == ToolType::STYLUS && !mStylusMtToolSeen) { mStylusMtToolSeen = true; // The multi-touch device produced a stylus event with MT_TOOL_PEN. Dynamically // re-configure this input device so that we add SOURCE_STYLUS if we haven't already. @@ -130,12 +130,11 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { bumpGeneration(); } } - if (shouldSimulateStylusWithTouch() && - outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + if (shouldSimulateStylusWithTouch() && outPointer.toolType == ToolType::FINGER) { + outPointer.toolType = ToolType::STYLUS; } - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE && (mTouchButtonAccumulator.isHovering() || (mRawPointerAxes.pressure.valid && inSlot.getPressure() <= 0)); outPointer.isHovering = isHovering; diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index 94cc1457a9..c0a35b196e 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -121,7 +121,7 @@ std::list RotaryEncoderInputMapper::sync(nsecs_t when, nsecs_t readT PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + pointerProperties.toolType = ToolType::UNKNOWN; uint32_t policyFlags = 0; if (getDeviceContext().isExternal()) { diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp index 13ad224111..f13417a93b 100644 --- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp @@ -41,7 +41,7 @@ void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outState->rawPointerData.pointerCount = 1; outState->rawPointerData.idToIndex[0] = 0; - bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE && + bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE && (mTouchButtonAccumulator.isHovering() || (mRawPointerAxes.pressure.valid && mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0)); @@ -61,8 +61,8 @@ void SingleTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) { outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX(); outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY(); outPointer.toolType = mTouchButtonAccumulator.getToolType(); - if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { - outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + if (outPointer.toolType == ToolType::UNKNOWN) { + outPointer.toolType = ToolType::FINGER; } outPointer.isHovering = isHovering; } diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index df7ba49b4d..073c18babb 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -229,11 +229,12 @@ void TouchInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, " "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, " "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, " - "toolType=%d, isHovering=%s\n", + "toolType=%s, isHovering=%s\n", i, pointer.id, pointer.x, pointer.y, pointer.pressure, pointer.touchMajor, pointer.touchMinor, pointer.toolMajor, pointer.toolMinor, pointer.orientation, pointer.tiltX, pointer.tiltY, - pointer.distance, pointer.toolType, toString(pointer.isHovering)); + pointer.distance, ftl::enum_string(pointer.toolType).c_str(), + toString(pointer.isHovering)); } dump += StringPrintf(INDENT3 "Last Cooked Button State: 0x%08x\n", @@ -248,7 +249,7 @@ void TouchInputMapper::dump(std::string& dump) { "pressure=%0.3f, touchMajor=%0.3f, touchMinor=%0.3f, " "toolMajor=%0.3f, toolMinor=%0.3f, " "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, " - "toolType=%d, isHovering=%s\n", + "toolType=%s, isHovering=%s\n", i, pointerProperties.id, pointerCoords.getX(), pointerCoords.getY(), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y), @@ -260,7 +261,7 @@ void TouchInputMapper::dump(std::string& dump) { pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT), pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), - pointerProperties.toolType, + ftl::enum_string(pointerProperties.toolType).c_str(), toString(mLastCookedState.cookedPointerData.isHovering(i))); } @@ -1582,10 +1583,10 @@ std::list TouchInputMapper::cookAndDispatch(nsecs_t when, nsecs_t re mCurrentRawState.rawPointerData.pointerForId(id); if (isStylusToolType(pointer.toolType)) { mCurrentCookedState.stylusIdBits.markBit(id); - } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER || - pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + } else if (pointer.toolType == ToolType::FINGER || + pointer.toolType == ToolType::UNKNOWN) { mCurrentCookedState.fingerIdBits.markBit(id); - } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_MOUSE) { + } else if (pointer.toolType == ToolType::MOUSE) { mCurrentCookedState.mouseIdBits.markBit(id); } } @@ -1704,7 +1705,7 @@ void TouchInputMapper::applyExternalStylusTouchState(nsecs_t when) { PointerCoords& coords = currentPointerData.editPointerCoordsWithId(*mFusedStylusPointerId); coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure); - if (mExternalStylusState.toolType != AMOTION_EVENT_TOOL_TYPE_UNKNOWN) { + if (mExternalStylusState.toolType != ToolType::UNKNOWN) { PointerProperties& properties = currentPointerData.editPointerPropertiesWithId(*mFusedStylusPointerId); properties.toolType = mExternalStylusState.toolType; @@ -2678,7 +2679,7 @@ std::list TouchInputMapper::dispatchPointerGestures(nsecs_t when, ns PointerProperties pointerProperties; pointerProperties.clear(); pointerProperties.id = 0; - pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties.toolType = ToolType::FINGER; PointerCoords pointerCoords; pointerCoords.clear(); @@ -2887,7 +2888,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); @@ -2922,8 +2923,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = - AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.tapX); @@ -3010,7 +3010,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); @@ -3040,9 +3040,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi uint32_t index = mPointerGesture.currentGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.currentGestureProperties[index]; const PointerCoords& coords = mPointerGesture.currentGestureCoords[index]; - ALOGD(" currentGesture[%d]: index=%d, toolType=%d, " + ALOGD(" currentGesture[%d]: index=%d, toolType=%s, " "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + id, index, ftl::enum_string(properties.toolType).c_str(), + coords.getAxisValue(AMOTION_EVENT_AXIS_X), coords.getAxisValue(AMOTION_EVENT_AXIS_Y), coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } @@ -3051,9 +3052,10 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when, bool* outCancelPrevi uint32_t index = mPointerGesture.lastGestureIdToIndex[id]; const PointerProperties& properties = mPointerGesture.lastGestureProperties[index]; const PointerCoords& coords = mPointerGesture.lastGestureCoords[index]; - ALOGD(" lastGesture[%d]: index=%d, toolType=%d, " + ALOGD(" lastGesture[%d]: index=%d, toolType=%s, " "x=%0.3f, y=%0.3f, pressure=%0.3f", - id, index, properties.toolType, coords.getAxisValue(AMOTION_EVENT_AXIS_X), + id, index, ftl::enum_string(properties.toolType).c_str(), + coords.getAxisValue(AMOTION_EVENT_AXIS_X), coords.getAxisValue(AMOTION_EVENT_AXIS_Y), coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); } @@ -3342,7 +3344,7 @@ void TouchInputMapper::prepareMultiFingerPointerGestures(nsecs_t when, bool* can mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0; mPointerGesture.currentGestureProperties[0].clear(); mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId; - mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[0].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[0].clear(); mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX); @@ -3435,7 +3437,7 @@ void TouchInputMapper::prepareMultiFingerPointerGestures(nsecs_t when, bool* can mPointerGesture.currentGestureProperties[i].clear(); mPointerGesture.currentGestureProperties[i].id = gestureId; - mPointerGesture.currentGestureProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mPointerGesture.currentGestureProperties[i].toolType = ToolType::FINGER; mPointerGesture.currentGestureCoords[i].clear(); mPointerGesture.currentGestureCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index ae7faa9909..bc358b97e6 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -78,8 +78,8 @@ struct RawPointerData { int32_t distance{}; int32_t tiltX{}; int32_t tiltY{}; - // A fully decoded AMOTION_EVENT_TOOL_TYPE constant. - int32_t toolType{AMOTION_EVENT_TOOL_TYPE_UNKNOWN}; + // A fully decoded ToolType constant. + ToolType toolType{ToolType::UNKNOWN}; bool isHovering{false}; }; diff --git a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp index f6a42bdea0..f70be72741 100644 --- a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp +++ b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.cpp @@ -154,18 +154,18 @@ void MultiTouchMotionAccumulator::warnIfNotInUse(const RawEvent& event, const Sl // --- MultiTouchMotionAccumulator::Slot --- -int32_t MultiTouchMotionAccumulator::Slot::getToolType() const { +ToolType MultiTouchMotionAccumulator::Slot::getToolType() const { if (mHaveAbsMtToolType) { switch (mAbsMtToolType) { case MT_TOOL_FINGER: - return AMOTION_EVENT_TOOL_TYPE_FINGER; + return ToolType::FINGER; case MT_TOOL_PEN: - return AMOTION_EVENT_TOOL_TYPE_STYLUS; + return ToolType::STYLUS; case MT_TOOL_PALM: - return AMOTION_EVENT_TOOL_TYPE_PALM; + return ToolType::PALM; } } - return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + return ToolType::UNKNOWN; } } // namespace android diff --git a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h index 3c1a2a9e64..943dde5ca2 100644 --- a/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h +++ b/services/inputflinger/reader/mapper/accumulator/MultiTouchMotionAccumulator.h @@ -45,7 +45,7 @@ public: inline int32_t getTrackingId() const { return mAbsMtTrackingId; } inline int32_t getPressure() const { return mAbsMtPressure; } inline int32_t getDistance() const { return mAbsMtDistance; } - int32_t getToolType() const; + ToolType getToolType() const; private: friend class MultiTouchMotionAccumulator; diff --git a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp index 6b84f32db2..8c4bed3267 100644 --- a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp +++ b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.cpp @@ -141,21 +141,21 @@ uint32_t TouchButtonAccumulator::getButtonState() const { return result; } -int32_t TouchButtonAccumulator::getToolType() const { +ToolType TouchButtonAccumulator::getToolType() const { if (mBtnToolMouse || mBtnToolLens) { - return AMOTION_EVENT_TOOL_TYPE_MOUSE; + return ToolType::MOUSE; } if (mBtnToolRubber) { - return AMOTION_EVENT_TOOL_TYPE_ERASER; + return ToolType::ERASER; } if (mBtnToolPen || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush) { - return AMOTION_EVENT_TOOL_TYPE_STYLUS; + return ToolType::STYLUS; } if (mBtnToolFinger || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap || mBtnToolQuintTap) { - return AMOTION_EVENT_TOOL_TYPE_FINGER; + return ToolType::FINGER; } - return AMOTION_EVENT_TOOL_TYPE_UNKNOWN; + return ToolType::UNKNOWN; } bool TouchButtonAccumulator::isToolActive() const { diff --git a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h index c2aa2adc0f..c5fd5f5168 100644 --- a/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h +++ b/services/inputflinger/reader/mapper/accumulator/TouchButtonAccumulator.h @@ -36,7 +36,7 @@ public: void process(const RawEvent* rawEvent); uint32_t getButtonState() const; - int32_t getToolType() const; + ToolType getToolType() const; bool isToolActive() const; bool isHovering() const; bool hasStylus() const; diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index 2714d03ea3..70e8fb7758 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -99,10 +99,10 @@ private: // We never need any PointerProperties other than the finger tool type, so we can just keep a // const array of them. const std::array mFingerProps = {{ - {.id = 0, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 1, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 2, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, - {.id = 3, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER}, + {.id = 0, .toolType = ToolType::FINGER}, + {.id = 1, .toolType = ToolType::FINGER}, + {.id = 2, .toolType = ToolType::FINGER}, + {.id = 3, .toolType = ToolType::FINGER}, }}; std::array mFakeFingerCoords = {}; diff --git a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp index d344babe72..e89262a71a 100644 --- a/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/HardwareStateConverter.cpp @@ -85,7 +85,7 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t MultiTouchMotionAccumulator::Slot slot = mMotionAccumulator.getSlot(i); // Some touchpads continue to report contacts even after they've identified them as palms. // We want to exclude these contacts from the HardwareStates. - if (!slot.isInUse() || slot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) { + if (!slot.isInUse() || slot.getToolType() == ToolType::PALM) { continue; } diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 33f404d56b..c6d541e962 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -93,7 +93,7 @@ TEST_F(GestureConverterTest, Move) { ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), + WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); @@ -111,7 +111,7 @@ TEST_F(GestureConverterTest, Move_Rotated) { ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithButtonState(0), + WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); @@ -133,14 +133,14 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), @@ -148,7 +148,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -162,7 +162,7 @@ TEST_F(GestureConverterTest, ButtonsChange) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Finally release the right button Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -175,12 +175,12 @@ TEST_F(GestureConverterTest, ButtonsChange) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, DragWithButton) { @@ -198,14 +198,14 @@ TEST_F(GestureConverterTest, DragWithButton) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -215,7 +215,7 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); @@ -231,12 +231,12 @@ TEST_F(GestureConverterTest, DragWithButton) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Scroll) { @@ -252,7 +252,7 @@ TEST_F(GestureConverterTest, Scroll) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime), + WithToolType(ToolType::FINGER), WithDownTime(downTime), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); args.pop_front(); ASSERT_THAT(std::get(args.front()), @@ -260,7 +260,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 10), WithGestureScrollDistance(0, 10, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); @@ -271,7 +271,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 15), WithGestureScrollDistance(0, 5, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, @@ -283,7 +283,7 @@ TEST_F(GestureConverterTest, Scroll) { WithCoords(POINTER_X, POINTER_Y - 15), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); } @@ -301,14 +301,14 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDownTime(downTime))); + WithToolType(ToolType::FINGER), WithDownTime(downTime))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X - 10, POINTER_Y), WithGestureScrollDistance(0, 10, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture); @@ -318,7 +318,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(POINTER_X - 15, POINTER_Y), WithGestureScrollDistance(0, 5, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1, GESTURES_FLING_START); @@ -329,7 +329,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(POINTER_X - 15, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Scroll_ClearsClassificationAndOffsetsAfterGesture) { @@ -393,7 +393,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get(args.front()); @@ -402,7 +402,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get(args.front()); @@ -411,7 +411,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); @@ -420,7 +420,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.01, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -437,7 +437,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0, -0.005, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -453,19 +453,19 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { @@ -560,7 +560,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get(args.front()); @@ -569,7 +569,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get(args.front()); @@ -578,7 +578,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get(args.front()); @@ -587,7 +587,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); PointerCoords finger3Start = arg.pointerCoords[3]; args.pop_front(); @@ -596,7 +596,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0.01, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); @@ -615,7 +615,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithGestureOffset(0.005, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15); @@ -633,26 +633,26 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(4u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_Inwards) { @@ -668,7 +668,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -676,7 +676,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -688,7 +688,7 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { WithGesturePinchScaleFactor(0.8f, EPSILON), WithPointerCoords(0, POINTER_X - 80, POINTER_Y), WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -699,13 +699,13 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_Outwards) { @@ -721,7 +721,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | @@ -729,7 +729,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); @@ -741,7 +741,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { WithGesturePinchScaleFactor(1.2f, EPSILON), WithPointerCoords(0, POINTER_X - 120, POINTER_Y), WithPointerCoords(1, POINTER_X + 120, POINTER_Y), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1, GESTURES_ZOOM_END); @@ -752,13 +752,13 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, Pinch_ClearsClassificationAndScaleFactorAfterGesture) { @@ -802,18 +802,18 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) { WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); ASSERT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ResetDuringScroll) { @@ -830,7 +830,7 @@ TEST_F(GestureConverterTest, ResetDuringScroll) { WithCoords(POINTER_X, POINTER_Y - 10), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), + WithToolType(ToolType::FINGER), WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))); } @@ -849,19 +849,19 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(3u), WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(2u), WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithPointerCount(1u), WithToolType(ToolType::FINGER))); } TEST_F(GestureConverterTest, ResetDuringPinch) { @@ -879,13 +879,13 @@ TEST_F(GestureConverterTest, ResetDuringPinch) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(2u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); args.pop_front(); EXPECT_THAT(std::get(args.front()), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCount(1u), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER))); + WithToolType(ToolType::FINGER))); } } // namespace android diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index e2996437bf..a58ad84e90 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -1464,7 +1464,7 @@ static InputEventInjectionResult injectKeyUp(const std::unique_ptrnotifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); // Second touch pointer down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(110).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) .build())); // First touch pointer lifts. The second one remains down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(110).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2069,8 +2069,8 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -2085,8 +2085,8 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { MotionEventBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, @@ -2102,7 +2102,7 @@ TEST_P(ShouldSplitTouchFixture, WallpaperWindowReceivesMultiTouch) { .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) .pointer(PointerBuilder(/* id */ 1, - AMOTION_EVENT_TOOL_TYPE_FINGER) + ToolType::FINGER) .x(100) .y(100)) .build(), @@ -2154,8 +2154,8 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(300).y(100)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -2179,8 +2179,8 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { const MotionEvent secondFingerMoveEvent = MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(310).y(110)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(310).y(110)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, @@ -2274,15 +2274,15 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); spyWindow->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2294,8 +2294,8 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_CANCEL, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL)); @@ -2313,7 +2313,7 @@ TEST_F(InputDispatcherTest, TwoPointerCancelInconsistentPolicy) { args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) .policyFlags(DEFAULT_POLICY_FLAGS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN)); @@ -2358,7 +2358,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(mouseDeviceId) .downTime(baseTime + 10) .eventTime(baseTime + 20) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(100)) .build())); @@ -2372,7 +2372,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(mouseDeviceId) .downTime(baseTime + 10) .eventTime(baseTime + 30) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(110) .y(100)) .build())); @@ -2386,7 +2386,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 40) .eventTime(baseTime + 40) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2401,7 +2401,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 40) .eventTime(baseTime + 50) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2415,7 +2415,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 60) .eventTime(baseTime + 60) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2429,7 +2429,7 @@ TEST_F(InputDispatcherTest, HoverFromLeftToRightAndTap) { .deviceId(touchDeviceId) .downTime(baseTime + 60) .eventTime(baseTime + 70) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2467,7 +2467,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -2477,7 +2477,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( @@ -2490,7 +2490,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2498,7 +2498,7 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); leftWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL)); @@ -2508,8 +2508,8 @@ TEST_F(InputDispatcherTest, MultiDeviceSplitTouch) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100)) .build())); leftWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId))); @@ -2547,21 +2547,21 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); // Second touch pointer down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); // First touch pointer lifts. The second one remains down mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -2572,7 +2572,7 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(320).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) .build())); window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), @@ -2584,7 +2584,7 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(320).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2592,8 +2592,8 @@ TEST_F(InputDispatcherTest, MixedTouchAndMouseWithPointerDown) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(350).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100)) .build())); // The pointer_down event should be ignored window->assertNoEvents(); @@ -2619,7 +2619,7 @@ TEST_F(InputDispatcherTest, UnfinishedInjectedEvent) { injectMotionEvent(mDispatcher, MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -2631,7 +2631,7 @@ TEST_F(InputDispatcherTest, UnfinishedInjectedEvent) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(300).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100)) .build())); window->consumeMotionEvent( @@ -2673,7 +2673,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -2685,7 +2685,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2695,7 +2695,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2709,7 +2709,7 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) .build())); @@ -2720,10 +2720,10 @@ TEST_F(InputDispatcherTest, HoverTapAndSplitTouch) { injectMotionEvent(mDispatcher, MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(300) .y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(1, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2756,7 +2756,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2768,7 +2768,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2781,7 +2781,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2794,7 +2794,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(100) .y(100)) .build())); @@ -2806,7 +2806,7 @@ TEST_F(InputDispatcherTest, StylusHoverAndTouchTap) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_STYLUS) .deviceId(stylusDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -2839,40 +2839,40 @@ TEST_F(InputDispatcherTest, StylusHoverAndDownNoInputChannel) { // Start hovering with stylus mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); // Stop hovering mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); // Stylus touches down mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); // Stylus goes up mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_UP)); // Again hover mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER)); // Stop hovering mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); @@ -2908,7 +2908,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -2919,7 +2919,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); @@ -2929,7 +2929,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(55).y(55)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2941,7 +2941,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(60).y(60)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2950,7 +2950,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent( @@ -2964,7 +2964,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -2974,7 +2974,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(110).y(110)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110)) .build())); spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); window->consumeMotionEvent(WithMotionAction(ACTION_MOVE)); @@ -2983,7 +2983,7 @@ TEST_F(InputDispatcherTest, TouchPilferAndMouseMove) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(65).y(65)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65)) .build())); // No more events @@ -3129,9 +3129,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(900) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3140,9 +3138,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3152,9 +3148,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); windowLeft->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); @@ -3165,9 +3159,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3177,9 +3169,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { AINPUT_SOURCE_MOUSE) .buttonState(0) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); @@ -3187,9 +3177,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); windowLeft->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -3198,9 +3186,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(900) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(900).y(400)) .build())); windowRight->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); @@ -3230,14 +3216,14 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); mDispatcher->notifyMotion(&( args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(100)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(120).y(120)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN)); @@ -3247,7 +3233,7 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(300).y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId), WithPointerCount(2u))); @@ -3258,7 +3244,7 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { .deviceId(mouseDeviceId) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(300).y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3267,8 +3253,8 @@ TEST_F(InputDispatcherTest, TwoPointersDownMouseClick) { mDispatcher->notifyMotion(&( args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(101).y(101)) - .pointer(PointerBuilder(1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(121).y(121)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101)) + .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121)) .build())); window->assertNoEvents(); } @@ -3293,7 +3279,7 @@ TEST_F(InputDispatcherTest, HoverWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(100) .y(100)) .build())); @@ -3327,7 +3313,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(100) .y(100)) .build())); @@ -3337,7 +3323,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(110) .y(110)) .build())); @@ -3356,7 +3342,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(200) .y(200)) .build())); @@ -3380,7 +3366,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(200) .y(200)) .build())); @@ -3397,7 +3383,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(250) .y(250)) .build())); @@ -3412,7 +3398,7 @@ TEST_F(InputDispatcherTest, MouseAndTouchWithSpyWindows) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(SECOND_DEVICE_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(0, ToolType::FINGER) .x(250) .y(250)) .build())); @@ -3441,9 +3427,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)); // Inject a series of mouse events for a mouse click @@ -3451,9 +3435,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT)); window->consumeMotionEvent(WithMotionAction(ACTION_DOWN)); @@ -3464,9 +3446,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS)); @@ -3476,9 +3456,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { AINPUT_SOURCE_MOUSE) .buttonState(0) .actionButton(AMOTION_EVENT_BUTTON_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE)); @@ -3486,9 +3464,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -3496,9 +3472,7 @@ TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_EXIT, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) - .x(300) - .y(400)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400)) .build())); window->assertNoEvents(); } @@ -3521,7 +3495,7 @@ TEST_F(InputDispatcherTest, HoverExitIsSentToRemovedWindow) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(400)) .build())); @@ -3551,7 +3525,7 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE) .deviceId(mouseDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE).x(10).y(10)) + .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10)) .build())); window->consumeMotionEvent( AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId))); @@ -3560,7 +3534,7 @@ TEST_F(InputDispatcherTest, TouchDownAfterMouseHover) { mDispatcher->notifyMotion( &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .deviceId(touchDeviceId) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50)) .build())); window->consumeMotionEvent( @@ -3633,7 +3607,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .displayId(ADISPLAY_ID_DEFAULT) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(300) .y(600)) .build())); @@ -3654,7 +3628,7 @@ TEST_F(InputDispatcherTest, HoverEnterMoveRemoveWindowsInSecondDisplay) { MotionEventBuilder(AMOTION_EVENT_ACTION_HOVER_MOVE, AINPUT_SOURCE_MOUSE) .displayId(ADISPLAY_ID_DEFAULT) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_MOUSE) + .pointer(PointerBuilder(0, ToolType::MOUSE) .x(400) .y(700)) .build())); @@ -3911,8 +3885,8 @@ TEST_F(InputDispatcherTest, NonSplitTouchableWindowReceivesMultiTouch) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(-30).y(-50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(-30).y(-50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -4033,7 +4007,7 @@ TEST_F(InputDispatcherDisplayProjectionTest, InjectionWithTransformInLogicalDisp MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER) .x(untransformedPoint.x) .y(untransformedPoint.y)) .build(); @@ -6076,7 +6050,7 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, NoFocusChangeFlag) { const MotionEvent event = MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(20).y(20)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(20).y(20)) .addFlag(AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, event)) @@ -7937,7 +7911,7 @@ protected: MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_STYLUS) .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) + .pointer(PointerBuilder(0, ToolType::STYLUS) .x(50) .y(50)) .build())); @@ -7949,7 +7923,7 @@ protected: MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(50) .y(50)) .build())); @@ -8038,8 +8012,8 @@ TEST_F(InputDispatcherDragTests, DragEnterAndPointerDownPilfersPointers) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(60).y(60)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(60).y(60)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8093,9 +8067,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) .buttonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(50) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT); @@ -8107,9 +8079,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_STYLUS) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(150) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT); @@ -8122,9 +8092,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) { injectMotionEvent(mDispatcher, MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_STYLUS) .buttonState(0) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_STYLUS) - .x(150) - .y(50)) + .pointer(PointerBuilder(0, ToolType::STYLUS).x(150).y(50)) .build())) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT); @@ -8182,8 +8150,8 @@ TEST_F(InputDispatcherDragTests, NoDragAndDropWhenMultiFingers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(75).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(75).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8209,8 +8177,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8225,8 +8193,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { const MotionEvent secondFingerMoveEvent = MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerMoveEvent, INJECT_EVENT_TIMEOUT, @@ -8239,8 +8207,8 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) { const MotionEvent secondFingerUpEvent = MotionEventBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT, @@ -8265,9 +8233,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { MotionEventBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(SECOND_DISPLAY_ID) - .pointer(PointerBuilder(0, AMOTION_EVENT_TOOL_TYPE_FINGER) - .x(100) - .y(100)) + .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, SECOND_DISPLAY_ID, /*expectedFlag=*/0); @@ -8311,7 +8277,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(50) .y(50)) .build())) @@ -8326,7 +8292,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_MOUSE) .buttonState(AMOTION_EVENT_BUTTON_PRIMARY) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(150) .y(50)) .build())) @@ -8341,7 +8307,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) { MotionEventBuilder(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_MOUSE) .buttonState(0) .pointer(PointerBuilder(MOUSE_POINTER_ID, - AMOTION_EVENT_TOOL_TYPE_MOUSE) + ToolType::MOUSE) .x(150) .y(50)) .build())) @@ -8813,8 +8779,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesMultiplePointers) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8845,8 +8811,8 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesSecondPointerAsDown) { const MotionEvent secondFingerDownEvent = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -8884,8 +8850,8 @@ TEST_F(InputDispatcherSpyWindowTest, SplitIfNoForegroundWindowTouched) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9007,8 +8973,8 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9022,9 +8988,9 @@ TEST_F(InputDispatcherPilferPointersTest, ContinuesToReceiveGestureAfterPilfer) MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(100).y(200)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) - .pointer(PointerBuilder(/*id=*/2, AMOTION_EVENT_TOOL_TYPE_FINGER).x(-5).y(-5)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(100).y(200)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(-5).y(-5)) .build(); ASSERT_EQ(InputEventInjectionResult::FAILED, injectMotionEvent(mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9058,8 +9024,8 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9073,9 +9039,9 @@ TEST_F(InputDispatcherPilferPointersTest, PartiallyPilferRequiredPointers) { MotionEventBuilder(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/2, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/2, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, thirdFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9119,8 +9085,8 @@ TEST_F(InputDispatcherPilferPointersTest, PilferAllRequiredPointers) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(50).y(50)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(50).y(50)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9166,8 +9132,8 @@ TEST_F(InputDispatcherPilferPointersTest, CanReceivePointersAfterPilfer) { MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .displayId(ADISPLAY_ID_DEFAULT) .eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) - .pointer(PointerBuilder(/*id=*/0, AMOTION_EVENT_TOOL_TYPE_FINGER).x(10).y(10)) - .pointer(PointerBuilder(/*id=*/1, AMOTION_EVENT_TOOL_TYPE_FINGER).x(150).y(150)) + .pointer(PointerBuilder(/*id=*/0, ToolType::FINGER).x(10).y(10)) + .pointer(PointerBuilder(/*id=*/1, ToolType::FINGER).x(150).y(150)) .build(); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, injectMotionEvent(mDispatcher, secondFingerDownEvent, INJECT_EVENT_TIMEOUT, @@ -9221,7 +9187,7 @@ public: NotifyMotionArgs motionArgs = generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS, ADISPLAY_ID_DEFAULT, {PointF{30, 40}}); - motionArgs.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + motionArgs.pointerProperties[0].toolType = ToolType::STYLUS; mDispatcher->notifyMotion(&motionArgs); } }; diff --git a/services/inputflinger/tests/InputProcessorConverter_test.cpp b/services/inputflinger/tests/InputProcessorConverter_test.cpp index 161a24ff70..4b42f4b141 100644 --- a/services/inputflinger/tests/InputProcessorConverter_test.cpp +++ b/services/inputflinger/tests/InputProcessorConverter_test.cpp @@ -30,7 +30,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = ToolType::FINGER; PointerCoords coords; coords.clear(); diff --git a/services/inputflinger/tests/InputProcessor_test.cpp b/services/inputflinger/tests/InputProcessor_test.cpp index b6deed8aae..0ffdef9daa 100644 --- a/services/inputflinger/tests/InputProcessor_test.cpp +++ b/services/inputflinger/tests/InputProcessor_test.cpp @@ -37,7 +37,7 @@ static NotifyMotionArgs generateBasicMotionArgs() { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = ToolType::FINGER; PointerCoords coords; coords.clear(); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 853c5b0115..92d5357d8e 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -1732,7 +1732,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId())); @@ -1751,7 +1751,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotNotified()); @@ -1768,7 +1768,7 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) { mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId())); } @@ -1864,12 +1864,12 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingTouchGe TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); @@ -1877,11 +1877,11 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingTouchGe TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Release the stylus button. @@ -1896,7 +1896,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsSurroundingHoverin const auto touchscreenId = TestFixture::mTouchscreenInfo.getId(); const auto stylusId = TestFixture::mStylusInfo.getId(); auto toolTypeDevice = - AllOf(WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithDeviceId(touchscreenId)); + AllOf(WithToolType(ToolType::STYLUS), WithDeviceId(touchscreenId)); // Press the stylus button. TestFixture::mStylus->pressKey(BTN_STYLUS); @@ -1980,7 +1980,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Press and release a stylus button. Each change in button state also generates a MOVE event. @@ -1990,12 +1990,12 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithButtonState(AMOTION_EVENT_BUTTON_STYLUS_PRIMARY), WithDeviceId(touchscreenId)))); @@ -2005,11 +2005,11 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Finish the stylus gesture. @@ -2017,7 +2017,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonsWithinTouchGesture TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); } @@ -2039,7 +2039,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Press and release a stylus button. Each change only generates a MOVE motion event. @@ -2050,7 +2050,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); TestFixture::mStylus->releaseKey(BTN_STYLUS); @@ -2059,7 +2059,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable WithKeyCode(AKEYCODE_STYLUS_BUTTON_PRIMARY), WithDeviceId(stylusId)))); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); // Finish the stylus gesture. @@ -2067,7 +2067,7 @@ TYPED_TEST(StylusButtonIntegrationTest, DISABLED_StylusButtonMotionEventsDisable TestFixture::mTouchscreen->sendSync(); ASSERT_NO_FATAL_FAILURE(TestFixture::mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId)))); } @@ -2108,7 +2108,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureReport mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(100.f / RAW_PRESSURE_MAX)))); // Change the pressure on the external stylus, and ensure the touchscreen generates a MOVE @@ -2116,7 +2116,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureReport stylus->setPressure(200); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(200.f / RAW_PRESSURE_MAX)))); // The external stylus did not generate any events. @@ -2162,7 +2162,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep // it shows up as a finger pointer. ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER), WithDeviceId(touchscreenId), + WithToolType(ToolType::FINGER), WithDeviceId(touchscreenId), WithPressure(1.f)))); // Change the pressure on the external stylus. Since the pressure was not present at the start @@ -2175,7 +2175,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); // Start a new gesture. Since we have a valid pressure value, it shows up as a stylus. mDevice->sendTrackingId(FIRST_TRACKING_ID); @@ -2184,7 +2184,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_FusedExternalStylusPressureNotRep mDevice->sendSync(); ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), WithButtonState(0), + WithToolType(ToolType::STYLUS), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(200.f / RAW_PRESSURE_MAX)))); // The external stylus did not generate any events. @@ -2220,7 +2220,7 @@ TEST_F(ExternalStylusIntegrationTest, DISABLED_UnfusedExternalStylus) { mTestListener ->assertNotifyMotionWasCalled(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithToolType( - AMOTION_EVENT_TOOL_TYPE_FINGER), + ToolType::FINGER), WithButtonState(0), WithDeviceId(touchscreenId), WithPressure(1.f)), @@ -3875,7 +3875,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3893,7 +3893,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 1.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3914,7 +3914,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -3932,7 +3932,7 @@ TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaStat ASSERT_EQ(0, args.edgeFlags); ASSERT_EQ(uint32_t(1), args.pointerCount); ASSERT_EQ(0, args.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, args.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertCursorPointerCoords(args.pointerCoords[0], 0.0f, 0.0f, 0.0f)); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision); ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision); @@ -5195,7 +5195,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5219,7 +5219,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5242,7 +5242,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfB ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5292,7 +5292,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMoves ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5315,7 +5315,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMoves ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5360,7 +5360,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5387,7 +5387,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5412,7 +5412,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture_VirtualDispl ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x, VIRTUAL_DISPLAY_WIDTH), toDisplayY(y, VIRTUAL_DISPLAY_HEIGHT), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -5455,7 +5455,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5480,7 +5480,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -5503,7 +5503,7 @@ TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) { ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -6151,14 +6151,14 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // eraser processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // stylus processKey(mapper, BTN_TOOL_RUBBER, 0); @@ -6166,7 +6166,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // brush processKey(mapper, BTN_TOOL_PEN, 0); @@ -6174,7 +6174,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // pencil processKey(mapper, BTN_TOOL_BRUSH, 0); @@ -6182,7 +6182,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // air-brush processKey(mapper, BTN_TOOL_PENCIL, 0); @@ -6190,7 +6190,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // mouse processKey(mapper, BTN_TOOL_AIRBRUSH, 0); @@ -6198,7 +6198,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // lens processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -6206,7 +6206,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // double-tap processKey(mapper, BTN_TOOL_LENS, 0); @@ -6214,7 +6214,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // triple-tap processKey(mapper, BTN_TOOL_DOUBLETAP, 0); @@ -6222,7 +6222,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // quad-tap processKey(mapper, BTN_TOOL_TRIPLETAP, 0); @@ -6230,7 +6230,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger processKey(mapper, BTN_TOOL_QUADTAP, 0); @@ -6238,28 +6238,28 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // stylus trumps finger processKey(mapper, BTN_TOOL_PEN, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // eraser trumps stylus processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // mouse trumps eraser processKey(mapper, BTN_TOOL_MOUSE, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // back to default tool type processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -6269,7 +6269,7 @@ TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { @@ -6659,7 +6659,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectSty processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_TRUE(fakePointerController->isPointerShown()); ASSERT_NO_FATAL_FAILURE( @@ -6683,7 +6683,7 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenConfigDisabled_ShouldNotShowDirec processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_FALSE(fakePointerController->isPointerShown()); } @@ -7125,7 +7125,7 @@ public: mStylusState.when = ARBITRARY_TIME; mStylusState.pressure = 0.f; - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mStylusState.toolType = ToolType::STYLUS; mReader->getContext()->setExternalStylusDevices({mExternalStylusDeviceInfo}); configureDevice(InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE); processExternalStylusState(mapper); @@ -7149,7 +7149,7 @@ protected: void testStartFusedStylusGesture(SingleTouchInputMapper& mapper) { auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); // The first pointer is withheld. processDown(mapper, 100, 200); @@ -7184,7 +7184,7 @@ protected: processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(EXPECTED_SOURCE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); mStylusState.pressure = 0.f; processExternalStylusState(mapper); @@ -7194,7 +7194,7 @@ protected: void testUnsuccessfulFusionGesture(SingleTouchInputMapper& mapper) { auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::FINGER)); // The first pointer is withheld when an external stylus is connected, // and a timeout is requested. @@ -7252,7 +7252,7 @@ TEST_F(ExternalStylusFusionTest, SuccessfulFusion_TouchFirst) { TEST_F(ExternalStylusFusionTest, SuccessfulFusion_PressureFirst) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); // The external stylus reports pressure first. It is ignored for now. mStylusState.pressure = 1.f; @@ -7295,7 +7295,7 @@ TEST_F(ExternalStylusFusionTest, FusionIsRepeatedForEachNewGesture) { TEST_F(ExternalStylusFusionTest, FusedPointerReportsPressureChanges) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); mStylusState.pressure = 0.8f; processExternalStylusState(mapper); @@ -7357,7 +7357,7 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsPressureChanges) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(EXPECTED_SOURCE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); @@ -7368,17 +7368,17 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { auto source = WithSource(EXPECTED_SOURCE); mStylusState.pressure = 1.f; - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_ERASER; + mStylusState.toolType = ToolType::ERASER; processExternalStylusState(mapper); processDown(mapper, 100, 200); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithToolType(AMOTION_EVENT_TOOL_TYPE_ERASER)))); + WithToolType(ToolType::ERASER)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); // The external stylus reports a tool change. We wait for some time for a touch event. - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + mStylusState.toolType = ToolType::STYLUS; processExternalStylusState(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); ASSERT_NO_FATAL_FAILURE( @@ -7389,11 +7389,11 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); // There is another tool type change. - mStylusState.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + mStylusState.toolType = ToolType::FINGER; processExternalStylusState(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); ASSERT_NO_FATAL_FAILURE( @@ -7404,13 +7404,13 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { handleTimeout(mapper, ARBITRARY_TIME + TOUCH_DATA_TIMEOUT); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); processUp(mapper); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(source, WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithToolType(AMOTION_EVENT_TOOL_TYPE_FINGER)))); + WithToolType(ToolType::FINGER)))); ASSERT_NO_FATAL_FAILURE(mReader->getContext()->assertTimeoutWasNotRequested()); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); @@ -7419,7 +7419,7 @@ TEST_F(ExternalStylusFusionTest, FusedPointerReportsToolTypeChanges) { TEST_F(ExternalStylusFusionTest, FusedPointerReportsButtons) { SingleTouchInputMapper& mapper = initializeInputMapperWithExternalStylus(); auto toolTypeSource = - AllOf(WithSource(EXPECTED_SOURCE), WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)); + AllOf(WithSource(EXPECTED_SOURCE), WithToolType(ToolType::STYLUS)); ASSERT_NO_FATAL_FAILURE(testStartFusedStylusGesture(mapper)); @@ -7636,7 +7636,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7655,9 +7655,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7686,9 +7686,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7715,9 +7715,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7738,7 +7738,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7763,7 +7763,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7790,9 +7790,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7819,9 +7819,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7842,7 +7842,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7865,7 +7865,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackin ASSERT_EQ(0, motionArgs.edgeFlags); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON); @@ -7953,7 +7953,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -7961,9 +7961,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -7983,9 +7983,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8002,9 +8002,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_0_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8014,7 +8014,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8029,7 +8029,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8047,9 +8047,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_0_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8066,9 +8066,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(ACTION_POINTER_1_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8078,7 +8078,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8090,7 +8090,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingId ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8123,7 +8123,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8131,9 +8131,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8151,9 +8151,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8171,9 +8171,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_0_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8183,7 +8183,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8196,7 +8196,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(1, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8212,9 +8212,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_0_DOWN, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8232,9 +8232,9 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(ACTION_POINTER_1_UP, motionArgs.action); ASSERT_EQ(size_t(2), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1, motionArgs.pointerProperties[1].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1], @@ -8244,7 +8244,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8256,7 +8256,7 @@ TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) { ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); ASSERT_EQ(size_t(1), motionArgs.pointerCount); ASSERT_EQ(0, motionArgs.pointerProperties[0].id); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0)); @@ -8783,14 +8783,14 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // eraser processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // stylus processKey(mapper, BTN_TOOL_RUBBER, 0); @@ -8798,7 +8798,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // brush processKey(mapper, BTN_TOOL_PEN, 0); @@ -8806,7 +8806,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // pencil processKey(mapper, BTN_TOOL_BRUSH, 0); @@ -8814,7 +8814,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // air-brush processKey(mapper, BTN_TOOL_PENCIL, 0); @@ -8822,7 +8822,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // mouse processKey(mapper, BTN_TOOL_AIRBRUSH, 0); @@ -8830,7 +8830,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // lens processKey(mapper, BTN_TOOL_MOUSE, 0); @@ -8838,7 +8838,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // double-tap processKey(mapper, BTN_TOOL_LENS, 0); @@ -8846,7 +8846,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // triple-tap processKey(mapper, BTN_TOOL_DOUBLETAP, 0); @@ -8854,7 +8854,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // quad-tap processKey(mapper, BTN_TOOL_TRIPLETAP, 0); @@ -8862,7 +8862,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger processKey(mapper, BTN_TOOL_QUADTAP, 0); @@ -8870,42 +8870,42 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // stylus trumps finger processKey(mapper, BTN_TOOL_PEN, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // eraser trumps stylus processKey(mapper, BTN_TOOL_RUBBER, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::ERASER, motionArgs.pointerProperties[0].toolType); // mouse trumps eraser processKey(mapper, BTN_TOOL_MOUSE, 1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::MOUSE, motionArgs.pointerProperties[0].toolType); // MT tool type trumps BTN tool types: MT_TOOL_FINGER processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // MT tool type trumps BTN tool types: MT_TOOL_PEN processToolType(mapper, MT_TOOL_PEN); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::STYLUS, motionArgs.pointerProperties[0].toolType); // back to default tool type processToolType(mapper, -1); // use a deliberately undefined tool type, for testing @@ -8916,7 +8916,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) { @@ -9531,7 +9531,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger move processId(mapper, 1); @@ -9539,14 +9539,14 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // finger up. processId(mapper, -1); processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // new finger down processId(mapper, 1); @@ -9554,7 +9554,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleSingleTouch) { processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } /** @@ -9576,7 +9576,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Tool changed to MT_TOOL_PALM expect sending the cancel event. processToolType(mapper, MT_TOOL_PALM); @@ -9602,7 +9602,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_SinglePointer processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); } /** @@ -9624,7 +9624,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9633,7 +9633,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_TwoPointers) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[1].toolType); // If the tool type of the first finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -9699,7 +9699,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9708,7 +9708,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // If the tool type of the first finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -9743,7 +9743,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_ShouldCancelW processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(uint32_t(1), motionArgs.pointerCount); // third finger move @@ -9797,7 +9797,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPoin processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // Second finger down. processSlot(mapper, SECOND_SLOT); @@ -9806,7 +9806,7 @@ TEST_F(MultiTouchInputMapperTest, Process_ShouldHandlePalmToolType_KeepFirstPoin processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(ACTION_POINTER_1_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); // If the tool type of the second finger changes to MT_TOOL_PALM, // we expect to receive ACTION_POINTER_UP with cancel flag. @@ -10003,7 +10003,7 @@ TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // Now that we know the device supports styluses, ensure that the device is re-configured with // the stylus source. @@ -10025,7 +10025,7 @@ TEST_F(MultiTouchInputMapperTest, StylusSourceIsAddedDynamicallyFromToolType) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithSource(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); } TEST_F(MultiTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectStylusPointer) { @@ -10048,7 +10048,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenConfigEnabled_ShouldShowDirectStyl processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_TRUE(fakePointerController->isPointerShown()); ASSERT_NO_FATAL_FAILURE( @@ -10075,7 +10075,7 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenConfigDisabled_ShouldNotShowDirect processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS), + WithToolType(ToolType::STYLUS), WithPointerCoords(0, toDisplayX(100), toDisplayY(200))))); ASSERT_FALSE(fakePointerController->isPointerShown()); } @@ -10468,7 +10468,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthSwipe) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE( assertPointerCoords(motionArgs.pointerCoords[0], 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)); @@ -10490,7 +10490,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthSwipe) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::TWO_FINGER_SWIPE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 0, movingDistance * mPointerMovementScale, 1, 0, 0, 0, @@ -10528,7 +10528,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthLowResolutionSwipe) ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE( assertPointerCoords(motionArgs.pointerCoords[0], 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)); @@ -10550,7 +10550,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthLowResolutionSwipe) ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::TWO_FINGER_SWIPE, motionArgs.classification); // New coordinate is the scaled relative coordinate from the initial coordinate. ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], 0, @@ -10584,7 +10584,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); // One pointer for PRESS, and its coordinate is used as the origin for pointer coordinates. ASSERT_NO_FATAL_FAILURE( @@ -10610,15 +10610,15 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, motionArgs.action); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(1U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_EQ(2U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN, motionArgs.action & AMOTION_EVENT_ACTION_MASK); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); // Two pointers' scaled relative coordinates from their initial centroid. // Initial y coordinates are 0 as y1 and y2 have the same value. @@ -10648,7 +10648,7 @@ TEST_F(MultiTouchPointerModeTest, PointerGestureMaxSwipeWidthFreeform) { ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs)); ASSERT_EQ(2U, motionArgs.pointerCount); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action); - ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType); + ASSERT_EQ(ToolType::FINGER, motionArgs.pointerProperties[0].toolType); ASSERT_EQ(MotionClassification::NONE, motionArgs.classification); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0], cookedX1, movingDistance * 2 * mPointerMovementScale, 1, 0, 0, @@ -10718,12 +10718,12 @@ TEST_F(MultiTouchPointerModeTest, WhenViewportActiveStatusChanged_PointerGesture ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // TODO(b/257078296): Pointer mode generates extra event. ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); // Make the viewport inactive. This will put the device in disabled mode, and the ongoing stylus @@ -10735,12 +10735,12 @@ TEST_F(MultiTouchPointerModeTest, WhenViewportActiveStatusChanged_PointerGesture ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); // TODO(b/257078296): Pointer mode generates extra event. ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL), WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS), - WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS)))); + WithToolType(ToolType::STYLUS)))); ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled()); } diff --git a/services/inputflinger/tests/NotifyArgs_test.cpp b/services/inputflinger/tests/NotifyArgs_test.cpp index 671558509d..15367568ab 100644 --- a/services/inputflinger/tests/NotifyArgs_test.cpp +++ b/services/inputflinger/tests/NotifyArgs_test.cpp @@ -54,7 +54,7 @@ TEST(NotifyMotionArgsTest, TestCopyAssignmentOperator) { for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, x++); diff --git a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp index 9014dfb48b..9818176cb0 100644 --- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp +++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp @@ -45,8 +45,8 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, PointerCoords pointerCoords[pointerCount]; const int32_t deviceId = isFromSource(source, TOUCHSCREEN) ? TOUCH_DEVICE_ID : STYLUS_DEVICE_ID; - const int32_t toolType = isFromSource(source, TOUCHSCREEN) ? AMOTION_EVENT_TOOL_TYPE_FINGER - : AMOTION_EVENT_TOOL_TYPE_STYLUS; + const ToolType toolType = + isFromSource(source, TOUCHSCREEN) ? ToolType::FINGER : ToolType::STYLUS; for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; @@ -278,20 +278,20 @@ TEST_F(PreferStylusOverTouchTest, MixedStylusAndTouchPointersAreIgnored) { // Event from a stylus device, but with finger tool type args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/1, DOWN, {{1, 2}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; assertNotBlocked(args); // Second pointer (stylus pointer) goes down, from the same device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/2, POINTER_1_DOWN, {{1, 2}, {10, 20}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; assertNotBlocked(args); // Second pointer (stylus pointer) goes down, from the same device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/3, MOVE, {{2, 3}, {11, 21}}, STYLUS); // Keep source stylus, but make the tool type touch - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; assertNotBlocked(args); } @@ -418,14 +418,14 @@ TEST_F(PreferStylusOverTouchTest, MixedStylusAndTouchDeviceIsCanceledAtFirst) { // Introduce a stylus pointer into the device 1 stream. It should be ignored. args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/3, POINTER_1_DOWN, {{1, 2}, {3, 4}}, TOUCHSCREEN); - args.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[1].toolType = ToolType::STYLUS; args.source = STYLUS; assertDropped(args); // Lift up touch from the mixed touch/stylus device args = generateMotionArgs(/*downTime=*/1, /*eventTime=*/4, CANCEL, {{1, 2}, {3, 4}}, TOUCHSCREEN); - args.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[1].toolType = ToolType::STYLUS; args.source = STYLUS; assertDropped(args); diff --git a/services/inputflinger/tests/TestInputListenerMatchers.h b/services/inputflinger/tests/TestInputListenerMatchers.h index 09f7ae8b1c..338b74766e 100644 --- a/services/inputflinger/tests/TestInputListenerMatchers.h +++ b/services/inputflinger/tests/TestInputListenerMatchers.h @@ -138,8 +138,8 @@ MATCHER_P(WithPressure, pressure, "InputEvent with specified pressure") { MATCHER_P(WithToolType, toolType, "InputEvent with specified tool type") { const auto argToolType = arg.pointerProperties[0].toolType; - *result_listener << "expected tool type " << motionToolTypeToString(toolType) << ", but got " - << motionToolTypeToString(argToolType); + *result_listener << "expected tool type " << ftl::enum_string(toolType) << ", but got " + << ftl::enum_string(argToolType); return argToolType == toolType; } diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp index 3f749b1fed..2a9ace00c5 100644 --- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp +++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp @@ -79,7 +79,7 @@ static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, for (size_t i = 0; i < pointerCount; i++) { pointerProperties[i].clear(); pointerProperties[i].id = i; - pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + pointerProperties[i].toolType = ToolType::FINGER; pointerCoords[i].clear(); pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, points[i].x); @@ -507,7 +507,7 @@ TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenResetHappens) { TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenStylusSourceWithFingerToolIsReceived) { mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()}); NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + args.pointerProperties[0].toolType = ToolType::FINGER; args.source = AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); } @@ -548,15 +548,15 @@ TEST_F(UnwantedInteractionBlockerTest, StylusAfterTouchWorks) { // Now touch down stylus args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/3, DOWN, {{10, 20, 30}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/4, MOVE, {{40, 50, 60}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/5, UP, {{40, 50, 60}}); - args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args.pointerProperties[0].toolType = ToolType::STYLUS; args.source |= AINPUT_SOURCE_STYLUS; mBlocker->notifyMotion(&args); } @@ -617,14 +617,14 @@ TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) { info.addSource(AINPUT_SOURCE_STYLUS); mBlocker->notifyInputDevicesChanged({info}); NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}}); - args1.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args1.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args1); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(DOWN)); // Move the stylus, setting large TOUCH_MAJOR/TOUCH_MINOR dimensions NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}}); - args2.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args2.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args2); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); @@ -632,7 +632,7 @@ TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) { // it's a palm. NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}); - args3.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args3.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args3); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP)); } @@ -655,21 +655,21 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { // Stylus pointer down NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, POINTER_1_DOWN, {{1, 2, 3}, {10, 20, 30}}); - args2.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args2.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args2); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(POINTER_1_DOWN)); // Large touch oval on the next finger move NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, MOVE, {{1, 2, 300}, {11, 21, 30}}); - args3.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args3.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args3); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); // Lift up the finger pointer. It should be canceled due to the heuristic filter. NotifyMotionArgs args4 = generateMotionArgs(/*downTime=*/0, 3 * RESAMPLE_PERIOD, POINTER_0_UP, {{1, 2, 300}, {11, 21, 30}}); - args4.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args4.pointerProperties[1].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args4); mTestListener.assertNotifyMotionWasCalled( AllOf(WithMotionAction(POINTER_0_UP), WithFlags(FLAG_CANCELED))); @@ -677,7 +677,7 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { NotifyMotionArgs args5 = generateMotionArgs(/*downTime=*/0, 4 * RESAMPLE_PERIOD, MOVE, {{12, 22, 30}}); args5.pointerProperties[0].id = args4.pointerProperties[1].id; - args5.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args5.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args5); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE)); @@ -685,7 +685,7 @@ TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) { NotifyMotionArgs args6 = generateMotionArgs(/*downTime=*/0, 5 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}); args6.pointerProperties[0].id = args4.pointerProperties[1].id; - args6.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS; + args6.pointerProperties[0].toolType = ToolType::STYLUS; mBlocker->notifyMotion(&args6); mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP)); } diff --git a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp index 2909129126..6617f65adf 100644 --- a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp @@ -28,7 +28,7 @@ NotifyMotionArgs generateFuzzedMotionArgs(FuzzedDataProvider &fdp) { // Create a basic motion event for testing PointerProperties properties; properties.id = 0; - properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + properties.toolType = getFuzzedToolType(fdp); PointerCoords coords; coords.clear(); for (int32_t i = 0; i < fdp.ConsumeIntegralInRange(0, MAX_AXES); i++) { diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h index 2cb5cdf9fc..d9a07b96d5 100644 --- a/services/inputflinger/tests/fuzzers/MapperHelpers.h +++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h @@ -66,6 +66,14 @@ constexpr size_t kMaxSize = 256; namespace android { +template +ToolType getFuzzedToolType(Fdp& fdp) { + const int32_t toolType = fdp.template ConsumeIntegralInRange( + static_cast(ToolType::ftl_first), + static_cast(ToolType::ftl_last)); + return static_cast(toolType); +} + class FuzzEventHub : public EventHubInterface { InputDeviceIdentifier mIdentifier; std::vector mVideoFrames; diff --git a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp index 59cb94a2e2..20db39d885 100644 --- a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp @@ -128,7 +128,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { StylusState state{fdp->ConsumeIntegral(), fdp->ConsumeFloatingPoint(), fdp->ConsumeIntegral(), - fdp->ConsumeIntegral()}; + getFuzzedToolType(*fdp)}; std::list unused = mapper.updateExternalStylusState(state); }, [&]() -> void { mapper.getAssociatedDisplayId(); }, -- cgit v1.2.3-59-g8ed1b From 63b6361f3e23ab44c7e1adfe06ce9e11270d5100 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 12 Apr 2023 11:00:23 -0700 Subject: Convert input event type to enum class This will increase type safety and simplify some of the printing. Bug: 274073185 Test: m checkinput Change-Id: I848c2f156cc23232c50d2338b4788be3232dba1a --- include/input/Input.h | 31 +++-- libs/gui/tests/EndToEndNativeInputTest.cpp | 18 +-- libs/input/Input.cpp | 126 ++++++++++--------- libs/input/android/os/InputEventInjectionSync.aidl | 3 + libs/input/tests/InputEvent_test.cpp | 4 +- .../input/tests/InputPublisherAndConsumer_test.cpp | 13 +- services/inputflinger/Android.bp | 1 + .../inputflinger/dispatcher/InputDispatcher.cpp | 34 +++-- .../inputflinger/tests/InputDispatcher_test.cpp | 137 ++++++++++----------- 9 files changed, 193 insertions(+), 174 deletions(-) (limited to 'libs/input/Input.cpp') diff --git a/include/input/Input.h b/include/input/Input.h index a033535f4b..1e810b438a 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -210,7 +210,20 @@ vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) */ float transformAngle(const ui::Transform& transform, float angleRadians); -const char* inputEventTypeToString(int32_t type); +/** + * The type of the InputEvent. + * This should have 1:1 correspondence with the values of anonymous enum defined in input.h. + */ +enum class InputEventType { + KEY = AINPUT_EVENT_TYPE_KEY, + MOTION = AINPUT_EVENT_TYPE_MOTION, + FOCUS = AINPUT_EVENT_TYPE_FOCUS, + CAPTURE = AINPUT_EVENT_TYPE_CAPTURE, + DRAG = AINPUT_EVENT_TYPE_DRAG, + TOUCH_MODE = AINPUT_EVENT_TYPE_TOUCH_MODE, + ftl_first = KEY, + ftl_last = TOUCH_MODE, +}; std::string inputEventSourceToString(int32_t source); @@ -482,7 +495,7 @@ class InputEvent : public AInputEvent { public: virtual ~InputEvent() { } - virtual int32_t getType() const = 0; + virtual InputEventType getType() const = 0; inline int32_t getId() const { return mId; } @@ -513,6 +526,8 @@ protected: std::array mHmac; }; +std::ostream& operator<<(std::ostream& out, const InputEvent& event); + /* * Key events. */ @@ -520,7 +535,7 @@ class KeyEvent : public InputEvent { public: virtual ~KeyEvent() { } - virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } + virtual InputEventType getType() const { return InputEventType::KEY; } inline int32_t getAction() const { return mAction; } @@ -571,7 +586,7 @@ class MotionEvent : public InputEvent { public: virtual ~MotionEvent() { } - virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } + virtual InputEventType getType() const { return InputEventType::MOTION; } inline int32_t getAction() const { return mAction; } @@ -899,7 +914,7 @@ class FocusEvent : public InputEvent { public: virtual ~FocusEvent() {} - virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; } + virtual InputEventType getType() const override { return InputEventType::FOCUS; } inline bool getHasFocus() const { return mHasFocus; } @@ -918,7 +933,7 @@ class CaptureEvent : public InputEvent { public: virtual ~CaptureEvent() {} - virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; } + virtual InputEventType getType() const override { return InputEventType::CAPTURE; } inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; } @@ -937,7 +952,7 @@ class DragEvent : public InputEvent { public: virtual ~DragEvent() {} - virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; } + virtual InputEventType getType() const override { return InputEventType::DRAG; } inline bool isExiting() const { return mIsExiting; } @@ -961,7 +976,7 @@ class TouchModeEvent : public InputEvent { public: virtual ~TouchModeEvent() {} - virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_TOUCH_MODE; } + virtual InputEventType getType() const override { return InputEventType::TOUCH_MODE; } inline bool isInTouchMode() const { return mIsInTouchMode; } diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp index 9e8c65c678..a5734b7af0 100644 --- a/libs/gui/tests/EndToEndNativeInputTest.cpp +++ b/libs/gui/tests/EndToEndNativeInputTest.cpp @@ -164,7 +164,7 @@ public: void assertFocusChange(bool hasFocus) { InputEvent *ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType()); + ASSERT_EQ(InputEventType::FOCUS, ev->getType()); FocusEvent *focusEvent = static_cast(ev); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); } @@ -172,7 +172,7 @@ public: void expectTap(int x, int y) { InputEvent* ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); MotionEvent* mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); EXPECT_EQ(x, mev->getX(0)); @@ -181,7 +181,7 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); @@ -190,7 +190,7 @@ public: void expectTapWithFlag(int x, int y, int32_t flags) { InputEvent *ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); MotionEvent *mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); EXPECT_EQ(x, mev->getX(0)); @@ -199,7 +199,7 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); EXPECT_EQ(flags, mev->getFlags() & flags); @@ -208,7 +208,7 @@ public: void expectTapInDisplayCoordinates(int displayX, int displayY) { InputEvent *ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); MotionEvent *mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction()); const PointerCoords &coords = *mev->getRawPointerCoords(0 /*pointerIndex*/); @@ -218,7 +218,7 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType()); + ASSERT_EQ(InputEventType::MOTION, ev->getType()); mev = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction()); EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS); @@ -227,7 +227,7 @@ public: void expectKey(uint32_t keycode) { InputEvent *ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType()); + ASSERT_EQ(InputEventType::KEY, ev->getType()); KeyEvent *keyEvent = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, keyEvent->getAction()); EXPECT_EQ(keycode, keyEvent->getKeyCode()); @@ -235,7 +235,7 @@ public: ev = consumeEvent(); ASSERT_NE(ev, nullptr); - ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, ev->getType()); + ASSERT_EQ(InputEventType::KEY, ev->getType()); keyEvent = static_cast(ev); EXPECT_EQ(AMOTION_EVENT_ACTION_UP, keyEvent->getAction()); EXPECT_EQ(keycode, keyEvent->getKeyCode()); diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 4dbf575490..00925ba555 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -170,30 +170,6 @@ float transformAngle(const ui::Transform& transform, float angleRadians) { return atan2f(transformedPoint.x, -transformedPoint.y); } -const char* inputEventTypeToString(int32_t type) { - switch (type) { - case AINPUT_EVENT_TYPE_KEY: { - return "KEY"; - } - case AINPUT_EVENT_TYPE_MOTION: { - return "MOTION"; - } - case AINPUT_EVENT_TYPE_FOCUS: { - return "FOCUS"; - } - case AINPUT_EVENT_TYPE_CAPTURE: { - return "CAPTURE"; - } - case AINPUT_EVENT_TYPE_DRAG: { - return "DRAG"; - } - case AINPUT_EVENT_TYPE_TOUCH_MODE: { - return "TOUCH_MODE"; - } - } - return "UNKNOWN"; -} - std::string inputEventSourceToString(int32_t source) { if (source == AINPUT_SOURCE_UNKNOWN) { return "UNKNOWN"; @@ -287,6 +263,37 @@ int32_t InputEvent::nextId() { return idGen.nextId(); } +std::ostream& operator<<(std::ostream& out, const InputEvent& event) { + switch (event.getType()) { + case InputEventType::KEY: { + const KeyEvent& keyEvent = static_cast(event); + out << keyEvent; + return out; + } + case InputEventType::MOTION: { + const MotionEvent& motionEvent = static_cast(event); + out << motionEvent; + return out; + } + case InputEventType::FOCUS: { + out << "FocusEvent"; + return out; + } + case InputEventType::CAPTURE: { + out << "CaptureEvent"; + return out; + } + case InputEventType::DRAG: { + out << "DragEvent"; + return out; + } + case InputEventType::TOUCH_MODE: { + out << "TouchModeEvent"; + return out; + } + } +} + // --- KeyEvent --- const char* KeyEvent::getLabel(int32_t keyCode) { @@ -1165,44 +1172,51 @@ TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() { void PooledInputEventFactory::recycle(InputEvent* event) { switch (event->getType()) { - case AINPUT_EVENT_TYPE_KEY: - if (mKeyEventPool.size() < mMaxPoolSize) { - mKeyEventPool.push(std::unique_ptr(static_cast(event))); - return; + case InputEventType::KEY: { + if (mKeyEventPool.size() < mMaxPoolSize) { + mKeyEventPool.push(std::unique_ptr(static_cast(event))); + return; + } + break; } - break; - case AINPUT_EVENT_TYPE_MOTION: - if (mMotionEventPool.size() < mMaxPoolSize) { - mMotionEventPool.push(std::unique_ptr(static_cast(event))); - return; + case InputEventType::MOTION: { + if (mMotionEventPool.size() < mMaxPoolSize) { + mMotionEventPool.push( + std::unique_ptr(static_cast(event))); + return; + } + break; } - break; - case AINPUT_EVENT_TYPE_FOCUS: - if (mFocusEventPool.size() < mMaxPoolSize) { - mFocusEventPool.push(std::unique_ptr(static_cast(event))); - return; + case InputEventType::FOCUS: { + if (mFocusEventPool.size() < mMaxPoolSize) { + mFocusEventPool.push(std::unique_ptr(static_cast(event))); + return; + } + break; } - break; - case AINPUT_EVENT_TYPE_CAPTURE: - if (mCaptureEventPool.size() < mMaxPoolSize) { - mCaptureEventPool.push( - std::unique_ptr(static_cast(event))); - return; + case InputEventType::CAPTURE: { + if (mCaptureEventPool.size() < mMaxPoolSize) { + mCaptureEventPool.push( + std::unique_ptr(static_cast(event))); + return; + } + break; } - break; - case AINPUT_EVENT_TYPE_DRAG: - if (mDragEventPool.size() < mMaxPoolSize) { - mDragEventPool.push(std::unique_ptr(static_cast(event))); - return; + case InputEventType::DRAG: { + if (mDragEventPool.size() < mMaxPoolSize) { + mDragEventPool.push(std::unique_ptr(static_cast(event))); + return; + } + break; } - break; - case AINPUT_EVENT_TYPE_TOUCH_MODE: - if (mTouchModeEventPool.size() < mMaxPoolSize) { - mTouchModeEventPool.push( - std::unique_ptr(static_cast(event))); - return; + case InputEventType::TOUCH_MODE: { + if (mTouchModeEventPool.size() < mMaxPoolSize) { + mTouchModeEventPool.push( + std::unique_ptr(static_cast(event))); + return; + } + break; } - break; } delete event; } diff --git a/libs/input/android/os/InputEventInjectionSync.aidl b/libs/input/android/os/InputEventInjectionSync.aidl index 95d24cb443..2d225fa452 100644 --- a/libs/input/android/os/InputEventInjectionSync.aidl +++ b/libs/input/android/os/InputEventInjectionSync.aidl @@ -33,4 +33,7 @@ enum InputEventInjectionSync { /* Waits for the input event to be completely processed. */ WAIT_FOR_FINISHED = 2, + + ftl_first = NONE, + ftl_last = WAIT_FOR_FINISHED, } diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 59125dd428..a9655730fc 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -197,7 +197,7 @@ TEST_F(KeyEventTest, Properties) { ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME); ASSERT_EQ(id, event.getId()); - ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType()); + ASSERT_EQ(InputEventType::KEY, event.getType()); ASSERT_EQ(2, event.getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource()); ASSERT_EQ(DISPLAY_ID, event.getDisplayId()); @@ -346,7 +346,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { // Check properties. ASSERT_EQ(mId, event->getId()); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); + ASSERT_EQ(InputEventType::MOTION, event->getType()); ASSERT_EQ(2, event->getDeviceId()); ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource()); ASSERT_EQ(DISPLAY_ID, event->getDisplayId()); diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp index 965fda73b4..3ecf8eed50 100644 --- a/libs/input/tests/InputPublisherAndConsumer_test.cpp +++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp @@ -98,8 +98,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() { ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType()) - << "consumer should have returned a key event"; + ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event"; KeyEvent* keyEvent = static_cast(event); EXPECT_EQ(seq, consumeSeq); @@ -207,7 +206,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() { ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()) + ASSERT_EQ(InputEventType::MOTION, event->getType()) << "consumer should have returned a motion event"; MotionEvent* motionEvent = static_cast(event); @@ -298,7 +297,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() { ASSERT_EQ(OK, status) << "consumer consume should return OK"; ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType()) + ASSERT_EQ(InputEventType::FOCUS, event->getType()) << "consumer should have returned a focus event"; FocusEvent* focusEvent = static_cast(event); @@ -339,7 +338,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeCaptureEvent() { ASSERT_EQ(OK, status) << "consumer consume should return OK"; ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_CAPTURE, event->getType()) + ASSERT_EQ(InputEventType::CAPTURE, event->getType()) << "consumer should have returned a capture event"; const CaptureEvent* captureEvent = static_cast(event); @@ -381,7 +380,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeDragEvent() { ASSERT_EQ(OK, status) << "consumer consume should return OK"; ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_DRAG, event->getType()) + ASSERT_EQ(InputEventType::DRAG, event->getType()) << "consumer should have returned a drag event"; const DragEvent& dragEvent = static_cast(*event); @@ -423,7 +422,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeTouchModeEvent() { ASSERT_EQ(OK, status) << "consumer consume should return OK"; ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event"; - ASSERT_EQ(AINPUT_EVENT_TYPE_TOUCH_MODE, event->getType()) + ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType()) << "consumer should have returned a touch mode event"; const TouchModeEvent& touchModeEvent = static_cast(*event); diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index b8854352ad..e04481ca50 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -213,6 +213,7 @@ phony { name: "checkinput", required: [ // native targets + "libgui_test", "libinput", "libinputflinger", "inputflinger_tests", diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 851f13c0d5..c39c408e0d 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -117,11 +117,7 @@ inline nsecs_t now() { return systemTime(SYSTEM_TIME_MONOTONIC); } -inline const char* toString(bool value) { - return value ? "true" : "false"; -} - -inline const std::string toString(const sp& binder) { +inline const std::string binderToString(const sp& binder) { if (binder == nullptr) { return ""; } @@ -2909,7 +2905,7 @@ std::string InputDispatcher::dumpWindowForTouchOcclusion(const WindowInfo* info, info->frameBottom, dumpRegion(info->touchableRegion).c_str(), info->name.c_str(), info->inputConfig.string().c_str(), toString(info->token != nullptr), info->applicationInfo.name.c_str(), - toString(info->applicationInfo.token).c_str()); + binderToString(info->applicationInfo.token).c_str()); } bool InputDispatcher::isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const { @@ -3623,8 +3619,8 @@ void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp& connection, bool notify) { if (DEBUG_DISPATCH_CYCLE) { - ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s", - connection->getInputChannelName().c_str(), toString(notify)); + LOG(DEBUG) << "channel '" << connection->getInputChannelName() << "'~ " << __func__ + << " - notify=" << toString(notify); } // Clear the dispatch queues. @@ -4376,10 +4372,10 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev std::chrono::milliseconds timeout, uint32_t policyFlags) { if (debugInboundEventDetails()) { - ALOGD("injectInputEvent - eventType=%d, targetUid=%s, syncMode=%d, timeout=%lld, " - "policyFlags=0x%08x", - event->getType(), targetUid ? std::to_string(*targetUid).c_str() : "none", syncMode, - timeout.count(), policyFlags); + LOG(DEBUG) << __func__ << ": targetUid=" << toString(targetUid) + << ", syncMode=" << ftl::enum_string(syncMode) << ", timeout=" << timeout.count() + << "ms, policyFlags=0x" << std::hex << policyFlags << std::dec + << ", event=" << *event; } nsecs_t endTime = now() + std::chrono::duration_cast(timeout).count(); @@ -4398,7 +4394,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev std::queue> injectedEntries; switch (event->getType()) { - case AINPUT_EVENT_TYPE_KEY: { + case InputEventType::KEY: { const KeyEvent& incomingKey = static_cast(*event); int32_t action = incomingKey.getAction(); if (!validateKeyEvent(action)) { @@ -4444,7 +4440,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev break; } - case AINPUT_EVENT_TYPE_MOTION: { + case InputEventType::MOTION: { const MotionEvent& motionEvent = static_cast(*event); const int32_t action = motionEvent.getAction(); const bool isPointerEvent = @@ -4520,7 +4516,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev } default: - ALOGW("Cannot inject %s events", inputEventTypeToString(event->getType())); + LOG(WARNING) << "Cannot inject " << ftl::enum_string(event->getType()) << " events"; return InputEventInjectionResult::FAILED; } @@ -4610,14 +4606,14 @@ std::unique_ptr InputDispatcher::verifyInputEvent(const Inpu std::array calculatedHmac; std::unique_ptr result; switch (event.getType()) { - case AINPUT_EVENT_TYPE_KEY: { + case InputEventType::KEY: { const KeyEvent& keyEvent = static_cast(event); VerifiedKeyEvent verifiedKeyEvent = verifiedKeyEventFromKeyEvent(keyEvent); result = std::make_unique(verifiedKeyEvent); calculatedHmac = sign(verifiedKeyEvent); break; } - case AINPUT_EVENT_TYPE_MOTION: { + case InputEventType::MOTION: { const MotionEvent& motionEvent = static_cast(event); VerifiedMotionEvent verifiedMotionEvent = verifiedMotionEventFromMotionEvent(motionEvent); @@ -5519,14 +5515,14 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) { windowInfo->frameTop, windowInfo->frameRight, windowInfo->frameBottom, windowInfo->globalScaleFactor, windowInfo->applicationInfo.name.c_str(), - toString(windowInfo->applicationInfo.token).c_str()); + binderToString(windowInfo->applicationInfo.token).c_str()); dump += dumpRegion(windowInfo->touchableRegion); dump += StringPrintf(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%" PRId64 "ms, hasToken=%s, " "touchOcclusionMode=%s\n", windowInfo->ownerPid, windowInfo->ownerUid, millis(windowInfo->dispatchingTimeout), - toString(windowInfo->token != nullptr), + binderToString(windowInfo->token).c_str(), toString(windowInfo->touchOcclusionMode).c_str()); windowInfo->transform.dump(dump, "transform", INDENT4); } diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index fb808eb2a3..5e51bfc1ea 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -213,7 +213,7 @@ public: void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) { assertFilterInputEventWasCalledInternal([&args](const InputEvent& event) { - ASSERT_EQ(event.getType(), AINPUT_EVENT_TYPE_KEY); + ASSERT_EQ(event.getType(), InputEventType::KEY); EXPECT_EQ(event.getDisplayId(), args.displayId); const auto& keyEvent = static_cast(event); @@ -224,7 +224,7 @@ public: void assertFilterInputEventWasCalled(const NotifyMotionArgs& args, vec2 point) { assertFilterInputEventWasCalledInternal([&](const InputEvent& event) { - ASSERT_EQ(event.getType(), AINPUT_EVENT_TYPE_MOTION); + ASSERT_EQ(event.getType(), InputEventType::MOTION); EXPECT_EQ(event.getDisplayId(), args.displayId); const auto& motionEvent = static_cast(event); @@ -530,17 +530,21 @@ private: bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { std::scoped_lock lock(mLock); switch (inputEvent->getType()) { - case AINPUT_EVENT_TYPE_KEY: { + case InputEventType::KEY: { const KeyEvent* keyEvent = static_cast(inputEvent); mFilteredEvent = std::make_unique(*keyEvent); break; } - case AINPUT_EVENT_TYPE_MOTION: { + case InputEventType::MOTION: { const MotionEvent* motionEvent = static_cast(inputEvent); mFilteredEvent = std::make_unique(*motionEvent); break; } + default: { + ADD_FAILURE() << "Should only filter keys or motions"; + break; + } } return true; } @@ -924,7 +928,7 @@ public: ASSERT_EQ(OK, status); } - void consumeEvent(int32_t expectedEventType, int32_t expectedAction, + void consumeEvent(InputEventType expectedEventType, int32_t expectedAction, std::optional expectedDisplayId, std::optional expectedFlags) { InputEvent* event = consume(); @@ -932,15 +936,15 @@ public: ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; ASSERT_EQ(expectedEventType, event->getType()) - << mName.c_str() << " expected " << inputEventTypeToString(expectedEventType) - << " event, got " << inputEventTypeToString(event->getType()) << " event"; + << mName.c_str() << " expected " << ftl::enum_string(expectedEventType) + << " event, got " << *event; if (expectedDisplayId.has_value()) { EXPECT_EQ(expectedDisplayId, event->getDisplayId()); } switch (expectedEventType) { - case AINPUT_EVENT_TYPE_KEY: { + case InputEventType::KEY: { const KeyEvent& keyEvent = static_cast(*event); EXPECT_EQ(expectedAction, keyEvent.getAction()); if (expectedFlags.has_value()) { @@ -948,7 +952,7 @@ public: } break; } - case AINPUT_EVENT_TYPE_MOTION: { + case InputEventType::MOTION: { const MotionEvent& motionEvent = static_cast(*event); assertMotionAction(expectedAction, motionEvent.getAction()); @@ -957,21 +961,18 @@ public: } break; } - case AINPUT_EVENT_TYPE_FOCUS: { + case InputEventType::FOCUS: { FAIL() << "Use 'consumeFocusEvent' for FOCUS events"; } - case AINPUT_EVENT_TYPE_CAPTURE: { + case InputEventType::CAPTURE: { FAIL() << "Use 'consumeCaptureEvent' for CAPTURE events"; } - case AINPUT_EVENT_TYPE_TOUCH_MODE: { + case InputEventType::TOUCH_MODE: { FAIL() << "Use 'consumeTouchModeEvent' for TOUCH_MODE events"; } - case AINPUT_EVENT_TYPE_DRAG: { + case InputEventType::DRAG: { FAIL() << "Use 'consumeDragEvent' for DRAG events"; } - default: { - FAIL() << mName.c_str() << ": invalid event type: " << expectedEventType; - } } } @@ -983,9 +984,8 @@ public: return nullptr; } - if (event->getType() != AINPUT_EVENT_TYPE_MOTION) { - ADD_FAILURE() << mName << " expected a MotionEvent, got " - << inputEventTypeToString(event->getType()) << " event"; + if (event->getType() != InputEventType::MOTION) { + ADD_FAILURE() << mName << " expected a MotionEvent, got " << *event; return nullptr; } return static_cast(event); @@ -1001,9 +1001,8 @@ public: InputEvent* event = consume(); ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; - ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType()) - << "Got " << inputEventTypeToString(event->getType()) - << " event instead of FOCUS event"; + ASSERT_EQ(InputEventType::FOCUS, event->getType()) + << "Instead of FocusEvent, got " << *event; ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; @@ -1016,9 +1015,8 @@ public: const InputEvent* event = consume(); ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; - ASSERT_EQ(AINPUT_EVENT_TYPE_CAPTURE, event->getType()) - << "Got " << inputEventTypeToString(event->getType()) - << " event instead of CAPTURE event"; + ASSERT_EQ(InputEventType::CAPTURE, event->getType()) + << "Instead of CaptureEvent, got " << *event; ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; @@ -1031,9 +1029,7 @@ public: const InputEvent* event = consume(); ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; - ASSERT_EQ(AINPUT_EVENT_TYPE_DRAG, event->getType()) - << "Got " << inputEventTypeToString(event->getType()) - << " event instead of DRAG event"; + ASSERT_EQ(InputEventType::DRAG, event->getType()) << "Instead of DragEvent, got " << *event; EXPECT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; @@ -1048,9 +1044,8 @@ public: const InputEvent* event = consume(); ASSERT_NE(nullptr, event) << mName.c_str() << ": consumer should have returned non-NULL event."; - ASSERT_EQ(AINPUT_EVENT_TYPE_TOUCH_MODE, event->getType()) - << "Got " << inputEventTypeToString(event->getType()) - << " event instead of TOUCH_MODE event"; + ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType()) + << "Instead of TouchModeEvent, got " << *event; ASSERT_EQ(ADISPLAY_ID_NONE, event->getDisplayId()) << mName.c_str() << ": event displayId should always be NONE."; @@ -1063,23 +1058,23 @@ public: if (event == nullptr) { return; } - if (event->getType() == AINPUT_EVENT_TYPE_KEY) { + if (event->getType() == InputEventType::KEY) { KeyEvent& keyEvent = static_cast(*event); ADD_FAILURE() << "Received key event " << KeyEvent::actionToString(keyEvent.getAction()); - } else if (event->getType() == AINPUT_EVENT_TYPE_MOTION) { + } else if (event->getType() == InputEventType::MOTION) { MotionEvent& motionEvent = static_cast(*event); ADD_FAILURE() << "Received motion event " << MotionEvent::actionToString(motionEvent.getAction()); - } else if (event->getType() == AINPUT_EVENT_TYPE_FOCUS) { + } else if (event->getType() == InputEventType::FOCUS) { FocusEvent& focusEvent = static_cast(*event); ADD_FAILURE() << "Received focus event, hasFocus = " << (focusEvent.getHasFocus() ? "true" : "false"); - } else if (event->getType() == AINPUT_EVENT_TYPE_CAPTURE) { + } else if (event->getType() == InputEventType::CAPTURE) { const auto& captureEvent = static_cast(*event); ADD_FAILURE() << "Received capture event, pointerCaptureEnabled = " << (captureEvent.getPointerCaptureEnabled() ? "true" : "false"); - } else if (event->getType() == AINPUT_EVENT_TYPE_TOUCH_MODE) { + } else if (event->getType() == InputEventType::TOUCH_MODE) { const auto& touchModeEvent = static_cast(*event); ADD_FAILURE() << "Received touch mode event, inTouchMode = " << (touchModeEvent.isInTouchMode() ? "true" : "false"); @@ -1239,12 +1234,11 @@ public: void setWindowOffset(float offsetX, float offsetY) { mInfo.transform.set(offsetX, offsetY); } void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, - expectedFlags); + consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags); } void consumeKeyUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, expectedDisplayId, expectedFlags); + consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, expectedDisplayId, expectedFlags); } void consumeMotionCancel(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, @@ -1266,7 +1260,7 @@ public: void consumeAnyMotionDown(std::optional expectedDisplayId = std::nullopt, std::optional expectedFlags = std::nullopt) { - consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId, + consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags); } @@ -1275,25 +1269,25 @@ public: int32_t expectedFlags = 0) { int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); - consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, expectedDisplayId, expectedFlags); + consumeEvent(InputEventType::MOTION, action, expectedDisplayId, expectedFlags); } void consumeMotionPointerUp(int32_t pointerIdx, int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { int32_t action = AMOTION_EVENT_ACTION_POINTER_UP | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); - consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, expectedDisplayId, expectedFlags); + consumeEvent(InputEventType::MOTION, action, expectedDisplayId, expectedFlags); } void consumeMotionUp(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { - consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId, + consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId, expectedFlags); } void consumeMotionOutside(int32_t expectedDisplayId = ADISPLAY_ID_DEFAULT, int32_t expectedFlags = 0) { - consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, expectedDisplayId, + consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE, expectedDisplayId, expectedFlags); } @@ -1301,7 +1295,7 @@ public: int32_t expectedFlags = 0) { InputEvent* event = consume(); ASSERT_NE(nullptr, event); - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()); + ASSERT_EQ(InputEventType::MOTION, event->getType()); const MotionEvent& motionEvent = static_cast(*event); EXPECT_EQ(AMOTION_EVENT_ACTION_OUTSIDE, motionEvent.getActionMasked()); EXPECT_EQ(0.f, motionEvent.getRawPointerCoords(0)->getX()); @@ -1326,7 +1320,7 @@ public: ASSERT_THAT(*motionEvent, matcher); } - void consumeEvent(int32_t expectedEventType, int32_t expectedAction, + void consumeEvent(InputEventType expectedEventType, int32_t expectedAction, std::optional expectedDisplayId, std::optional expectedFlags) { ASSERT_NE(mInputReceiver, nullptr) << "Invalid consume event on window with no receiver"; @@ -1375,9 +1369,8 @@ public: ADD_FAILURE() << "Consume failed : no event"; return nullptr; } - if (event->getType() != AINPUT_EVENT_TYPE_MOTION) { - ADD_FAILURE() << "Instead of motion event, got " - << inputEventTypeToString(event->getType()); + if (event->getType() != InputEventType::MOTION) { + ADD_FAILURE() << "Instead of motion event, got " << *event; return nullptr; } return static_cast(event); @@ -3678,7 +3671,7 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { // on the app side. NotifyDeviceResetArgs args(/*id=*/10, /*eventTime=*/20, DEVICE_ID); mDispatcher->notifyDeviceReset(&args); - window->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT, + window->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT, AKEY_EVENT_FLAG_CANCELED); } @@ -4752,8 +4745,8 @@ public: sp getToken() { return mInputReceiver->getToken(); } void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN, - expectedDisplayId, expectedFlags); + mInputReceiver->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, + expectedFlags); } std::optional receiveEvent() { return mInputReceiver->receiveEvent(); } @@ -4761,17 +4754,17 @@ public: void finishEvent(uint32_t consumeSeq) { return mInputReceiver->finishEvent(consumeSeq); } void consumeMotionDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, + mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId, expectedFlags); } void consumeMotionMove(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE, + mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, expectedDisplayId, expectedFlags); } void consumeMotionUp(int32_t expectedDisplayId, int32_t expectedFlags = 0) { - mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_UP, + mInputReceiver->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_UP, expectedDisplayId, expectedFlags); } @@ -4785,7 +4778,7 @@ public: void consumeMotionPointerDown(int32_t pointerIdx) { int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN | (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); - mInputReceiver->consumeEvent(AINPUT_EVENT_TYPE_MOTION, action, ADISPLAY_ID_DEFAULT, + mInputReceiver->consumeEvent(InputEventType::MOTION, action, ADISPLAY_ID_DEFAULT, /*expectedFlags=*/0); } @@ -4795,8 +4788,8 @@ public: ADD_FAILURE() << "No event was produced"; return nullptr; } - if (event->getType() != AINPUT_EVENT_TYPE_MOTION) { - ADD_FAILURE() << "Received event of type " << event->getType() << " instead of motion"; + if (event->getType() != InputEventType::MOTION) { + ADD_FAILURE() << "Expected MotionEvent, got " << *event; return nullptr; } return static_cast(event); @@ -4952,7 +4945,7 @@ TEST_F(InputDispatcherTest, TestMoveEvent) { motionArgs.pointerCoords[0].getX() - 10); mDispatcher->notifyMotion(&motionArgs); - window->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT, + window->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT, /*expectedFlags=*/0); } @@ -5423,8 +5416,7 @@ protected: InputEvent* repeatEvent = mWindow->consume(); ASSERT_NE(nullptr, repeatEvent); - uint32_t eventType = repeatEvent->getType(); - ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, eventType); + ASSERT_EQ(InputEventType::KEY, repeatEvent->getType()); KeyEvent* repeatKeyEvent = static_cast(repeatEvent); uint32_t eventAction = repeatKeyEvent->getAction(); @@ -5439,7 +5431,7 @@ protected: mDispatcher->notifyKey(&keyArgs); // Window should receive key down event. - mWindow->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT, + mWindow->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT, /*expectedFlags=*/0); } }; @@ -5612,7 +5604,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {}}}); // Old focus should receive a cancel event. - windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE, + windowInSecondary->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE, AKEY_EVENT_FLAG_CANCELED); // Test inject a key down, should timeout because of no target window. @@ -5883,7 +5875,7 @@ protected: InputEvent* received = mWindow->consume(); ASSERT_NE(nullptr, received); ASSERT_EQ(resolvedDeviceId, received->getDeviceId()); - ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_KEY); + ASSERT_EQ(received->getType(), InputEventType::KEY); KeyEvent& keyEvent = static_cast(*received); ASSERT_EQ(flags, keyEvent.getFlags()); } @@ -5918,7 +5910,7 @@ protected: InputEvent* received = mWindow->consume(); ASSERT_NE(nullptr, received); ASSERT_EQ(resolvedDeviceId, received->getDeviceId()); - ASSERT_EQ(received->getType(), AINPUT_EVENT_TYPE_MOTION); + ASSERT_EQ(received->getType(), InputEventType::MOTION); MotionEvent& motionEvent = static_cast(*received); ASSERT_EQ(flags, motionEvent.getFlags()); } @@ -6099,9 +6091,8 @@ protected: ASSERT_NE(nullptr, event) << name.c_str() << ": consumer should have returned non-NULL event."; - ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType()) - << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION) - << " event, got " << inputEventTypeToString(event->getType()) << " event"; + ASSERT_EQ(InputEventType::MOTION, event->getType()) + << name.c_str() << ": expected MotionEvent, got " << *event; const MotionEvent& motionEvent = static_cast(*event); assertMotionAction(expectedAction, motionEvent.getAction()); @@ -6798,7 +6789,7 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsive) { FOCUSED_WINDOW_LOCATION)) << "Inject motion event should return InputEventInjectionResult::SUCCEEDED"; mFocusedWindow->consumeMotionDown(); - mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, + mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE, ADISPLAY_ID_DEFAULT, /*flags=*/0); // We consumed all events, so no ANR ASSERT_TRUE(mDispatcher->waitForIdle()); @@ -6872,7 +6863,7 @@ TEST_F(InputDispatcherMultiWindowAnr, TwoWindows_BothUnresponsiveWithSameTimeout // At the same time, FLAG_WATCH_OUTSIDE_TOUCH targets should not receive any events. TEST_F(InputDispatcherMultiWindowAnr, DuringAnr_SecondTapIsIgnored) { tapOnFocusedWindow(); - mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, + mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE, ADISPLAY_ID_DEFAULT, /*flags=*/0); // Receive the events, but don't respond std::optional downEventSequenceNum = mFocusedWindow->receiveEvent(); // ACTION_DOWN @@ -7001,7 +6992,7 @@ TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) { generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, {FOCUSED_WINDOW_LOCATION}); mDispatcher->notifyMotion(&motionArgs); - mUnfocusedWindow->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_OUTSIDE, + mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE, ADISPLAY_ID_DEFAULT, /*flags=*/0); // Touch Window 2 @@ -7022,7 +7013,7 @@ TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) { ASSERT_TRUE(moveOrCancelSequenceNum); mFocusedWindow->finishEvent(*moveOrCancelSequenceNum); ASSERT_NE(nullptr, event); - ASSERT_EQ(event->getType(), AINPUT_EVENT_TYPE_MOTION); + ASSERT_EQ(event->getType(), InputEventType::MOTION); MotionEvent& motionEvent = static_cast(*event); if (motionEvent.getAction() == AMOTION_EVENT_ACTION_MOVE) { mFocusedWindow->consumeMotionCancel(); @@ -8234,7 +8225,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { .displayId(SECOND_DISPLAY_ID) .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100)) .build())); - windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, + windowInSecondary->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_DOWN, SECOND_DISPLAY_ID, /*expectedFlag=*/0); // Update window again. mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {windowInSecondary}}}); -- cgit v1.2.3-59-g8ed1b