Create Native getTouchpadHardwareProperties()
Create Native method to get the hardware properties of touchpad and
connected it to InputManagerService.java using JNI
Bug: 286551975
Test: Verified that the data flow works correctly and the method references are valid.
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: Ic6c32eabd3078ff2b50e3b3bb430abadd9dd752c
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index 42a03c1..2f9d658 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -35,6 +35,7 @@
#include "PointerControllerInterface.h"
#include "VibrationElement.h"
+#include "include/gestures.h"
// Maximum supported size of a vibration pattern.
// Must be at least 2.
@@ -363,6 +364,8 @@
virtual std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) = 0;
+ virtual std::optional<HardwareProperties> getTouchpadHardwareProperties(int32_t deviceId) = 0;
+
/* Return true if the device can send input events to the specified display. */
virtual bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) = 0;
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 2daf195..70f024e 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -725,6 +725,15 @@
return count;
}
+std::optional<HardwareProperties> InputDevice::getTouchpadHardwareProperties() {
+ std::optional<HardwareProperties> result = first_in_mappers<HardwareProperties>(
+ [](InputMapper& mapper) -> std::optional<HardwareProperties> {
+ return mapper.getTouchpadHardwareProperties();
+ });
+
+ return result;
+}
+
void InputDevice::updateLedState(bool reset) {
for_each_mapper([reset](InputMapper& mapper) { mapper.updateLedState(reset); });
}
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index f0e53b5..a5b1249 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -33,6 +33,7 @@
#include <utils/Thread.h>
#include "InputDevice.h"
+#include "include/gestures.h"
using android::base::StringPrintf;
@@ -817,6 +818,18 @@
return device->getDeviceInfo().getSensors();
}
+std::optional<HardwareProperties> InputReader::getTouchpadHardwareProperties(int32_t deviceId) {
+ std::scoped_lock _l(mLock);
+
+ InputDevice* device = findInputDeviceLocked(deviceId);
+
+ if (device == nullptr) {
+ return {};
+ }
+
+ return device->getTouchpadHardwareProperties();
+}
+
bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) {
std::scoped_lock _l(mLock);
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 93785f6..021978d 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -141,6 +141,8 @@
size_t getMapperCount();
+ std::optional<HardwareProperties> getTouchpadHardwareProperties();
+
// construct and add a mapper to the input device
template <class T, typename... Args>
T& addMapper(int32_t eventHubId, Args... args) {
diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h
index 4f60a8a..2cc0a00 100644
--- a/services/inputflinger/reader/include/InputReader.h
+++ b/services/inputflinger/reader/include/InputReader.h
@@ -104,6 +104,8 @@
std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) override;
+ std::optional<HardwareProperties> getTouchpadHardwareProperties(int32_t deviceId) override;
+
bool setLightColor(int32_t deviceId, int32_t lightId, int32_t color) override;
bool setLightPlayerId(int32_t deviceId, int32_t lightId, int32_t playerId) override;
diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp
index c44c48c..627df7f 100644
--- a/services/inputflinger/reader/mapper/InputMapper.cpp
+++ b/services/inputflinger/reader/mapper/InputMapper.cpp
@@ -140,4 +140,7 @@
dump += StringPrintf(INDENT4 "Tool Type: %s\n", ftl::enum_string(state.toolType).c_str());
}
+std::optional<HardwareProperties> InputMapper::getTouchpadHardwareProperties() {
+ return std::nullopt;
+}
} // namespace android
diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h
index e5afcc7..75cc4bb 100644
--- a/services/inputflinger/reader/mapper/InputMapper.h
+++ b/services/inputflinger/reader/mapper/InputMapper.h
@@ -122,6 +122,8 @@
virtual std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() { return std::nullopt; }
virtual void updateLedState(bool reset) {}
+ virtual std::optional<HardwareProperties> getTouchpadHardwareProperties();
+
protected:
InputDeviceContext& mDeviceContext;
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
index 5c5fd3f..7931613 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp
@@ -251,7 +251,8 @@
}
mGestureInterpreter->Initialize(GESTURES_DEVCLASS_TOUCHPAD);
- mGestureInterpreter->SetHardwareProperties(createHardwareProperties(deviceContext));
+ mHardwareProperties = createHardwareProperties(deviceContext);
+ mGestureInterpreter->SetHardwareProperties(mHardwareProperties);
// Even though we don't explicitly delete copy/move semantics, it's safe to
// give away pointers to TouchpadInputMapper and its members here because
// 1) mGestureInterpreter's lifecycle is determined by TouchpadInputMapper, and
@@ -493,4 +494,8 @@
return mDisplayId;
}
+std::optional<HardwareProperties> TouchpadInputMapper::getTouchpadHardwareProperties() {
+ return mHardwareProperties;
+}
+
} // namespace android
diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
index 8baa63e..8bfc159 100644
--- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h
@@ -68,6 +68,8 @@
std::optional<ui::LogicalDisplayId> getAssociatedDisplayId() override;
+ std::optional<HardwareProperties> getTouchpadHardwareProperties() override;
+
private:
void resetGestureInterpreter(nsecs_t when);
explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
@@ -92,6 +94,7 @@
HardwareStateConverter mStateConverter;
GestureConverter mGestureConverter;
CapturedTouchpadEventConverter mCapturedEventConverter;
+ HardwareProperties mHardwareProperties;
bool mPointerCaptured = false;
bool mResettingInterpreter = false;
diff --git a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
index d552c19..3e4a19b 100644
--- a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp
@@ -117,6 +117,10 @@
return reader->getSensors(deviceId);
}
+ std::optional<HardwareProperties> getTouchpadHardwareProperties(int32_t deviceId) {
+ return reader->getTouchpadHardwareProperties(deviceId);
+ }
+
bool canDispatchToDisplay(int32_t deviceId, ui::LogicalDisplayId displayId) {
return reader->canDispatchToDisplay(deviceId, displayId);
}