InputDevice: return std::optional from getAbsoluteAxisInfo
This also allows us to remove the valid field from RawAbsoluteAxisInfo,
since we can represent "invalid" axes (which usually just meant absent
ones) using std::nullopt.
Test: atest inputflinger_tests
Test: m checkinput
Test: Check "Raw Touch Axes" section of touch input mapper info in
dumpsys input
Bug: 245989146
Flag: EXEMPT refactor
Change-Id: I045a2e0b61a84657f2f8171c1fee3cc3e331ac86
diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
index 140bb0c..869feb4 100644
--- a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
@@ -44,7 +44,7 @@
bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE &&
(mTouchButtonAccumulator.isHovering() ||
- (mRawPointerAxes.pressure.valid &&
+ (mRawPointerAxes.pressure &&
mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0));
outState->rawPointerData.markIdBit(0, isHovering);
@@ -72,13 +72,15 @@
void SingleTouchInputMapper::configureRawPointerAxes() {
TouchInputMapper::configureRawPointerAxes();
- getAbsoluteAxisInfo(ABS_X, &mRawPointerAxes.x);
- getAbsoluteAxisInfo(ABS_Y, &mRawPointerAxes.y);
- getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPointerAxes.pressure);
- getAbsoluteAxisInfo(ABS_TOOL_WIDTH, &mRawPointerAxes.toolMajor);
- getAbsoluteAxisInfo(ABS_DISTANCE, &mRawPointerAxes.distance);
- getAbsoluteAxisInfo(ABS_TILT_X, &mRawPointerAxes.tiltX);
- getAbsoluteAxisInfo(ABS_TILT_Y, &mRawPointerAxes.tiltY);
+ // We can safely assume that ABS_X and _Y axes will be available, as EventHub won't classify a
+ // device as a touch device if they're not present.
+ mRawPointerAxes.x = getAbsoluteAxisInfo(ABS_X).value();
+ mRawPointerAxes.y = getAbsoluteAxisInfo(ABS_Y).value();
+ mRawPointerAxes.pressure = getAbsoluteAxisInfo(ABS_PRESSURE);
+ mRawPointerAxes.toolMajor = getAbsoluteAxisInfo(ABS_TOOL_WIDTH);
+ mRawPointerAxes.distance = getAbsoluteAxisInfo(ABS_DISTANCE);
+ mRawPointerAxes.tiltX = getAbsoluteAxisInfo(ABS_TILT_X);
+ mRawPointerAxes.tiltY = getAbsoluteAxisInfo(ABS_TILT_Y);
}
bool SingleTouchInputMapper::hasStylus() const {