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

Commit c7482415 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

Expose the desktop location of an unconsumed drag and drop

When dispatching DragEvent for ACTION_DRAG_ENDED action
getX and getY will return the location of the drop if it was not
consumed by any app.

Consumed drops will return (0,0) location as before.

Bug: 25486808
Change-Id: Ic57d94b42de62d8327e9ce47d92ba335c21b8ae2
parent 853fde69
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import android.content.ClipDescription;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Binder;
import android.os.IBinder;
import android.os.Message;
import android.os.Process;
@@ -52,6 +51,7 @@ class DragState {
    SurfaceControl mSurfaceControl;
    int mFlags;
    IBinder mLocalWin;
    int mPid;
    int mUid;
    ClipData mData;
    ClipDescription mDataDescription;
@@ -270,8 +270,15 @@ class DragState {
            Slog.d(WindowManagerService.TAG, "broadcasting DRAG_ENDED");
        }
        for (WindowState ws : mNotifiedWindows) {
            float x = 0;
            float y = 0;
            if (!mDragResult && (ws.mSession.mPid == mPid)) {
                // Report unconsumed drop location back to the app that started the drag.
                x = mCurrentX;
                y = mCurrentY;
            }
            DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
                    0, 0, null, null, null, null, mDragResult);
                    x, y, null, null, null, null, mDragResult);
            try {
                ws.mClient.dispatchDragEvent(evt);
            } catch (RemoteException e) {
+10 −4
Original line number Diff line number Diff line
@@ -698,7 +698,7 @@ public class WindowManagerService extends IWindowManager.Stub
                            if (DEBUG_DRAG) Slog.d(TAG, "Button no longer pressed; dropping at "
                                    + newX + "," + newY);
                            synchronized (mWindowMap) {
                                endDrag = completeDrop(newX, newY);
                                endDrag = completeDropLw(newX, newY);
                            }
                        } else {
                            synchronized (mWindowMap) {
@@ -712,7 +712,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
                                + newX + "," + newY);
                        synchronized (mWindowMap) {
                            endDrag = completeDrop(newX, newY);
                            endDrag = completeDropLw(newX, newY);
                        }
                    } break;

@@ -742,11 +742,15 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    private boolean completeDrop(float x, float y) {
    private boolean completeDropLw(float x, float y) {
        WindowState dropTargetWin = mDragState.getDropTargetWinLw(x, y);

        mDragState.mCurrentX = x;
        mDragState.mCurrentY = y;

        DropPermissionHolder dropPermissionHolder = null;
        if ((mDragState.mFlags & View.DRAG_FLAG_GLOBAL) != 0 &&
        if (dropTargetWin != null &&
                (mDragState.mFlags & View.DRAG_FLAG_GLOBAL) != 0 &&
                (mDragState.mFlags & DRAG_FLAGS_URI_ACCESS) != 0) {
            dropPermissionHolder = new DropPermissionHolder(
                    mDragState.mData,
@@ -7020,6 +7024,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    + " asbinder=" + window.asBinder());
        }

        final int callerPid = Binder.getCallingPid();
        final int callerUid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
        IBinder token = null;
@@ -7045,6 +7050,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        final IBinder winBinder = window.asBinder();
                        token = new Binder();
                        mDragState = new DragState(this, token, surface, flags, winBinder);
                        mDragState.mPid = callerPid;
                        mDragState.mUid = callerUid;
                        token = mDragState.mToken = new Binder();