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

Commit 8fcba035 authored by Rhed Jao's avatar Rhed Jao
Browse files

Fixes long press the a11y shortcut no response

An a11y service targeting sdk version > Q and requesting a11y button
should be turned on by the Settings when it's assigned to the a11y
shortcut by the user. An a11y button callback is sent to the a11y
service when the user long press the a11y shortcut.

This issue happened when an disabled a11y service is assigned to the
a11y shortcut, and upgraded to the target sdk version > Q. Framework
fails to send the callback and no response when user long press the
shortcut.

Turns on the a11y service and show up a toast to fix this issue.

Bug: 153517972
Test: atest AccessibilityShortcutControllerTest
Change-Id: Ie4fc9bbeaf08ba674cfe6382eab214b2a15c004c
parent f3b2dc9b
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -232,9 +232,8 @@ public class AccessibilityShortcutController {
    }

    /**
     * Show toast if current assigned shortcut target is an accessibility service and its target
     * sdk version is less than or equal to Q, or greater than Q and does not request
     * accessibility button.
     * Show toast to alert the user that the accessibility shortcut turned on or off an
     * accessibility service.
     */
    private void showToast() {
        final AccessibilityServiceInfo serviceInfo = getInfoForTargetService();
@@ -247,12 +246,15 @@ public class AccessibilityShortcutController {
        }
        final boolean requestA11yButton = (serviceInfo.flags
                & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0;
        if (serviceInfo.getResolveInfo().serviceInfo.applicationInfo
                .targetSdkVersion > Build.VERSION_CODES.Q && requestA11yButton) {
        final boolean isServiceEnabled = isServiceEnabled(serviceInfo);
        if (serviceInfo.getResolveInfo().serviceInfo.applicationInfo.targetSdkVersion
                > Build.VERSION_CODES.Q && requestA11yButton && isServiceEnabled) {
            // An accessibility button callback is sent to the target accessibility service.
            // No need to show up a toast in this case.
            return;
        }
        // For accessibility services, show a toast explaining what we're doing.
        String toastMessageFormatString = mContext.getString(isServiceEnabled(serviceInfo)
        String toastMessageFormatString = mContext.getString(isServiceEnabled
                ? R.string.accessibility_shortcut_disabling_service
                : R.string.accessibility_shortcut_enabling_service);
        String toastMessage = String.format(toastMessageFormatString, serviceName);
+6 −0
Original line number Diff line number Diff line
@@ -462,6 +462,7 @@ public class AccessibilityShortcutControllerTest {
        configureValidShortcutService();
        configureApplicationTargetSdkVersion(Build.VERSION_CODES.R);
        configureRequestAccessibilityButton();
        configureEnabledService();
        Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 1);
        getController().performAccessibilityShortcut();

@@ -610,6 +611,11 @@ public class AccessibilityShortcutControllerTest {
        }).when(mHandler).sendMessageAtTime(any(), anyLong());
    }

    private void configureEnabledService() throws Exception {
        when(mAccessibilityManagerService.getEnabledAccessibilityServiceList(anyInt(), anyInt()))
                .thenReturn(Collections.singletonList(mServiceInfo));
    }

    private AccessibilityShortcutController getController() {
        AccessibilityShortcutController accessibilityShortcutController =
                new AccessibilityShortcutController(mContext, mHandler, 0);
+12 −1
Original line number Diff line number Diff line
@@ -2441,7 +2441,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
     *    accessibility button.
     * 2) For {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} type and service targeting sdk
     *    version <= Q: turns on / off the accessibility service.
     * 3) For services targeting sdk version > Q:
     * 3) For {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} type and service targeting sdk
     *    version > Q and request accessibility button: turn on the accessibility service if it's
     *    not in the enabled state.
     *    (It'll happen when a service is disabled and assigned to shortcut then upgraded.)
     * 4) For services targeting sdk version > Q:
     *    a) Turns on / off the accessibility service, if service does not request accessibility
     *       button.
     *    b) Callbacks to accessibility service if service is bounded and requests accessibility
@@ -2475,6 +2479,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                }
                return true;
            }
            if (shortcutType == ACCESSIBILITY_SHORTCUT_KEY && targetSdk > Build.VERSION_CODES.Q
                    && requestA11yButton) {
                if (!userState.getEnabledServicesLocked().contains(assignedTarget)) {
                    enableAccessibilityServiceLocked(assignedTarget, mCurrentUserId);
                    return true;
                }
            }
            // Callbacks to a11y service if it's bounded and requests a11y button.
            if (serviceConnection == null
                    || !userState.mBoundServices.contains(serviceConnection)