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

Commit 7b0a3941 authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge "Add plumbing for touchpad settings"

parents d8879254 a996e77d
Loading
Loading
Loading
Loading
+26 −32
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.os.VibratorManager;
@@ -1163,6 +1164,7 @@ public final class InputManager {
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public void setPointerSpeed(Context context, int speed) {
        if (speed < MIN_POINTER_SPEED || speed > MAX_POINTER_SPEED) {
            throw new IllegalArgumentException("speed out of range");
@@ -2183,9 +2185,9 @@ public final class InputManager {
     * @hide
     */
    public int getTouchpadPointerSpeed(@NonNull Context context) {
        int speed = DEFAULT_POINTER_SPEED;
        // TODO: obtain the actual speed from the settings
        return speed;
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_POINTER_SPEED, DEFAULT_POINTER_SPEED,
                UserHandle.USER_CURRENT);
    }

    /**
@@ -2199,31 +2201,14 @@ public final class InputManager {
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public void setTouchpadPointerSpeed(@NonNull Context context, int speed) {
        if (speed < MIN_POINTER_SPEED || speed > MAX_POINTER_SPEED) {
            throw new IllegalArgumentException("speed out of range");
        }

        // TODO: set the right setting
    }

    /**
     * Changes the touchpad pointer speed temporarily, but does not save the setting.
     *
     * The new speed will only apply to gesture-compatible touchpads.
     * Requires {@link android.Manifest.permission#SET_POINTER_SPEED}.
     *
     * @param speed The pointer speed as a value between {@link #MIN_POINTER_SPEED} and
     * {@link #MAX_POINTER_SPEED}, or the default value {@link #DEFAULT_POINTER_SPEED}.
     *
     * @hide
     */
    public void tryTouchpadPointerSpeed(int speed) {
        if (speed < MIN_POINTER_SPEED || speed > MAX_POINTER_SPEED) {
            throw new IllegalArgumentException("speed out of range");
        }

        // TODO: set the touchpad pointer speed on the gesture library
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_POINTER_SPEED, speed, UserHandle.USER_CURRENT);
    }

    /**
@@ -2267,8 +2252,8 @@ public final class InputManager {
     * @hide
     */
    public boolean useTouchpadNaturalScrolling(@NonNull Context context) {
        // TODO: obtain the actual behavior from the settings
        return true;
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_NATURAL_SCROLLING, 0, UserHandle.USER_CURRENT) == 1;
    }

    /**
@@ -2282,8 +2267,11 @@ public final class InputManager {
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public void setTouchpadNaturalScrolling(@NonNull Context context, boolean enabled) {
        // TODO: set the right setting
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_NATURAL_SCROLLING, enabled ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
@@ -2297,8 +2285,8 @@ public final class InputManager {
     * @hide
     */
    public boolean useTouchpadTapToClick(@NonNull Context context) {
        // TODO: obtain the actual behavior from the settings
        return true;
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_TAP_TO_CLICK, 0, UserHandle.USER_CURRENT) == 1;
    }

    /**
@@ -2311,8 +2299,11 @@ public final class InputManager {
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public void setTouchpadTapToClick(@NonNull Context context, boolean enabled) {
        // TODO: set the right setting
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_TAP_TO_CLICK, enabled ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
@@ -2355,8 +2346,8 @@ public final class InputManager {
     * @hide
     */
    public boolean useTouchpadRightClickZone(@NonNull Context context) {
        // TODO: obtain the actual behavior from the settings
        return true;
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE, 0, UserHandle.USER_CURRENT) == 1;
    }

    /**
@@ -2369,8 +2360,11 @@ public final class InputManager {
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public void setTouchpadRightClickZone(@NonNull Context context, boolean enabled) {
        // TODO: set the right setting
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE, enabled ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
+42 −0
Original line number Diff line number Diff line
@@ -5664,6 +5664,44 @@ public final class Settings {
        @Readable
        public static final String POINTER_SPEED = "pointer_speed";
        /**
         * Touchpad pointer speed setting.
         * This is an integer value in a range between -7 and +7, so there are 15 possible values.
         *   -7 = slowest
         *    0 = default speed
         *   +7 = fastest
         * @hide
         */
        public static final String TOUCHPAD_POINTER_SPEED = "touchpad_pointer_speed";
        /**
         * Whether to invert the touchpad scrolling direction.
         *
         * If set to 1 (the default), moving two fingers downwards on the touchpad will scroll
         * upwards, consistent with normal touchscreen scrolling. If set to 0, moving two fingers
         * downwards will scroll downwards.
         *
         * @hide
         */
        public static final String TOUCHPAD_NATURAL_SCROLLING = "touchpad_natural_scrolling";
        /**
         * Whether to enable tap-to-click on touchpads.
         *
         * @hide
         */
        public static final String TOUCHPAD_TAP_TO_CLICK = "touchpad_tap_to_click";
        /**
         * Whether to enable a right-click zone on touchpads.
         *
         * When set to 1, pressing to click in a section on the right-hand side of the touchpad will
         * result in a context click (a.k.a. right click).
         *
         * @hide
         */
        public static final String TOUCHPAD_RIGHT_CLICK_ZONE = "touchpad_right_click_zone";
        /**
         * Whether lock-to-app will be triggered by long-press on recents.
         * @hide
@@ -5850,6 +5888,10 @@ public final class Settings {
            PRIVATE_SETTINGS.add(DISPLAY_COLOR_MODE_VENDOR_HINT);
            PRIVATE_SETTINGS.add(DESKTOP_MODE);
            PRIVATE_SETTINGS.add(LOCALE_PREFERENCES);
            PRIVATE_SETTINGS.add(TOUCHPAD_POINTER_SPEED);
            PRIVATE_SETTINGS.add(TOUCHPAD_NATURAL_SCROLLING);
            PRIVATE_SETTINGS.add(TOUCHPAD_TAP_TO_CLICK);
            PRIVATE_SETTINGS.add(TOUCHPAD_RIGHT_CLICK_ZONE);
        }
        /**
+12 −1
Original line number Diff line number Diff line
@@ -195,6 +195,17 @@ message SystemSettingsProto {
    optional Text text = 29;

    optional SettingProto time_12_24 = 30 [ (android.privacy).dest = DEST_AUTOMATIC ];

    message Touchpad {
        option (android.msg_privacy).dest = DEST_EXPLICIT;

        optional SettingProto natural_scrolling = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto pointer_speed = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto right_click_zone = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto tap_to_click = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
    }
    optional Touchpad touchpad = 36;

    optional SettingProto tty_mode = 31 [ (android.privacy).dest = DEST_AUTOMATIC ];

    message Vibrate {
@@ -252,5 +263,5 @@ message SystemSettingsProto {

    // Please insert fields in alphabetical order and group them into messages
    // if possible (to avoid reaching the method limit).
    // Next tag = 36;
    // Next tag = 37;
}
+5 −1
Original line number Diff line number Diff line
@@ -92,6 +92,10 @@ public class SystemSettings {
        Settings.System.CLOCKWORK_BLUETOOTH_SETTINGS_PREF,
        Settings.System.UNREAD_NOTIFICATION_DOT_INDICATOR,
        Settings.System.AUTO_LAUNCH_MEDIA_CONTROLS,
        Settings.System.LOCALE_PREFERENCES
        Settings.System.LOCALE_PREFERENCES,
        Settings.System.TOUCHPAD_POINTER_SPEED,
        Settings.System.TOUCHPAD_NATURAL_SCROLLING,
        Settings.System.TOUCHPAD_TAP_TO_CLICK,
        Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE,
    };
}
+4 −0
Original line number Diff line number Diff line
@@ -186,6 +186,10 @@ public class SystemSettingsValidators {
        VALIDATORS.put(System.SIP_ADDRESS_ONLY, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.SIP_ASK_ME_EACH_TIME, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.POINTER_SPEED, new InclusiveFloatRangeValidator(-7, 7));
        VALIDATORS.put(System.TOUCHPAD_POINTER_SPEED, new InclusiveIntegerRangeValidator(-7, 7));
        VALIDATORS.put(System.TOUCHPAD_NATURAL_SCROLLING, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_TAP_TO_CLICK, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_RIGHT_CLICK_ZONE, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.LOCK_TO_APP_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(
                System.EGG_MODE,
Loading