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

Commit 47ad7871 authored by nergi's avatar nergi
Browse files

Add @TestApi to set mouse scaling for any display

Currently disabling mouse scaling is only possible for VirtualDisplay.
As connected displays tests are being developed, testing VirtualMouse
interaction in / between default display and overlay/virtual displays
are required for better coverage.

Bug: 405848641
Test: atest CtsInputTestCases
Flag: EXEMPT test_only
Change-Id: I11b486d9a86b810e7e20a6e0cb46f8e97b55efeb
parent 1706fcfe
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1813,6 +1813,7 @@ package android.hardware.input {
    method @FlaggedApi("com.android.input.flags.device_associations") @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void removeUniqueIdAssociationByDescriptor(@NonNull String);
    method @RequiresPermission("android.permission.ASSOCIATE_INPUT_DEVICE_TO_DISPLAY") public void removeUniqueIdAssociationByPort(@NonNull String);
    method public void resetLockedModifierState();
    method @RequiresPermission(android.Manifest.permission.SET_POINTER_SPEED) public void setMouseScalingEnabled(boolean, int);
    field public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L; // 0x96aec7eL
  }

+2 −0
Original line number Diff line number Diff line
@@ -305,4 +305,6 @@ interface IInputManager {
    AidlInputGestureData[] getAppLaunchBookmarks();

    void resetLockedModifierState();

    void setMouseScalingEnabled(boolean enabled, int displayId);
}
+22 −0
Original line number Diff line number Diff line
@@ -1620,6 +1620,28 @@ public final class InputManager {
        }
    }

    /**
     * Set whether all pointer scaling, including linear scaling based on the
     * user's pointer speed setting, should be enabled or disabled for mice.
     *
     * Note that this only affects pointer movements from mice (that is, pointing devices which send
     * relative motions, including trackballs and pointing sticks), not from other pointer devices
     * such as touchpads and styluses.
     *
     * Scaling is enabled by default on new displays until it is explicitly disabled.
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
    @RequiresPermission(Manifest.permission.SET_POINTER_SPEED)
    public void setMouseScalingEnabled(boolean enabled, int displayId) {
        try {
            mIm.setMouseScalingEnabled(enabled, displayId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * A callback used to be notified about battery state changes for an input device. The
     * {@link #onBatteryStateChanged(int, long, BatteryState)} method will be called once after the
+7 −5
Original line number Diff line number Diff line
@@ -102,26 +102,28 @@ class InputController {
    private final NativeWrapper mNativeWrapper;
    private final DisplayManagerInternal mDisplayManagerInternal;
    private final InputManagerInternal mInputManagerInternal;
    private final InputManager mInputManager;
    private final WindowManager mWindowManager;
    private final AttributionSource mAttributionSource;
    private final DeviceCreationThreadVerifier mThreadVerifier;

    InputController(@NonNull Handler handler,
    InputController(@NonNull Handler handler, @NonNull InputManager inputManager,
            @NonNull WindowManager windowManager, AttributionSource attributionSource) {
        this(new NativeWrapper(), handler, windowManager, attributionSource,
        this(new NativeWrapper(), handler, inputManager, windowManager, attributionSource,
                // Verify that virtual devices are not created on the handler thread.
                () -> !handler.getLooper().isCurrentThread());
    }

    @VisibleForTesting
    InputController(@NonNull NativeWrapper nativeWrapper,
            @NonNull Handler handler, @NonNull WindowManager windowManager,
    InputController(@NonNull NativeWrapper nativeWrapper, @NonNull Handler handler,
            @NonNull InputManager inputManager, @NonNull WindowManager windowManager,
            AttributionSource attributionSource,
            @NonNull DeviceCreationThreadVerifier threadVerifier) {
        mHandler = handler;
        mNativeWrapper = nativeWrapper;
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
        mInputManager = inputManager;
        mWindowManager = windowManager;
        mAttributionSource = attributionSource;
        mThreadVerifier = threadVerifier;
@@ -266,7 +268,7 @@ class InputController {
    }

    void setMouseScalingEnabled(boolean enabled, int displayId) {
        mInputManagerInternal.setMouseScalingEnabled(enabled, displayId);
        mInputManager.setMouseScalingEnabled(enabled, displayId);
    }

    void setDisplayEligibilityForPointerCapture(boolean isEligible, int displayId) {
+3 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import android.hardware.display.DisplayManagerGlobal;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.display.IVirtualDisplayCallback;
import android.hardware.display.VirtualDisplayConfig;
import android.hardware.input.InputManager;
import android.hardware.input.VirtualDpadConfig;
import android.hardware.input.VirtualKeyEvent;
import android.hardware.input.VirtualKeyboardConfig;
@@ -474,8 +475,8 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        mBaseVirtualDisplayFlags = flags;

        if (inputController == null) {
            mInputController = new InputController(
                    context.getMainThreadHandler(),
            mInputController = new InputController(context.getMainThreadHandler(),
                    context.getSystemService(InputManager.class),
                    context.getSystemService(WindowManager.class), mAttributionSource);
        } else {
            mInputController = inputController;
Loading