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

Commit 67ca4520 authored by Asmita Poddar's avatar Asmita Poddar
Browse files

Mouse Keys Accessibility Feature

Creating mouse keys as a physical keyboard accessibility feature on Android.
If enabled, mouse keys will  allow users to use a physical keyboard to control
the mouse on the display.

Bug: 341799888
Test: atest FrameworksServicesTests:MouseKeysInterceptorTest
Flag: com.android.hardware.input.keyboard_a11y_mouse_keys
Change-Id: I49fa605375928f16180bbd9b3b63909f9261afbf
parent 9f8fe766
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -61,3 +61,10 @@ flag {
    description: "Allows system to provide keyboard specific key drawables and shortcuts via config files"
    bug: "345440920"
}

flag {
    namespace: "input_native"
    name: "keyboard_a11y_mouse_keys"
    description: "Controls if the mouse keys accessibility feature for physical keyboard is available to the user"
    bug: "341799888"
}
+12 −0
Original line number Diff line number Diff line
@@ -12323,6 +12323,18 @@ public final class Settings {
        public static final String ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED =
                "accessibility_force_invert_color_enabled";
        /**
         * Whether to enable mouse keys for Physical Keyboard accessibility.
         *
         * If set to true, key presses (of the mouse keys) on
         * physical keyboard will control mouse pointer on the display.
         *
         * @hide
         */
        @Readable
        public static final String ACCESSIBILITY_MOUSE_KEYS_ENABLED =
                "accessibility_mouse_keys_enabled";
        /**
         * Whether the Adaptive connectivity option is enabled.
         *
+1 −0
Original line number Diff line number Diff line
@@ -228,6 +228,7 @@ public class SecureSettings {
        Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED,
        Settings.Secure.ACCESSIBILITY_MAGNIFICATION_JOYSTICK_ENABLED,
        Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
        Settings.Secure.ACCESSIBILITY_MOUSE_KEYS_ENABLED,
        Settings.Secure.ACCESSIBILITY_PINCH_TO_ZOOM_ANYWHERE_ENABLED,
        Settings.Secure.ACCESSIBILITY_SINGLE_FINGER_PANNING_ENABLED,
        Settings.Secure.ODI_CAPTIONS_VOLUME_UI_ENABLED,
+1 −0
Original line number Diff line number Diff line
@@ -439,6 +439,7 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.ON_DEVICE_INFERENCE_UNBIND_TIMEOUT_MS, ANY_LONG_VALIDATOR);
        VALIDATORS.put(Secure.ON_DEVICE_INTELLIGENCE_UNBIND_TIMEOUT_MS, ANY_LONG_VALIDATOR);
        VALIDATORS.put(Secure.ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS, NONE_NEGATIVE_LONG_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_MOUSE_KEYS_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.MANDATORY_BIOMETRICS, new InclusiveIntegerRangeValidator(0, 1));
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.annotation.MainThread;
import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Region;
import android.hardware.input.InputManager;
import android.os.Looper;
import android.os.PowerManager;
import android.os.SystemClock;
import android.provider.Settings;
@@ -54,6 +56,7 @@ import com.android.server.policy.WindowManagerPolicy;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;
import java.util.StringJoiner;

/**
@@ -158,6 +161,13 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
     */
    static final int FLAG_FEATURE_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP = 0x00001000;

    /**
     * Flag for enabling the Accessibility mouse key events feature.
     *
     * @see #setUserAndEnabledFeatures(int, int)
     */
    static final int FLAG_FEATURE_MOUSE_KEYS = 0x00002000;

    static final int FEATURES_AFFECTING_MOTION_EVENTS =
            FLAG_FEATURE_INJECT_MOTION_EVENTS
                    | FLAG_FEATURE_AUTOCLICK
@@ -189,6 +199,8 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo

    private KeyboardInterceptor mKeyboardInterceptor;

    private MouseKeysInterceptor mMouseKeysInterceptor;

    private boolean mInstalled;

    private int mUserId;
@@ -733,6 +745,15 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
            // default display.
            addFirstEventHandler(Display.DEFAULT_DISPLAY, mKeyboardInterceptor);
        }

        if ((mEnabledFeatures & FLAG_FEATURE_MOUSE_KEYS) != 0) {
            mMouseKeysInterceptor = new MouseKeysInterceptor(mAms,
                    Objects.requireNonNull(mContext.getSystemService(
                            InputManager.class)),
                    Looper.myLooper(),
                    Display.DEFAULT_DISPLAY);
            addFirstEventHandler(Display.DEFAULT_DISPLAY, mMouseKeysInterceptor);
        }
    }

    /**
@@ -816,6 +837,11 @@ class AccessibilityInputFilter extends InputFilter implements EventStreamTransfo
            mKeyboardInterceptor.onDestroy();
            mKeyboardInterceptor = null;
        }

        if (mMouseKeysInterceptor != null) {
            mMouseKeysInterceptor.onDestroy();
            mMouseKeysInterceptor = null;
        }
    }

    private MagnificationGestureHandler createMagnificationGestureHandler(
Loading