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

Commit 440ea840 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "global-monitor-to-focus-monitor" into main

* changes:
  PointerEventDispatcher: Convert to spy window with flag DO_NOT_PILFER
  InputManagerService: Convert global monitors to focus input monitors
parents 4fb415dc c42e38af
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public final class InputWindowHandle {
            InputConfig.CLONE,
            InputConfig.SENSITIVE_FOR_PRIVACY,
            InputConfig.DISPLAY_TOPOLOGY_AWARE,
            InputConfig.DO_NOT_PILFER,
    })
    public @interface InputConfigFlags {}

+10 −3
Original line number Diff line number Diff line
@@ -451,6 +451,9 @@ public class InputManagerService extends IInputManager.Stub
    // system gestures (e.g. navigation bar, edge-back, etc) while there is an active
    // handwriting session.
    public static final int INPUT_OVERLAY_LAYER_HANDWRITING_SURFACE = 2;
    // The layer where the pointer event dispatcher is added by WindowManager to get an
    // uninterrupted stream of all pointer events on each display.
    public static final int INPUT_OVERLAY_POINTER_EVENT_DISPATCHER = Integer.MAX_VALUE;


    private final String mVelocityTrackerStrategy;
@@ -809,19 +812,23 @@ public class InputManagerService extends IInputManager.Stub
    }

    /**
     * Creates an input channel that will receive all input from the input dispatcher.
     * Creates an input channel that will receive all non-pointer input going to focused windows
     * from the input dispatcher.
     *
     * This API is intended to be used only for creating debugging tools to visualize focus input.
     *
     * @param inputChannelName The input channel name.
     * @param displayId Target display id.
     * @return The input channel.
     */
    public InputChannel monitorInput(@NonNull String inputChannelName, int displayId) {
    public InputChannel monitorFocusInput(@NonNull String inputChannelName, int displayId) {
        Objects.requireNonNull(inputChannelName, "inputChannelName not be null");

        if (displayId < Display.DEFAULT_DISPLAY) {
            throw new IllegalArgumentException("displayId must >= 0.");
        }

        return mNative.createInputMonitor(displayId, inputChannelName, Binder.getCallingPid());
        return mNative.createFocusInputMonitor(displayId, inputChannelName, Binder.getCallingPid());
    }

    @NonNull
+2 −2
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ interface NativeInputManagerService {

    InputChannel createInputChannel(String name);

    InputChannel createInputMonitor(int displayId, String name, int pid);
    InputChannel createFocusInputMonitor(int displayId, String name, int pid);

    void removeInputChannel(IBinder connectionToken);

@@ -372,7 +372,7 @@ interface NativeInputManagerService {
        public native InputChannel createInputChannel(String name);

        @Override
        public native InputChannel createInputMonitor(int displayId, String name, int pid);
        public native InputChannel createFocusInputMonitor(int displayId, String name, int pid);

        @Override
        public native void removeInputChannel(IBinder connectionToken);
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class FocusEventDebugGlobalMonitor extends InputEventReceiver {
    private final FocusEventDebugView mDebugView;

    FocusEventDebugGlobalMonitor(FocusEventDebugView debugView, InputManagerService service) {
        super(service.monitorInput("FocusEventDebugGlobalMonitor", Display.DEFAULT_DISPLAY),
        super(service.monitorFocusInput("FocusEventDebugGlobalMonitor", Display.DEFAULT_DISPLAY),
            UiThread.getHandler().getLooper());
        mDebugView = debugView;
    }
+45 −3
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import static android.internal.perfetto.protos.Windowmanagerservice.RemoteInsets
import static android.internal.perfetto.protos.Windowmanagerservice.RemoteInsetsControlTargetProto.REQUESTED_VISIBLE_TYPES;
import static android.internal.perfetto.protos.Windowmanagerservice.WindowContainerChildProto.DISPLAY_CONTENT;
import static android.os.Build.VERSION_CODES.N;
import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.os.UserHandle.USER_NULL;
import static android.util.DisplayMetrics.DENSITY_DEFAULT;
@@ -193,6 +194,7 @@ import android.os.Debug;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.InputConfig;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteCallbackList;
@@ -225,8 +227,10 @@ import android.view.IDecorViewGestureListener;
import android.view.IDisplayWindowInsetsController;
import android.view.ISystemGestureExclusionListener;
import android.view.IWindow;
import android.view.InputApplicationHandle;
import android.view.InputChannel;
import android.view.InputDevice;
import android.view.InputWindowHandle;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.MagnificationSpec;
@@ -259,6 +263,7 @@ import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.ToBooleanFunction;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledPredicate;
import com.android.server.input.InputManagerService;
import com.android.server.inputmethod.InputMethodManagerInternal;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.wm.utils.RegionUtils;
@@ -342,6 +347,12 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    private SurfaceControl mInputOverlayLayer;

    /**
     * A special input overlay layer that is always created for each display that receives all
     * pointer input on the display.
     */
    private SurfaceControl mPointerEventDispatcherOverlayLayer;

    /** A surfaceControl specifically for accessibility overlays. */
    private SurfaceControl mA11yOverlayLayer;

@@ -1191,9 +1202,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        mUnknownAppVisibilityController = new UnknownAppVisibilityController(mWmService, this);
        mRemoteDisplayChangeController = new RemoteDisplayChangeController(this);

        final InputChannel inputChannel = mWmService.mInputManager.monitorInput(
                "PointerEventDispatcher" + mDisplayId, mDisplayId);
        mPointerEventDispatcher = new PointerEventDispatcher(inputChannel);
        final InputChannel pointerSpyInputChannel =
                mWmService.mInputManager.createInputChannel("PointerEventDispatcher" + mDisplayId);
        mPointerEventDispatcher = new PointerEventDispatcher(pointerSpyInputChannel);

        if (mWmService.mAtmService.getRecentTasks() != null) {
            registerPointerEventListener(
@@ -1342,6 +1353,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            transaction.reparent(mInputOverlayLayer, mSurfaceControl);
        }

        if (mPointerEventDispatcherOverlayLayer == null) {
            final var name = "PointerEventDispatcherOverlay" + mDisplayId;
            mPointerEventDispatcherOverlayLayer =
                    b.setName(name).setParent(mInputOverlayLayer).build();
            configurePointerEventDispatcherOverlayLayer(transaction, name);
        }

        if (mA11yOverlayLayer == null) {
            mA11yOverlayLayer =
                    b.setName("Accessibility Overlays").setParent(mSurfaceControl).build();
@@ -1356,10 +1374,34 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                .show(mOverlayLayer)
                .setLayer(mInputOverlayLayer, Integer.MAX_VALUE - 1)
                .show(mInputOverlayLayer)
                .show(mPointerEventDispatcherOverlayLayer)
                .setLayer(mA11yOverlayLayer, Integer.MAX_VALUE - 2)
                .show(mA11yOverlayLayer);
    }

    private void configurePointerEventDispatcherOverlayLayer(SurfaceControl.Transaction transaction,
            String name) {
        final var handle = new InputWindowHandle(
                new InputApplicationHandle(null, name, DEFAULT_DISPATCHING_TIMEOUT_MILLIS),
                mDisplayId);
        handle.name = name;
        handle.token = mPointerEventDispatcher.getToken();
        handle.layoutParamsType = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
        handle.dispatchingTimeoutMillis = DEFAULT_DISPATCHING_TIMEOUT_MILLIS;
        handle.ownerPid = WindowManagerService.MY_PID;
        handle.ownerUid = WindowManagerService.MY_UID;
        handle.scaleFactor = 1.0f;
        handle.replaceTouchableRegionWithCrop(null /* use this surface's bounds */);
        handle.inputConfig =
                InputConfig.NOT_FOCUSABLE | InputConfig.SPY | InputConfig.DO_NOT_PILFER;
        handle.setTrustedOverlay(transaction, mPointerEventDispatcherOverlayLayer, true);
        transaction
                .setInputWindowInfo(mPointerEventDispatcherOverlayLayer, handle)
                .setLayer(mPointerEventDispatcherOverlayLayer,
                        InputManagerService.INPUT_OVERLAY_POINTER_EVENT_DISPATCHER)
                .setCrop(mPointerEventDispatcherOverlayLayer, null /* crop to parent surface */);
    }

    DisplayRotationReversionController getRotationReversionController() {
        return mRotationReversionController;
    }
Loading