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

Commit 9e9a350f authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Add Bounce keys A11Y feature flag and Setting

DD: go/pk_accessibility
Bug: 294546335
Test: None
Change-Id: If9b7e767632959e052b2e27dd79f9310460bd011
parent fae25ec1
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.hardware.input;

import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;

import android.Manifest;
import android.annotation.FloatRange;
import android.annotation.NonNull;
@@ -58,6 +60,11 @@ public class InputSettings {
     */
    public static final float DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH = .8f;

    /**
     * The maximum allowed Accessibility bounce keys threshold.
     * @hide
     */
    public static final int MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS = 5000;

    private InputSettings() {
    }
@@ -328,4 +335,70 @@ public class InputSettings {
                       .getBoolean(com.android.internal.R.bool.config_enableStylusPointerIcon)
               || InputProperties.force_enable_stylus_pointer_icon().orElse(false);
    }

    /**
     * Whether Accessibility bounce keys is enabled.
     *
     * <p>
     * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
     * that allows the user to configure the device to ignore rapid, repeated keypresses of the
     * same key.
     * </p>
     *
     * @hide
     */
    public static boolean isAccessibilityBounceKeysEnabled(@NonNull Context context) {
        return getAccessibilityBounceKeysThreshold(context) != 0;
    }

    /**
     * Get Accessibility bounce keys threshold duration in milliseconds.
     *
     * <p>
     * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
     * that allows the user to configure the device to ignore rapid, repeated keypresses of the
     * same key.
     * </p>
     *
     * @hide
     */
    public static int getAccessibilityBounceKeysThreshold(@NonNull Context context) {
        if (!keyboardA11yBounceKeysFlag()) {
            return 0;
        }
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS, 0, UserHandle.USER_CURRENT);
    }

    /**
     * Set Accessibility bounce keys threshold duration in milliseconds.
     * @param thresholdTimeMillis time duration for which a key down will be ignored after a
     *                            previous key up for the same key on the same device between 0 and
     *                            {@link MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS}
     *
     * <p>
     * ‘Bounce keys’ is an accessibility feature to aid users who have physical disabilities,
     * that allows the user to configure the device to ignore rapid, repeated keypresses of the
     * same key.
     * </p>
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setAccessibilityBounceKeysThreshold(@NonNull Context context,
            int thresholdTimeMillis) {
        if (!keyboardA11yBounceKeysFlag()) {
            return;
        }
        if (thresholdTimeMillis < 0
                || thresholdTimeMillis > MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS) {
            throw new IllegalArgumentException(
                    "Provided Bounce keys threshold should be in range [0, "
                            + MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS + "]");
        }
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS, thresholdTimeMillis,
                UserHandle.USER_CURRENT);
    }

}
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,12 @@ flag {
    bug: "294546335"
}

flag {
    namespace: "input_native"
    name: "keyboard_a11y_bounce_keys_flag"
    description: "Controls if the bounce keys accessibility feature for physical keyboard is available to the user"
    bug: "294546335"
}

flag {
    namespace: "input_native"
+11 −0
Original line number Diff line number Diff line
@@ -7739,6 +7739,16 @@ public final class Settings {
        @SuppressLint("NoSettingsProvider")
        public static final String SHOW_IME_WITH_HARD_KEYBOARD = "show_ime_with_hard_keyboard";
        /**
         * Whether to enable bounce keys for Physical Keyboard accessibility.
         *
         * If set to non-zero value, any key press on physical keyboard within the provided
         * threshold duration (in milliseconds) of the same key, will be ignored.
         *
         * @hide
         */
        public static final String ACCESSIBILITY_BOUNCE_KEYS = "accessibility_bounce_keys";
        /**
         * Whether stylus button presses are disabled. This is a boolean that
         * determines if stylus buttons are ignored.
@@ -12057,6 +12067,7 @@ public final class Settings {
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_CHANGER);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD);
            CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS);
            CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES);
        }
+1 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class SecureSettings {
        Settings.Secure.TTS_ENABLED_PLUGINS,
        Settings.Secure.TTS_DEFAULT_LOCALE,
        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
        Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS,
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,            // moved to global
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,               // moved to global
        Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT,                        // moved to global
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.TTS_ENABLED_PLUGINS, new PackageNameListValidator(" "));
        VALIDATORS.put(Secure.TTS_DEFAULT_LOCALE, TTS_LIST_VALIDATOR);
        VALIDATORS.put(Secure.SHOW_IME_WITH_HARD_KEYBOARD, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_BOUNCE_KEYS, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, NON_NEGATIVE_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, NON_NEGATIVE_INTEGER_VALIDATOR);
Loading