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

Commit a5bd2ed7 authored by Nergi Rahardi's avatar Nergi Rahardi Committed by Android (Google) Code Review
Browse files

Merge "[DnD] Pass displayId to DragEvent" into main

parents 7e678dcb 82146561
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -156,6 +156,11 @@ public class DragEvent implements Parcelable {
    private float mOffsetX;
    private float mOffsetY;

    /**
     * The id of the display where the `mX` and `mY` of this event belongs to.
     */
    private int mDisplayId;

    /**
     * The View#DRAG_FLAG_* flags used to start the current drag, only provided if the target window
     * has the {@link WindowManager.LayoutParams#PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP} flag
@@ -297,14 +302,15 @@ public class DragEvent implements Parcelable {
    private DragEvent() {
    }

    private void init(int action, float x, float y, float offsetX, float offsetY, int flags,
            ClipDescription description, ClipData data, SurfaceControl dragSurface,
    private void init(int action, float x, float y, float offsetX, float offsetY, int displayId,
            int flags, ClipDescription description, ClipData data, SurfaceControl dragSurface,
            IDragAndDropPermissions dragAndDropPermissions, Object localState, boolean result) {
        mAction = action;
        mX = x;
        mY = y;
        mOffsetX = offsetX;
        mOffsetY = offsetY;
        mDisplayId = displayId;
        mFlags = flags;
        mClipDescription = description;
        mClipData = data;
@@ -315,20 +321,20 @@ public class DragEvent implements Parcelable {
    }

    static DragEvent obtain() {
        return DragEvent.obtain(0, 0f, 0f, 0f, 0f, 0, null, null, null, null, null, false);
        return DragEvent.obtain(0, 0f, 0f, 0f, 0f, 0, 0, null, null, null, null, null, false);
    }

    /** @hide */
    public static DragEvent obtain(int action, float x, float y, float offsetX, float offsetY,
            int flags, Object localState, ClipDescription description, ClipData data,
            int displayId, int flags, Object localState, ClipDescription description, ClipData data,
            SurfaceControl dragSurface, IDragAndDropPermissions dragAndDropPermissions,
            boolean result) {
        final DragEvent ev;
        synchronized (gRecyclerLock) {
            if (gRecyclerTop == null) {
                ev = new DragEvent();
                ev.init(action, x, y, offsetX, offsetY, flags, description, data, dragSurface,
                        dragAndDropPermissions, localState, result);
                ev.init(action, x, y, offsetX, offsetY, displayId, flags, description, data,
                        dragSurface, dragAndDropPermissions, localState, result);
                return ev;
            }
            ev = gRecyclerTop;
@@ -339,7 +345,7 @@ public class DragEvent implements Parcelable {
        ev.mRecycled = false;
        ev.mNext = null;

        ev.init(action, x, y, offsetX, offsetY, flags, description, data, dragSurface,
        ev.init(action, x, y, offsetX, offsetY, displayId, flags, description, data, dragSurface,
                dragAndDropPermissions, localState, result);

        return ev;
@@ -349,8 +355,9 @@ public class DragEvent implements Parcelable {
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static DragEvent obtain(DragEvent source) {
        return obtain(source.mAction, source.mX, source.mY, source.mOffsetX, source.mOffsetY,
                source.mFlags, source.mLocalState, source.mClipDescription, source.mClipData,
                source.mDragSurface, source.mDragAndDropPermissions, source.mDragResult);
                source.mDisplayId, source.mFlags, source.mLocalState, source.mClipDescription,
                source.mClipData, source.mDragSurface, source.mDragAndDropPermissions,
                source.mDragResult);
    }

    /**
@@ -398,6 +405,11 @@ public class DragEvent implements Parcelable {
        return mOffsetY;
    }

    /** @hide */
    public int getDisplayId() {
        return mDisplayId;
    }

    /**
     * Returns the {@link android.content.ClipData} object sent to the system as part of the call
     * to
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ public abstract class InputEventReceiver {
     *                 drag
     *                 if true, the window associated with this input channel has just lost drag
     */
    public void onDragEvent(boolean isExiting, float x, float y) {
    public void onDragEvent(boolean isExiting, float x, float y, int displayId) {
    }

    /**
+5 −5
Original line number Diff line number Diff line
@@ -10561,13 +10561,13 @@ public final class ViewRootImpl implements ViewParent,
        }
        @Override
        public void onDragEvent(boolean isExiting, float x, float y) {
        public void onDragEvent(boolean isExiting, float x, float y, int displayId) {
            // force DRAG_EXITED_EVENT if appropriate
            DragEvent event = DragEvent.obtain(
                    isExiting ? DragEvent.ACTION_DRAG_EXITED : DragEvent.ACTION_DRAG_LOCATION,
                    x, y, 0 /* offsetX */, 0 /* offsetY */, 0 /* flags */, null/* localState */,
                    null/* description */, null /* data */, null /* dragSurface */,
                    null /* dragAndDropPermissions */, false /* result */);
                    isExiting ? DragEvent.ACTION_DRAG_EXITED : DragEvent.ACTION_DRAG_LOCATION, x, y,
                    0 /* offsetX */, 0 /* offsetY */, displayId, 0 /* flags */,
                    null/* localState */, null/* description */, null /* data */,
                    null /* dragSurface */, null /* dragAndDropPermissions */, false /* result */);
            dispatchDragEvent(event);
        }
+3 −2
Original line number Diff line number Diff line
@@ -441,7 +441,8 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
                    }
                    env->CallVoidMethod(receiverObj.get(), gInputEventReceiverClassInfo.onDragEvent,
                                        jboolean(dragEvent->isExiting()), dragEvent->getX(),
                                        dragEvent->getY());
                                        dragEvent->getY(),
                                        static_cast<jint>(dragEvent->getDisplayId().val()));
                    finishInputEvent(seq, /*handled=*/true);
                    continue;
                }
