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/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
index 3af1d04..7cc8940 100644
--- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
@@ -33,7 +33,7 @@
void ExternalStylusInputMapper::populateDeviceInfo(InputDeviceInfo& info) {
InputMapper::populateDeviceInfo(info);
- if (mRawPressureAxis.valid) {
+ if (mRawPressureAxis) {
info.addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, AINPUT_SOURCE_STYLUS, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f);
}
@@ -50,7 +50,7 @@
std::list<NotifyArgs> ExternalStylusInputMapper::reconfigure(nsecs_t when,
const InputReaderConfiguration& config,
ConfigurationChanges changes) {
- getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPressureAxis);
+ mRawPressureAxis = getAbsoluteAxisInfo(ABS_PRESSURE);
mTouchButtonAccumulator.configure();
return {};
}
@@ -82,10 +82,10 @@
mStylusState.toolType = ToolType::STYLUS;
}
- if (mRawPressureAxis.valid) {
+ if (mRawPressureAxis) {
auto rawPressure = static_cast<float>(mSingleTouchMotionAccumulator.getAbsolutePressure());
- mStylusState.pressure = (rawPressure - mRawPressureAxis.minValue) /
- static_cast<float>(mRawPressureAxis.maxValue - mRawPressureAxis.minValue);
+ mStylusState.pressure = (rawPressure - mRawPressureAxis->minValue) /
+ static_cast<float>(mRawPressureAxis->maxValue - mRawPressureAxis->minValue);
} else if (mTouchButtonAccumulator.hasButtonTouch()) {
mStylusState.pressure = mTouchButtonAccumulator.isHovering() ? 0.0f : 1.0f;
}