Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8619eb31 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent 43736725
Loading
Loading
Loading
Loading
+10 −13
Original line number Original line Diff line number Diff line
@@ -1761,10 +1761,8 @@ bool InputDispatcher::dispatchMotionLocked(nsecs_t currentTime, std::shared_ptr<
        inputTargets =
        inputTargets =
                findTouchedWindowTargetsLocked(currentTime, *entry, &conflictingPointerActions,
                findTouchedWindowTargetsLocked(currentTime, *entry, &conflictingPointerActions,
                                               /*byref*/ injectionResult);
                                               /*byref*/ injectionResult);
        if (injectionResult != InputEventInjectionResult::SUCCEEDED) {
        LOG_ALWAYS_FATAL_IF(injectionResult != InputEventInjectionResult::SUCCEEDED &&
            // No events should be dispatched if the injection didn't succeed
                            !inputTargets.empty());
            inputTargets = {};
        }
    } else {
    } else {
        // Non touch event.  (eg. trackball)
        // Non touch event.  (eg. trackball)
        sp<WindowInfoHandle> focusedWindow =
        sp<WindowInfoHandle> focusedWindow =
@@ -2184,7 +2182,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
                  displayId);
                  displayId);
            // TODO: test multiple simultaneous input streams.
            // TODO: test multiple simultaneous input streams.
            outInjectionResult = InputEventInjectionResult::FAILED;
            outInjectionResult = InputEventInjectionResult::FAILED;
            return targets; // wrong device
            return {}; // wrong device
        }
        }
        tempTouchState.clearWindowsWithoutPointers();
        tempTouchState.clearWindowsWithoutPointers();
        tempTouchState.deviceId = entry.deviceId;
        tempTouchState.deviceId = entry.deviceId;
@@ -2196,7 +2194,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
              displayId);
              displayId);
        // TODO: test multiple simultaneous input streams.
        // TODO: test multiple simultaneous input streams.
        outInjectionResult = InputEventInjectionResult::FAILED;
        outInjectionResult = InputEventInjectionResult::FAILED;
        return targets; // wrong device
        return {}; // wrong device
    }
    }


    if (isHoverAction) {
    if (isHoverAction) {
@@ -2231,7 +2229,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            ALOGW("Dropping injected touch event: %s", (*err).c_str());
            ALOGW("Dropping injected touch event: %s", (*err).c_str());
            outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
            outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
            newTouchedWindowHandle = nullptr;
            newTouchedWindowHandle = nullptr;
            goto Failed;
            return {};
        }
        }


        // Figure out whether splitting will be allowed for this window.
        // Figure out whether splitting will be allowed for this window.
@@ -2262,7 +2260,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            ALOGI("Dropping event because there is no touchable window at (%d, %d) on display %d.",
            ALOGI("Dropping event because there is no touchable window at (%d, %d) on display %d.",
                  x, y, displayId);
                  x, y, displayId);
            outInjectionResult = InputEventInjectionResult::FAILED;
            outInjectionResult = InputEventInjectionResult::FAILED;
            goto Failed;
            return {};
        }
        }


        for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
        for (const sp<WindowInfoHandle>& windowHandle : newTouchedWindows) {
@@ -2353,7 +2351,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
                     "dropped the pointer down event in display %" PRId32 ": %s",
                     "dropped the pointer down event in display %" PRId32 ": %s",
                     displayId, entry.getDescription().c_str());
                     displayId, entry.getDescription().c_str());
            outInjectionResult = InputEventInjectionResult::FAILED;
            outInjectionResult = InputEventInjectionResult::FAILED;
            goto Failed;
            return {};
        }
        }


        addDragEventLocked(entry);
        addDragEventLocked(entry);
@@ -2371,7 +2369,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
            if (const auto err = verifyTargetedInjection(newTouchedWindowHandle, entry); err) {
                ALOGW("Dropping injected event: %s", (*err).c_str());
                ALOGW("Dropping injected event: %s", (*err).c_str());
                outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
                outInjectionResult = os::InputEventInjectionResult::TARGET_MISMATCH;
                goto Failed;
                return {};
            }
            }


            // Drop touch events if requested by input feature
            // Drop touch events if requested by input feature
@@ -2465,7 +2463,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
        ALOGI("Dropping event because there is no touched window on display %d to receive it: %s",
        ALOGI("Dropping event because there is no touched window on display %d to receive it: %s",
              displayId, entry.getDescription().c_str());
              displayId, entry.getDescription().c_str());
        outInjectionResult = InputEventInjectionResult::FAILED;
        outInjectionResult = InputEventInjectionResult::FAILED;
        goto Failed;
        return {};
    }
    }


    // Ensure that all touched windows are valid for injection.
    // Ensure that all touched windows are valid for injection.
@@ -2485,7 +2483,7 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
                  "%d:%s",
                  "%d:%s",
                  *entry.injectionState->targetUid, errs.c_str());
                  *entry.injectionState->targetUid, errs.c_str());
            outInjectionResult = InputEventInjectionResult::TARGET_MISMATCH;
            outInjectionResult = InputEventInjectionResult::TARGET_MISMATCH;
            goto Failed;
            return {};
        }
        }
    }
    }


@@ -2521,7 +2519,6 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
    // in the next iteration.
    // in the next iteration.
    tempTouchState.filterNonAsIsTouchWindows();
    tempTouchState.filterNonAsIsTouchWindows();


Failed:
    // Update final pieces of touch state if the injector had permission.
    // Update final pieces of touch state if the injector had permission.
    if (switchedDevice) {
    if (switchedDevice) {
        if (DEBUG_FOCUS) {
        if (DEBUG_FOCUS) {