diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-08-15 23:26:13 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-08-15 23:26:13 +0000 |
commit | 5bc5973ebb9497468412c670bdccad8f39db0b91 (patch) | |
tree | 50f15c5cdf30a987cefba9763c3cc6fa9b08fe30 | |
parent | d2908695c81d8738470e9c2340d03f58a502eba4 (diff) | |
parent | 1d1009201f3ee20dd2052b9334accf06398dbf8b (diff) | |
download | native-5bc5973ebb9497468412c670bdccad8f39db0b91.tar.gz |
Snap for 8948976 from 1d1009201f3ee20dd2052b9334accf06398dbf8b to tm-qpr1-release
Change-Id: Ib700db68e3f19cef34d1e844a94610a4cdaa845f
-rw-r--r-- | services/inputflinger/UnwantedInteractionBlocker.cpp | 26 | ||||
-rw-r--r-- | services/inputflinger/UnwantedInteractionBlocker.h | 2 | ||||
-rw-r--r-- | services/inputflinger/reader/InputDevice.cpp | 9 | ||||
-rw-r--r-- | services/inputflinger/reader/InputReader.cpp | 9 | ||||
-rw-r--r-- | services/inputflinger/tests/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/tests/TestInputListener.cpp | 7 | ||||
-rw-r--r-- | services/inputflinger/tests/TestInputListener.h | 3 | ||||
-rw-r--r-- | services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp | 65 |
8 files changed, 88 insertions, 34 deletions
diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp index 4e0f0c3bf5..1c27a52d2e 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.cpp +++ b/services/inputflinger/UnwantedInteractionBlocker.cpp @@ -99,17 +99,15 @@ static bool isPalmRejectionEnabled() { return false; } -static int getLinuxToolType(int32_t toolType) { - switch (toolType) { - case AMOTION_EVENT_TOOL_TYPE_FINGER: - return MT_TOOL_FINGER; - case AMOTION_EVENT_TOOL_TYPE_STYLUS: - return MT_TOOL_PEN; - case AMOTION_EVENT_TOOL_TYPE_PALM: - return MT_TOOL_PALM; +static int getLinuxToolCode(int toolType) { + if (toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS) { + return BTN_TOOL_PEN; } - ALOGW("Got tool type %" PRId32 ", converting to MT_TOOL_FINGER", toolType); - return MT_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) { @@ -562,7 +560,7 @@ std::vector<::ui::InProgressTouchEvdev> getTouches(const NotifyMotionArgs& args, touches.emplace_back(::ui::InProgressTouchEvdev()); touches.back().major = args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR); touches.back().minor = args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR); - touches.back().tool_type = getLinuxToolType(args.pointerProperties[i].toolType); + // The field 'tool_type' is not used for palm rejection // Whether there is new information for the touch. touches.back().altered = true; @@ -609,10 +607,10 @@ std::vector<::ui::InProgressTouchEvdev> getTouches(const NotifyMotionArgs& args, // The fields 'radius_x' and 'radius_x' are not used for palm rejection touches.back().pressure = args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE); - touches.back().tool_code = BTN_TOOL_FINGER; + touches.back().tool_code = getLinuxToolCode(args.pointerProperties[i].toolType); // The field 'orientation' is not used for palm rejection // The fields 'tilt_x' and 'tilt_y' are not used for palm rejection - touches.back().reported_tool_type = ::ui::EventPointerType::kTouch; + // The field 'reported_tool_type' is not used for palm rejection touches.back().stylus_button = false; } return touches; @@ -691,7 +689,7 @@ std::vector<NotifyMotionArgs> PalmRejector::processMotion(const NotifyMotionArgs return argsWithoutUnwantedPointers; } -const AndroidPalmFilterDeviceInfo& PalmRejector::getPalmFilterDeviceInfo() { +const AndroidPalmFilterDeviceInfo& PalmRejector::getPalmFilterDeviceInfo() const { return mDeviceInfo; } diff --git a/services/inputflinger/UnwantedInteractionBlocker.h b/services/inputflinger/UnwantedInteractionBlocker.h index 8ff965851f..1878849452 100644 --- a/services/inputflinger/UnwantedInteractionBlocker.h +++ b/services/inputflinger/UnwantedInteractionBlocker.h @@ -147,7 +147,7 @@ public: std::vector<NotifyMotionArgs> processMotion(const NotifyMotionArgs& args); // Get the device info of this device, for comparison purposes - const AndroidPalmFilterDeviceInfo& getPalmFilterDeviceInfo(); + const AndroidPalmFilterDeviceInfo& getPalmFilterDeviceInfo() const; std::string dump() const; private: diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index ba5083bec3..a0119986a6 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -110,7 +110,8 @@ void InputDevice::dump(std::string& dump, const std::string& eventHubDevStr) { dump += "<none>\n"; } dump += StringPrintf(INDENT2 "HasMic: %s\n", toString(mHasMic)); - dump += StringPrintf(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources()); + dump += StringPrintf(INDENT2 "Sources: %s\n", + inputEventSourceToString(deviceInfo.getSources()).c_str()); dump += StringPrintf(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType()); dump += StringPrintf(INDENT2 "ControllerNum: %d\n", deviceInfo.getControllerNumber()); @@ -128,10 +129,10 @@ void InputDevice::dump(std::string& dump, const std::string& eventHubDevStr) { snprintf(name, sizeof(name), "%d", range.axis); } dump += StringPrintf(INDENT3 - "%s: source=0x%08x, " + "%s: source=%s, " "min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f, resolution=%0.3f\n", - name, range.source, range.min, range.max, range.flat, range.fuzz, - range.resolution); + name, inputEventSourceToString(range.source).c_str(), range.min, + range.max, range.flat, range.fuzz, range.resolution); } } diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index 9c5a129213..9bcf463c36 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -196,9 +196,9 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { "(ignored non-input device)", device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str()); } else { - ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=0x%08x", + ALOGI("Device added: id=%d, eventHubId=%d, name='%s', descriptor='%s',sources=%s", device->getId(), eventHubId, identifier.name.c_str(), identifier.descriptor.c_str(), - device->getSources()); + inputEventSourceToString(device->getSources()).c_str()); } mDevices.emplace(eventHubId, device); @@ -250,9 +250,10 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { device->getId(), eventHubId, device->getName().c_str(), device->getDescriptor().c_str()); } else { - ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=0x%08x", + ALOGI("Device removed: id=%d, eventHubId=%d, name='%s', descriptor='%s', sources=%s", device->getId(), eventHubId, device->getName().c_str(), - device->getDescriptor().c_str(), device->getSources()); + device->getDescriptor().c_str(), + inputEventSourceToString(device->getSources()).c_str()); } device->removeEventHubDevice(eventHubId); diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index 76a7c19086..75cd9da782 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -60,6 +60,7 @@ cc_test { }, static_libs: [ "libc++fs", + "libgmock", ], require_root: true, test_suites: ["device-tests"], diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp index 6a26c636d9..57b382c718 100644 --- a/services/inputflinger/tests/TestInputListener.cpp +++ b/services/inputflinger/tests/TestInputListener.cpp @@ -69,6 +69,13 @@ void TestInputListener::assertNotifyMotionWasCalled(NotifyMotionArgs* outEventAr "Expected notifyMotion() to have been called.")); } +void TestInputListener::assertNotifyMotionWasCalled( + const ::testing::Matcher<NotifyMotionArgs>& matcher) { + NotifyMotionArgs outEventArgs; + ASSERT_NO_FATAL_FAILURE(assertNotifyMotionWasCalled(&outEventArgs)); + ASSERT_THAT(outEventArgs, matcher); +} + void TestInputListener::assertNotifyMotionWasNotCalled() { ASSERT_NO_FATAL_FAILURE( assertNotCalled<NotifyMotionArgs>("notifyMotion() should not be called.")); diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h index 626cdfc8c8..0bdfc6b9fb 100644 --- a/services/inputflinger/tests/TestInputListener.h +++ b/services/inputflinger/tests/TestInputListener.h @@ -18,6 +18,7 @@ #define _UI_TEST_INPUT_LISTENER_H #include <android-base/thread_annotations.h> +#include <gmock/gmock.h> #include <gtest/gtest.h> #include "InputListener.h" @@ -48,6 +49,8 @@ public: void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = nullptr); + void assertNotifyMotionWasCalled(const ::testing::Matcher<NotifyMotionArgs>& matcher); + void assertNotifyMotionWasNotCalled(); void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = nullptr); diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp index 8af387174a..9313a4500d 100644 --- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp +++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp @@ -16,13 +16,17 @@ #include "../UnwantedInteractionBlocker.h" #include <android-base/silent_death_test.h> +#include <gmock/gmock.h> #include <gtest/gtest.h> #include <gui/constants.h> #include <linux/input.h> #include <thread> +#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h" #include "TestInputListener.h" +using ::testing::AllOf; + namespace android { constexpr int32_t DEVICE_ID = 3; @@ -30,6 +34,8 @@ constexpr int32_t X_RESOLUTION = 11; constexpr int32_t Y_RESOLUTION = 11; constexpr int32_t MAJOR_RESOLUTION = 1; +const nsecs_t RESAMPLE_PERIOD = ::ui::kResamplePeriod.InNanoseconds(); + constexpr int POINTER_0_DOWN = AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); constexpr int POINTER_1_DOWN = @@ -47,6 +53,19 @@ constexpr int MOVE = AMOTION_EVENT_ACTION_MOVE; constexpr int UP = AMOTION_EVENT_ACTION_UP; constexpr int CANCEL = AMOTION_EVENT_ACTION_CANCEL; +constexpr int32_t FLAG_CANCELED = AMOTION_EVENT_FLAG_CANCELED; + +MATCHER_P(WithAction, action, "MotionEvent with specified action") { + bool result = true; + if (action == CANCEL) { + result &= (arg.flags & FLAG_CANCELED) != 0; + } + result &= arg.action == action; + *result_listener << "expected to receive " << MotionEvent::actionToString(action) + << " but received " << MotionEvent::actionToString(arg.action) << " instead."; + return result; +} + static nsecs_t toNs(std::chrono::nanoseconds duration) { return duration.count(); } @@ -256,7 +275,7 @@ TEST(CancelSuppressedPointersTest, NewlySuppressedPointerIsCanceled) { /*newSuppressedPointerIds*/ {1}); ASSERT_EQ(2u, result.size()); assertArgs(result[0], POINTER_1_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}, {2, {7, 8, 9}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); assertArgs(result[1], MOVE, {{0, {1, 2, 3}}, {2, {7, 8, 9}}}); } @@ -271,7 +290,7 @@ TEST(CancelSuppressedPointersTest, SingleSuppressedPointerIsCanceled) { /*newSuppressedPointerIds*/ {0}); ASSERT_EQ(1u, result.size()); assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); } /** @@ -286,7 +305,7 @@ TEST(CancelSuppressedPointersTest, SuppressedPointer1GoingUpIsCanceled) { /*newSuppressedPointerIds*/ {1}); ASSERT_EQ(1u, result.size()); assertArgs(result[0], POINTER_1_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}, {2, {7, 8, 9}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); } /** @@ -301,7 +320,7 @@ TEST(CancelSuppressedPointersTest, SuppressedPointer0GoingUpIsCanceled) { /*newSuppressedPointerIds*/ {0}); ASSERT_EQ(1u, result.size()); assertArgs(result[0], POINTER_0_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); } /** @@ -316,7 +335,7 @@ TEST(CancelSuppressedPointersTest, TwoNewlySuppressedPointersAreBothCanceled) { /*newSuppressedPointerIds*/ {0, 1}); ASSERT_EQ(1u, result.size()); assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}, {1, {4, 5, 6}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); } /** @@ -332,7 +351,7 @@ TEST(CancelSuppressedPointersTest, TwoPointersAreCanceledDuringPointerUp) { /*newSuppressedPointerIds*/ {0, 1}); ASSERT_EQ(1u, result.size()); assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}}); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, result[0].flags); + ASSERT_EQ(FLAG_CANCELED, result[0].flags); } /** @@ -573,6 +592,30 @@ TEST_F(UnwantedInteractionBlockerTest, DumpCanBeAccessedOnAnotherThread) { dumpThread.join(); } +/** + * Heuristic filter that's present in the palm rejection model blocks touches early if the size + * of the touch is large. This is an integration test that checks that this filter kicks in. + */ +TEST_F(UnwantedInteractionBlockerTest, HeuristicFilterWorks) { + mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()}); + // Small touch down + NotifyMotionArgs args1 = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}}); + mBlocker->notifyMotion(&args1); + mTestListener.assertNotifyMotionWasCalled(WithAction(DOWN)); + + // Large touch oval on the next move + NotifyMotionArgs args2 = + generateMotionArgs(0 /*downTime*/, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}}); + mBlocker->notifyMotion(&args2); + mTestListener.assertNotifyMotionWasCalled(WithAction(MOVE)); + + // Lift up the touch to force the model to decide on whether it's a palm + NotifyMotionArgs args3 = + generateMotionArgs(0 /*downTime*/, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}); + mBlocker->notifyMotion(&args3); + mTestListener.assertNotifyMotionWasCalled(WithAction(CANCEL)); +} + using UnwantedInteractionBlockerTestDeathTest = UnwantedInteractionBlockerTest; /** @@ -672,7 +715,7 @@ TEST_F(PalmRejectorTest, TwoPointersAreCanceled) { {{1433.0, 751.0, 44.0}, {1070.0, 771.0, 13.0}})); ASSERT_EQ(2u, argsList.size()); ASSERT_EQ(POINTER_0_UP, argsList[0].action); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, argsList[0].flags); + ASSERT_EQ(FLAG_CANCELED, argsList[0].flags); ASSERT_EQ(MOVE, argsList[1].action); ASSERT_EQ(1u, argsList[1].pointerCount); ASSERT_EQ(0, argsList[1].flags); @@ -849,7 +892,7 @@ TEST_F(PalmRejectorFakeFilterTest, OneOfTwoPointersIsCanceled) { ASSERT_EQ(2u, argsList.size()); // First event - cancel pointer 1 ASSERT_EQ(POINTER_1_UP, argsList[0].action); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, argsList[0].flags); + ASSERT_EQ(FLAG_CANCELED, argsList[0].flags); // Second event - send MOVE for the remaining pointer ASSERT_EQ(MOVE, argsList[1].action); ASSERT_EQ(0, argsList[1].flags); @@ -890,7 +933,7 @@ TEST_F(PalmRejectorFakeFilterTest, NewDownEventAfterCancel) { // Cancel all ASSERT_EQ(CANCEL, argsList[0].action); ASSERT_EQ(2u, argsList[0].pointerCount); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, argsList[0].flags); + ASSERT_EQ(FLAG_CANCELED, argsList[0].flags); // Future move events are ignored argsList = mPalmRejector->processMotion( @@ -936,7 +979,7 @@ TEST_F(PalmRejectorFakeFilterTest, TwoPointersCanceledWhenOnePointerGoesUp) { {{1414.0, 702.0, 41.0}, {1059.0, 731.0, 12.0}})); ASSERT_EQ(1u, argsList.size()); ASSERT_EQ(CANCEL, argsList[0].action) << MotionEvent::actionToString(argsList[0].action); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, argsList[0].flags); + ASSERT_EQ(FLAG_CANCELED, argsList[0].flags); // Future move events should not go to the listener. argsList = mPalmRejector->processMotion( @@ -970,7 +1013,7 @@ TEST_F(PalmRejectorFakeFilterTest, CancelTwoPointers) { {{1417.0, 685.0, 41.0}, {1060, 700, 10.0}})); ASSERT_EQ(2u, argsList.size()); ASSERT_EQ(POINTER_1_UP, argsList[0].action); - ASSERT_EQ(AMOTION_EVENT_FLAG_CANCELED, argsList[0].flags); + ASSERT_EQ(FLAG_CANCELED, argsList[0].flags); ASSERT_EQ(MOVE, argsList[1].action) << MotionEvent::actionToString(argsList[1].action); ASSERT_EQ(0, argsList[1].flags); |