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

Commit a66d65e1 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Wait for dispatcher idle before asserting policy callbacks

Before this CL, the policy state was asserted too early. The dispatcher
might not have finished processing the commands yet.

To fix this, force the tests to wait until dispatcher is idle by
providing a dispatcher reference to the assertion function.

Bug: 282837934
Test: atest inputflinger_tests
Change-Id: Ie427071f774d2bfb4b9ebfef94c7971656a69509
parent 3218fc08
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6589,7 +6589,7 @@ void InputDispatcher::monitor() {
 * this method can be safely called from any thread, as long as you've ensured that
 * the work you are interested in completing has already been queued.
 */
bool InputDispatcher::waitForIdle() {
bool InputDispatcher::waitForIdle() const {
    /**
     * Timeout should represent the longest possible time that a device might spend processing
     * events and commands.
+3 −3
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public:

    void dump(std::string& dump) override;
    void monitor() override;
    bool waitForIdle() override;
    bool waitForIdle() const override;
    status_t start() override;
    status_t stop() override;

@@ -169,10 +169,10 @@ private:
    InputDispatcherPolicyInterface& mPolicy;
    android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock);

    std::mutex mLock;
    mutable std::mutex mLock;

    std::condition_variable mDispatcherIsAlive;
    std::condition_variable mDispatcherEnteredIdle;
    mutable std::condition_variable mDispatcherEnteredIdle;

    sp<Looper> mLooper;

+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public:
     * Return true if the dispatcher is idle.
     * Return false if the timeout waiting for the dispatcher to become idle has expired.
     */
    virtual bool waitForIdle() = 0;
    virtual bool waitForIdle() const = 0;

    /* Make the dispatcher start processing events.
     *
+9 −7
Original line number Diff line number Diff line
@@ -383,7 +383,9 @@ public:
        mPointerCaptureRequest.reset();
    }

    void assertDropTargetEquals(const sp<IBinder>& targetToken) {
    void assertDropTargetEquals(const InputDispatcherInterface& dispatcher,
                                const sp<IBinder>& targetToken) {
        dispatcher.waitForIdle();
        std::scoped_lock lock(mLock);
        ASSERT_TRUE(mNotifyDropWindowWasCalled);
        ASSERT_EQ(targetToken, mDropTargetWindowToken);
@@ -8446,7 +8448,7 @@ TEST_F(InputDispatcherDragTests, DragAndDrop) {
                             {150, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
    mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken());
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
}
@@ -8477,7 +8479,7 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) {
    mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
    mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
    mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken());

    // nothing to the window.
    ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
@@ -8523,7 +8525,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropOnInvalidWindow) {
                             {150, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(nullptr);
    mFakePolicy->assertDropTargetEquals(*mDispatcher, nullptr);
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
}
@@ -8606,7 +8608,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenSplitTouch) {
              injectMotionEvent(mDispatcher, secondFingerUpEvent, INJECT_EVENT_TIMEOUT,
                                InputEventInjectionSync::WAIT_FOR_RESULT));
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(mWindow->getToken());
    mFakePolicy->assertDropTargetEquals(*mDispatcher, mWindow->getToken());
    mWindow->assertNoEvents();
    mSecondWindow->consumeMotionMove();
}
@@ -8656,7 +8658,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) {
                             {150, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
    mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken());
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
}
@@ -8705,7 +8707,7 @@ TEST_F(InputDispatcherDragTests, MouseDragAndDrop) {
                                        .build()))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(mSecondWindow->getToken());
    mFakePolicy->assertDropTargetEquals(*mDispatcher, mSecondWindow->getToken());
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
}