@@ -643,7 +644,7 @@ int register_android_view_InputEventReceiver(JNIEnv* env) {
            GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onPointerCaptureEvent",
                             "(Z)V");
    gInputEventReceiverClassInfo.onDragEvent =
            GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onDragEvent", "(ZFF)V");
            GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onDragEvent", "(ZFFI)V");
    gInputEventReceiverClassInfo.onTouchModeChanged =
            GetMethodIDOrDie(env, gInputEventReceiverClassInfo.clazz, "onTouchModeChanged", "(Z)V");
    gInputEventReceiverClassInfo.onBatchedInputEventPending =
+3 −3
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import org.mockito.kotlin.verify
 */
@SmallTest
@RunWith(AndroidJUnit4::class)
class UnhandledDragControllerTest : ShellTestCase() {
class GlobalDragListenerTest : ShellTestCase() {
    private val mIWindowManager = mock<IWindowManager>()
    private val mMainExecutor = mock<ShellExecutor>()

@@ -74,7 +74,7 @@ class UnhandledDragControllerTest : ShellTestCase() {
    @Test
    fun onUnhandledDrop_noListener_expectNotifyUnhandled() {
        // Simulate an unhandled drop
        val dropEvent = DragEvent.obtain(ACTION_DROP, 0f, 0f, 0f, 0f, 0, null, null, null,
        val dropEvent = DragEvent.obtain(ACTION_DROP, 0f, 0f, 0f, 0f, 0, 0, null, null, null,
            null, null, false)
        val wmCallback = mock<IUnhandledDragCallback>()
        mController.onUnhandledDrop(dropEvent, wmCallback)
@@ -98,7 +98,7 @@ class UnhandledDragControllerTest : ShellTestCase() {

        // Simulate an unhandled drop
        val dragSurface = mock<SurfaceControl>()
        val dropEvent = DragEvent.obtain(ACTION_DROP, 0f, 0f, 0f, 0f, 0, null, null, null,
        val dropEvent = DragEvent.obtain(ACTION_DROP, 0f, 0f, 0f, 0f, 0, 0, null, null, null,
            dragSurface, null, false)
        val wmCallback = mock<IUnhandledDragCallback>()
        mController.onUnhandledDrop(dropEvent, wmCallback)
Loading