InputMapper refactor: TouchInputMapper
Add a factory method for TouchInputMapper(s) to be configured on
initilisation
Test: m checkinput && atest libinput_tests inputflinger_tests
Bug: 256009910
Change-Id: I738e2947ff98016e00c290365292ab01b04e7d26
diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h
index f017317..06de4c2 100644
--- a/services/inputflinger/reader/mapper/InputMapper.h
+++ b/services/inputflinger/reader/mapper/InputMapper.h
@@ -25,6 +25,20 @@
#include "VibrationElement.h"
namespace android {
+/**
+ * This is the factory method that must be used to create any InputMapper
+ */
+template <class T, class... Args>
+std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig, Args... args) {
+ // Using `new` to access non-public constructors.
+ std::unique_ptr<T> mapper(new T(deviceContext, readerConfig, args...));
+ // We need to reset and configure the mapper to ensure it is ready to process event
+ nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+ std::list<NotifyArgs> unused = mapper->reset(now);
+ unused += mapper->reconfigure(now, readerConfig, /*changes=*/{});
+ return mapper;
+}
/* An input mapper transforms raw input events into cooked event data.
* A single input device can have multiple associated input mappers in order to interpret
@@ -39,8 +53,15 @@
*/
class InputMapper {
public:
- explicit InputMapper(InputDeviceContext& deviceContext,
- const InputReaderConfiguration& readerConfig);
+ /**
+ * Subclasses must either provide a public constructor
+ * or must be-friend the factory method.
+ */
+ template <class T, class... Args>
+ friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig,
+ Args... args);
+
virtual ~InputMapper();
inline int32_t getDeviceId() { return mDeviceContext.getId(); }
@@ -102,6 +123,9 @@
protected:
InputDeviceContext& mDeviceContext;
+ explicit InputMapper(InputDeviceContext& deviceContext,
+ const InputReaderConfiguration& readerConfig);
+
status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
void bumpGeneration();