Report motion ranges for touchpads in new stack
Bug: 272745137
Test: use a test app to dump motion ranges for a touchpad
Change-Id: If51e4124b323b9d915db130aaf3d0df4fbdba97d
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index 3309767..4c56b05 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -206,6 +206,11 @@
return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD;
}
+void TouchpadInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+ InputMapper::populateDeviceInfo(info);
+ mGestureConverter.populateMotionRanges(*info);
+}
+
void TouchpadInputMapper::dump(std::string& dump) {
dump += INDENT2 "Touchpad Input Mapper:\n";
dump += INDENT3 "Gesture converter:\n";
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
index d693bca..94da1b3 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
@@ -41,6 +41,7 @@
~TouchpadInputMapper();
uint32_t getSources() const override;
+ void populateDeviceInfo(InputDeviceInfo* deviceInfo) override;
void dump(std::string& dump) override;
[[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when,
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
index bc9f4c0..707b1f3 100644
--- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
+++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp
@@ -16,13 +16,14 @@
#include "gestures/GestureConverter.h"
+#include <optional>
#include <sstream>
#include <android-base/stringprintf.h>
-#include <android/input.h>
#include <ftl/enum.h>
#include <linux/input-event-codes.h>
#include <log/log_main.h>
+#include <ui/FloatRect.h>
#include "TouchCursorInputMapperCommon.h"
#include "input/Input.h"
@@ -75,6 +76,28 @@
mButtonState = 0;
}
+void GestureConverter::populateMotionRanges(InputDeviceInfo& info) const {
+ info.addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, SOURCE, 0.0f, 1.0f, 0, 0, 0);
+
+ // TODO(b/259547750): set this using the raw axis ranges from the touchpad when pointer capture
+ // is enabled.
+ if (std::optional<FloatRect> rect = mPointerController->getBounds(); rect.has_value()) {
+ info.addMotionRange(AMOTION_EVENT_AXIS_X, SOURCE, rect->left, rect->right, 0, 0, 0);
+ info.addMotionRange(AMOTION_EVENT_AXIS_Y, SOURCE, rect->top, rect->bottom, 0, 0, 0);
+ }
+
+ info.addMotionRange(AMOTION_EVENT_AXIS_GESTURE_X_OFFSET, SOURCE, -1.0f, 1.0f, 0, 0, 0);
+ info.addMotionRange(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET, SOURCE, -1.0f, 1.0f, 0, 0, 0);
+
+ // The other axes that can be reported don't have ranges that are easy to define. RELATIVE_X/Y
+ // and GESTURE_SCROLL_X/Y_DISTANCE are the result of acceleration functions being applied to
+ // finger movements, so their maximum values can't simply be derived from the size of the
+ // touchpad. GESTURE_PINCH_SCALE_FACTOR's maximum value depends on the minimum finger separation
+ // that the pad can report, which cannot be determined from its raw axis information. (Assuming
+ // a minimum finger separation of 1 unit would let us calculate a theoretical maximum, but it
+ // would be orders of magnitude too high, so probably not very useful.)
+}
+
std::list<NotifyArgs> GestureConverter::handleGesture(nsecs_t when, nsecs_t readTime,
const Gesture& gesture) {
switch (gesture.type) {
@@ -418,10 +441,7 @@
const PointerProperties* pointerProperties,
const PointerCoords* pointerCoords,
float xCursorPosition, float yCursorPosition) {
- // TODO(b/260226362): consider what the appropriate source for these events is.
- const uint32_t source = AINPUT_SOURCE_MOUSE;
-
- return NotifyMotionArgs(mReaderContext.getNextId(), when, readTime, mDeviceId, source,
+ return NotifyMotionArgs(mReaderContext.getNextId(), when, readTime, mDeviceId, SOURCE,
mPointerController->getDisplayId(), /* policyFlags= */ POLICY_FLAG_WAKE,
action, /* actionButton= */ actionButton, /* flags= */ 0,
mReaderContext.getGlobalMetaState(), buttonState,
diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h
index 2ec5841..a10dcce 100644
--- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h
+++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h
@@ -21,6 +21,7 @@
#include <memory>
#include <PointerControllerInterface.h>
+#include <android/input.h>
#include <utils/Timers.h>
#include "EventHub.h"
@@ -45,6 +46,8 @@
void setOrientation(ui::Rotation orientation) { mOrientation = orientation; }
void reset();
+ void populateMotionRanges(InputDeviceInfo& info) const;
+
[[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
const Gesture& gesture);
@@ -98,6 +101,9 @@
{.id = 3, .toolType = AMOTION_EVENT_TOOL_TYPE_FINGER},
}};
std::array<PointerCoords, MAX_FAKE_FINGERS> mFakeFingerCoords = {};
+
+ // TODO(b/260226362): consider what the appropriate source for these events is.
+ static constexpr uint32_t SOURCE = AINPUT_SOURCE_MOUSE;
};
} // namespace android