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

Commit 73fe4819 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Reland: InputDispatcher: Allow all windows to be removed from a display

Previoulsy reverted for b/240320932. No changes.

Previously, if there were no windows reported on a displayId by the
OnWindowInfosChangedListener, InputDispatcher did not remove the
existing windows from that displayId.

Here, we fix the bug so that when OnWindowInfosChangedListener reports
no windows on a display, the windows are removed from the displayId in
dispatcher.

Bug: 239788987
Test: atest inputflinger_tests
Change-Id: I444cf8c510997742e268d51c358ed78fa48a43f9
(cherry picked from commit 814fe08d)
parent 901a5975
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -6330,6 +6330,13 @@ void InputDispatcher::onWindowInfosChanged(const std::vector<WindowInfo>& window

    { // acquire lock
        std::scoped_lock _l(mLock);

        // Ensure that we have an entry created for all existing displays so that if a displayId has
        // no windows, we can tell that the windows were removed from the display.
        for (const auto& [displayId, _] : mWindowHandlesByDisplay) {
            handlesPerDisplay[displayId];
        }

        mDisplayInfos.clear();
        for (const auto& displayInfo : displayInfos) {
            mDisplayInfos.emplace(displayInfo.displayId, displayInfo);
+29 −0
Original line number Diff line number Diff line
@@ -2293,6 +2293,35 @@ TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) {
    thirdWindow->consumeMotionDown();
}

TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) {
    std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
    sp<FakeWindowHandle> window =
            new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT);
    window->setFocusable(true);

    mDispatcher->onWindowInfosChanged({*window->getInfo()}, {});
    setFocusedWindow(window);

    window->consumeFocusEvent(true);

    NotifyKeyArgs keyDown = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
    NotifyKeyArgs keyUp = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
    mDispatcher->notifyKey(&keyDown);
    mDispatcher->notifyKey(&keyUp);

    window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
    window->consumeKeyUp(ADISPLAY_ID_DEFAULT);

    // All windows are removed from the display. Ensure that we can no longer dispatch to it.
    mDispatcher->onWindowInfosChanged({}, {});

    window->consumeFocusEvent(false);

    mDispatcher->notifyKey(&keyDown);
    mDispatcher->notifyKey(&keyUp);
    window->assertNoEvents();
}

/**
 * Ensure the correct coordinate spaces are used by InputDispatcher.
 *