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

Commit 97cef717 authored by Harry Cutts's avatar Harry Cutts
Browse files

InputSettings: add setting to disable touchpads

For accessibility reasons, we want users to be able to disable
touchpads. For example, users who are visually impaired may want to
disable the touchpad from a keyboard/touchpad combo device to avoid
accidental clicks or pointer movements, while still using the keyboard.

Due to the potentially disruptive nature of the setting it will not be
backed up and restored. For example, if a user thought that their built
in touchpad was broken and attempted a factory reset to fix it,
restoring the settings would then “break” it again.

This can be tested with the following ADB command:

    $ adb shell settings put system touchpad_enabled 0

(Or the same with 1 to re-enable.)

Test: connect a touchpad, disable touchpads, check it stops working.
      Turn the toggle back on, check it starts working
Test: with touchpads disabled, connect a touchpad, check it doesn't
      work. Turn the toggle back on, check it starts working
Test: with a keyboard/touchpad combo (I tested with the Lenovo P12 Pro's
      detachable unit), check that the keyboard remains usable when the
      touchpad is disabled
Test: $ atest com.android.server.input.InputManagerServiceTests
Test: $ atest SettingsProviderTest
Flag: com.android.hardware.input.touchpad_disable
Bug: 372857036
Bug: 376669241
Change-Id: I1938512872b462e66e4ad822b08614a254280f01
parent e0c0a7f5
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.hardware.input.Flags.mouseScrollingAcceleration;
import static com.android.hardware.input.Flags.mouseReverseVerticalScrolling;
import static com.android.hardware.input.Flags.mouseSwapPrimaryButton;
import static com.android.hardware.input.Flags.pointerAcceleration;
import static com.android.hardware.input.Flags.touchpadDisable;
import static com.android.hardware.input.Flags.touchpadSystemGestureDisable;
import static com.android.hardware.input.Flags.touchpadThreeFingerTapShortcut;
import static com.android.hardware.input.Flags.touchpadVisualizer;
@@ -434,6 +435,15 @@ public class InputSettings {
        return touchpadSystemGestureDisable();
    }

    /**
     * Returns true if the feature flag for disabling touchpads is enabled.
     *
     * @hide
     */
    public static boolean isTouchpadDisableFeatureFlagEnabled() {
        return touchpadDisable();
    }

    /**
     * Returns true if the feature flag for touchpad visualizer is enabled.
     *
@@ -636,6 +646,39 @@ public class InputSettings {
                Settings.System.TOUCHPAD_SYSTEM_GESTURES, enabled ? 1 : 0, UserHandle.USER_CURRENT);
    }

    /**
     * Returns true if touchpads should be enabled.
     *
     * @param context The application context.
     * @return Whether touchpads are enabled
     *
     * @hide
     */
    public static boolean useTouchpads(@NonNull Context context) {
        if (!isTouchpadDisableFeatureFlagEnabled()) {
            return true;
        }
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_ENABLED, 1, UserHandle.USER_CURRENT) == 1;
    }

    /**
     * Sets whether touchpads are enabled.
     *
     * @param context The application context.
     * @param enabled True to enable touchpads.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setTouchpadsEnabled(@NonNull Context context, boolean enabled) {
        if (!isTouchpadDisableFeatureFlagEnabled()) {
            return;
        }
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
    }

    /**
     * Whether a pointer icon will be shown over the location of a stylus pointer.
     *
+7 −0
Original line number Diff line number Diff line
@@ -229,3 +229,10 @@ flag {
    description: "Enables shortcut for quick settings panel"
    bug: "423899230"
}

flag {
    name: "touchpad_disable"
    namespace: "input"
    description: "Adds an accessibility setting to disable touchpads"
    bug: "372857036"
}
+8 −0
Original line number Diff line number Diff line
@@ -6452,6 +6452,13 @@ public final class Settings {
        public static final String TOUCHPAD_ACCELERATION_ENABLED =
                "touchpad_acceleration_enabled";
        /**
         * Whether to enable touchpads.
         *
         * @hide
         */
        public static final String TOUCHPAD_ENABLED = "touchpad_enabled";
        /**
         * Whether to enable reversed vertical scrolling for connected mice.
         *
@@ -6773,6 +6780,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(TOUCHPAD_RIGHT_CLICK_ZONE);
            PRIVATE_SETTINGS.add(TOUCHPAD_SYSTEM_GESTURES);
            PRIVATE_SETTINGS.add(TOUCHPAD_ACCELERATION_ENABLED);
            PRIVATE_SETTINGS.add(TOUCHPAD_ENABLED);
            PRIVATE_SETTINGS.add(CAMERA_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION_COLOR);
+3 −1
Original line number Diff line number Diff line
@@ -958,7 +958,9 @@ public class SettingsBackupTest {
                        Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ,
                        Settings.System.MULTI_AUDIO_FOCUS_ENABLED, // form-factor/OEM specific
                        // Potentially disruptive to on-boarding flow on new devices
                        Settings.System.TOUCHPAD_SYSTEM_GESTURES
                        Settings.System.TOUCHPAD_SYSTEM_GESTURES,
                        // Potentially disruptive to on-boarding flow on new devices
                        Settings.System.TOUCHPAD_ENABLED
                );
        if (!Flags.backUpSmoothDisplayAndForcePeakRefreshRate()) {
            settings.add(Settings.System.MIN_REFRESH_RATE);
+6 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ class InputSettingsObserver extends ContentObserver {
                        (reason) -> updateTouchpadSystemGesturesEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_ACCELERATION_ENABLED),
                        (reason) -> updateTouchpadAccelerationEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_ENABLED),
                        (reason) -> updateTouchpadsEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.SHOW_TOUCHES),
                        (reason) -> updateShowTouches()),
                Map.entry(Settings.System.getUriFor(Settings.System.POINTER_LOCATION),
@@ -248,6 +250,10 @@ class InputSettingsObserver extends ContentObserver {
                InputSettings.isTouchpadAccelerationEnabled(mContext));
    }

    private void updateTouchpadsEnabled() {
        mNative.setTouchpadsEnabled(InputSettings.useTouchpads(mContext));
    }

    private void updateShowTouches() {
        mNative.setShowTouches(getBoolean(Settings.System.SHOW_TOUCHES, false));
    }
Loading