diff options
4 files changed, 31 insertions, 188 deletions
diff --git a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp index dd46bbc543..c8e7790c86 100644 --- a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp +++ b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp @@ -20,19 +20,14 @@ #include <sstream> #include <android-base/stringprintf.h> -#include <com_android_input_flags.h> #include <input/PrintTools.h> #include <linux/input-event-codes.h> #include <log/log_main.h> -namespace input_flags = com::android::input::flags; - namespace android { namespace { -static constexpr uint32_t SOURCE = AINPUT_SOURCE_TOUCHPAD; - int32_t actionWithIndex(int32_t action, int32_t index) { return action | (index << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); } @@ -48,12 +43,6 @@ size_t firstUnmarkedBit(T set) { return i; } -void addRawMotionRange(InputDeviceInfo& deviceInfo, int32_t androidAxis, - RawAbsoluteAxisInfo& evdevAxis) { - deviceInfo.addMotionRange(androidAxis, SOURCE, evdevAxis.minValue, evdevAxis.maxValue, - evdevAxis.flat, evdevAxis.fuzz, evdevAxis.resolution); -} - } // namespace CapturedTouchpadEventConverter::CapturedTouchpadEventConverter( @@ -119,15 +108,8 @@ std::string CapturedTouchpadEventConverter::dump() const { } void CapturedTouchpadEventConverter::populateMotionRanges(InputDeviceInfo& info) const { - if (input_flags::include_relative_axis_values_for_captured_touchpads()) { - tryAddRawMotionRangeWithRelative(/*byref*/ info, AMOTION_EVENT_AXIS_X, - AMOTION_EVENT_AXIS_RELATIVE_X, ABS_MT_POSITION_X); - tryAddRawMotionRangeWithRelative(/*byref*/ info, AMOTION_EVENT_AXIS_Y, - AMOTION_EVENT_AXIS_RELATIVE_Y, ABS_MT_POSITION_Y); - } else { - tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_X, ABS_MT_POSITION_X); - tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_Y, ABS_MT_POSITION_Y); - } + tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_X, ABS_MT_POSITION_X); + tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_Y, ABS_MT_POSITION_Y); tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_TOUCH_MAJOR, ABS_MT_TOUCH_MAJOR); tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_TOUCH_MINOR, ABS_MT_TOUCH_MINOR); tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_TOOL_MAJOR, ABS_MT_WIDTH_MAJOR); @@ -153,23 +135,8 @@ void CapturedTouchpadEventConverter::tryAddRawMotionRange(InputDeviceInfo& devic int32_t evdevAxis) const { std::optional<RawAbsoluteAxisInfo> info = mDeviceContext.getAbsoluteAxisInfo(evdevAxis); if (info) { - addRawMotionRange(/*byref*/ deviceInfo, androidAxis, *info); - } -} - -void CapturedTouchpadEventConverter::tryAddRawMotionRangeWithRelative(InputDeviceInfo& deviceInfo, - int32_t androidAxis, - int32_t androidRelativeAxis, - int32_t evdevAxis) const { - std::optional<RawAbsoluteAxisInfo> axisInfo = mDeviceContext.getAbsoluteAxisInfo(evdevAxis); - if (axisInfo) { - addRawMotionRange(/*byref*/ deviceInfo, androidAxis, *axisInfo); - - // The largest movement we could possibly report on a relative axis is from the minimum to - // the maximum (or vice versa) of the absolute axis. - float range = axisInfo->maxValue - axisInfo->minValue; - deviceInfo.addMotionRange(androidRelativeAxis, SOURCE, -range, range, axisInfo->flat, - axisInfo->fuzz, axisInfo->resolution); + deviceInfo.addMotionRange(androidAxis, SOURCE, info->minValue, info->maxValue, info->flat, + info->fuzz, info->resolution); } } @@ -196,7 +163,7 @@ std::list<NotifyArgs> CapturedTouchpadEventConverter::sync(nsecs_t when, nsecs_t std::list<NotifyArgs> out; std::vector<PointerCoords> coords; std::vector<PointerProperties> properties; - std::map<size_t /*slotNumber*/, size_t /*coordsIndex*/> coordsIndexForSlotNumber; + std::map<size_t, size_t> coordsIndexForSlotNumber; // For all the touches that were already down, send a MOVE event with their updated coordinates. // A convention of the MotionEvent API is that pointer coordinates in UP events match the @@ -208,19 +175,11 @@ std::list<NotifyArgs> CapturedTouchpadEventConverter::sync(nsecs_t when, nsecs_t // to stay perfectly still between frames, and if it does the worst that can happen is // an extra MOVE event, so it's not worth the overhead of checking for changes. coordsIndexForSlotNumber[slotNumber] = coords.size(); - coords.push_back(makePointerCoordsForSlot(slotNumber)); + coords.push_back(makePointerCoordsForSlot(mMotionAccumulator.getSlot(slotNumber))); properties.push_back({.id = pointerId, .toolType = ToolType::FINGER}); } out.push_back( makeMotionArgs(when, readTime, AMOTION_EVENT_ACTION_MOVE, coords, properties)); - if (input_flags::include_relative_axis_values_for_captured_touchpads()) { - // For any further events we send from this sync, the pointers won't have moved relative - // to the positions we just reported in this MOVE event, so zero out the relative axes. - for (PointerCoords& pointer : coords) { - pointer.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, 0); - pointer.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, 0); - } - } } std::vector<size_t> upSlots, downSlots; @@ -275,9 +234,6 @@ std::list<NotifyArgs> CapturedTouchpadEventConverter::sync(nsecs_t when, nsecs_t /*flags=*/cancel ? AMOTION_EVENT_FLAG_CANCELED : 0)); freePointerIdForSlot(slotNumber); - if (input_flags::include_relative_axis_values_for_captured_touchpads()) { - mPreviousCoordsForSlotNumber.erase(slotNumber); - } coords.erase(coords.begin() + indexToRemove); properties.erase(properties.begin() + indexToRemove); // Now that we've removed some coords and properties, we might have to update the slot @@ -298,7 +254,7 @@ std::list<NotifyArgs> CapturedTouchpadEventConverter::sync(nsecs_t when, nsecs_t : actionWithIndex(AMOTION_EVENT_ACTION_POINTER_DOWN, coordsIndex); coordsIndexForSlotNumber[slotNumber] = coordsIndex; - coords.push_back(makePointerCoordsForSlot(slotNumber)); + coords.push_back(makePointerCoordsForSlot(mMotionAccumulator.getSlot(slotNumber))); properties.push_back( {.id = allocatePointerIdToSlot(slotNumber), .toolType = ToolType::FINGER}); @@ -330,22 +286,12 @@ NotifyMotionArgs CapturedTouchpadEventConverter::makeMotionArgs( AMOTION_EVENT_INVALID_CURSOR_POSITION, mDownTime, /*videoFrames=*/{}); } -PointerCoords CapturedTouchpadEventConverter::makePointerCoordsForSlot(size_t slotNumber) { - const MultiTouchMotionAccumulator::Slot& slot = mMotionAccumulator.getSlot(slotNumber); +PointerCoords CapturedTouchpadEventConverter::makePointerCoordsForSlot( + const MultiTouchMotionAccumulator::Slot& slot) const { PointerCoords coords; coords.clear(); coords.setAxisValue(AMOTION_EVENT_AXIS_X, slot.getX()); coords.setAxisValue(AMOTION_EVENT_AXIS_Y, slot.getY()); - if (input_flags::include_relative_axis_values_for_captured_touchpads()) { - if (auto it = mPreviousCoordsForSlotNumber.find(slotNumber); - it != mPreviousCoordsForSlotNumber.end()) { - auto [oldX, oldY] = it->second; - coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, slot.getX() - oldX); - coords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, slot.getY() - oldY); - } - mPreviousCoordsForSlotNumber[slotNumber] = std::make_pair(slot.getX(), slot.getY()); - } - coords.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, slot.getTouchMajor()); coords.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, slot.getTouchMinor()); coords.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, slot.getToolMajor()); diff --git a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.h b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.h index d6c0708f4a..9b6df7a222 100644 --- a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.h +++ b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.h @@ -21,7 +21,6 @@ #include <map> #include <set> #include <string> -#include <utility> #include <vector> #include <android/input.h> @@ -50,14 +49,12 @@ public: private: void tryAddRawMotionRange(InputDeviceInfo& deviceInfo, int32_t androidAxis, int32_t evdevAxis) const; - void tryAddRawMotionRangeWithRelative(InputDeviceInfo& deviceInfo, int32_t androidAxis, - int32_t androidRelativeAxis, int32_t evdevAxis) const; [[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when, nsecs_t readTime); [[nodiscard]] NotifyMotionArgs makeMotionArgs(nsecs_t when, nsecs_t readTime, int32_t action, const std::vector<PointerCoords>& coords, const std::vector<PointerProperties>& properties, int32_t actionButton = 0, int32_t flags = 0); - PointerCoords makePointerCoordsForSlot(size_t slotNumber); + PointerCoords makePointerCoordsForSlot(const MultiTouchMotionAccumulator::Slot& slot) const; int32_t allocatePointerIdToSlot(size_t slotNumber); void freePointerIdForSlot(size_t slotNumber); @@ -79,7 +76,8 @@ private: std::bitset<MAX_POINTER_ID + 1> mPointerIdsInUse; std::map<size_t, int32_t> mPointerIdForSlotNumber; - std::map<size_t, std::pair<float, float>> mPreviousCoordsForSlotNumber; + + static constexpr uint32_t SOURCE = AINPUT_SOURCE_TOUCHPAD; }; } // namespace android diff --git a/services/inputflinger/tests/CapturedTouchpadEventConverter_test.cpp b/services/inputflinger/tests/CapturedTouchpadEventConverter_test.cpp index d39ad3fd1e..f20c43c523 100644 --- a/services/inputflinger/tests/CapturedTouchpadEventConverter_test.cpp +++ b/services/inputflinger/tests/CapturedTouchpadEventConverter_test.cpp @@ -20,7 +20,6 @@ #include <memory> #include <EventHub.h> -#include <com_android_input_flags.h> #include <gtest/gtest.h> #include <linux/input-event-codes.h> #include <linux/input.h> @@ -33,8 +32,6 @@ #include "TestEventMatchers.h" #include "TestInputListener.h" -namespace input_flags = com::android::input::flags; - namespace android { using testing::AllOf; @@ -50,8 +47,6 @@ public: mReader(mFakeEventHub, mFakePolicy, mFakeListener), mDevice(newDevice()), mDeviceContext(*mDevice, EVENTHUB_ID) { - input_flags::include_relative_axis_values_for_captured_touchpads(true); - const size_t slotCount = 8; mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_SLOT, 0, slotCount - 1, 0, 0, 0); mAccumulator.configure(mDeviceContext, slotCount, /*usingSlotsProtocol=*/true); @@ -131,7 +126,7 @@ protected: TEST_F(CapturedTouchpadEventConverterTest, MotionRanges_allAxesPresent_populatedCorrectly) { mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, 0, 4000, 0, 0, 45); - mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 2000, 0, 0, 40); + mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, 0, 2500, 0, 0, 40); mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_TOUCH_MAJOR, 0, 1100, 0, 0, 35); mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_TOUCH_MINOR, 0, 1000, 0, 0, 30); mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_WIDTH_MAJOR, 0, 900, 0, 0, 25); @@ -155,8 +150,8 @@ TEST_F(CapturedTouchpadEventConverterTest, MotionRanges_allAxesPresent_populated const InputDeviceInfo::MotionRange* posY = info.getMotionRange(AMOTION_EVENT_AXIS_Y, AINPUT_SOURCE_TOUCHPAD); ASSERT_NE(nullptr, posY); - EXPECT_NEAR(-500, posY->min, EPSILON); - EXPECT_NEAR(2000, posY->max, EPSILON); + EXPECT_NEAR(0, posY->min, EPSILON); + EXPECT_NEAR(2500, posY->max, EPSILON); EXPECT_NEAR(40, posY->resolution, EPSILON); const InputDeviceInfo::MotionRange* touchMajor = @@ -187,22 +182,8 @@ TEST_F(CapturedTouchpadEventConverterTest, MotionRanges_allAxesPresent_populated EXPECT_NEAR(800, toolMinor->max, EPSILON); EXPECT_NEAR(20, toolMinor->resolution, EPSILON); - // ...except for the relative motion axes, derived from the corresponding absolute ones: - const InputDeviceInfo::MotionRange* relX = - info.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_X, AINPUT_SOURCE_TOUCHPAD); - ASSERT_NE(nullptr, relX); - EXPECT_NEAR(-4000, relX->min, EPSILON); - EXPECT_NEAR(4000, relX->max, EPSILON); - EXPECT_NEAR(45, relX->resolution, EPSILON); - - const InputDeviceInfo::MotionRange* relY = - info.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_Y, AINPUT_SOURCE_TOUCHPAD); - ASSERT_NE(nullptr, relY); - EXPECT_NEAR(-2500, relY->min, EPSILON); - EXPECT_NEAR(2500, relY->max, EPSILON); - EXPECT_NEAR(40, relY->resolution, EPSILON); - - // ...orientation and pressure, which get scaled: + // ...except orientation and pressure, which get scaled, and size, which is generated from other + // values. const InputDeviceInfo::MotionRange* orientation = info.getMotionRange(AMOTION_EVENT_AXIS_ORIENTATION, AINPUT_SOURCE_TOUCHPAD); ASSERT_NE(nullptr, orientation); @@ -217,7 +198,6 @@ TEST_F(CapturedTouchpadEventConverterTest, MotionRanges_allAxesPresent_populated EXPECT_NEAR(1, pressure->max, EPSILON); EXPECT_NEAR(0, pressure->resolution, EPSILON); - // ... and size, which is generated from other values. const InputDeviceInfo::MotionRange* size = info.getMotionRange(AMOTION_EVENT_AXIS_SIZE, AINPUT_SOURCE_TOUCHPAD); ASSERT_NE(nullptr, size); @@ -239,9 +219,7 @@ TEST_F(CapturedTouchpadEventConverterTest, MotionRanges_bareMinimumAxesPresent_p // present, since it's generated from axes that aren't provided by this device). EXPECT_NE(nullptr, info.getMotionRange(AMOTION_EVENT_AXIS_X, AINPUT_SOURCE_TOUCHPAD)); EXPECT_NE(nullptr, info.getMotionRange(AMOTION_EVENT_AXIS_Y, AINPUT_SOURCE_TOUCHPAD)); - EXPECT_NE(nullptr, info.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_X, AINPUT_SOURCE_TOUCHPAD)); - EXPECT_NE(nullptr, info.getMotionRange(AMOTION_EVENT_AXIS_RELATIVE_Y, AINPUT_SOURCE_TOUCHPAD)); - EXPECT_EQ(4u, info.getMotionRanges().size()); + EXPECT_EQ(2u, info.getMotionRanges().size()); } TEST_F(CapturedTouchpadEventConverterTest, OneFinger_motionReportedCorrectly) { @@ -257,16 +235,14 @@ TEST_F(CapturedTouchpadEventConverterTest, OneFinger_motionReportedCorrectly) { EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithPointerCount(1u), - WithCoords(50, 100), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER))); + WithCoords(50, 100), WithToolType(ToolType::FINGER))); processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 52); processAxis(conv, EV_ABS, ABS_MT_POSITION_Y, 99); EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithPointerCount(1u), - WithCoords(52, 99), WithRelativeMotion(2, -1), - WithToolType(ToolType::FINGER))); + WithCoords(52, 99), WithToolType(ToolType::FINGER))); processAxis(conv, EV_ABS, ABS_MT_TRACKING_ID, -1); processAxis(conv, EV_KEY, BTN_TOUCH, 0); @@ -279,9 +255,8 @@ TEST_F(CapturedTouchpadEventConverterTest, OneFinger_motionReportedCorrectly) { VariantWith<NotifyMotionArgs>( WithMotionAction(AMOTION_EVENT_ACTION_UP)))); EXPECT_THAT(args, - Each(VariantWith<NotifyMotionArgs>( - AllOf(WithCoords(52, 99), WithRelativeMotion(0, 0), WithPointerCount(1u), - WithToolType(ToolType::FINGER))))); + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(52, 99), WithPointerCount(1u), + WithToolType(ToolType::FINGER))))); } TEST_F(CapturedTouchpadEventConverterTest, OneFinger_touchDimensionsPassedThrough) { @@ -532,13 +507,13 @@ TEST_F(CapturedTouchpadEventConverterTest, PalmTurningIntoFinger_reported) { EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithPointerCount(1u), - WithCoords(51, 100), WithRelativeMotion(0, 0))); + WithCoords(51, 100))); processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 52); EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithPointerCount(1u), - WithCoords(52, 100), WithRelativeMotion(1, 0))); + WithCoords(52, 100))); } TEST_F(CapturedTouchpadEventConverterTest, FingerArrivingAfterPalm_onlyFingerReported) { @@ -578,7 +553,7 @@ TEST_F(CapturedTouchpadEventConverterTest, FingerArrivingAfterPalm_onlyFingerRep EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithPointerCount(1u), - WithCoords(98, 148), WithRelativeMotion(-2, -2))); + WithCoords(98, 148))); } TEST_F(CapturedTouchpadEventConverterTest, FingerAndFingerTurningIntoPalm_partiallyCancelled) { @@ -685,8 +660,7 @@ TEST_F(CapturedTouchpadEventConverterTest, TwoFingers_motionReportedCorrectly) { EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithPointerCount(1u), - WithCoords(50, 100), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER))); + WithCoords(50, 100), WithToolType(ToolType::FINGER))); processAxis(conv, EV_ABS, ABS_MT_SLOT, 0); processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 52); @@ -704,16 +678,13 @@ TEST_F(CapturedTouchpadEventConverterTest, TwoFingers_motionReportedCorrectly) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithPointerCount(1u), WithCoords(52, 99), - WithRelativeMotion(2, -1), WithToolType(ToolType::FINGER))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithPointerCount(2u), WithPointerCoords(0, 52, 99), - WithPointerRelativeMotion(0, 0, 0), WithPointerCoords(1, 250, 200), - WithPointerRelativeMotion(1, 0, 0), WithPointerToolType(0, ToolType::FINGER), WithPointerToolType(1, ToolType::FINGER))))); @@ -729,17 +700,14 @@ TEST_F(CapturedTouchpadEventConverterTest, TwoFingers_motionReportedCorrectly) { std::list<NotifyArgs> args = processSync(conv); EXPECT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithPointerRelativeMotion(1, 5, 2))), - VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction( - AMOTION_EVENT_ACTION_POINTER_UP | - 0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithPointerRelativeMotion(1, 0, 0))))); + WithMotionAction(AMOTION_EVENT_ACTION_MOVE)), + VariantWith<NotifyMotionArgs>(WithMotionAction( + AMOTION_EVENT_ACTION_POINTER_UP | + 0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)))); EXPECT_THAT(args, Each(VariantWith<NotifyMotionArgs>( AllOf(WithPointerCount(2u), WithPointerCoords(0, 52, 99), - WithPointerRelativeMotion(0, 0, 0), WithPointerCoords(1, 255, 202), + WithPointerCoords(1, 255, 202), WithPointerToolType(1, ToolType::FINGER), WithPointerToolType(0, ToolType::FINGER))))); @@ -755,69 +723,9 @@ TEST_F(CapturedTouchpadEventConverterTest, TwoFingers_motionReportedCorrectly) { WithMotionAction(AMOTION_EVENT_ACTION_UP)))); EXPECT_THAT(args, Each(VariantWith<NotifyMotionArgs>(AllOf(WithPointerCount(1u), WithCoords(255, 202), - WithPointerRelativeMotion(1, 0, 0), WithToolType(ToolType::FINGER))))); } -TEST_F(CapturedTouchpadEventConverterTest, RelativeMotionAxesClearedForNewFingerInSlot) { - CapturedTouchpadEventConverter conv = createConverter(); - // Put down one finger. - processAxis(conv, EV_ABS, ABS_MT_SLOT, 0); - processAxis(conv, EV_ABS, ABS_MT_TRACKING_ID, 1); - processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 50); - processAxis(conv, EV_ABS, ABS_MT_POSITION_Y, 100); - - processAxis(conv, EV_KEY, BTN_TOUCH, 1); - processAxis(conv, EV_KEY, BTN_TOOL_FINGER, 1); - - EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithPointerCount(1u), - WithCoords(50, 100), WithRelativeMotion(0, 0))); - - // Move it in negative X and Y directions. - processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 47); - processAxis(conv, EV_ABS, ABS_MT_POSITION_Y, 97); - - EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(47, 97), - WithRelativeMotion(-3, -3))); - - // Lift it. - processAxis(conv, EV_ABS, ABS_MT_TRACKING_ID, -1); - processAxis(conv, EV_KEY, BTN_TOUCH, 0); - processAxis(conv, EV_KEY, BTN_TOOL_FINGER, 0); - - std::list<NotifyArgs> args = processSync(conv); - EXPECT_THAT(args, - ElementsAre(VariantWith<NotifyMotionArgs>( - WithMotionAction(AMOTION_EVENT_ACTION_MOVE)), - VariantWith<NotifyMotionArgs>( - WithMotionAction(AMOTION_EVENT_ACTION_UP)))); - EXPECT_THAT(args, - Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(47, 97), - WithRelativeMotion(0, 0), - WithPointerCount(1u))))); - - // Put down another finger using the same slot. Relative axis values should be cleared. - processAxis(conv, EV_ABS, ABS_MT_TRACKING_ID, 2); - processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 60); - processAxis(conv, EV_ABS, ABS_MT_POSITION_Y, 60); - - processAxis(conv, EV_KEY, BTN_TOUCH, 1); - processAxis(conv, EV_KEY, BTN_TOOL_FINGER, 1); - - EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithPointerCount(1u), - WithCoords(60, 60), WithRelativeMotion(0, 0))); - - processAxis(conv, EV_ABS, ABS_MT_POSITION_X, 64); - processAxis(conv, EV_ABS, ABS_MT_POSITION_Y, 58); - - EXPECT_THAT(processSyncAndExpectSingleMotionArg(conv), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithPointerCount(1u), - WithCoords(64, 58), WithRelativeMotion(4, -2))); -} - // Pointer IDs max out at 31, and so must be reused once a touch is lifted to avoid running out. TEST_F(CapturedTouchpadEventConverterTest, PointerIdsReusedAfterLift) { CapturedTouchpadEventConverter conv = createConverter(); diff --git a/services/inputflinger/tests/TestEventMatchers.h b/services/inputflinger/tests/TestEventMatchers.h index f3be04115a..cfedc6eb1a 100644 --- a/services/inputflinger/tests/TestEventMatchers.h +++ b/services/inputflinger/tests/TestEventMatchers.h @@ -654,15 +654,6 @@ MATCHER_P2(WithRelativeMotion, x, y, "InputEvent with specified relative motion" return argX == x && argY == y; } -MATCHER_P3(WithPointerRelativeMotion, pointer, x, y, - "InputEvent with specified relative motion for pointer") { - const auto argX = arg.pointerCoords[pointer].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X); - const auto argY = arg.pointerCoords[pointer].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y); - *result_listener << "expected pointer " << pointer << " to have relative motion (" << x << ", " - << y << "), but got (" << argX << ", " << argY << ")"; - 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); |