summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Arpit Singh <arpitks@google.com> 2023-05-11 08:16:53 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-05-11 08:16:53 +0000
commitde78d99fe5408eb46ba2d9ca8f68b3678656d72d (patch)
tree36ee9bf80927a1d3b64f6a1fd14f0e717590acbe
parentf706615310be085111ebe3d7ed1462cf5758ae5d (diff)
parent54a45f6450005c3527046273d18a08209a92a8aa (diff)
Merge "InputMapper refactor: SwitchInputMapper" into udc-dev
-rw-r--r--services/inputflinger/reader/InputDevice.cpp2
-rw-r--r--services/inputflinger/reader/mapper/SwitchInputMapper.h8
-rw-r--r--services/inputflinger/tests/InputReader_test.cpp6
3 files changed, 10 insertions, 6 deletions
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 29b1e31f77..d32482677e 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -446,7 +446,7 @@ std::vector<std::unique_ptr<InputMapper>> InputDevice::createMappers(
// Switch-like devices.
if (classes.test(InputDeviceClass::SWITCH)) {
- mappers.push_back(std::make_unique<SwitchInputMapper>(contextPtr, readerConfig));
+ mappers.push_back(createInputMapper<SwitchInputMapper>(contextPtr, readerConfig));
}
// Scroll wheel-like devices.
diff --git a/services/inputflinger/reader/mapper/SwitchInputMapper.h b/services/inputflinger/reader/mapper/SwitchInputMapper.h
index 7ec282b721..2fb48bbf25 100644
--- a/services/inputflinger/reader/mapper/SwitchInputMapper.h
+++ b/services/inputflinger/reader/mapper/SwitchInputMapper.h
@@ -22,8 +22,10 @@ namespace android {
class SwitchInputMapper : public InputMapper {
public:
- explicit SwitchInputMapper(InputDeviceContext& deviceContext,
- const InputReaderConfiguration& readerConfig);
+ template <class T, class... Args>
+ friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig,
+ Args... args);
virtual ~SwitchInputMapper();
virtual uint32_t getSources() const override;
@@ -36,6 +38,8 @@ private:
uint32_t mSwitchValues;
uint32_t mUpdatedSwitchMask;
+ explicit SwitchInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
void processSwitch(int32_t switchCode, int32_t switchValue);
[[nodiscard]] std::list<NotifyArgs> sync(nsecs_t when);
};
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 032ea15993..b0f5270a09 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2603,13 +2603,13 @@ protected:
};
TEST_F(SwitchInputMapperTest, GetSources) {
- SwitchInputMapper& mapper = addMapperAndConfigure<SwitchInputMapper>();
+ SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper.getSources());
}
TEST_F(SwitchInputMapperTest, GetSwitchState) {
- SwitchInputMapper& mapper = addMapperAndConfigure<SwitchInputMapper>();
+ SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
mFakeEventHub->setSwitchState(EVENTHUB_ID, SW_LID, 1);
ASSERT_EQ(1, mapper.getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
@@ -2619,7 +2619,7 @@ TEST_F(SwitchInputMapperTest, GetSwitchState) {
}
TEST_F(SwitchInputMapperTest, Process) {
- SwitchInputMapper& mapper = addMapperAndConfigure<SwitchInputMapper>();
+ SwitchInputMapper& mapper = constructAndAddMapper<SwitchInputMapper>();
std::list<NotifyArgs> out;
out = process(mapper, ARBITRARY_TIME, READ_TIME, EV_SW, SW_LID, 1);
ASSERT_TRUE(out.empty());