From 61dd33e220cb88bcd76aaf7be92ce8e4f06b3468 Mon Sep 17 00:00:00 2001 From: Arpit Singh Date: Wed, 26 Apr 2023 15:07:55 +0000 Subject: InputMapper refactor: SensorInputMapper Add a factory method for SensorInputMapper to be configured on initilisation Test: m checkinput && atest libinput_tests inputflinger_tests Bug: 256009910 Change-Id: Ib1b32424cebc57c789288ce86d7c5e8d145dc552 (cherry picked from commit fb706c3835608366381f4bbb5e921e798be4fe52) --- services/inputflinger/reader/InputDevice.cpp | 2 +- services/inputflinger/reader/mapper/SensorInputMapper.h | 9 +++++++-- services/inputflinger/tests/InputReader_test.cpp | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index ec8a443eba..93b26faee2 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -515,7 +515,7 @@ std::vector> InputDevice::createMappers( // Motion sensor enabled devices. if (classes.test(InputDeviceClass::SENSOR)) { - mappers.push_back(std::make_unique(contextPtr, readerConfig)); + mappers.push_back(createInputMapper(contextPtr, readerConfig)); } // External stylus-like devices. diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.h b/services/inputflinger/reader/mapper/SensorInputMapper.h index 1f82559db8..a55dcd1905 100644 --- a/services/inputflinger/reader/mapper/SensorInputMapper.h +++ b/services/inputflinger/reader/mapper/SensorInputMapper.h @@ -27,8 +27,10 @@ static constexpr ssize_t SENSOR_VEC_LEN = 3; class SensorInputMapper : public InputMapper { public: - explicit SensorInputMapper(InputDeviceContext& deviceContext, - const InputReaderConfiguration& readerConfig); + template + friend std::unique_ptr createInputMapper(InputDeviceContext& deviceContext, + const InputReaderConfiguration& readerConfig, + Args... args); ~SensorInputMapper() override; uint32_t getSources() const override; @@ -106,6 +108,9 @@ private: } }; + explicit SensorInputMapper(InputDeviceContext& deviceContext, + const InputReaderConfiguration& readerConfig); + static Axis createAxis(const AxisInfo& AxisInfo, const RawAbsoluteAxisInfo& rawAxisInfo); // Axes indexed by raw ABS_* axis index. diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index ae3ae6c006..f821ef430a 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2784,7 +2784,7 @@ void SensorInputMapperTest::setGyroProperties() { } TEST_F(SensorInputMapperTest, GetSources) { - SensorInputMapper& mapper = addMapperAndConfigure(); + SensorInputMapper& mapper = constructAndAddMapper(); ASSERT_EQ(static_cast(AINPUT_SOURCE_SENSOR), mapper.getSources()); } @@ -2792,7 +2792,7 @@ TEST_F(SensorInputMapperTest, GetSources) { TEST_F(SensorInputMapperTest, ProcessAccelerometerSensor) { setAccelProperties(); prepareAccelAxes(); - SensorInputMapper& mapper = addMapperAndConfigure(); + SensorInputMapper& mapper = constructAndAddMapper(); ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::ACCELEROMETER, std::chrono::microseconds(10000), @@ -2822,7 +2822,7 @@ TEST_F(SensorInputMapperTest, ProcessAccelerometerSensor) { TEST_F(SensorInputMapperTest, ProcessGyroscopeSensor) { setGyroProperties(); prepareGyroAxes(); - SensorInputMapper& mapper = addMapperAndConfigure(); + SensorInputMapper& mapper = constructAndAddMapper(); ASSERT_TRUE(mapper.enableSensor(InputDeviceSensorType::GYROSCOPE, std::chrono::microseconds(10000), -- cgit v1.2.3-59-g8ed1b