Return a std::optional from EventHub::getAbsoluteAxisInfo
InputDevice::getAbsoluteAxisInfo will be refactored similarly in a
follow-up.
Test: atest inputflinger_tests
Test: m checkinput
Test: build and run inputflinger_multitouch_input_fuzzer for a while
Bug: 245989146
Flag: EXEMPT refactor
Change-Id: I57de645c889de53c8be0f9f8744a62e92fafdadb
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index fe70a51..7052c61 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -998,26 +998,23 @@
return *device->configuration;
}
-status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
- RawAbsoluteAxisInfo* outAxisInfo) const {
- outAxisInfo->clear();
+std::optional<RawAbsoluteAxisInfo> EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis) const {
if (axis < 0 || axis > ABS_MAX) {
- return NAME_NOT_FOUND;
+ return std::nullopt;
}
std::scoped_lock _l(mLock);
const Device* device = getDeviceLocked(deviceId);
if (device == nullptr) {
- return NAME_NOT_FOUND;
+ return std::nullopt;
}
// We can read the RawAbsoluteAxisInfo even if the device is disabled and doesn't have a valid
// fd, because the info is populated once when the device is first opened, and it doesn't change
// throughout the device lifecycle.
auto it = device->absState.find(axis);
if (it == device->absState.end()) {
- return NAME_NOT_FOUND;
+ return std::nullopt;
}
- *outAxisInfo = it->second.info;
- return OK;
+ return it->second.info;
}
bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const {