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

Commit 1cb6fcdd authored by Vaibhav Devmurari's avatar Vaibhav Devmurari Committed by Android (Google) Code Review
Browse files

Merge "Add flag and API to enable/disable Slow keys" into main

parents 505c3692 9cf16a57
Loading
Loading
Loading
Loading
+87 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.input;
package android.hardware.input;


import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;
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.keyboardA11yStickyKeysFlag;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;
import static com.android.input.flags.Flags.enableInputFilterRustImpl;


@@ -68,6 +69,12 @@ public class InputSettings {
     */
     */
    public static final int MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS = 5000;
    public static final int MAX_ACCESSIBILITY_BOUNCE_KEYS_THRESHOLD_MILLIS = 5000;


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

    private InputSettings() {
    private InputSettings() {
    }
    }


@@ -418,6 +425,86 @@ public class InputSettings {
                UserHandle.USER_CURRENT);
                UserHandle.USER_CURRENT);
    }
    }


    /**
     * Whether Accessibility slow keys feature flags is enabled.
     *
     * <p>
     * 'Slow keys' is an accessibility feature to aid users who have physical disabilities, that
     * allows the user to specify the duration for which one must press-and-hold a key before the
     * system accepts the keypress.
     * </p>
     *
     * @hide
     */
    public static boolean isAccessibilitySlowKeysFeatureFlagEnabled() {
        return keyboardA11ySlowKeysFlag() && enableInputFilterRustImpl();
    }

    /**
     * Whether Accessibility slow keys is enabled.
     *
     * <p>
     * 'Slow keys' is an accessibility feature to aid users who have physical disabilities, that
     * allows the user to specify the duration for which one must press-and-hold a key before the
     * system accepts the keypress.
     * </p>
     *
     * @hide
     */
    public static boolean isAccessibilitySlowKeysEnabled(@NonNull Context context) {
        return getAccessibilitySlowKeysThreshold(context) != 0;
    }

    /**
     * Get Accessibility slow keys threshold duration in milliseconds.
     *
     * <p>
     * 'Slow keys' is an accessibility feature to aid users who have physical disabilities, that
     * allows the user to specify the duration for which one must press-and-hold a key before the
     * system accepts the keypress.
     * </p>
     *
     * @hide
     */
    public static int getAccessibilitySlowKeysThreshold(@NonNull Context context) {
        if (!isAccessibilitySlowKeysFeatureFlagEnabled()) {
            return 0;
        }
        return Settings.Secure.getIntForUser(context.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_SLOW_KEYS, 0, UserHandle.USER_CURRENT);
    }

    /**
     * Set Accessibility slow keys threshold duration in milliseconds.
     * @param thresholdTimeMillis time duration for which a key should be pressed to be registered
     *                            in the system. The threshold must be between 0 and
     *                            {@link MAX_ACCESSIBILITY_SLOW_KEYS_THRESHOLD_MILLIS}
     *
     * <p>
     * 'Slow keys' is an accessibility feature to aid users who have physical disabilities, that
     * allows the user to specify the duration for which one must press-and-hold a key before the
     * system accepts the keypress.
     * </p>
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setAccessibilitySlowKeysThreshold(@NonNull Context context,
            int thresholdTimeMillis) {
        if (!isAccessibilitySlowKeysFeatureFlagEnabled()) {
            return;
        }
        if (thresholdTimeMillis < 0
                || thresholdTimeMillis > MAX_ACCESSIBILITY_SLOW_KEYS_THRESHOLD_MILLIS) {
            throw new IllegalArgumentException(
                    "Provided Slow keys threshold should be in range [0, "
                            + MAX_ACCESSIBILITY_SLOW_KEYS_THRESHOLD_MILLIS + "]");
        }
        Settings.Secure.putIntForUser(context.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_SLOW_KEYS, thresholdTimeMillis,
                UserHandle.USER_CURRENT);
    }

    /**
    /**
     * Whether Accessibility sticky keys feature is enabled.
     * Whether Accessibility sticky keys feature is enabled.
     *
     *
+7 −0
Original line number Original line Diff line number Diff line
@@ -30,3 +30,10 @@ flag {
    description: "Makes MotionEvent.PointerCoords#isResampled() a public API"
    description: "Makes MotionEvent.PointerCoords#isResampled() a public API"
    bug: "298197511"
    bug: "298197511"
}
}

flag {
    namespace: "input_native"
    name: "keyboard_a11y_slow_keys_flag"
    description: "Controls if the slow keys accessibility feature for physical keyboard is available to the user"
    bug: "294546335"
}
 No newline at end of file
+13 −0
Original line number Original line Diff line number Diff line
@@ -7880,6 +7880,17 @@ public final class Settings {
         */
         */
        public static final String ACCESSIBILITY_BOUNCE_KEYS = "accessibility_bounce_keys";
        public static final String ACCESSIBILITY_BOUNCE_KEYS = "accessibility_bounce_keys";
        /**
         * Whether to enable slow keys for Physical Keyboard accessibility.
         *
         * If set to non-zero value, any key press on physical keyboard needs to be pressed and
         * held for the provided threshold duration (in milliseconds) to be registered in the
         * system.
         *
         * @hide
         */
        public static final String ACCESSIBILITY_SLOW_KEYS = "accessibility_slow_keys";
        /**
        /**
         * Whether to enable sticky keys for Physical Keyboard accessibility.
         * Whether to enable sticky keys for Physical Keyboard accessibility.
         *
         *
@@ -12276,6 +12287,8 @@ public final class Settings {
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD);
            CLONE_TO_MANAGED_PROFILE.add(SHOW_IME_WITH_HARD_KEYBOARD);
            CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS);
            CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_BOUNCE_KEYS);
            CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_SLOW_KEYS);
            CLONE_TO_MANAGED_PROFILE.add(ACCESSIBILITY_STICKY_KEYS);
            CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES);
            CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_BUBBLES);
            CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_HISTORY_ENABLED);
            CLONE_TO_MANAGED_PROFILE.add(NOTIFICATION_HISTORY_ENABLED);
        }
        }
+1 −0
Original line number Original line Diff line number Diff line
@@ -74,6 +74,7 @@ public class SecureSettings {
        Settings.Secure.TTS_DEFAULT_LOCALE,
        Settings.Secure.TTS_DEFAULT_LOCALE,
        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
        Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD,
        Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS,
        Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS,
        Settings.Secure.ACCESSIBILITY_SLOW_KEYS,
        Settings.Secure.ACCESSIBILITY_STICKY_KEYS,
        Settings.Secure.ACCESSIBILITY_STICKY_KEYS,
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,            // moved to global
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,            // moved to global
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,               // moved to global
        Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,               // moved to global
+1 −0
Original line number Original line Diff line number Diff line
@@ -120,6 +120,7 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.TTS_DEFAULT_LOCALE, TTS_LIST_VALIDATOR);
        VALIDATORS.put(Secure.TTS_DEFAULT_LOCALE, TTS_LIST_VALIDATOR);
        VALIDATORS.put(Secure.SHOW_IME_WITH_HARD_KEYBOARD, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.SHOW_IME_WITH_HARD_KEYBOARD, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_BOUNCE_KEYS, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_BOUNCE_KEYS, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_SLOW_KEYS, ANY_INTEGER_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_STICKY_KEYS, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_STICKY_KEYS, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, BOOLEAN_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_NETWORKS_AVAILABLE_REPEAT_DELAY, NON_NEGATIVE_INTEGER_VALIDATOR);
Loading