Return std::optional from getAbsoluteAxisValue
This makes the methods nicer to use, and forces callers to clearly
handle the case where there's no value to return.
Test: m checkinput
Test: atest inputflinger_tests
Test: build and run inputflinger_multitouch_input_fuzzer for a while
Bug: 245989146
Flag: EXEMPT refactor
Change-Id: I51c750d21d8a95ef631d93365ee76d18ebf71d43
diff --git a/services/inputflinger/tests/FakeEventHub.cpp b/services/inputflinger/tests/FakeEventHub.cpp
index 1e9be0e..12736c8 100644
--- a/services/inputflinger/tests/FakeEventHub.cpp
+++ b/services/inputflinger/tests/FakeEventHub.cpp
@@ -417,18 +417,15 @@
return AKEY_STATE_UNKNOWN;
}
-status_t FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
- int32_t* outValue) const {
+std::optional<int32_t> FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis) const {
Device* device = getDevice(deviceId);
if (device) {
ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
if (index >= 0) {
- *outValue = device->absoluteAxisValue.valueAt(index);
- return OK;
+ return device->absoluteAxisValue.valueAt(index);
}
}
- *outValue = 0;
- return -1;
+ return std::nullopt;
}
void FakeEventHub::setMtSlotValues(int32_t deviceId, int32_t axis,