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

Commit 59403a8c authored by Nergi Rahardi's avatar Nergi Rahardi
Browse files

[DnD] Update handleMotionEvent to accept displayId

This is used to prepare connected displays dnd work.
go/connected-displays-dnd.

Bug: 365512241
Test: atest WmTests:DragDropControllerTests
Flag: EXEMPT no behavior change
Change-Id: I5f000734cb2a15e2291b6b5aa982485415b4f4f3
parent e42b9e7c
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -289,7 +289,8 @@ class DragDropController {
                transaction.setAlpha(surfaceControl, mDragState.mOriginalAlpha);
                transaction.show(surfaceControl);
                displayContent.reparentToOverlay(transaction, surfaceControl);
                mDragState.updateDragSurfaceLocked(true, touchX, touchY);
                mDragState.updateDragSurfaceLocked(true /* keepHandling */,
                        displayContent.getDisplayId(), touchX, touchY);
                if (SHOW_LIGHT_TRANSACTIONS) {
                    Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
                }
@@ -483,10 +484,11 @@ class DragDropController {
     * Handles motion events.
     * @param keepHandling Whether if the drag operation is continuing or this is the last motion
     *          event.
     * @param displayId id of the display the X,Y coordinate is n.
     * @param newX X coordinate value in dp in the screen coordinate
     * @param newY Y coordinate value in dp in the screen coordinate
     */
    void handleMotionEvent(boolean keepHandling, float newX, float newY) {
    void handleMotionEvent(boolean keepHandling, int displayId, float newX, float newY) {
        synchronized (mService.mGlobalLock) {
            if (!dragDropActiveLocked()) {
                // The drag has ended but the clean-up message has not been processed by
@@ -495,7 +497,7 @@ class DragDropController {
                return;
            }

            mDragState.updateDragSurfaceLocked(keepHandling, newX, newY);
            mDragState.updateDragSurfaceLocked(keepHandling, displayId, newX, newY);
        }
    }

+4 −2
Original line number Diff line number Diff line
@@ -22,13 +22,13 @@ import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.MotionEvent.BUTTON_STYLUS_PRIMARY;

import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.os.Looper;
import android.util.Slog;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputEvent;
import android.view.InputEventReceiver;
import android.view.MotionEvent;
@@ -63,6 +63,7 @@ class DragInputEventReceiver extends InputEventReceiver {
                return;
            }
            final MotionEvent motionEvent = (MotionEvent) event;
            final int displayId = motionEvent.getDisplayId();
            final float newX = motionEvent.getRawX();
            final float newY = motionEvent.getRawY();
            final boolean isStylusButtonDown =
@@ -102,7 +103,8 @@ class DragInputEventReceiver extends InputEventReceiver {
                    return;
            }

            mDragDropController.handleMotionEvent(!mMuteInput /* keepHandling */, newX, newY);
            mDragDropController.handleMotionEvent(!mMuteInput /* keepHandling */, displayId, newX,
                    newY);
            handled = true;
        } catch (Exception e) {
            Slog.e(TAG_WM, "Exception caught by drag handleMotion", e);
+16 −6
Original line number Diff line number Diff line
@@ -685,12 +685,21 @@ class DragState {
        mAnimator = createCancelAnimationLocked();
    }

    void updateDragSurfaceLocked(boolean keepHandling, float x, float y) {
    /**
     * Updates the position of the drag surface.
     *
     * @param keepHandling whether to keep handling the drag.
     * @param displayId the display ID of the drag surface.
     * @param displayX the x-coordinate of the drag surface in the display's coordinate frame.
     * @param displayY the y-coordinate of the drag surface in the display's coordinate frame.
     */
    void updateDragSurfaceLocked(boolean keepHandling, int displayId, float displayX,
            float displayY) {
        if (mAnimator != null) {
            return;
        }
        mCurrentX = x;
        mCurrentY = y;
        mCurrentX = displayX;
        mCurrentY = displayY;

        if (!keepHandling) {
            return;
@@ -700,9 +709,10 @@ class DragState {
        if (SHOW_LIGHT_TRANSACTIONS) {
            Slog.i(TAG_WM, ">>> OPEN TRANSACTION notifyMoveLocked");
        }
        mTransaction.setPosition(mSurfaceControl, x - mThumbOffsetX, y - mThumbOffsetY).apply();
        ProtoLog.i(WM_SHOW_TRANSACTIONS, "DRAG %s: pos=(%d,%d)", mSurfaceControl,
                (int) (x - mThumbOffsetX), (int) (y - mThumbOffsetY));
        mTransaction.setPosition(mSurfaceControl, displayX - mThumbOffsetX,
                displayY - mThumbOffsetY).apply();
        ProtoLog.i(WM_SHOW_TRANSACTIONS, "DRAG %s: displayId=%d, pos=(%d,%d)", mSurfaceControl,
                displayId, (int) (displayX - mThumbOffsetX), (int) (displayY - mThumbOffsetY));
    }

    /**
+18 −13
Original line number Diff line number Diff line
@@ -150,8 +150,8 @@ public class DragDropControllerTests extends WindowTestsBase {
                mProcess).build();

        // Use a new TestIWindow so we don't collect events for other windows
        final WindowState window = createWindow(null, TYPE_BASE_APPLICATION, activity, name,
                ownerId, false, new TestIWindow());
        final WindowState window = newWindowBuilder(name, TYPE_BASE_APPLICATION).setWindowToken(
                activity).setOwnerId(ownerId).setClientWindow(new TestIWindow()).build();
        InputChannel channel = new InputChannel();
        window.openInputChannel(channel);
        window.mHasSurface = true;
@@ -249,7 +249,7 @@ public class DragDropControllerTests extends WindowTestsBase {
                        mTarget.mDeferDragStateClosed = true;
                        mTarget.reportDropWindow(mWindow.mInputChannelToken, 0, 0);
                        // Verify the drop event includes the drag surface
                        mTarget.handleMotionEvent(false, 0, 0);
                        mTarget.handleMotionEvent(false, mWindow.getDisplayId(), 0, 0);
                        final DragEvent dropEvent = dragEvents.get(dragEvents.size() - 1);
                        assertTrue(dropEvent.getDragSurface() != null);

@@ -296,7 +296,7 @@ public class DragDropControllerTests extends WindowTestsBase {
                            0).getClipData().willParcelWithActivityInfo());

                    mTarget.reportDropWindow(globalInterceptWindow.mInputChannelToken, 0, 0);
                    mTarget.handleMotionEvent(false, 0, 0);
                    mTarget.handleMotionEvent(false, globalInterceptWindow.getDisplayId(), 0, 0);
                    mToken = globalInterceptWindow.mClient.asBinder();

                    // Verify the drop event is only sent for the global intercept window
@@ -334,8 +334,8 @@ public class DragDropControllerTests extends WindowTestsBase {
                    try {
                        mTarget.mDeferDragStateClosed = true;
                        mTarget.reportDropWindow(mWindow.mInputChannelToken, 0, 0);
                        // // Verify the drop event does not have the drag flags
                        mTarget.handleMotionEvent(false, 0, 0);
                        // Verify the drop event does not have the drag flags
                        mTarget.handleMotionEvent(false, mWindow.getDisplayId(), 0, 0);
                        final DragEvent dropEvent = dragEvents.get(dragEvents.size() - 1);
                        assertTrue(dropEvent.getDragFlags() == (View.DRAG_FLAG_GLOBAL
                                | View.DRAG_FLAG_START_INTENT_SENDER_ON_UNHANDLED_DRAG));
@@ -520,7 +520,7 @@ public class DragDropControllerTests extends WindowTestsBase {

                    // Verify after consuming that the drag surface is relinquished
                    mTarget.reportDropWindow(otherWindow.mInputChannelToken, 0, 0);
                    mTarget.handleMotionEvent(false, 0, 0);
                    mTarget.handleMotionEvent(false, otherWindow.getDisplayId(), 0, 0);
                    mToken = otherWindow.mClient.asBinder();
                    mTarget.reportDropResult(otherIWindow, true);

@@ -551,7 +551,7 @@ public class DragDropControllerTests extends WindowTestsBase {

                    // Verify after consuming that the drag surface is relinquished
                    mTarget.reportDropWindow(otherWindow.mInputChannelToken, 0, 0);
                    mTarget.handleMotionEvent(false, 0, 0);
                    mTarget.handleMotionEvent(false, otherWindow.getDisplayId(), 0, 0);
                    mToken = otherWindow.mClient.asBinder();
                    mTarget.reportDropResult(otherIWindow, false);

@@ -586,7 +586,8 @@ public class DragDropControllerTests extends WindowTestsBase {
                ClipData.newPlainText("label", "Test"), () -> {
                    // Trigger an unhandled drop and verify the global drag listener was called
                    mTarget.reportDropWindow(mWindow.mInputChannelToken, invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */, invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */, mWindow.getDisplayId(),
                            invalidXY, invalidXY);
                    mTarget.reportDropResult(mWindow.mClient, false);
                    mTarget.onUnhandledDropCallback(true);
                    mToken = null;
@@ -610,7 +611,8 @@ public class DragDropControllerTests extends WindowTestsBase {
                ClipData.newPlainText("label", "Test"), () -> {
                    // Trigger an unhandled drop and verify the global drag listener was called
                    mTarget.reportDropWindow(mock(IBinder.class), invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */, invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */, mWindow.getDisplayId(),
                            invalidXY, invalidXY);
                    mTarget.onUnhandledDropCallback(true);
                    mToken = null;
                    try {
@@ -632,7 +634,8 @@ public class DragDropControllerTests extends WindowTestsBase {
        startDrag(View.DRAG_FLAG_GLOBAL, ClipData.newPlainText("label", "Test"), () -> {
            // Trigger an unhandled drop and verify the global drag listener was not called
            mTarget.reportDropWindow(mock(IBinder.class), invalidXY, invalidXY);
            mTarget.handleMotionEvent(false /* keepHandling */, invalidXY, invalidXY);
            mTarget.handleMotionEvent(false /* keepHandling */, mDisplayContent.getDisplayId(),
                    invalidXY, invalidXY);
            mToken = null;
            try {
                verify(listener, never()).onUnhandledDrop(any(), any());
@@ -654,7 +657,8 @@ public class DragDropControllerTests extends WindowTestsBase {
                ClipData.newPlainText("label", "Test"), () -> {
                    // Trigger an unhandled drop and verify the global drag listener was called
                    mTarget.reportDropWindow(mock(IBinder.class), invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */, invalidXY, invalidXY);
                    mTarget.handleMotionEvent(false /* keepHandling */,
                            mDisplayContent.getDisplayId(), invalidXY, invalidXY);

                    // Verify that the unhandled drop listener callback timeout has been scheduled
                    final Handler handler = mTarget.getHandler();
@@ -673,7 +677,8 @@ public class DragDropControllerTests extends WindowTestsBase {
    private void doDragAndDrop(int flags, ClipData data, float dropX, float dropY) {
        startDrag(flags, data, () -> {
            mTarget.reportDropWindow(mWindow.mInputChannelToken, dropX, dropY);
            mTarget.handleMotionEvent(false /* keepHandling */, dropX, dropY);
            mTarget.handleMotionEvent(false /* keepHandling */, mWindow.getDisplayId(), dropX,
                    dropY);
            mToken = mWindow.mClient.asBinder();
        });
    }