diff options
author | 2024-07-16 15:42:56 +0000 | |
---|---|---|
committer | 2024-07-18 09:20:45 +0000 | |
commit | 71c6f73ada569787a7064af4ea2a4c01adb75a85 (patch) | |
tree | e47fc67150f1f48bd7f20c80d417898f3884b576 | |
parent | 41750190227be028706594a3e0544022b32b92b3 (diff) |
Update MotionEvent's id when a new sample is added.
Until now the MotionEvent's id was set during the "initialize" call, and it was equal to the first sample's eventId. We want to use the latest sample's eventId.
Bug: b/350907221
Test: atest libinput_tests inputflinger_tests
Flag: EXEMPT bugfix
Change-Id: I0d967e7fe644fc2b2c09d044c3ee8ed13276d787
-rw-r--r-- | include/input/Input.h | 4 | ||||
-rw-r--r-- | libs/input/Input.cpp | 8 | ||||
-rw-r--r-- | libs/input/InputConsumer.cpp | 4 | ||||
-rw-r--r-- | libs/input/InputConsumerNoResampling.cpp | 2 | ||||
-rw-r--r-- | libs/input/MotionPredictor.cpp | 2 | ||||
-rw-r--r-- | libs/input/tests/InputEvent_test.cpp | 20 | ||||
-rw-r--r-- | libs/input/tests/MotionPredictorMetricsManager_test.cpp | 3 |
7 files changed, 29 insertions, 14 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index 77d7448db3..1a3cb6a884 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -900,9 +900,7 @@ public: void splitFrom(const MotionEvent& other, std::bitset<MAX_POINTER_ID + 1> splitPointerIds, int32_t newEventId); - void addSample( - nsecs_t eventTime, - const PointerCoords* pointerCoords); + void addSample(nsecs_t eventTime, const PointerCoords* pointerCoords, int32_t eventId); void offsetLocation(float xOffset, float yOffset); diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index b09814797f..a2bb3453fe 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -580,7 +580,7 @@ void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, &pointerProperties[pointerCount]); mSampleEventTimes.clear(); mSamplePointerCoords.clear(); - addSample(eventTime, pointerCoords); + addSample(eventTime, pointerCoords, mId); } void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { @@ -640,9 +640,9 @@ void MotionEvent::splitFrom(const android::MotionEvent& other, mSampleEventTimes = other.mSampleEventTimes; } -void MotionEvent::addSample( - int64_t eventTime, - const PointerCoords* pointerCoords) { +void MotionEvent::addSample(int64_t eventTime, const PointerCoords* pointerCoords, + int32_t eventId) { + mId = eventId; mSampleEventTimes.push_back(eventTime); mSamplePointerCoords.insert(mSamplePointerCoords.end(), &pointerCoords[0], &pointerCoords[getPointerCount()]); diff --git a/libs/input/InputConsumer.cpp b/libs/input/InputConsumer.cpp index dce528f763..1eeb4e678c 100644 --- a/libs/input/InputConsumer.cpp +++ b/libs/input/InputConsumer.cpp @@ -135,7 +135,7 @@ void addSample(MotionEvent& event, const InputMessage& msg) { } event.setMetaState(event.getMetaState() | msg.body.motion.metaState); - event.addSample(msg.body.motion.eventTime, pointerCoords); + event.addSample(msg.body.motion.eventTime, pointerCoords, msg.body.motion.eventId); } void initializeTouchModeEvent(TouchModeEvent& event, const InputMessage& msg) { @@ -697,7 +697,7 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event, currentCoords.getY(), otherCoords.getX(), otherCoords.getY(), alpha); } - event->addSample(sampleTime, touchState.lastResample.pointers); + event->addSample(sampleTime, touchState.lastResample.pointers, event->getId()); } status_t InputConsumer::sendFinishedSignal(uint32_t seq, bool handled) { diff --git a/libs/input/InputConsumerNoResampling.cpp b/libs/input/InputConsumerNoResampling.cpp index da494b5ba3..c145d5c286 100644 --- a/libs/input/InputConsumerNoResampling.cpp +++ b/libs/input/InputConsumerNoResampling.cpp @@ -114,7 +114,7 @@ void addSample(MotionEvent& event, const InputMessage& msg) { // TODO(b/329770983): figure out if it's safe to combine events with mismatching metaState event.setMetaState(event.getMetaState() | msg.body.motion.metaState); - event.addSample(msg.body.motion.eventTime, pointerCoords.data()); + event.addSample(msg.body.motion.eventTime, pointerCoords.data(), msg.body.motion.eventId); } std::unique_ptr<TouchModeEvent> createTouchModeEvent(const InputMessage& msg) { diff --git a/libs/input/MotionPredictor.cpp b/libs/input/MotionPredictor.cpp index 9204b95745..9c70535ef5 100644 --- a/libs/input/MotionPredictor.cpp +++ b/libs/input/MotionPredictor.cpp @@ -345,7 +345,7 @@ std::unique_ptr<MotionEvent> MotionPredictor::predict(nsecs_t timestamp) { event.getRawTransform(), event.getDownTime(), predictionTime, event.getPointerCount(), event.getPointerProperties(), &coords); } else { - prediction->addSample(predictionTime, &coords); + prediction->addSample(predictionTime, &coords, prediction->getId()); } axisFrom = axisTo; diff --git a/libs/input/tests/InputEvent_test.cpp b/libs/input/tests/InputEvent_test.cpp index 3717f49fef..a67e1ef472 100644 --- a/libs/input/tests/InputEvent_test.cpp +++ b/libs/input/tests/InputEvent_test.cpp @@ -371,8 +371,8 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) { mTransform, 2.0f, 2.1f, AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, mRawTransform, ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME, 2, mPointerProperties, mSamples[0].pointerCoords); - event->addSample(ARBITRARY_EVENT_TIME + 1, mSamples[1].pointerCoords); - event->addSample(ARBITRARY_EVENT_TIME + 2, mSamples[2].pointerCoords); + event->addSample(ARBITRARY_EVENT_TIME + 1, mSamples[1].pointerCoords, event->getId()); + event->addSample(ARBITRARY_EVENT_TIME + 2, mSamples[2].pointerCoords, event->getId()); } void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) { @@ -591,6 +591,22 @@ TEST_F(MotionEventTest, CopyFrom_DoNotKeepHistory) { ASSERT_EQ(event.getX(0), copy.getX(0)); } +TEST_F(MotionEventTest, CheckEventIdWithHistoryIsIncremented) { + MotionEvent event; + constexpr int32_t ARBITRARY_ID = 42; + event.initialize(ARBITRARY_ID, 2, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, INVALID_HMAC, + AMOTION_EVENT_ACTION_MOVE, 0, 0, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, + AMOTION_EVENT_BUTTON_PRIMARY, MotionClassification::NONE, mTransform, 0, 0, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, + mRawTransform, ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME, 2, + mPointerProperties, mSamples[0].pointerCoords); + ASSERT_EQ(event.getId(), ARBITRARY_ID); + event.addSample(ARBITRARY_EVENT_TIME + 1, mSamples[1].pointerCoords, ARBITRARY_ID + 1); + ASSERT_EQ(event.getId(), ARBITRARY_ID + 1); + event.addSample(ARBITRARY_EVENT_TIME + 2, mSamples[2].pointerCoords, ARBITRARY_ID + 2); + ASSERT_EQ(event.getId(), ARBITRARY_ID + 2); +} + TEST_F(MotionEventTest, SplitPointerDown) { MotionEvent event = MotionEventBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN) .downTime(ARBITRARY_DOWN_TIME) diff --git a/libs/input/tests/MotionPredictorMetricsManager_test.cpp b/libs/input/tests/MotionPredictorMetricsManager_test.cpp index cc41eeb5e7..0542f39f6d 100644 --- a/libs/input/tests/MotionPredictorMetricsManager_test.cpp +++ b/libs/input/tests/MotionPredictorMetricsManager_test.cpp @@ -167,7 +167,8 @@ MotionEvent makeMotionEvent(const std::vector<PredictionPoint>& predictionPoints .y(predictionPoints[i].position[0]) .axis(AMOTION_EVENT_AXIS_PRESSURE, predictionPoints[i].pressure) .buildCoords(); - predictionEvent.addSample(predictionPoints[i].targetTimestamp, &coords); + predictionEvent.addSample(predictionPoints[i].targetTimestamp, &coords, + predictionEvent.getId()); } return predictionEvent; } |