Remove goto from InputDispatcher
The goto instructions inside findTouchedWindowTargetsLocked have made it
very difficult to reason about this function.
Remove the goto statements in this CL.
Bug: 211379801
Test: m inputflinger_tests && $ANDROID_HOST_OUT/nativetest64/inputflinger_tests/inputflinger_tests
Change-Id: I9d645cefe6cd8d9a9a0816f36efd7a024a0447a7
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 7974b2c..dc9f02a 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -1761,10 +1761,8 @@
inputTargets =
findTouchedWindowTargetsLocked(currentTime, *entry, &conflictingPointerActions,
/*byref*/ injectionResult);
- if (injectionResult != InputEventInjectionResult::SUCCEEDED) {
- // No events should be dispatched if the injection didn't succeed
- inputTargets = {};
- }
+ LOG_ALWAYS_FATAL_IF(injectionResult != InputEventInjectionResult::SUCCEEDED &&
+ !inputTargets.empty());
} else {
// Non touch event. (eg. trackball)
sp<WindowInfoHandle> focusedWindow =
@@ -2184,7 +2182,7 @@
displayId);
// TODO: test multiple simultaneous input streams.
outInjectionResult = InputEventInjectionResult::FAILED;
- return targets; // wrong device
+ return {}; // wrong device
}
tempTouchState.clearWindowsWithoutPointers();
tempTouchState.deviceId = entry.deviceId;
@@ -2196,7 +2194,7 @@
displayId);
// TODO: test multiple simultaneous input streams.
outInjectionResult = InputEventInjectionResult::FAILED;
- return targets; // wrong device
+ return {}; // wrong device
}
if (isHoverAction) {
@@ -2231,7 +2229,7 @@
ALOGW("Dropping injected touch event: %s", (*err).c_str());
outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
newTouchedWindowHandle = nullptr;
- goto Failed;
+ return {};
}
// Figure out whether splitting will be allowed for this window.
@@ -2262,7 +2260,7 @@
ALOGI("Dropping event because there is no touchable window at (%d, %d) on display %d.",
x, y, displayId);
outInjectionResult = InputEventInjectionResult::FAILED;
- goto Failed;
+ return {};
}
for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
@@ -2353,7 +2351,7 @@
"dropped the pointer down event in display %" PRId32 ": %s",
displayId, entry.getDescription().c_str());
outInjectionResult = InputEventInjectionResult::FAILED;
- goto Failed;
+ return {};
}
addDragEventLocked(entry);
@@ -2371,7 +2369,7 @@
if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
ALOGW("Dropping injected event: %s", (*err).c_str());
outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
- goto Failed;
+ return {};
}
// Drop touch events if requested by input feature
@@ -2465,7 +2463,7 @@
ALOGI("Dropping event because there is no touched window on display %d to receive it: %s",
displayId, entry.getDescription().c_str());
outInjectionResult = InputEventInjectionResult::FAILED;
- goto Failed;
+ return {};
}
// Ensure that all touched windows are valid for injection.
@@ -2485,7 +2483,7 @@
"%d:%s",
*entry.injectionState->targetUid, errs.c_str());
outInjectionResult = InputEventInjectionResult::TARGET_MISMATCH;
- goto Failed;
+ return {};
}
}
@@ -2521,7 +2519,6 @@
// in the next iteration.
tempTouchState.filterNonAsIsTouchWindows();
-Failed:
// Update final pieces of touch state if the injector had permission.
if (switchedDevice) {
if (DEBUG_FOCUS) {