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

Commit 98b8468c authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Set trusted overlay on SurfaceControl instead of InputWindow

When trusted overlays are set on the SC, the property is inherited so
children will also be trusted overlays. This is the expected behavior
since there are often child layers created outside system server that
should also be trusted overlays when their parent is

InputWindow also has a way to set trusted overlays, but that way is only
set on the immediate window and not children. Convert all places setting
trusted overlay on their InputWindow to instead set on the
SurfaceControl.

Test: TrustedOverlayTests
Bug: 292032926
Bug: 300094445
Change-Id: I6e0b6a9f023210e7ef1515f534792e5f8a2db4b3
parent 1f5b8523
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ import java.lang.ref.WeakReference;
 * @hide
 * @hide
 */
 */
public final class InputWindowHandle {
public final class InputWindowHandle {
    // TODO (b/300094445): Convert to use correct flagging infrastructure
    public static final boolean USE_SURFACE_TRUSTED_OVERLAY = true;


    /**
    /**
     * An internal annotation for all the {@link android.os.InputConfig} flags that can be
     * An internal annotation for all the {@link android.os.InputConfig} flags that can be
@@ -59,7 +61,6 @@ public final class InputWindowHandle {
            InputConfig.DUPLICATE_TOUCH_TO_WALLPAPER,
            InputConfig.DUPLICATE_TOUCH_TO_WALLPAPER,
            InputConfig.IS_WALLPAPER,
            InputConfig.IS_WALLPAPER,
            InputConfig.PAUSE_DISPATCHING,
            InputConfig.PAUSE_DISPATCHING,
            InputConfig.TRUSTED_OVERLAY,
            InputConfig.WATCH_OUTSIDE_TOUCH,
            InputConfig.WATCH_OUTSIDE_TOUCH,
            InputConfig.SLIPPERY,
            InputConfig.SLIPPERY,
            InputConfig.DISABLE_USER_ACTIVITY,
            InputConfig.DISABLE_USER_ACTIVITY,
@@ -272,4 +273,13 @@ public final class InputWindowHandle {
        }
        }
        this.inputConfig &= ~inputConfig;
        this.inputConfig &= ~inputConfig;
    }
    }

    public void setTrustedOverlay(SurfaceControl.Transaction t, SurfaceControl sc,
            boolean isTrusted) {
        if (USE_SURFACE_TRUSTED_OVERLAY) {
            t.setTrustedOverlay(sc, isTrusted);
        } else if (isTrusted) {
            inputConfig |= InputConfig.TRUSTED_OVERLAY;
        }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -62,10 +62,10 @@ class GestureMonitorSpyWindow {
        mWindowHandle.ownerUid = uid;
        mWindowHandle.ownerUid = uid;
        mWindowHandle.scaleFactor = 1.0f;
        mWindowHandle.scaleFactor = 1.0f;
        mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);
        mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);
        mWindowHandle.inputConfig =
        mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE | InputConfig.SPY;
                InputConfig.NOT_FOCUSABLE | InputConfig.SPY | InputConfig.TRUSTED_OVERLAY;


        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mWindowHandle.setTrustedOverlay(t, mInputSurface, true);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_GESTURE_MONITOR);
        t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_GESTURE_MONITOR);
        t.setPosition(mInputSurface, 0, 0);
        t.setPosition(mInputSurface, 0, 0);
+2 −2
Original line number Original line Diff line number Diff line
@@ -57,13 +57,13 @@ final class HandwritingEventReceiverSurface {
                InputConfig.NOT_FOCUSABLE
                InputConfig.NOT_FOCUSABLE
                        | InputConfig.NOT_TOUCHABLE
                        | InputConfig.NOT_TOUCHABLE
                        | InputConfig.SPY
                        | InputConfig.SPY
                        | InputConfig.INTERCEPTS_STYLUS
                        | InputConfig.INTERCEPTS_STYLUS;
                        | InputConfig.TRUSTED_OVERLAY;


        // Configure the surface to receive stylus events across the entire display.
        // Configure the surface to receive stylus events across the entire display.
        mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);
        mWindowHandle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);


        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        mWindowHandle.setTrustedOverlay(t, mInputSurface, true);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_HANDWRITING_SURFACE);
        t.setLayer(mInputSurface, InputManagerService.INPUT_OVERLAY_LAYER_HANDWRITING_SURFACE);
        t.setPosition(mInputSurface, 0, 0);
        t.setPosition(mInputSurface, 0, 0);
+5 −8
Original line number Original line Diff line number Diff line
@@ -21,7 +21,6 @@ import static android.content.ClipDescription.MIMETYPE_APPLICATION_SHORTCUT;
import static android.content.ClipDescription.MIMETYPE_APPLICATION_TASK;
import static android.content.ClipDescription.MIMETYPE_APPLICATION_TASK;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INTERCEPT_GLOBAL_DRAG_AND_DROP;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ORIENTATION;
import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_ORIENTATION;
import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
import static com.android.internal.protolog.ProtoLogGroup.WM_SHOW_TRANSACTIONS;
import static com.android.server.wm.DragDropController.MSG_ANIMATION_END;
import static com.android.server.wm.DragDropController.MSG_ANIMATION_END;
@@ -33,7 +32,6 @@ import static com.android.server.wm.WindowManagerDebugConfig.SHOW_LIGHT_TRANSACT
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.MY_PID;
import static com.android.server.wm.WindowManagerService.MY_PID;
import static com.android.server.wm.WindowManagerService.MY_UID;
import static com.android.server.wm.WindowManagerService.MY_UID;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.completedFuture;


import android.animation.Animator;
import android.animation.Animator;
@@ -48,7 +46,6 @@ import android.hardware.input.InputManagerGlobal;
import android.os.Binder;
import android.os.Binder;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
import android.os.InputConfig;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
@@ -186,8 +183,13 @@ class DragState {
        // Crop the input surface to the display size.
        // Crop the input surface to the display size.
        mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y);
        mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y);


        // Make trusted overlay to not block any touches while D&D ongoing and allowing
        // touches to pass through to windows underneath. This allows user to interact with the
        // UI to navigate while dragging.
        h.setTrustedOverlay(mTransaction, mInputSurface, true);
        mTransaction.show(mInputSurface)
        mTransaction.show(mInputSurface)
                .setInputWindowInfo(mInputSurface, h)
                .setInputWindowInfo(mInputSurface, h)
                .setTrustedOverlay(mInputSurface, true)
                .setLayer(mInputSurface, Integer.MAX_VALUE)
                .setLayer(mInputSurface, Integer.MAX_VALUE)
                .setCrop(mInputSurface, mTmpClipRect);
                .setCrop(mInputSurface, mTmpClipRect);


@@ -377,11 +379,6 @@ class DragState {
            mDragWindowHandle.ownerUid = MY_UID;
            mDragWindowHandle.ownerUid = MY_UID;
            mDragWindowHandle.scaleFactor = 1.0f;
            mDragWindowHandle.scaleFactor = 1.0f;


            // InputConfig.TRUSTED_OVERLAY: To not block any touches while D&D ongoing and allowing
            // touches to pass through to windows underneath. This allows user to interact with the
            // UI to navigate while dragging.
            mDragWindowHandle.inputConfig = InputConfig.TRUSTED_OVERLAY;

            // The drag window cannot receive new touches.
            // The drag window cannot receive new touches.
            mDragWindowHandle.touchableRegion.setEmpty();
            mDragWindowHandle.touchableRegion.setEmpty();


+3 −1
Original line number Original line Diff line number Diff line
@@ -74,7 +74,7 @@ class InputConsumerImpl implements IBinder.DeathRecipient {
        mWindowHandle.ownerPid = WindowManagerService.MY_PID;
        mWindowHandle.ownerPid = WindowManagerService.MY_PID;
        mWindowHandle.ownerUid = WindowManagerService.MY_UID;
        mWindowHandle.ownerUid = WindowManagerService.MY_UID;
        mWindowHandle.scaleFactor = 1.0f;
        mWindowHandle.scaleFactor = 1.0f;
        mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE | InputConfig.TRUSTED_OVERLAY;
        mWindowHandle.inputConfig = InputConfig.NOT_FOCUSABLE;


        mInputSurface = mService.makeSurfaceBuilder(
        mInputSurface = mService.makeSurfaceBuilder(
                        mService.mRoot.getDisplayContent(displayId).getSession())
                        mService.mRoot.getDisplayContent(displayId).getSession())
@@ -129,12 +129,14 @@ class InputConsumerImpl implements IBinder.DeathRecipient {


    void show(SurfaceControl.Transaction t, WindowContainer w) {
    void show(SurfaceControl.Transaction t, WindowContainer w) {
        t.show(mInputSurface);
        t.show(mInputSurface);
        mWindowHandle.setTrustedOverlay(t, mInputSurface, true);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setRelativeLayer(mInputSurface, w.getSurfaceControl(), 1);
        t.setRelativeLayer(mInputSurface, w.getSurfaceControl(), 1);
    }
    }


    void show(SurfaceControl.Transaction t, int layer) {
    void show(SurfaceControl.Transaction t, int layer) {
        t.show(mInputSurface);
        t.show(mInputSurface);
        mWindowHandle.setTrustedOverlay(t, mInputSurface, true);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setInputWindowInfo(mInputSurface, mWindowHandle);
        t.setLayer(mInputSurface, layer);
        t.setLayer(mInputSurface, layer);
    }
    }
Loading