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

Commit 1a239822 authored by David Padlipsky's avatar David Padlipsky
Browse files

Implement key gesture to activate Select to Speak

Adds new shortcut (Meta + Alt + S) to first enable the select to speak
service and then activate it once it is enabled.

The select to speak service to use is controlled via the
config_defaultSelectToSpeakService value and is empty by default. This
select to speak service to use is checked to make sure it is
pre-installed from the OEM.

Bug: 375277034
Test: atest AccessibilityManagerServiceTest
Test: Manually on device
Flag: com.android.hardware.input.enable_talkback_and_magnifier_key_gestures

Change-Id: Ic22e12fd66010890d6d495b6c52a52008dc0ca9e
parent f39fa244
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ public final class KeyGestureEvent {
    public static final int KEY_GESTURE_TYPE_MAGNIFIER_ZOOM_IN = 72;
    public static final int KEY_GESTURE_TYPE_MAGNIFIER_ZOOM_OUT = 73;
    public static final int KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION = 74;
    public static final int KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK = 75;

    public static final int FLAG_CANCELLED = 1;

@@ -209,6 +210,7 @@ public final class KeyGestureEvent {
            KEY_GESTURE_TYPE_MAGNIFIER_ZOOM_IN,
            KEY_GESTURE_TYPE_MAGNIFIER_ZOOM_OUT,
            KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
            KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface KeyGestureType {
@@ -785,6 +787,8 @@ public final class KeyGestureEvent {
                return "KEY_GESTURE_TYPE_MAGNIFIER_ZOOM_OUT";
            case KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION:
                return "KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION";
            case KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK:
                return "KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK";
            default:
                return Integer.toHexString(value);
        }
+5 −0
Original line number Diff line number Diff line
@@ -4596,6 +4596,11 @@
         exists on the device, the accessibility shortcut will be disabled by default. -->
    <string name="config_defaultAccessibilityService" translatable="false"></string>

    <!-- The component name, flattened to a string, for the default select to speak service to be
         enabled by the accessibility keyboard shortcut. If the service with the specified component
         name is not preinstalled then this shortcut will do nothing. -->
    <string name="config_defaultSelectToSpeakService" translatable="false"></string>

    <!-- URI for default Accessibility notification sound when to enable accessibility shortcut. -->
    <string name="config_defaultAccessibilityNotificationSound" translatable="false"></string>

+1 −0
Original line number Diff line number Diff line
@@ -3718,6 +3718,7 @@
  <java-symbol type="string" name="color_correction_feature_name" />
  <java-symbol type="string" name="reduce_bright_colors_feature_name" />
  <java-symbol type="string" name="config_defaultAccessibilityService" />
  <java-symbol type="string" name="config_defaultSelectToSpeakService" />
  <java-symbol type="string" name="config_defaultAccessibilityNotificationSound" />
  <java-symbol type="string" name="accessibility_shortcut_spoken_feedback" />
  <java-symbol type="array" name="config_trustedAccessibilityServices" />
+30 −1
Original line number Diff line number Diff line
@@ -522,7 +522,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                @Override
                public boolean isKeyGestureSupported(int gestureType) {
                    return switch (gestureType) {
                        case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION -> true;
                        case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
                             KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK -> true;
                        default -> false;
                    };
                }
@@ -685,6 +686,34 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION:
                targetName = MAGNIFICATION_CONTROLLER_NAME;
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK:
                targetName = mContext.getString(R.string.config_defaultSelectToSpeakService);
                if (targetName.isEmpty()) {
                    return false;
                }

                final ComponentName targetServiceComponent = TextUtils.isEmpty(targetName)
                        ? null : ComponentName.unflattenFromString(targetName);
                AccessibilityServiceInfo accessibilityServiceInfo;
                synchronized (mLock) {
                    AccessibilityUserState userState = getCurrentUserStateLocked();
                    accessibilityServiceInfo =
                            userState.getInstalledServiceInfoLocked(targetServiceComponent);
                }
                if (accessibilityServiceInfo == null) {
                    return false;
                }

                // Skip enabling if a warning dialog is required for the feature.
                // TODO(b/377752960): Explore better options to instead show the warning dialog
                //  in this scenario.
                if (isAccessibilityServiceWarningRequired(accessibilityServiceInfo)) {
                    Slog.w(LOG_TAG,
                            "Accessibility warning is required before this service can be "
                                    + "activated automatically via KEY_GESTURE shortcut.");
                    return false;
                }
                break;
            default:
                return false;
        }
+3 −0
Original line number Diff line number Diff line
@@ -224,6 +224,9 @@ final class InputGestureManager {
            systemShortcuts.add(createKeyGesture(KeyEvent.KEYCODE_M,
                    KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION));
            systemShortcuts.add(createKeyGesture(KeyEvent.KEYCODE_S,
                    KeyEvent.META_META_ON | KeyEvent.META_ALT_ON,
                    KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK));
        }
        if (keyboardA11yShortcutControl()) {
            if (InputSettings.isAccessibilityBounceKeysFeatureEnabled()) {
Loading