Remove disabled a11yservices from the binding services list.

This could cause race conditions if a service connection is exited after
starting binding but before finishing binding.
If the service is mid-initialization when it gets disabled then there is
already logic to prevent full initialization and to exit the connection.

Bug: 252884894
Test: atest AccessibilityPrivacySourceTest --iterations 30
Change-Id: Ib5aa761bb4c9189df53d04d7dc5329aece650141
This commit is contained in:
Daniel Norman
2022-10-21 12:17:04 -07:00
parent ab707471e1
commit 3a5a791dfe
2 changed files with 10 additions and 6 deletions

View File

@@ -4142,7 +4142,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
if (readEnabledAccessibilityServicesLocked(userState)) {
mSecurityPolicy.onEnabledServicesChangedLocked(userState.mUserId,
userState.mEnabledServices);
userState.updateCrashedServicesIfNeededLocked();
userState.removeDisabledServicesFromTemporaryStatesLocked();
onUserStateChangedLocked(userState);
}
} else if (mTouchExplorationGrantedAccessibilityServicesUri.equals(uri)) {

View File

@@ -381,18 +381,22 @@ class AccessibilityUserState {
}
/**
* Remove service from crashed service list if users disable it.
* Remove the service from the crashed and binding service lists if the user disabled it.
*/
void updateCrashedServicesIfNeededLocked() {
void removeDisabledServicesFromTemporaryStatesLocked() {
for (int i = 0, count = mInstalledServices.size(); i < count; i++) {
final AccessibilityServiceInfo installedService = mInstalledServices.get(i);
final ComponentName componentName = ComponentName.unflattenFromString(
installedService.getId());
if (mCrashedServices.contains(componentName)
&& !mEnabledServices.contains(componentName)) {
// Remove it from mCrashedServices since users toggle the switch bar to retry.
if (!mEnabledServices.contains(componentName)) {
// Remove from mCrashedServices, since users may toggle the on/off switch to retry.
mCrashedServices.remove(componentName);
// Remove from mBindingServices, since services can get stuck in the binding state
// if binding starts but never finishes. If the service later attempts to finish
// binding but it is not in the enabled list then it will exit before initializing;
// see AccessibilityServiceConnection#initializeService().
mBindingServices.remove(componentName);
}
}
}