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

Commit 302fee24 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "InputDispatcher: Fix crash with out-of-order pointer capture requests" into sc-dev

parents 194d5d31 167e6d9e
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1247,9 +1247,10 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked(
        nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry,
        DropReason& dropReason) {
    const bool haveWindowWithPointerCapture = mWindowTokenWithPointerCapture != nullptr;
    if (entry->pointerCaptureEnabled == haveWindowWithPointerCapture) {
        LOG_ALWAYS_FATAL_IF(mFocusedWindowRequestedPointerCapture,
                            "The Pointer Capture state has already been dispatched to the window.");
    if (entry->pointerCaptureEnabled && haveWindowWithPointerCapture) {
        LOG_ALWAYS_FATAL("Pointer Capture has already been enabled for the window.");
    }
    if (!entry->pointerCaptureEnabled && !haveWindowWithPointerCapture) {
        // Pointer capture was already forcefully disabled because of focus change.
        dropReason = DropReason::NOT_DROPPED;
        return;
+23 −0
Original line number Diff line number Diff line
@@ -4217,4 +4217,27 @@ TEST_F(InputDispatcherPointerCaptureTests, UnexpectedStateChangeDisablesPointerC
    mWindow->assertNoEvents();
}

TEST_F(InputDispatcherPointerCaptureTests, OutOfOrderRequests) {
    requestAndVerifyPointerCapture(mWindow, true);

    // The first window loses focus.
    setFocusedWindow(mSecondWindow);
    mFakePolicy->waitForSetPointerCapture(false);
    mWindow->consumeCaptureEvent(false);

    // Request Pointer Capture from the second window before the notification from InputReader
    // arrives.
    mDispatcher->requestPointerCapture(mSecondWindow->getToken(), true);
    mFakePolicy->waitForSetPointerCapture(true);

    // InputReader notifies Pointer Capture was disabled (because of the focus change).
    notifyPointerCaptureChanged(false);

    // InputReader notifies Pointer Capture was enabled (because of mSecondWindow's request).
    notifyPointerCaptureChanged(true);

    mSecondWindow->consumeFocusEvent(true);
    mSecondWindow->consumeCaptureEvent(true);
}

} // namespace android::inputdispatcher