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

Commit cf4651ff authored by Asmita Poddar's avatar Asmita Poddar Committed by Android (Google) Code Review
Browse files

Merge "Interface with Repeat keys feature flag and Settings" into main

parents 6079d9d3 9ea5f010
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1797,11 +1797,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"
}