Ensure deviceTimestamp is cleared
Add native test to ensure that deviceTimestamp field
is cleared.
Bug: 62940136
Test: m -j inputflinger_tests_InputReader_test
inputflinger_tests_InputDispatcher_test && adb push
out/target/product/$TARGET_PRODUCT/data/nativetest64/*
/data/nativetest64/
(adb shell mkdir /data/nativetest64 if needed)
on device: /data/nativetest64/inputflinger_tests # ./InputReader_test
Change-Id: Id70f07b143c22fc337fa94b264bc7fafa3f8d3fd
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 0a961cb..22f15a0 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -5911,5 +5911,38 @@
ASSERT_EQ(1000U, args.deviceTimestamp);
}
+TEST_F(MultiTouchInputMapperTest, WhenMapperIsReset_TimestampIsCleared) {
+ MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+
+ addConfigurationProperty("touch.deviceType", "touchScreen");
+ prepareDisplay(DISPLAY_ORIENTATION_0);
+ prepareAxes(POSITION);
+ addMapperAndConfigure(mapper);
+ NotifyMotionArgs args;
+
+ // Send a touch event with a timestamp
+ processPosition(mapper, 100, 100);
+ processTimestamp(mapper, 1);
+ processMTSync(mapper);
+ processSync(mapper);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+ ASSERT_EQ(1U, args.deviceTimestamp);
+
+ // Since the data accumulates, and new timestamp has not arrived, deviceTimestamp won't change
+ processPosition(mapper, 100, 200);
+ processMTSync(mapper);
+ processSync(mapper);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+ ASSERT_EQ(1U, args.deviceTimestamp);
+
+ mapper->reset(/* when */ 0);
+ // After the mapper is reset, deviceTimestamp should become zero again
+ processPosition(mapper, 100, 300);
+ processMTSync(mapper);
+ processSync(mapper);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+ ASSERT_EQ(0U, args.deviceTimestamp);
+}
+
} // namespace android