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

Commit e92c80c0 authored by Robert Carr's avatar Robert Carr
Browse files

Port other InputWindowHandles to input surfaces.

Various places in the WM that receive input but are neither a
WindowState nor an InputConsumer. Perhaps they should just be
InputConsumers, but for now, we just make them work.

Bug: 80101428
Bug: 113136004
Bug: 111440400
Test: Manual
Change-Id: Ie2320e02199e1ee3bf3d9cc0cf9f41dacdeac2f7
parent a80ad04b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -74,8 +74,15 @@ class DragDropController {
        return mDragState != null;
    }

    InputWindowHandle getInputWindowHandleLocked() {
        return mDragState.getInputWindowHandle();
    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
        mDragState.showInputSurface(t, displayId);
    }

    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (mDragState != null) {
            // TODO: Are we guaranteed to get here?
            mDragState.hideInputSurface(t, displayId);
        }
    }

    void registerCallback(IDragDropCallback callback) {
+42 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.annotation.Nullable;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Point;
import android.hardware.input.InputManager;
import android.os.Build;
@@ -118,6 +119,11 @@ class DragState {
    private final Interpolator mCubicEaseOutInterpolator = new DecelerateInterpolator(1.5f);
    private Point mDisplaySize = new Point();

    // A surface used to catch input events for the drag-and-drop operation.
    SurfaceControl mInputSurface;

    private final Rect mTmpClipRect = new Rect();

    DragState(WindowManagerService service, DragDropController controller, IBinder token,
            SurfaceControl surface, int flags, IBinder localWin) {
        mService = service;
@@ -127,6 +133,42 @@ class DragState {
        mFlags = flags;
        mLocalWin = localWin;
        mNotifiedWindows = new ArrayList<WindowState>();

    }

    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (displayId != mDisplayContent.getDisplayId()) {
            return;
        }

        if (mInputSurface != null) {
            t.hide(mInputSurface);
        }
    }

    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (displayId != mDisplayContent.getDisplayId()) {
            return;
        }

        if (mInputSurface == null) {
            mInputSurface = mService.makeSurfaceBuilder(mService.mRoot.getDisplayContent(displayId)
                    .getSession()).setContainerLayer(true)
                    .setName("Drag and Drop Input Consumer").setSize(1, 1).build();
        }
        final InputWindowHandle h = getInputWindowHandle();
        if (h == null) {
            Slog.w(TAG_WM, "Drag is in progress but there is no "
                    + "drag window handle.");
            return;
        }

        t.show(mInputSurface);
        t.setInputWindowInfo(mInputSurface, h);
        t.setLayer(mInputSurface, Integer.MAX_VALUE);

        mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y);
        t.setWindowCrop(mSurfaceControl, mTmpClipRect);
    }

    /**
+6 −16
Original line number Diff line number Diff line
@@ -274,14 +274,9 @@ final class InputMonitor {
            if (DEBUG_DRAG) {
                Log.d(TAG_WM, "Inserting drag window");
            }
            final InputWindowHandle dragWindowHandle =
                    mService.mDragDropController.getInputWindowHandleLocked();
            if (dragWindowHandle == null) {
                Slog.w(TAG_WM, "Drag is in progress but there is no "
                        + "drag window handle.");
            } else if (dragWindowHandle.displayId == mDisplayId) {
                addInputWindowHandle(dragWindowHandle);
            }
            mService.mDragDropController.showInputSurface(mInputTransaction, mDisplayId);
        } else {
            mService.mDragDropController.hideInputSurface(mInputTransaction, mDisplayId);
        }

        final boolean inPositioning = mService.mTaskPositioningController.isPositioningLocked();
@@ -289,14 +284,9 @@ final class InputMonitor {
            if (DEBUG_TASK_POSITIONING) {
                Log.d(TAG_WM, "Inserting window handle for repositioning");
            }
            final InputWindowHandle dragWindowHandle =
                    mService.mTaskPositioningController.getDragWindowHandleLocked();
            if (dragWindowHandle == null) {
                Slog.e(TAG_WM,
                        "Repositioning is in progress but there is no drag window handle.");
            } else if (dragWindowHandle.displayId == mDisplayId) {
                addInputWindowHandle(dragWindowHandle);
            }
            mService.mTaskPositioningController.showInputSurface(mInputTransaction, mDisplayId);
        } else {
            mService.mTaskPositioningController.hideInputSurface(mInputTransaction, mDisplayId);
        }

        // Add all windows on the default display.
+47 −0
Original line number Diff line number Diff line
@@ -21,10 +21,14 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;

import android.annotation.Nullable;
import android.app.IActivityTaskManager;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.util.Slog;
import android.view.Display;
import android.view.SurfaceControl;
import android.view.IWindow;

import com.android.internal.annotations.GuardedBy;
@@ -39,10 +43,14 @@ class TaskPositioningController {
    private final InputManagerService mInputManager;
    private final IActivityTaskManager mActivityManager;
    private final Handler mHandler;
    private SurfaceControl mInputSurface;
    private DisplayContent mPositioningDisplay;

    @GuardedBy("WindowManagerSerivce.mWindowMap")
    private @Nullable TaskPositioner mTaskPositioner;

    private final Rect mTmpClipRect = new Rect();

    boolean isPositioningLocked() {
        return mTaskPositioner != null;
    }
@@ -59,6 +67,43 @@ class TaskPositioningController {
        mHandler = new Handler(looper);
    }

    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (mPositioningDisplay != null && mPositioningDisplay.getDisplayId() == displayId
                && mInputSurface != null) {
            t.hide(mInputSurface);
        }
    }

    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
        if (mPositioningDisplay == null || mPositioningDisplay.getDisplayId() != displayId) {
            return;
        }
        final DisplayContent dc = mService.mRoot.getDisplayContent(displayId);
        if (mInputSurface == null) {
            mInputSurface = mService.makeSurfaceBuilder(dc.getSession())
                    .setContainerLayer(true)
                    .setName("Drag and Drop Input Consumer").setSize(1, 1).build();
        }

        final InputWindowHandle h = getDragWindowHandleLocked();
        if (h == null) {
            Slog.w(TAG_WM, "Drag is in progress but there is no "
                    + "drag window handle.");
            return;
        }

        t.show(mInputSurface);
        t.setInputWindowInfo(mInputSurface, h);
        t.setLayer(mInputSurface, Integer.MAX_VALUE);

        final Display display = dc.getDisplay();
        final Point p = new Point();
        display.getRealSize(p);

        mTmpClipRect.set(0, 0, p.x, p.y);
        t.setWindowCrop(mInputSurface, mTmpClipRect);
    }

    boolean startMovingTask(IWindow window, float startX, float startY) {
        WindowState win = null;
        synchronized (mService.mGlobalLock) {
@@ -122,6 +167,7 @@ class TaskPositioningController {
            Slog.w(TAG_WM, "startPositioningLocked: Invalid display content " + win);
            return false;
        }
        mPositioningDisplay = displayContent;

        mTaskPositioner = TaskPositioner.create(mService);
        mTaskPositioner.register(displayContent);
@@ -157,6 +203,7 @@ class TaskPositioningController {
                    mTaskPositioner.unregister();
                    mTaskPositioner = null;
                }
                mPositioningDisplay = null;
            }
        });
    }