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

Commit 5c85e059 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputDispatcher: Assert that all spy windows are trusted overlays

Bug: 162194035
Test: atest inputflinger_tests
Change-Id: I6491a08ff4403db685562a37694d37e0f51581f6
parent d65552bb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4718,6 +4718,11 @@ void InputDispatcher::setInputWindowsLocked(
            window->releaseChannel();
        }

        // Ensure all spy windows are trusted overlays
        LOG_ALWAYS_FATAL_IF(info.isSpy() && !info.trustedOverlay,
                            "%s has feature SPY, but is not a trusted overlay.",
                            window->getName().c_str());

        // Ensure all stylus interceptors are trusted overlays
        LOG_ALWAYS_FATAL_IF(info.interceptsStylus() && !info.trustedOverlay,
                            "%s has feature INTERCEPTS_STYLUS, but is not a trusted overlay.",
+11 −22
Original line number Diff line number Diff line
@@ -6300,6 +6300,7 @@ public:
        sp<FakeWindowHandle> spy =
                new FakeWindowHandle(application, mDispatcher, name.c_str(), ADISPLAY_ID_DEFAULT);
        spy->setInputFeatures(WindowInfo::Feature::SPY);
        spy->setTrustedOverlay(true);
        spy->addFlags(flags);
        return spy;
    }
@@ -6317,6 +6318,16 @@ private:
    int mSpyCount{0};
};

/**
 * Adding a spy window that is not a trusted overlay causes Dispatcher to abort.
 */
TEST_F(InputDispatcherSpyWindowTest, UntrustedSpy_AbortsDispatcher) {
    auto spy = createSpy(WindowInfo::Flag::NOT_TOUCH_MODAL);
    spy->setTrustedOverlay(false);
    ASSERT_DEATH(mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spy}}}),
                 ".* not a trusted overlay");
}

/**
 * Input injection into a display with a spy window but no foreground windows should succeed.
 */
@@ -6476,28 +6487,6 @@ TEST_F(InputDispatcherSpyWindowTest, WatchOutsideTouches) {
    spy->consumeMotionOutside();
}

/**
 * When configured to block untrusted touches, events will not be dispatched to windows below a spy
 * window if it is not a trusted overly.
 */
TEST_F(InputDispatcherSpyWindowTest, BlockUntrustedTouches) {
    mDispatcher->setBlockUntrustedTouchesMode(android::os::BlockUntrustedTouchesMode::BLOCK);

    auto window = createForeground();
    auto spy = createSpy(WindowInfo::Flag::NOT_TOUCH_MODAL);
    window->setOwnerInfo(111, 111);
    spy->setOwnerInfo(222, 222);
    spy->setTouchOcclusionMode(TouchOcclusionMode::BLOCK_UNTRUSTED);
    mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spy, window}}});

    // Inject an event outside the spy window's frame and touchable region.
    ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
              injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    spy->consumeMotionDown();
    window->assertNoEvents();
}

/**
 * A spy window can pilfer pointers. When this happens, touch gestures that are currently sent to
 * any other windows - including other spy windows - will also be cancelled.