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

Commit 9ea5f010 authored by Asmita Poddar's avatar Asmita Poddar
Browse files

Interface with Repeat keys feature flag and Settings

Add the APIs to check whether repeat keys feature is enabled and to set
the configurable values for the key repeat timeout[1] and key repeat
delay[2] if it is to be set via Settings.
[1] Key repeat timeout is the time duration before which the key starts
repeating on being pressed down.
[2] Key repeat delay is the time interval between successive key repeats
when a key is pressed down.
The minimum and maximum values for both settings are set according the
the corresponding values set in ChromeOS for consistency.

Bug: 363979307
Flag: com.android.hardware.input.keyboard_repeat_keys
Test: Presubmit
Change-Id: I7120cdf54c9c3c65e03751290b94ac767cbef900
parent 6501946f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1801,11 +1801,15 @@ package android.hardware.input {

  public class InputSettings {
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_bounce_keys_flag") public static int getAccessibilityBounceKeysThreshold(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_repeat_keys") public static int getAccessibilityRepeatKeysDelay(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_repeat_keys") public static int getAccessibilityRepeatKeysTimeout(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_slow_keys_flag") public static int getAccessibilitySlowKeysThreshold(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_mouse_keys") public static boolean isAccessibilityMouseKeysEnabled(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_sticky_keys_flag") public static boolean isAccessibilityStickyKeysEnabled(@NonNull android.content.Context);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_bounce_keys_flag") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilityBounceKeysThreshold(@NonNull android.content.Context, int);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_mouse_keys") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilityMouseKeysEnabled(@NonNull android.content.Context, boolean);
    method @FlaggedApi("com.android.hardware.input.keyboard_repeat_keys") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilityRepeatKeysDelay(@NonNull android.content.Context, int);
    method @FlaggedApi("com.android.hardware.input.keyboard_repeat_keys") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilityRepeatKeysTimeout(@NonNull android.content.Context, int);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_slow_keys_flag") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilitySlowKeysThreshold(@NonNull android.content.Context, int);
    method @FlaggedApi("com.android.hardware.input.keyboard_a11y_sticky_keys_flag") @RequiresPermission(android.Manifest.permission.WRITE_SETTINGS) public static void setAccessibilityStickyKeysEnabled(@NonNull android.content.Context, boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public static void setMaximumObscuringOpacityForTouch(@NonNull android.content.Context, @FloatRange(from=0, to=1) float);
+164 −0
Original line number Diff line number Diff line
@@ -20,10 +20,12 @@ import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_BOUNCE_KEYS_FL
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_MOUSE_KEYS;
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_SLOW_KEYS_FLAG;
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_A11Y_STICKY_KEYS_FLAG;
import static com.android.hardware.input.Flags.FLAG_KEYBOARD_REPEAT_KEYS;
import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11ySlowKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yStickyKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yMouseKeys;
import static com.android.hardware.input.Flags.keyboardRepeatKeys;
import static com.android.hardware.input.Flags.touchpadTapDragging;
import static com.android.hardware.input.Flags.touchpadVisualizer;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;
@@ -40,6 +42,7 @@ import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
import android.sysprop.InputProperties;
import android.view.ViewConfiguration;

/**
 * InputSettings encapsulates reading and writing settings related to input
@@ -90,6 +93,30 @@ public class InputSettings {
     */
    public static final int DEFAULT_STYLUS_POINTER_ICON_ENABLED = 1;

    /**
     * The minimum allowed repeat keys timeout before starting key repeats.
     * @hide
     */
    public static final int MIN_KEY_REPEAT_TIMEOUT_MILLIS = 150;

    /**
     * The maximum allowed repeat keys timeout before starting key repeats.
     * @hide
     */
    public static final int MAX_KEY_REPEAT_TIMEOUT_MILLIS = 2000;

    /**
     * The minimum allowed repeat keys delay between successive key repeats.
     * @hide
     */
    public static final int MIN_KEY_REPEAT_DELAY_MILLIS = 20;

    /**
     * The maximum allowed repeat keys delay between successive key repeats.
     * @hide
     */
    public static final int MAX_KEY_REPEAT_DELAY_MILLIS = 2000;

    private InputSettings() {
    }

@@ -767,4 +794,141 @@ public class InputSettings {
                Settings.Secure.ACCESSIBILITY_MOUSE_KEYS_ENABLED, enabled ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
     * Whether "Repeat keys" feature flag is enabled.
     *
     * <p>
     * ‘Repeat keys’ is a feature which allows users to generate key repeats when a particular
     * key on the physical keyboard is held down. This accessibility feature allows the user
     * to configure the timeout before the key repeats begin as well as the delay
     * between successive key repeats.
     * </p>
     *
     * @hide
     */
    public static boolean isRepeatKeysFeatureFlagEnabled() {
        return keyboardRepeatKeys();
    }

    /**
     * Get Accessibility repeat keys timeout duration in milliseconds.
     * The default key repeat timeout is {@link ViewConfiguration#DEFAULT_KEY_REPEAT_TIMEOUT_MS}.
     *
     * @param context The application context
     * @return The time duration for which a key should be pressed after
     *         which the pressed key will be repeated. The timeout must be between
     *         {@link #MIN_KEY_REPEAT_TIMEOUT_MILLIS} and
     *         {@link #MAX_KEY_REPEAT_TIMEOUT_MILLIS}
     *
     * <p>
     * ‘Repeat keys’ is a feature which allows users to generate key repeats when a particular
     * key on the physical keyboard is held down. This accessibility feature allows the user
     * to configure the timeout before the key repeats begin as well as the delay
     * between successive key repeats.
     * </p>
     *
     * @hide
     */
    @TestApi
    @FlaggedApi(FLAG_KEYBOARD_REPEAT_KEYS)
    public static int getAccessibilityRepeatKeysTimeout(@NonNull Context context) {
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.KEY_REPEAT_TIMEOUT_MS, ViewConfiguration.getKeyRepeatTimeout(),
                UserHandle.USER_CURRENT);
    }

    /**
     * Get Accessibility repeat keys delay rate in milliseconds.
     * The default key repeat delay is {@link ViewConfiguration#DEFAULT_KEY_REPEAT_DELAY_MS}.
     *
     * @param context The application context
     * @return Time duration between successive key repeats when a key is
     *         pressed down. The delay duration must be between
     *         {@link #MIN_KEY_REPEAT_DELAY_MILLIS} and
     *         {@link #MAX_KEY_REPEAT_DELAY_MILLIS}
     *
     * <p>
     * ‘Repeat keys’ is a feature which allows users to generate key repeats when a particular
     * key on the physical keyboard is held down. This accessibility feature allows the user
     * to configure the timeout before the key repeats begin as well as the delay
     * between successive key repeats.
     * </p>
     *
     * @hide
     */
    @TestApi
    @FlaggedApi(FLAG_KEYBOARD_REPEAT_KEYS)
    public static int getAccessibilityRepeatKeysDelay(@NonNull Context context) {
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.KEY_REPEAT_DELAY_MS, ViewConfiguration.getKeyRepeatDelay(),
                UserHandle.USER_CURRENT);
    }

    /**
     * Set Accessibility repeat keys timeout duration in milliseconds.
     *
     * @param timeoutTimeMillis time duration for which a key should be pressed after which the
     *                          pressed key will be repeated. The timeout must be between
     *                          {@link #MIN_KEY_REPEAT_TIMEOUT_MILLIS} and
     *                          {@link #MAX_KEY_REPEAT_TIMEOUT_MILLIS}
     *
     *  <p>
     * ‘Repeat keys’ is a feature which allows users to generate key repeats when a particular
     * key on the physical keyboard is held down. This accessibility feature allows the user
     * to configure the timeout before the key repeats begin as well as the delay
     *  between successive key repeats.
     * </p>
     *
     * @hide
     */
    @TestApi
    @FlaggedApi(FLAG_KEYBOARD_REPEAT_KEYS)
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setAccessibilityRepeatKeysTimeout(@NonNull Context context,
            int timeoutTimeMillis) {
        if (timeoutTimeMillis < MIN_KEY_REPEAT_TIMEOUT_MILLIS
                || timeoutTimeMillis > MAX_KEY_REPEAT_TIMEOUT_MILLIS) {
            throw new IllegalArgumentException(
                    "Provided repeat keys timeout should be in range ("
                            + MIN_KEY_REPEAT_TIMEOUT_MILLIS + ","
                            + MAX_KEY_REPEAT_TIMEOUT_MILLIS + ")");
        }
        Settings.Secure.putIntForUser(context.getContentResolver(),
                Settings.Secure.KEY_REPEAT_TIMEOUT_MS, timeoutTimeMillis,
                UserHandle.USER_CURRENT);
    }

    /**
     * Set Accessibility repeat key delay duration in milliseconds.
     *
     * @param delayTimeMillis Time duration between successive key repeats when a key is
     *                        pressed down. The delay duration must be between
     *                        {@link #MIN_KEY_REPEAT_DELAY_MILLIS} and
     *                        {@link #MAX_KEY_REPEAT_DELAY_MILLIS}
     * <p>
     * ‘Repeat keys’ is a feature which allows users to generate key repeats when a particular
     * key on the physical keyboard is held down. This accessibility feature allows the user
     * to configure the timeout before the key repeats begin as well as the delay
     * between successive key repeats.
     * </p>
     *
     * @hide
     */
    @TestApi
    @FlaggedApi(FLAG_KEYBOARD_REPEAT_KEYS)
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setAccessibilityRepeatKeysDelay(@NonNull Context context,
            int delayTimeMillis) {
        if (delayTimeMillis < MIN_KEY_REPEAT_DELAY_MILLIS
                || delayTimeMillis > MAX_KEY_REPEAT_DELAY_MILLIS) {
            throw new IllegalArgumentException(
                    "Provided repeat keys delay should be in range ("
                            + MIN_KEY_REPEAT_DELAY_MILLIS + ","
                            + MAX_KEY_REPEAT_DELAY_MILLIS + ")");
        }
        Settings.Secure.putIntForUser(context.getContentResolver(),
                Settings.Secure.KEY_REPEAT_DELAY_MS, delayTimeMillis,
                UserHandle.USER_CURRENT);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -99,3 +99,10 @@ flag {
  description: "Refactor ModifierShortcutManager internal representation of shortcuts."
  bug: "358603902"
}

flag {
  name: "keyboard_repeat_keys"
  namespace: "input"
  description: "Allow configurable timeout before key repeat and repeat delay rate for key repeats"
  bug: "336585002"
}