Revert "InputDevice: return std::optional from getAbsoluteAxisInfo"
This reverts commit 67e1ae63301dc02f4d940b5f480b1f495b3b977e.
Reason for revert: b/353921348
Change-Id: I6148dec70b7ca1c9a21d841b791168b5bfc67ca3
diff --git a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp
index c8e7790..90685de 100644
--- a/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp
+++ b/services/inputflinger/reader/mapper/CapturedTouchpadEventConverter.cpp
@@ -16,7 +16,6 @@
#include "CapturedTouchpadEventConverter.h"
-#include <optional>
#include <sstream>
#include <android-base/stringprintf.h>
@@ -54,33 +53,32 @@
mMotionAccumulator(motionAccumulator),
mHasTouchMinor(deviceContext.hasAbsoluteAxis(ABS_MT_TOUCH_MINOR)),
mHasToolMinor(deviceContext.hasAbsoluteAxis(ABS_MT_WIDTH_MINOR)) {
- if (std::optional<RawAbsoluteAxisInfo> orientation =
- deviceContext.getAbsoluteAxisInfo(ABS_MT_ORIENTATION);
- orientation) {
- if (orientation->maxValue > 0) {
- mOrientationScale = M_PI_2 / orientation->maxValue;
- } else if (orientation->minValue < 0) {
- mOrientationScale = -M_PI_2 / orientation->minValue;
+ RawAbsoluteAxisInfo orientationInfo;
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &orientationInfo);
+ if (orientationInfo.valid) {
+ if (orientationInfo.maxValue > 0) {
+ mOrientationScale = M_PI_2 / orientationInfo.maxValue;
+ } else if (orientationInfo.minValue < 0) {
+ mOrientationScale = -M_PI_2 / orientationInfo.minValue;
}
}
// TODO(b/275369880): support touch.pressure.calibration and .scale properties when captured.
- if (std::optional<RawAbsoluteAxisInfo> pressure =
- deviceContext.getAbsoluteAxisInfo(ABS_MT_PRESSURE);
- pressure && pressure->maxValue > 0) {
- mPressureScale = 1.0 / pressure->maxValue;
+ RawAbsoluteAxisInfo pressureInfo;
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_PRESSURE, &pressureInfo);
+ if (pressureInfo.valid && pressureInfo.maxValue > 0) {
+ mPressureScale = 1.0 / pressureInfo.maxValue;
}
- std::optional<RawAbsoluteAxisInfo> touchMajor =
- deviceContext.getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR);
- std::optional<RawAbsoluteAxisInfo> toolMajor =
- deviceContext.getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR);
- mHasTouchMajor = touchMajor.has_value();
- mHasToolMajor = toolMajor.has_value();
- if (mHasTouchMajor && touchMajor->maxValue != 0) {
- mSizeScale = 1.0f / touchMajor->maxValue;
- } else if (mHasToolMajor && toolMajor->maxValue != 0) {
- mSizeScale = 1.0f / toolMajor->maxValue;
+ RawAbsoluteAxisInfo touchMajorInfo, toolMajorInfo;
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR, &touchMajorInfo);
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR, &toolMajorInfo);
+ mHasTouchMajor = touchMajorInfo.valid;
+ mHasToolMajor = toolMajorInfo.valid;
+ if (mHasTouchMajor && touchMajorInfo.maxValue != 0) {
+ mSizeScale = 1.0f / touchMajorInfo.maxValue;
+ } else if (mHasToolMajor && toolMajorInfo.maxValue != 0) {
+ mSizeScale = 1.0f / toolMajorInfo.maxValue;
}
}
@@ -115,13 +113,15 @@
tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_TOOL_MAJOR, ABS_MT_WIDTH_MAJOR);
tryAddRawMotionRange(/*byref*/ info, AMOTION_EVENT_AXIS_TOOL_MINOR, ABS_MT_WIDTH_MINOR);
- if (mDeviceContext.hasAbsoluteAxis(ABS_MT_PRESSURE)) {
+ RawAbsoluteAxisInfo pressureInfo;
+ mDeviceContext.getAbsoluteAxisInfo(ABS_MT_PRESSURE, &pressureInfo);
+ if (pressureInfo.valid) {
info.addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, SOURCE, 0, 1, 0, 0, 0);
}
- if (std::optional<RawAbsoluteAxisInfo> orientation =
- mDeviceContext.getAbsoluteAxisInfo(ABS_MT_ORIENTATION);
- orientation && (orientation->maxValue > 0 || orientation->minValue < 0)) {
+ RawAbsoluteAxisInfo orientationInfo;
+ mDeviceContext.getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &orientationInfo);
+ if (orientationInfo.valid && (orientationInfo.maxValue > 0 || orientationInfo.minValue < 0)) {
info.addMotionRange(AMOTION_EVENT_AXIS_ORIENTATION, SOURCE, -M_PI_2, M_PI_2, 0, 0, 0);
}
@@ -133,10 +133,11 @@
void CapturedTouchpadEventConverter::tryAddRawMotionRange(InputDeviceInfo& deviceInfo,
int32_t androidAxis,
int32_t evdevAxis) const {
- std::optional<RawAbsoluteAxisInfo> info = mDeviceContext.getAbsoluteAxisInfo(evdevAxis);
- if (info) {
- deviceInfo.addMotionRange(androidAxis, SOURCE, info->minValue, info->maxValue, info->flat,
- info->fuzz, info->resolution);
+ RawAbsoluteAxisInfo info;
+ mDeviceContext.getAbsoluteAxisInfo(evdevAxis, &info);
+ if (info.valid) {
+ deviceInfo.addMotionRange(androidAxis, SOURCE, info.minValue, info.maxValue, info.flat,
+ info.fuzz, info.resolution);
}
}
diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp
index 7cc8940..3af1d04 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) {
+ if (mRawPressureAxis.valid) {
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) {
- mRawPressureAxis = getAbsoluteAxisInfo(ABS_PRESSURE);
+ getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPressureAxis);
mTouchButtonAccumulator.configure();
return {};
}
@@ -82,10 +82,10 @@
mStylusState.toolType = ToolType::STYLUS;
}
- if (mRawPressureAxis) {
+ if (mRawPressureAxis.valid) {
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;
}
diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
index d48fd9b..c040a7b 100644
--- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
+++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h
@@ -16,8 +16,6 @@
#pragma once
-#include <optional>
-
#include "InputMapper.h"
#include "SingleTouchMotionAccumulator.h"
@@ -45,7 +43,7 @@
private:
SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
- std::optional<RawAbsoluteAxisInfo> mRawPressureAxis;
+ RawAbsoluteAxisInfo mRawPressureAxis;
TouchButtonAccumulator mTouchButtonAccumulator;
StylusState mStylusState;
diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp
index c44c48c..b6c5c98 100644
--- a/services/inputflinger/reader/mapper/InputMapper.cpp
+++ b/services/inputflinger/reader/mapper/InputMapper.cpp
@@ -18,7 +18,6 @@
#include "InputMapper.h"
-#include <optional>
#include <sstream>
#include <ftl/enum.h>
@@ -117,16 +116,15 @@
return {};
}
-std::optional<RawAbsoluteAxisInfo> InputMapper::getAbsoluteAxisInfo(int32_t axis) {
- return getDeviceContext().getAbsoluteAxisInfo(axis);
+status_t InputMapper::getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo) {
+ return getDeviceContext().getAbsoluteAxisInfo(axis, axisInfo);
}
void InputMapper::bumpGeneration() {
getDeviceContext().bumpGeneration();
}
-void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump,
- const std::optional<RawAbsoluteAxisInfo>& axis,
+void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis,
const char* name) {
std::stringstream out;
out << INDENT4 << name << ": " << axis << "\n";
diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h
index e5afcc7..2c51448 100644
--- a/services/inputflinger/reader/mapper/InputMapper.h
+++ b/services/inputflinger/reader/mapper/InputMapper.h
@@ -16,8 +16,6 @@
#pragma once
-#include <optional>
-
#include "EventHub.h"
#include "InputDevice.h"
#include "InputListener.h"
@@ -128,11 +126,10 @@
explicit InputMapper(InputDeviceContext& deviceContext,
const InputReaderConfiguration& readerConfig);
- std::optional<RawAbsoluteAxisInfo> getAbsoluteAxisInfo(int32_t axis);
+ status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
void bumpGeneration();
- static void dumpRawAbsoluteAxisInfo(std::string& dump,
- const std::optional<RawAbsoluteAxisInfo>& axis,
+ static void dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis,
const char* name);
static void dumpStylusState(std::string& dump, const StylusState& state);
};
diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
index 3091714..41e018d 100644
--- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp
@@ -117,8 +117,9 @@
continue; // axis must be claimed by a different device
}
- if (std::optional<RawAbsoluteAxisInfo> rawAxisInfo = getAbsoluteAxisInfo(abs);
- rawAxisInfo) {
+ RawAbsoluteAxisInfo rawAxisInfo;
+ getAbsoluteAxisInfo(abs, &rawAxisInfo);
+ if (rawAxisInfo.valid) {
// Map axis.
AxisInfo axisInfo;
const bool explicitlyMapped = !getDeviceContext().mapAxis(abs, &axisInfo);
@@ -128,7 +129,7 @@
axisInfo.mode = AxisInfo::MODE_NORMAL;
axisInfo.axis = -1;
}
- mAxes.insert({abs, createAxis(axisInfo, rawAxisInfo.value(), explicitlyMapped)});
+ mAxes.insert({abs, createAxis(axisInfo, rawAxisInfo, explicitlyMapped)});
}
}
diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
index 3ea3c20..1986fe2 100644
--- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp
@@ -133,7 +133,7 @@
bool isHovering = mTouchButtonAccumulator.getToolType() != ToolType::MOUSE &&
(mTouchButtonAccumulator.isHovering() ||
- (mRawPointerAxes.pressure && inSlot.getPressure() <= 0));
+ (mRawPointerAxes.pressure.valid && inSlot.getPressure() <= 0));
outPointer.isHovering = isHovering;
// Assign pointer id using tracking id if available.
@@ -189,23 +189,21 @@
void MultiTouchInputMapper::configureRawPointerAxes() {
TouchInputMapper::configureRawPointerAxes();
- // We can safely assume that ABS_MT_POSITION_X and _Y axes will be available, as EventHub won't
- // classify a device as multitouch if they're not present.
- mRawPointerAxes.x = getAbsoluteAxisInfo(ABS_MT_POSITION_X).value();
- mRawPointerAxes.y = getAbsoluteAxisInfo(ABS_MT_POSITION_Y).value();
- mRawPointerAxes.touchMajor = getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR);
- mRawPointerAxes.touchMinor = getAbsoluteAxisInfo(ABS_MT_TOUCH_MINOR);
- mRawPointerAxes.toolMajor = getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR);
- mRawPointerAxes.toolMinor = getAbsoluteAxisInfo(ABS_MT_WIDTH_MINOR);
- mRawPointerAxes.orientation = getAbsoluteAxisInfo(ABS_MT_ORIENTATION);
- mRawPointerAxes.pressure = getAbsoluteAxisInfo(ABS_MT_PRESSURE);
- mRawPointerAxes.distance = getAbsoluteAxisInfo(ABS_MT_DISTANCE);
- mRawPointerAxes.trackingId = getAbsoluteAxisInfo(ABS_MT_TRACKING_ID);
- mRawPointerAxes.slot = getAbsoluteAxisInfo(ABS_MT_SLOT);
+ getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mRawPointerAxes.x);
+ getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mRawPointerAxes.y);
+ getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR, &mRawPointerAxes.touchMajor);
+ getAbsoluteAxisInfo(ABS_MT_TOUCH_MINOR, &mRawPointerAxes.touchMinor);
+ getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR, &mRawPointerAxes.toolMajor);
+ getAbsoluteAxisInfo(ABS_MT_WIDTH_MINOR, &mRawPointerAxes.toolMinor);
+ getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &mRawPointerAxes.orientation);
+ getAbsoluteAxisInfo(ABS_MT_PRESSURE, &mRawPointerAxes.pressure);
+ getAbsoluteAxisInfo(ABS_MT_DISTANCE, &mRawPointerAxes.distance);
+ getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId);
+ getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot);
- if (mRawPointerAxes.trackingId && mRawPointerAxes.slot && mRawPointerAxes.slot->minValue == 0 &&
- mRawPointerAxes.slot->maxValue > 0) {
- size_t slotCount = mRawPointerAxes.slot->maxValue + 1;
+ if (mRawPointerAxes.trackingId.valid && mRawPointerAxes.slot.valid &&
+ mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) {
+ size_t slotCount = mRawPointerAxes.slot.maxValue + 1;
if (slotCount > MAX_SLOTS) {
ALOGW("MultiTouch Device %s reported %zu slots but the framework "
"only supports a maximum of %zu slots at this time.",
diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.cpp b/services/inputflinger/reader/mapper/SensorInputMapper.cpp
index 4233f78..d7f2993 100644
--- a/services/inputflinger/reader/mapper/SensorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/SensorInputMapper.cpp
@@ -133,8 +133,9 @@
.test(InputDeviceClass::SENSOR))) {
continue;
}
- if (std::optional<RawAbsoluteAxisInfo> rawAxisInfo = getAbsoluteAxisInfo(abs);
- rawAxisInfo) {
+ RawAbsoluteAxisInfo rawAxisInfo;
+ getAbsoluteAxisInfo(abs, &rawAxisInfo);
+ if (rawAxisInfo.valid) {
AxisInfo axisInfo;
// Axis doesn't need to be mapped, as sensor mapper doesn't generate any motion
// input events
@@ -145,7 +146,7 @@
if (ret.ok()) {
InputDeviceSensorType sensorType = (*ret).first;
int32_t sensorDataIndex = (*ret).second;
- const Axis& axis = createAxis(axisInfo, rawAxisInfo.value());
+ const Axis& axis = createAxis(axisInfo, rawAxisInfo);
parseSensorConfiguration(sensorType, abs, sensorDataIndex, axis);
mAxes.insert({abs, axis});
diff --git a/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp b/services/inputflinger/reader/mapper/SingleTouchInputMapper.cpp
index 869feb4..140bb0c 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 &&
+ (mRawPointerAxes.pressure.valid &&
mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0));
outState->rawPointerData.markIdBit(0, isHovering);
@@ -72,15 +72,13 @@
void SingleTouchInputMapper::configureRawPointerAxes() {
TouchInputMapper::configureRawPointerAxes();
- // 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);
+ 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);
}
bool SingleTouchInputMapper::hasStylus() const {
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index beba3b8..81ec24e 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -600,10 +600,10 @@
const float diagonalSize = hypotf(mDisplayBounds.width, mDisplayBounds.height);
// Size factors.
- if (mRawPointerAxes.touchMajor && mRawPointerAxes.touchMajor->maxValue != 0) {
- mSizeScale = 1.0f / mRawPointerAxes.touchMajor->maxValue;
- } else if (mRawPointerAxes.toolMajor && mRawPointerAxes.toolMajor->maxValue != 0) {
- mSizeScale = 1.0f / mRawPointerAxes.toolMajor->maxValue;
+ if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.touchMajor.maxValue != 0) {
+ mSizeScale = 1.0f / mRawPointerAxes.touchMajor.maxValue;
+ } else if (mRawPointerAxes.toolMajor.valid && mRawPointerAxes.toolMajor.maxValue != 0) {
+ mSizeScale = 1.0f / mRawPointerAxes.toolMajor.maxValue;
} else {
mSizeScale = 0.0f;
}
@@ -618,18 +618,18 @@
.resolution = 0,
};
- if (mRawPointerAxes.touchMajor) {
- mRawPointerAxes.touchMajor->resolution =
- clampResolution("touchMajor", mRawPointerAxes.touchMajor->resolution);
- mOrientedRanges.touchMajor->resolution = mRawPointerAxes.touchMajor->resolution;
+ if (mRawPointerAxes.touchMajor.valid) {
+ mRawPointerAxes.touchMajor.resolution =
+ clampResolution("touchMajor", mRawPointerAxes.touchMajor.resolution);
+ mOrientedRanges.touchMajor->resolution = mRawPointerAxes.touchMajor.resolution;
}
mOrientedRanges.touchMinor = mOrientedRanges.touchMajor;
mOrientedRanges.touchMinor->axis = AMOTION_EVENT_AXIS_TOUCH_MINOR;
- if (mRawPointerAxes.touchMinor) {
- mRawPointerAxes.touchMinor->resolution =
- clampResolution("touchMinor", mRawPointerAxes.touchMinor->resolution);
- mOrientedRanges.touchMinor->resolution = mRawPointerAxes.touchMinor->resolution;
+ if (mRawPointerAxes.touchMinor.valid) {
+ mRawPointerAxes.touchMinor.resolution =
+ clampResolution("touchMinor", mRawPointerAxes.touchMinor.resolution);
+ mOrientedRanges.touchMinor->resolution = mRawPointerAxes.touchMinor.resolution;
}
mOrientedRanges.toolMajor = InputDeviceInfo::MotionRange{
@@ -641,18 +641,18 @@
.fuzz = 0,
.resolution = 0,
};
- if (mRawPointerAxes.toolMajor) {
- mRawPointerAxes.toolMajor->resolution =
- clampResolution("toolMajor", mRawPointerAxes.toolMajor->resolution);
- mOrientedRanges.toolMajor->resolution = mRawPointerAxes.toolMajor->resolution;
+ if (mRawPointerAxes.toolMajor.valid) {
+ mRawPointerAxes.toolMajor.resolution =
+ clampResolution("toolMajor", mRawPointerAxes.toolMajor.resolution);
+ mOrientedRanges.toolMajor->resolution = mRawPointerAxes.toolMajor.resolution;
}
mOrientedRanges.toolMinor = mOrientedRanges.toolMajor;
mOrientedRanges.toolMinor->axis = AMOTION_EVENT_AXIS_TOOL_MINOR;
- if (mRawPointerAxes.toolMinor) {
- mRawPointerAxes.toolMinor->resolution =
- clampResolution("toolMinor", mRawPointerAxes.toolMinor->resolution);
- mOrientedRanges.toolMinor->resolution = mRawPointerAxes.toolMinor->resolution;
+ if (mRawPointerAxes.toolMinor.valid) {
+ mRawPointerAxes.toolMinor.resolution =
+ clampResolution("toolMinor", mRawPointerAxes.toolMinor.resolution);
+ mOrientedRanges.toolMinor->resolution = mRawPointerAxes.toolMinor.resolution;
}
if (mCalibration.sizeCalibration == Calibration::SizeCalibration::GEOMETRIC) {
@@ -704,10 +704,9 @@
mCalibration.pressureCalibration == Calibration::PressureCalibration::AMPLITUDE) {
if (mCalibration.pressureScale) {
mPressureScale = *mCalibration.pressureScale;
- pressureMax = mPressureScale *
- (mRawPointerAxes.pressure ? mRawPointerAxes.pressure->maxValue : 0);
- } else if (mRawPointerAxes.pressure && mRawPointerAxes.pressure->maxValue != 0) {
- mPressureScale = 1.0f / mRawPointerAxes.pressure->maxValue;
+ pressureMax = mPressureScale * mRawPointerAxes.pressure.maxValue;
+ } else if (mRawPointerAxes.pressure.valid && mRawPointerAxes.pressure.maxValue != 0) {
+ mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue;
}
}
@@ -726,18 +725,18 @@
mTiltXScale = 0;
mTiltYCenter = 0;
mTiltYScale = 0;
- mHaveTilt = mRawPointerAxes.tiltX && mRawPointerAxes.tiltY;
+ mHaveTilt = mRawPointerAxes.tiltX.valid && mRawPointerAxes.tiltY.valid;
if (mHaveTilt) {
- mTiltXCenter = avg(mRawPointerAxes.tiltX->minValue, mRawPointerAxes.tiltX->maxValue);
- mTiltYCenter = avg(mRawPointerAxes.tiltY->minValue, mRawPointerAxes.tiltY->maxValue);
+ mTiltXCenter = avg(mRawPointerAxes.tiltX.minValue, mRawPointerAxes.tiltX.maxValue);
+ mTiltYCenter = avg(mRawPointerAxes.tiltY.minValue, mRawPointerAxes.tiltY.maxValue);
mTiltXScale = M_PI / 180;
mTiltYScale = M_PI / 180;
- if (mRawPointerAxes.tiltX->resolution) {
- mTiltXScale = 1.0 / mRawPointerAxes.tiltX->resolution;
+ if (mRawPointerAxes.tiltX.resolution) {
+ mTiltXScale = 1.0 / mRawPointerAxes.tiltX.resolution;
}
- if (mRawPointerAxes.tiltY->resolution) {
- mTiltYScale = 1.0 / mRawPointerAxes.tiltY->resolution;
+ if (mRawPointerAxes.tiltY.resolution) {
+ mTiltYScale = 1.0 / mRawPointerAxes.tiltY.resolution;
}
mOrientedRanges.tilt = InputDeviceInfo::MotionRange{
@@ -767,11 +766,11 @@
} else if (mCalibration.orientationCalibration != Calibration::OrientationCalibration::NONE) {
if (mCalibration.orientationCalibration ==
Calibration::OrientationCalibration::INTERPOLATED) {
- if (mRawPointerAxes.orientation) {
- if (mRawPointerAxes.orientation->maxValue > 0) {
- mOrientationScale = M_PI_2 / mRawPointerAxes.orientation->maxValue;
- } else if (mRawPointerAxes.orientation->minValue < 0) {
- mOrientationScale = -M_PI_2 / mRawPointerAxes.orientation->minValue;
+ if (mRawPointerAxes.orientation.valid) {
+ if (mRawPointerAxes.orientation.maxValue > 0) {
+ mOrientationScale = M_PI_2 / mRawPointerAxes.orientation.maxValue;
+ } else if (mRawPointerAxes.orientation.minValue < 0) {
+ mOrientationScale = -M_PI_2 / mRawPointerAxes.orientation.minValue;
} else {
mOrientationScale = 0;
}
@@ -796,14 +795,14 @@
mDistanceScale = mCalibration.distanceScale.value_or(1.0f);
}
- const bool hasDistance = mRawPointerAxes.distance.has_value();
mOrientedRanges.distance = InputDeviceInfo::MotionRange{
+
.axis = AMOTION_EVENT_AXIS_DISTANCE,
.source = mSource,
- .min = hasDistance ? mRawPointerAxes.distance->minValue * mDistanceScale : 0,
- .max = hasDistance ? mRawPointerAxes.distance->maxValue * mDistanceScale : 0,
+ .min = mRawPointerAxes.distance.minValue * mDistanceScale,
+ .max = mRawPointerAxes.distance.maxValue * mDistanceScale,
.flat = 0,
- .fuzz = hasDistance ? mRawPointerAxes.distance->fuzz * mDistanceScale : 0,
+ .fuzz = mRawPointerAxes.distance.fuzz * mDistanceScale,
.resolution = 0,
};
}
@@ -944,7 +943,12 @@
const std::optional<DisplayViewport> newViewportOpt = findViewport();
// Ensure the device is valid and can be used.
- if (!newViewportOpt) {
+ if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) {
+ ALOGW("Touch device '%s' did not report support for X or Y axis! "
+ "The device will be inoperable.",
+ getDeviceName().c_str());
+ mDeviceMode = DeviceMode::DISABLED;
+ } else if (!newViewportOpt) {
ALOGI("Touch device '%s' could not query the properties of its associated "
"display. The device will be inoperable until the display size "
"becomes available.",
@@ -1233,7 +1237,7 @@
void TouchInputMapper::resolveCalibration() {
// Size
- if (mRawPointerAxes.touchMajor || mRawPointerAxes.toolMajor) {
+ if (mRawPointerAxes.touchMajor.valid || mRawPointerAxes.toolMajor.valid) {
if (mCalibration.sizeCalibration == Calibration::SizeCalibration::DEFAULT) {
mCalibration.sizeCalibration = Calibration::SizeCalibration::GEOMETRIC;
}
@@ -1242,7 +1246,7 @@
}
// Pressure
- if (mRawPointerAxes.pressure) {
+ if (mRawPointerAxes.pressure.valid) {
if (mCalibration.pressureCalibration == Calibration::PressureCalibration::DEFAULT) {
mCalibration.pressureCalibration = Calibration::PressureCalibration::PHYSICAL;
}
@@ -1251,7 +1255,7 @@
}
// Orientation
- if (mRawPointerAxes.orientation) {
+ if (mRawPointerAxes.orientation.valid) {
if (mCalibration.orientationCalibration == Calibration::OrientationCalibration::DEFAULT) {
mCalibration.orientationCalibration = Calibration::OrientationCalibration::INTERPOLATED;
}
@@ -1260,7 +1264,7 @@
}
// Distance
- if (mRawPointerAxes.distance) {
+ if (mRawPointerAxes.distance.valid) {
if (mCalibration.distanceCalibration == Calibration::DistanceCalibration::DEFAULT) {
mCalibration.distanceCalibration = Calibration::DistanceCalibration::SCALED;
}
@@ -2247,25 +2251,25 @@
case Calibration::SizeCalibration::DIAMETER:
case Calibration::SizeCalibration::BOX:
case Calibration::SizeCalibration::AREA:
- if (mRawPointerAxes.touchMajor && mRawPointerAxes.toolMajor) {
+ if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) {
touchMajor = in.touchMajor;
- touchMinor = mRawPointerAxes.touchMinor ? in.touchMinor : in.touchMajor;
+ touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor;
toolMajor = in.toolMajor;
- toolMinor = mRawPointerAxes.toolMinor ? in.toolMinor : in.toolMajor;
- size = mRawPointerAxes.touchMinor ? avg(in.touchMajor, in.touchMinor)
- : in.touchMajor;
- } else if (mRawPointerAxes.touchMajor) {
+ toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor;
+ size = mRawPointerAxes.touchMinor.valid ? avg(in.touchMajor, in.touchMinor)
+ : in.touchMajor;
+ } else if (mRawPointerAxes.touchMajor.valid) {
toolMajor = touchMajor = in.touchMajor;
toolMinor = touchMinor =
- mRawPointerAxes.touchMinor ? in.touchMinor : in.touchMajor;
- size = mRawPointerAxes.touchMinor ? avg(in.touchMajor, in.touchMinor)
- : in.touchMajor;
- } else if (mRawPointerAxes.toolMajor) {
+ mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor;
+ size = mRawPointerAxes.touchMinor.valid ? avg(in.touchMajor, in.touchMinor)
+ : in.touchMajor;
+ } else if (mRawPointerAxes.toolMajor.valid) {
touchMajor = toolMajor = in.toolMajor;
touchMinor = toolMinor =
- mRawPointerAxes.toolMinor ? in.toolMinor : in.toolMajor;
- size = mRawPointerAxes.toolMinor ? avg(in.toolMajor, in.toolMinor)
- : in.toolMajor;
+ mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor;
+ size = mRawPointerAxes.toolMinor.valid ? avg(in.toolMajor, in.toolMinor)
+ : in.toolMajor;
} else {
ALOG_ASSERT(false,
"No touch or tool axes. "
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h
index beab6e7..30c58a5 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.h
@@ -61,17 +61,17 @@
struct RawPointerAxes {
RawAbsoluteAxisInfo x{};
RawAbsoluteAxisInfo y{};
- std::optional<RawAbsoluteAxisInfo> pressure{};
- std::optional<RawAbsoluteAxisInfo> touchMajor{};
- std::optional<RawAbsoluteAxisInfo> touchMinor{};
- std::optional<RawAbsoluteAxisInfo> toolMajor{};
- std::optional<RawAbsoluteAxisInfo> toolMinor{};
- std::optional<RawAbsoluteAxisInfo> orientation{};
- std::optional<RawAbsoluteAxisInfo> distance{};
- std::optional<RawAbsoluteAxisInfo> tiltX{};
- std::optional<RawAbsoluteAxisInfo> tiltY{};
- std::optional<RawAbsoluteAxisInfo> trackingId{};
- std::optional<RawAbsoluteAxisInfo> slot{};
+ RawAbsoluteAxisInfo pressure{};
+ RawAbsoluteAxisInfo touchMajor{};
+ RawAbsoluteAxisInfo touchMinor{};
+ RawAbsoluteAxisInfo toolMajor{};
+ RawAbsoluteAxisInfo toolMinor{};
+ RawAbsoluteAxisInfo orientation{};
+ RawAbsoluteAxisInfo distance{};
+ RawAbsoluteAxisInfo tiltX{};
+ RawAbsoluteAxisInfo tiltY{};
+ RawAbsoluteAxisInfo trackingId{};
+ RawAbsoluteAxisInfo slot{};
inline int32_t getRawWidth() const { return x.maxValue - x.minValue + 1; }
inline int32_t getRawHeight() const { return y.maxValue - y.minValue + 1; }
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index daab636..24efae8 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -240,15 +240,14 @@
mGestureConverter(*getContext(), deviceContext, getDeviceId()),
mCapturedEventConverter(*getContext(), deviceContext, mMotionAccumulator, getDeviceId()),
mMetricsId(metricsIdFromInputDeviceIdentifier(deviceContext.getDeviceIdentifier())) {
- if (std::optional<RawAbsoluteAxisInfo> slotAxis =
- deviceContext.getAbsoluteAxisInfo(ABS_MT_SLOT);
- slotAxis && slotAxis->maxValue >= 0) {
- mMotionAccumulator.configure(deviceContext, slotAxis->maxValue + 1, true);
- } else {
+ RawAbsoluteAxisInfo slotAxisInfo;
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_SLOT, &slotAxisInfo);
+ if (!slotAxisInfo.valid || slotAxisInfo.maxValue < 0) {
LOG(WARNING) << "Touchpad " << deviceContext.getName()
<< " doesn't have a valid ABS_MT_SLOT axis, and probably won't work properly.";
- mMotionAccumulator.configure(deviceContext, 1, true);
+ slotAxisInfo.maxValue = 0;
}
+ mMotionAccumulator.configure(deviceContext, slotAxisInfo.maxValue + 1, true);
mGestureInterpreter->Initialize(GESTURES_DEVCLASS_TOUCHPAD);
mGestureInterpreter->SetHardwareProperties(createHardwareProperties(deviceContext));
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
index 9924d0d..e8e7376 100644
--- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
+++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
@@ -66,11 +66,10 @@
const InputDeviceContext& deviceContext, int32_t deviceId)
: mDeviceId(deviceId),
mReaderContext(readerContext),
- mEnableFlingStop(input_flags::enable_touchpad_fling_stop()),
- // We can safely assume that ABS_MT_POSITION_X and _Y axes will be available, as EventHub
- // won't classify a device as a touchpad if they're not present.
- mXAxisInfo(deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_X).value()),
- mYAxisInfo(deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_Y).value()) {}
+ mEnableFlingStop(input_flags::enable_touchpad_fling_stop()) {
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mXAxisInfo);
+ deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mYAxisInfo);
+}
std::string GestureConverter::dump() const {
std::stringstream out;
diff --git a/services/inputflinger/reader/mapper/gestures/HardwareProperties.cpp b/services/inputflinger/reader/mapper/gestures/HardwareProperties.cpp
index d8a1f50..04655dc 100644
--- a/services/inputflinger/reader/mapper/gestures/HardwareProperties.cpp
+++ b/services/inputflinger/reader/mapper/gestures/HardwareProperties.cpp
@@ -16,8 +16,6 @@
#include "HardwareProperties.h"
-#include <optional>
-
namespace android {
namespace {
@@ -35,34 +33,26 @@
HardwareProperties createHardwareProperties(const InputDeviceContext& context) {
HardwareProperties props;
- // We can safely assume that ABS_MT_POSITION_X and _Y axes will be available, as EventHub won't
- // classify a device as a touchpad if they're not present.
- RawAbsoluteAxisInfo absMtPositionX = context.getAbsoluteAxisInfo(ABS_MT_POSITION_X).value();
+ RawAbsoluteAxisInfo absMtPositionX;
+ context.getAbsoluteAxisInfo(ABS_MT_POSITION_X, &absMtPositionX);
props.left = absMtPositionX.minValue;
props.right = absMtPositionX.maxValue;
props.res_x = absMtPositionX.resolution;
- RawAbsoluteAxisInfo absMtPositionY = context.getAbsoluteAxisInfo(ABS_MT_POSITION_Y).value();
+ RawAbsoluteAxisInfo absMtPositionY;
+ context.getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &absMtPositionY);
props.top = absMtPositionY.minValue;
props.bottom = absMtPositionY.maxValue;
props.res_y = absMtPositionY.resolution;
- if (std::optional<RawAbsoluteAxisInfo> absMtOrientation =
- context.getAbsoluteAxisInfo(ABS_MT_ORIENTATION);
- absMtOrientation) {
- props.orientation_minimum = absMtOrientation->minValue;
- props.orientation_maximum = absMtOrientation->maxValue;
- } else {
- props.orientation_minimum = 0;
- props.orientation_maximum = 0;
- }
+ RawAbsoluteAxisInfo absMtOrientation;
+ context.getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &absMtOrientation);
+ props.orientation_minimum = absMtOrientation.minValue;
+ props.orientation_maximum = absMtOrientation.maxValue;
- if (std::optional<RawAbsoluteAxisInfo> absMtSlot = context.getAbsoluteAxisInfo(ABS_MT_SLOT);
- absMtSlot) {
- props.max_finger_cnt = absMtSlot->maxValue - absMtSlot->minValue + 1;
- } else {
- props.max_finger_cnt = 1;
- }
+ RawAbsoluteAxisInfo absMtSlot;
+ context.getAbsoluteAxisInfo(ABS_MT_SLOT, &absMtSlot);
+ props.max_finger_cnt = absMtSlot.maxValue - absMtSlot.minValue + 1;
props.max_touch_cnt = getMaxTouchCount(context);
// T5R2 ("Track 5, Report 2") is a feature of some old Synaptics touchpads that could track 5
@@ -81,7 +71,9 @@
// are haptic.
props.is_haptic_pad = false;
- props.reports_pressure = context.hasAbsoluteAxis(ABS_MT_PRESSURE);
+ RawAbsoluteAxisInfo absMtPressure;
+ context.getAbsoluteAxisInfo(ABS_MT_PRESSURE, &absMtPressure);
+ props.reports_pressure = absMtPressure.valid;
return props;
}