Native support for rotary encoder high-res scroll
Test: atest RotaryEncoderInputMapperTest
Test: atest VirtualRotaryEncoderTest
Flag: android.companion.virtualdevice.flags.high_resolution_scroll
Bug: 320328752
Change-Id: Iac9092597010582bd3f55e51ee63e9eb9c8d9433
diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
index 20fd359..b72cc6e 100644
--- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp
@@ -27,11 +27,14 @@
namespace android {
+constexpr float kDefaultScaleFactor = 1.0f;
+
RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
const InputReaderConfiguration& readerConfig)
- : InputMapper(deviceContext, readerConfig), mOrientation(ui::ROTATION_0) {
- mSource = AINPUT_SOURCE_ROTARY_ENCODER;
-}
+ : InputMapper(deviceContext, readerConfig),
+ mSource(AINPUT_SOURCE_ROTARY_ENCODER),
+ mScalingFactor(kDefaultScaleFactor),
+ mOrientation(ui::ROTATION_0) {}
RotaryEncoderInputMapper::~RotaryEncoderInputMapper() {}
@@ -51,9 +54,10 @@
std::optional<float> scalingFactor = config.getFloat("device.scalingFactor");
if (!scalingFactor.has_value()) {
ALOGW("Rotary Encoder device configuration file didn't specify scaling factor,"
- "default to 1.0!\n");
+ "default to %f!\n",
+ kDefaultScaleFactor);
}
- mScalingFactor = scalingFactor.value_or(1.0f);
+ mScalingFactor = scalingFactor.value_or(kDefaultScaleFactor);
info.addMotionRange(AMOTION_EVENT_AXIS_SCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f,
res.value_or(0.0f) * mScalingFactor);
}
diff --git a/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.cpp b/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.cpp
index 06315e2..5373440 100644
--- a/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.cpp
+++ b/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.cpp
@@ -55,14 +55,14 @@
switch (rawEvent.code) {
case REL_WHEEL_HI_RES:
if (mHaveRelWheelHighRes) {
- mRelWheel = rawEvent.value /
- static_cast<float>(kEvdevMouseHighResScrollUnitsPerDetent);
+ mRelWheel =
+ rawEvent.value / static_cast<float>(kEvdevHighResScrollUnitsPerDetent);
}
break;
case REL_HWHEEL_HI_RES:
if (mHaveRelHWheelHighRes) {
- mRelHWheel = rawEvent.value /
- static_cast<float>(kEvdevMouseHighResScrollUnitsPerDetent);
+ mRelHWheel =
+ rawEvent.value / static_cast<float>(kEvdevHighResScrollUnitsPerDetent);
}
break;
case REL_WHEEL:
diff --git a/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.h b/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.h
index 6990d20..d3373cc 100644
--- a/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.h
+++ b/services/inputflinger/reader/mapper/accumulator/CursorScrollAccumulator.h
@@ -16,8 +16,6 @@
#pragma once
-#include <stdint.h>
-
namespace android {
class InputDeviceContext;
@@ -36,8 +34,6 @@
inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
- inline int32_t getRelativeX() const { return mRelX; }
- inline int32_t getRelativeY() const { return mRelY; }
inline float getRelativeVWheel() const { return mRelWheel; }
inline float getRelativeHWheel() const { return mRelHWheel; }
@@ -47,8 +43,6 @@
bool mHaveRelWheelHighRes;
bool mHaveRelHWheelHighRes;
- int32_t mRelX;
- int32_t mRelY;
float mRelWheel;
float mRelHWheel;