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

This commit is contained in:
Rhed Jao
2020-04-16 05:59:54 +00:00
committed by Android (Google) Code Review
3 changed files with 26 additions and 7 deletions

View File

@@ -232,9 +232,8 @@ public class AccessibilityShortcutController {
} }
/** /**
* Show toast if current assigned shortcut target is an accessibility service and its target * Show toast to alert the user that the accessibility shortcut turned on or off an
* sdk version is less than or equal to Q, or greater than Q and does not request * accessibility service.
* accessibility button.
*/ */
private void showToast() { private void showToast() {
final AccessibilityServiceInfo serviceInfo = getInfoForTargetService(); final AccessibilityServiceInfo serviceInfo = getInfoForTargetService();
@@ -247,12 +246,15 @@ public class AccessibilityShortcutController {
} }
final boolean requestA11yButton = (serviceInfo.flags final boolean requestA11yButton = (serviceInfo.flags
& AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0; & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0;
if (serviceInfo.getResolveInfo().serviceInfo.applicationInfo final boolean isServiceEnabled = isServiceEnabled(serviceInfo);
.targetSdkVersion > Build.VERSION_CODES.Q && requestA11yButton) { 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; return;
} }
// For accessibility services, show a toast explaining what we're doing. // 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_disabling_service
: R.string.accessibility_shortcut_enabling_service); : R.string.accessibility_shortcut_enabling_service);
String toastMessage = String.format(toastMessageFormatString, serviceName); String toastMessage = String.format(toastMessageFormatString, serviceName);

View File

@@ -462,6 +462,7 @@ public class AccessibilityShortcutControllerTest {
configureValidShortcutService(); configureValidShortcutService();
configureApplicationTargetSdkVersion(Build.VERSION_CODES.R); configureApplicationTargetSdkVersion(Build.VERSION_CODES.R);
configureRequestAccessibilityButton(); configureRequestAccessibilityButton();
configureEnabledService();
Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 1); Settings.Secure.putInt(mContentResolver, ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 1);
getController().performAccessibilityShortcut(); getController().performAccessibilityShortcut();
@@ -610,6 +611,11 @@ public class AccessibilityShortcutControllerTest {
}).when(mHandler).sendMessageAtTime(any(), anyLong()); }).when(mHandler).sendMessageAtTime(any(), anyLong());
} }
private void configureEnabledService() throws Exception {
when(mAccessibilityManagerService.getEnabledAccessibilityServiceList(anyInt(), anyInt()))
.thenReturn(Collections.singletonList(mServiceInfo));
}
private AccessibilityShortcutController getController() { private AccessibilityShortcutController getController() {
AccessibilityShortcutController accessibilityShortcutController = AccessibilityShortcutController accessibilityShortcutController =
new AccessibilityShortcutController(mContext, mHandler, 0); new AccessibilityShortcutController(mContext, mHandler, 0);

View File

@@ -2441,7 +2441,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
* accessibility button. * accessibility button.
* 2) For {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} type and service targeting sdk * 2) For {@link AccessibilityManager#ACCESSIBILITY_SHORTCUT_KEY} type and service targeting sdk
* version <= Q: turns on / off the accessibility service. * 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 * a) Turns on / off the accessibility service, if service does not request accessibility
* button. * button.
* b) Callbacks to accessibility service if service is bounded and requests accessibility * b) Callbacks to accessibility service if service is bounded and requests accessibility
@@ -2475,6 +2479,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
} }
return true; 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. // Callbacks to a11y service if it's bounded and requests a11y button.
if (serviceConnection == null if (serviceConnection == null
|| !userState.mBoundServices.contains(serviceConnection) || !userState.mBoundServices.contains(serviceConnection)