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

Commit 6b81f535 authored by Harry Cutts's avatar Harry Cutts
Browse files

input: replace pointer acceleration factor with a boolean

InputManagerService's setPointerAcceleration method is only ever called
with values of 1 (which disables pointer acceleration completely) or 3
(the default, as specified in IInputConstants.aidl), so it is
effectively being used as a boolean toggle for acceleration. Exposing a
single number to control pointer acceleration only makes sense because
our acceleration "curve" is basically a flat line, of which the number
controls the gradient.

We are about to replace the acceleration curve with a more sophisticated
one, and keeping this numerical factor would make that work more
complicated. Since there is only a use case for disabling acceleration
altogether, replace setPointerAcceleration with
setMousePointerAccelerationEnabled, which takes a boolean.

Since the new touchpad mapper was implemented, the pointer speed and
acceleration for touchpads and mice have been implemented and controlled
separately, so also add "mouse" to the method name to make it clear that
only one type of pointer input is affected by the setting.

Bug: 315313622
Test: atest InputTests
Test: atest FrameworksServicesTests:com.android.server.companion.virtual.VirtualDeviceManagerServiceTest
Test: atest VirtualMouseTest
Test: atest VirtualDeviceMirrorDisplayTest
Change-Id: I88dba6788c51644e7a4672cceca4e0338cde0168
parent 660c3c94
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -245,8 +245,8 @@ class InputController {
        mInputManagerInternal.setPointerIconVisible(visible, displayId);
    }

    void setPointerAcceleration(float pointerAcceleration, int displayId) {
        mInputManagerInternal.setPointerAcceleration(pointerAcceleration, displayId);
    void setMousePointerAccelerationEnabled(boolean enabled, int displayId) {
        mInputManagerInternal.setMousePointerAccelerationEnabled(enabled, displayId);
    }

    void setDisplayEligibilityForPointerCapture(boolean isEligible, int displayId) {
+1 −1
Original line number Diff line number Diff line
@@ -1110,7 +1110,7 @@ final class VirtualDeviceImpl extends IVirtualDevice.Stub
        final long token = Binder.clearCallingIdentity();
        try {
            mInputController.setShowPointerIcon(showPointer, displayId);
            mInputController.setPointerAcceleration(1f, displayId);
            mInputController.setMousePointerAccelerationEnabled(false, displayId);
            mInputController.setDisplayEligibilityForPointerCapture(/* isEligible= */ false,
                    displayId);
            // WM throws a SecurityException if the display is untrusted.
+6 −3
Original line number Diff line number Diff line
@@ -104,10 +104,13 @@ public abstract class InputManagerInternal {
    public abstract PointF getCursorPosition();

    /**
     * Sets the pointer acceleration.
     * See {@code frameworks/native/include/input/VelocityControl.h#VelocityControlParameters}.
     * Enables or disables pointer acceleration for mouse movements.
     *
     * 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.
     */
    public abstract void setPointerAcceleration(float acceleration, int displayId);
    public abstract void setMousePointerAccelerationEnabled(boolean enabled, int displayId);

    /**
     * Sets the eligibility of windows on a given display for pointer capture. If a display is
+21 −15
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import android.os.CombinedVibration;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.IInputConstants;
import android.os.IVibratorStateListener;
import android.os.InputEventInjectionResult;
import android.os.InputEventInjectionSync;
@@ -1367,9 +1366,9 @@ public class InputManagerService extends IInputManager.Stub
        mNative.setPointerSpeed(speed);
    }

    private void setPointerAcceleration(float acceleration, int displayId) {
    private void setMousePointerAccelerationEnabled(boolean enabled, int displayId) {
        updateAdditionalDisplayInputProperties(displayId,
                properties -> properties.pointerAcceleration = acceleration);
                properties -> properties.mousePointerAccelerationEnabled = enabled);
    }

    private void setPointerIconVisible(boolean visible, int displayId) {
@@ -2256,7 +2255,8 @@ public class InputManagerService extends IInputManager.Stub
                            + mAdditionalDisplayInputProperties.keyAt(i));
                    final AdditionalDisplayInputProperties properties =
                            mAdditionalDisplayInputProperties.valueAt(i);
                    pw.println("pointerAcceleration: " + properties.pointerAcceleration);
                    pw.println("mousePointerAccelerationEnabled: "
                            + properties.mousePointerAccelerationEnabled);
                    pw.println("pointerIconVisible: " + properties.pointerIconVisible);
                }
                pw.decreaseIndent();
@@ -3257,8 +3257,8 @@ public class InputManagerService extends IInputManager.Stub
        }

        @Override
        public void setPointerAcceleration(float acceleration, int displayId) {
            InputManagerService.this.setPointerAcceleration(acceleration, displayId);
        public void setMousePointerAccelerationEnabled(boolean enabled, int displayId) {
            InputManagerService.this.setMousePointerAccelerationEnabled(enabled, displayId);
        }

        @Override
@@ -3350,11 +3350,15 @@ public class InputManagerService extends IInputManager.Stub
    private static class AdditionalDisplayInputProperties {

        static final boolean DEFAULT_POINTER_ICON_VISIBLE = true;
        static final float DEFAULT_POINTER_ACCELERATION =
                (float) IInputConstants.DEFAULT_POINTER_ACCELERATION;
        static final boolean DEFAULT_MOUSE_POINTER_ACCELERATION_ENABLED = true;

        // The pointer acceleration for this display.
        public float pointerAcceleration;
        /**
         * Whether to enable mouse pointer acceleration on this display. 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.
         */
        public boolean mousePointerAccelerationEnabled;

        // Whether the pointer icon should be visible or hidden on this display.
        public boolean pointerIconVisible;
@@ -3364,12 +3368,12 @@ public class InputManagerService extends IInputManager.Stub
        }

        public boolean allDefaults() {
            return Float.compare(pointerAcceleration, DEFAULT_POINTER_ACCELERATION) == 0
            return mousePointerAccelerationEnabled == DEFAULT_MOUSE_POINTER_ACCELERATION_ENABLED
                    && pointerIconVisible == DEFAULT_POINTER_ICON_VISIBLE;
        }

        public void reset() {
            pointerAcceleration = DEFAULT_POINTER_ACCELERATION;
            mousePointerAccelerationEnabled = DEFAULT_MOUSE_POINTER_ACCELERATION_ENABLED;
            pointerIconVisible = DEFAULT_POINTER_ICON_VISIBLE;
        }
    }
@@ -3401,9 +3405,11 @@ public class InputManagerService extends IInputManager.Stub
            }
        }

        if (properties.pointerAcceleration != mCurrentDisplayProperties.pointerAcceleration) {
            mCurrentDisplayProperties.pointerAcceleration = properties.pointerAcceleration;
            mNative.setPointerAcceleration(properties.pointerAcceleration);
        if (properties.mousePointerAccelerationEnabled
                != mCurrentDisplayProperties.mousePointerAccelerationEnabled) {
            mCurrentDisplayProperties.mousePointerAccelerationEnabled =
                    properties.mousePointerAccelerationEnabled;
            mNative.setMousePointerAccelerationEnabled(properties.mousePointerAccelerationEnabled);
        }
    }

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

    void setPointerSpeed(int speed);

    void setPointerAcceleration(float acceleration);
    void setMousePointerAccelerationEnabled(boolean enabled);

    void setTouchpadPointerSpeed(int speed);

@@ -351,7 +351,7 @@ interface NativeInputManagerService {
        public native void setPointerSpeed(int speed);

        @Override
        public native void setPointerAcceleration(float acceleration);
        public native void setMousePointerAccelerationEnabled(boolean enabled);

        @Override
        public native void setTouchpadPointerSpeed(int speed);
Loading