Prevent entries with identical times
Currently, VelocityTracker adds all MotionEvents with actions DOWN,
MOVE, and POINTER_DOWN. But sometimes these events can have identical
timestamps, for example MOVE and the following POINTER_DOWN.
This breaks algorithms that rely on computing differences between
times of the events. If the difference is zero, and division is
performed, then very large numbers can result from this.
Bug: 129797752
Test: atest libinput_tests
Change-Id: I843fd9efbdbf786ab7aa5ed62b4e1395ae7cf335
diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp
index 731665d..368446f 100644
--- a/libs/input/tests/VelocityTracker_test.cpp
+++ b/libs/input/tests/VelocityTracker_test.cpp
@@ -774,9 +774,8 @@
* Three fingers quickly tap the screen. Since this is a tap, the velocities should be zero.
* If the events with POINTER_UP or POINTER_DOWN are not handled correctly (these should not be
* part of the fitted data), this can cause large velocity values to be reported instead.
- * TODO(b/129797752) currently evaluates velocity to -159559.78125
*/
-TEST_F(VelocityTrackerTest, DISABLED_LeastSquaresVelocityTrackerStrategyEstimator_ThreeFingerTap) {
+TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_ThreeFingerTap) {
std::vector<MotionEventEntry> motions = {
{ 0us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} },
{ 10800us, {{1063, 1128}, {682, 1318}, {NAN, NAN}} }, // POINTER_DOWN
@@ -786,8 +785,10 @@
{ 272700us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} },
};
- computeAndCheckVelocity("lsq2", motions, AMOTION_EVENT_AXIS_X, 0);
- computeAndCheckVelocity("lsq2", motions, AMOTION_EVENT_AXIS_Y, 0);
+ // Velocity should actually be zero, but we expect 0.016 here instead.
+ // This is close enough to zero, and is likely caused by division by a very small number.
+ computeAndCheckVelocity("lsq2", motions, AMOTION_EVENT_AXIS_X, -0.016);
+ computeAndCheckVelocity("lsq2", motions, AMOTION_EVENT_AXIS_Y, -0.016);
computeAndCheckVelocity("impulse", motions, AMOTION_EVENT_AXIS_X, 0);
computeAndCheckVelocity("impulse", motions, AMOTION_EVENT_AXIS_Y, 0);
}