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

Commit a712240b authored by Harry Cutts's avatar Harry Cutts
Browse files

input: add method to request specific pointer capture mode

Currently there are only two modes, UNCAPTURED and ABSOLUTE, which are
equivalent to the existing uncaptured and captured states respectively,
but this will allow us to add a new RELATIVE mode in upcoming changes.

Test: check that a test app can still request and release capture, and
      receives events as appropriate in each state
Test: $ atest CtsInputTestCases:android.input.cts.\
              {TouchpadAbsoluteCaptureModeTest,MouseCaptureTest}
Bug: 403531245
Flag: com.android.hardware.input.pointer_capture_modes
Change-Id: I39036091e9e338d9904f8c491b19af01ae069833
parent 980ed5e0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -54865,6 +54865,7 @@ package android.view {
    method public final boolean requestFocusFromTouch();
    method @CallSuper public void requestLayout();
    method public void requestPointerCapture();
    method @FlaggedApi("com.android.hardware.input.pointer_capture_modes") public void requestPointerCapture(int);
    method public boolean requestRectangleOnScreen(android.graphics.Rect);
    method public boolean requestRectangleOnScreen(android.graphics.Rect, boolean);
    method @FlaggedApi("android.view.accessibility.request_rectangle_with_source") public boolean requestRectangleOnScreen(@NonNull android.graphics.Rect, boolean, int);
@@ -55176,6 +55177,8 @@ package android.view {
    field public static final int OVER_SCROLL_ALWAYS = 0; // 0x0
    field public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; // 0x1
    field public static final int OVER_SCROLL_NEVER = 2; // 0x2
    field @FlaggedApi("com.android.hardware.input.pointer_capture_modes") public static final int POINTER_CAPTURE_MODE_ABSOLUTE = 1; // 0x1
    field @FlaggedApi("com.android.hardware.input.pointer_capture_modes") public static final int POINTER_CAPTURE_MODE_UNCAPTURED = 0; // 0x0
    field protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET;
    field protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET;
    field protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET;
+2 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.hardware.lights.Light;
import android.hardware.lights.LightState;
import android.os.IBinder;
import android.os.IVibratorStateListener;
import android.os.PointerCaptureMode;
import android.os.VibrationEffect;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
@@ -162,7 +163,7 @@ interface IInputManager {
    boolean setPointerIcon(in PointerIcon icon, int displayId, int deviceId, int pointerId,
            in IBinder inputToken);

    oneway void requestPointerCapture(IBinder inputChannelToken, boolean enabled);
    oneway void requestPointerCapture(IBinder inputChannelToken, PointerCaptureMode mode);

    /** Create an input monitor for gestures. */
    InputMonitor monitorGestureInput(IBinder token, String name, int displayId);
+9 −6
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.VerifiedInputEvent;
import android.view.View;
import android.view.View.PointerCaptureMode;
import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
@@ -1078,16 +1080,17 @@ public final class InputManager {
    /**
     * Request or release pointer capture.
     * <p>
     * When in capturing mode, the pointer icon disappears and all mouse events are dispatched to
     * the window which has requested the capture. Relative position changes are available through
     * {@link MotionEvent#getX} and {@link MotionEvent#getY}.
     * When in capturing mode, the pointer icon disappears and all mouse and touchpad events are
     * dispatched to the window which has requested the capture.
     *
     * @param enable true when requesting pointer capture, false when releasing.
     * @param mode the capture mode to request.
     *
     * @see View#requestPointerCapture()
     *
     * @hide
     */
    public void requestPointerCapture(IBinder windowToken, boolean enable) {
        mGlobal.requestPointerCapture(windowToken, enable);
    public void requestPointerCapture(@NonNull IBinder windowToken, @PointerCaptureMode int mode) {
        mGlobal.requestPointerCapture(windowToken, mode);
    }

    /**
+12 −2
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ import android.view.InputMonitor;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.PointerIcon;
import android.view.View;
import android.view.View.PointerCaptureMode;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;

@@ -1730,9 +1732,17 @@ public final class InputManagerGlobal {
    /**
     * @see android.view.View#requestPointerCapture()
     */
    public void requestPointerCapture(IBinder windowToken, boolean enable) {
    public void requestPointerCapture(@NonNull IBinder windowToken, @PointerCaptureMode int mode) {
        // We need to check the mode is valid here too, since the binder call is oneway, so the
        // check in InputManagerService#requestPointerCapture would not result in the exception
        // being propagated to the caller.
        if (mode != View.POINTER_CAPTURE_MODE_UNCAPTURED
                && mode != View.POINTER_CAPTURE_MODE_ABSOLUTE) {
            throw new IllegalArgumentException("Invalid pointer capture mode " + mode);
        }

        try {
            mIm.requestPointerCapture(windowToken, enable);
            mIm.requestPointerCapture(windowToken, mode);
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
+8 −0
Original line number Diff line number Diff line
@@ -236,3 +236,11 @@ flag {
    description: "Disable settings pages for virtual devices created using VDM or InputManager"
    bug: "402596982"
}

flag {
    name: "pointer_capture_modes"
    namespace: "input"
    description: "Enable pointer capture modes with different touchpad behaviours, and default to relative events from captured touchpads"
    is_exported: true
    bug: "403531245"
}
Loading