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

Commit a790f45c authored by Rhed Jao's avatar Rhed Jao Committed by Automerger Merge Worker
Browse files

Merge "Fixes long press the a11y shortcut no response" into rvc-dev am:...

Merge "Fixes long press the a11y shortcut no response" into rvc-dev am: 2a58cd10 am: 17a2941e am: 388710c7 am: 4276848f

Change-Id: I4f892ca07934bd05c1d90465df8f5bd82e58b90c
parents a90fff91 4276848f
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
@@ -2488,7 +2488,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
@@ -2522,6 +2526,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)