diff options
3 files changed, 26 insertions, 7 deletions
diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java index d64b5f1118dc..be66d0c238cc 100644 --- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java +++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java @@ -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); diff --git a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java index 4a33da680585..b21504c73772 100644 --- a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java @@ -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); diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java index 7230b00f87ad..d252f9e69a22 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -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) |