InputMapper refactor: VibratorInputMapper
Add a factory method for VibratorInputMapper to be configured with
on initilisation
Test: m checkinput && atest libinput_tests inputflinger_tests
Bug: 256009910
Change-Id: I3c1ad85a8fc293ec1a8c1a5c82da36e304538046
(cherry picked from commit 0f26b30cc1a730a828f1b7bd16a1ff77dbc7282d)
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 721bb0a..ae38236 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -456,7 +456,7 @@
// Vibrator-like devices.
if (classes.test(InputDeviceClass::VIBRATOR)) {
- mappers.push_back(std::make_unique<VibratorInputMapper>(contextPtr, readerConfig));
+ mappers.push_back(createInputMapper<VibratorInputMapper>(contextPtr, readerConfig));
}
// Battery-like devices or light-containing devices.
diff --git a/services/inputflinger/reader/mapper/VibratorInputMapper.h b/services/inputflinger/reader/mapper/VibratorInputMapper.h
index 384c075..9079c73 100644
--- a/services/inputflinger/reader/mapper/VibratorInputMapper.h
+++ b/services/inputflinger/reader/mapper/VibratorInputMapper.h
@@ -22,8 +22,10 @@
class VibratorInputMapper : public InputMapper {
public:
- explicit VibratorInputMapper(InputDeviceContext& deviceContext,
- const InputReaderConfiguration& readerConfig);
+ template <class T, class... Args>
+ friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig,
+ Args... args);
virtual ~VibratorInputMapper();
virtual uint32_t getSources() const override;
@@ -46,6 +48,8 @@
ssize_t mIndex;
nsecs_t mNextStepTime;
+ explicit VibratorInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
[[nodiscard]] std::list<NotifyArgs> nextStep();
[[nodiscard]] NotifyVibratorStateArgs stopVibrating();
};
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index ae3ae6c..e1dbaa4 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2645,13 +2645,13 @@
};
TEST_F(VibratorInputMapperTest, GetSources) {
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
+ VibratorInputMapper& mapper = constructAndAddMapper<VibratorInputMapper>();
ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mapper.getSources());
}
TEST_F(VibratorInputMapperTest, GetVibratorIds) {
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
+ VibratorInputMapper& mapper = constructAndAddMapper<VibratorInputMapper>();
ASSERT_EQ(mapper.getVibratorIds().size(), 2U);
}
@@ -2659,7 +2659,7 @@
TEST_F(VibratorInputMapperTest, Vibrate) {
constexpr uint8_t DEFAULT_AMPLITUDE = 192;
constexpr int32_t VIBRATION_TOKEN = 100;
- VibratorInputMapper& mapper = addMapperAndConfigure<VibratorInputMapper>();
+ VibratorInputMapper& mapper = constructAndAddMapper<VibratorInputMapper>();
VibrationElement pattern(2);
VibrationSequence sequence(2);