Return a copy of InputDeviceLightInfo instead of pointer
Refactor InputReaderInterface to return a copy instead of pointer. This
will ensure that we don't read from memory that's been freed.
Also, refactor InputDevice api's to return a list of infos instead of
having to query each individually. In all usages so far, there's no need
to get a specific info by type.
Bug: 190126442
Test: atest inputflinger_tests libinput_tests
Change-Id: I7f993a14259bb802e2631663c1c8bb65cc9b6702
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index e91f84e..10c04f6 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -406,9 +406,7 @@
for (auto& devicePair : mDevices) {
std::shared_ptr<InputDevice>& device = devicePair.second;
if (device->getClasses().test(InputDeviceClass::EXTERNAL_STYLUS) && !device->isIgnored()) {
- InputDeviceInfo info;
- device->getDeviceInfo(&info);
- outDevices.push_back(info);
+ outDevices.push_back(device->getDeviceInfo());
}
}
}
@@ -498,9 +496,7 @@
for (const auto& [device, eventHubIds] : mDeviceToEventHubIdsMap) {
if (!device->isIgnored()) {
- InputDeviceInfo info;
- device->getDeviceInfo(&info);
- outInputDevices.push_back(info);
+ outInputDevices.push_back(device->getDeviceInfo());
}
}
return outInputDevices;
@@ -695,28 +691,26 @@
return std::nullopt;
}
-std::vector<int32_t> InputReader::getLightIds(int32_t deviceId) {
+std::vector<InputDeviceLightInfo> InputReader::getLights(int32_t deviceId) {
std::scoped_lock _l(mLock);
InputDevice* device = findInputDeviceLocked(deviceId);
- if (device) {
- InputDeviceInfo info;
- device->getDeviceInfo(&info);
- return info.getLightIds();
+ if (device == nullptr) {
+ return {};
}
- return {};
+
+ return device->getDeviceInfo().getLights();
}
-const InputDeviceLightInfo* InputReader::getLightInfo(int32_t deviceId, int32_t lightId) {
+std::vector<InputDeviceSensorInfo> InputReader::getSensors(int32_t deviceId) {
std::scoped_lock _l(mLock);
InputDevice* device = findInputDeviceLocked(deviceId);
- if (device) {
- InputDeviceInfo info;
- device->getDeviceInfo(&info);
- return info.getLightInfo(lightId);
+ if (device == nullptr) {
+ return {};
}
- return nullptr;
+
+ return device->getDeviceInfo().getSensors();
}
bool InputReader::setLightColor(int32_t deviceId, int32_t lightId, int32_t color) {