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/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index 24efae8..daab636 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -240,14 +240,15 @@
mGestureConverter(*getContext(), deviceContext, getDeviceId()),
mCapturedEventConverter(*getContext(), deviceContext, mMotionAccumulator, getDeviceId()),
mMetricsId(metricsIdFromInputDeviceIdentifier(deviceContext.getDeviceIdentifier())) {
- RawAbsoluteAxisInfo slotAxisInfo;
- deviceContext.getAbsoluteAxisInfo(ABS_MT_SLOT, &slotAxisInfo);
- if (!slotAxisInfo.valid || slotAxisInfo.maxValue < 0) {
+ if (std::optional<RawAbsoluteAxisInfo> slotAxis =
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_SLOT);
+ slotAxis && slotAxis->maxValue >= 0) {
+ mMotionAccumulator.configure(deviceContext, slotAxis->maxValue + 1, true);
+ } else {
LOG(WARNING) << "Touchpad " << deviceContext.getName()
<< " doesn't have a valid ABS_MT_SLOT axis, and probably won't work properly.";
- slotAxisInfo.maxValue = 0;
+ mMotionAccumulator.configure(deviceContext, 1, true);
}
- mMotionAccumulator.configure(deviceContext, slotAxisInfo.maxValue + 1, true);
mGestureInterpreter->Initialize(GESTURES_DEVCLASS_TOUCHPAD);
mGestureInterpreter->SetHardwareProperties(createHardwareProperties(deviceContext));