Add test to ensure values outside the abs axis range are accepted
Although it is not explicitly mentioned in the evdev protocol docs, it
may make sense to send values outside of the min and max range for
absolute axes in some cases. For example, a positional axis value
outside its range may indicate a touch point outside the min and max
range that maps to the touchscreen's display. For the pressure axis,
having a max may not make sense, as there is no theoretical maximum for
pressure, outside of what the sensor can detect.
We add a test to ensure that we accept these values that are outside of
their range reported in input_abs_info.
Bug: 295125932
Test: atest inputflinger_tests
Change-Id: Ifa88bec96dea92a44be82d2c761bd30f5c5d5123
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 1b19870..72fe2af 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -1829,6 +1829,38 @@
ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
}
+/**
+ * Some drivers historically have reported axis values outside of the range specified in the
+ * evdev axis info. Ensure we don't crash when this happens. For example, a driver may report a
+ * pressure value greater than the reported maximum, since it unclear what specific meaning the
+ * maximum value for pressure has (beyond the maximum value that can be produced by a sensor),
+ * and no units for pressure (resolution) is specified by the evdev documentation.
+ */
+TEST_P(TouchIntegrationTest, AcceptsAxisValuesOutsideReportedRange) {
+ const Point centerPoint = mDevice->getCenterPoint();
+
+ // Down with pressure outside the reported range
+ mDevice->sendSlot(FIRST_SLOT);
+ mDevice->sendTrackingId(FIRST_TRACKING_ID);
+ mDevice->sendDown(centerPoint);
+ mDevice->sendPressure(UinputTouchScreen::RAW_PRESSURE_MAX + 2);
+ mDevice->sendSync();
+ ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(
+ WithMotionAction(AMOTION_EVENT_ACTION_DOWN)));
+
+ // Move to a point outside the reported range
+ mDevice->sendMove(Point(DISPLAY_WIDTH, DISPLAY_HEIGHT) + Point(1, 1));
+ mDevice->sendSync();
+ ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(
+ WithMotionAction(AMOTION_EVENT_ACTION_MOVE)));
+
+ // Up
+ mDevice->sendUp();
+ mDevice->sendSync();
+ ASSERT_NO_FATAL_FAILURE(
+ mTestListener->assertNotifyMotionWasCalled(WithMotionAction(AMOTION_EVENT_ACTION_UP)));
+}
+
TEST_P(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) {
const Point centerPoint = mDevice->getCenterPoint();