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

Commit b77d4f5f authored by Arthur Hung's avatar Arthur Hung Committed by Automerger Merge Worker
Browse files

Merge "Fix the drag window still alive after drop failed" into sc-dev am: 286c7f2a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14141266

Change-Id: Ic032979ef95230aaca3c7024b413541ee2d55467
parents 90ac11f4 286c7f2a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2326,6 +2326,8 @@ void InputDispatcher::finishDragAndDrop(int32_t displayId, float x, float y) {
    if (dropWindow) {
        vec2 local = dropWindow->getInfo()->transform.transform(x, y);
        notifyDropWindowLocked(dropWindow->getToken(), local.x, local.y);
    } else {
        notifyDropWindowLocked(nullptr, 0, 0);
    }
    mDragState.reset();
}
@@ -2372,6 +2374,7 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) {
    } else if (maskedAction == AMOTION_EVENT_ACTION_UP) {
        finishDragAndDrop(entry.displayId, x, y);
    } else if (maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
        notifyDropWindowLocked(nullptr, 0, 0);
        mDragState.reset();
    }
}
+40 −0
Original line number Diff line number Diff line
@@ -268,7 +268,9 @@ public:

    void assertDropTargetEquals(const sp<IBinder>& targetToken) {
        std::scoped_lock lock(mLock);
        ASSERT_TRUE(mNotifyDropWindowWasCalled);
        ASSERT_EQ(targetToken, mDropTargetWindowToken);
        mNotifyDropWindowWasCalled = false;
    }

private:
@@ -290,6 +292,7 @@ private:
    std::condition_variable mNotifyAnr;

    sp<IBinder> mDropTargetWindowToken GUARDED_BY(mLock);
    bool mNotifyDropWindowWasCalled GUARDED_BY(mLock) = false;

    void notifyConfigurationChanged(nsecs_t when) override {
        std::scoped_lock lock(mLock);
@@ -403,6 +406,7 @@ private:

    void notifyDropWindow(const sp<IBinder>& token, float x, float y) override {
        std::scoped_lock lock(mLock);
        mNotifyDropWindowWasCalled = true;
        mDropTargetWindowToken = token;
    }

@@ -4951,4 +4955,40 @@ TEST_F(InputDispatcherDragTests, StylusDragAndDrop) {
    mSecondWindow->assertNoEvents();
}

TEST_F(InputDispatcherDragTests, DragAndDrop_InvalidWindow) {
    performDrag();

    // Set second window invisible.
    mSecondWindow->setVisible(false);
    mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mDragWindow, mWindow, mSecondWindow}}});

    // Move on window.
    ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
              injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
                                ADISPLAY_ID_DEFAULT, {50, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
    mWindow->consumeDragEvent(false, 50, 50);
    mSecondWindow->assertNoEvents();

    // Move to another window.
    ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
              injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
                                ADISPLAY_ID_DEFAULT, {150, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT);
    mWindow->consumeDragEvent(true, 150, 50);
    mSecondWindow->assertNoEvents();

    // drop to another window.
    ASSERT_EQ(InputEventInjectionResult::SUCCEEDED,
              injectMotionUp(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
                             {150, 50}))
            << "Inject motion event should return InputEventInjectionResult::SUCCEEDED";
    mDragWindow->consumeMotionUp(ADISPLAY_ID_DEFAULT);
    mFakePolicy->assertDropTargetEquals(nullptr);
    mWindow->assertNoEvents();
    mSecondWindow->assertNoEvents();
}

} // namespace android::inputdispatcher