From 6f8218a442a8de50ef33d20263a59cd47c513e62 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Wed, 20 Feb 2013 16:28:39 -0800 Subject: [PATCH] Trying to unregister a semi connected accessibility service. When an accessibility service connects we get a callback in which we either add the service, if this service is in the list of connecting services (we still want the service to connect), or we unbind and clear the state, if the service is no longer in the list of connecting services (we do not want this service to connect because something change between the bind request and the connection callback). The problem is that when the service connects and it is not in the list of connecting services on service connected we called the clean up code before the connection was complete. However, the clean up code expects fully configured services. Now we fully connect the service and in case there is a problem - disconnect it. bug:8232627 Change-Id: I939e544e31ffc1406035265a012c180f2ca95d7c --- .../AccessibilityManagerService.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java index 9c518a11637f4..fd5e79a99268c 100644 --- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -934,12 +934,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { * @param service The service. * @return True if the service was removed, false otherwise. */ - private void removeServiceLocked(Service service) { - UserState userState = getUserStateLocked(service.mUserId); + private void removeServiceLocked(Service service, UserState userState) { userState.mBoundServices.remove(service); userState.mComponentNameToServiceMap.remove(service.mComponentName); service.unlinkToOwnDeath(); - service.dispose(); } /** @@ -1672,11 +1670,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { public boolean bindLocked() { UserState userState = getUserStateLocked(mUserId); if (!mIsAutomation) { - if (mService == null) { - if (mContext.bindServiceAsUser(mIntent, this, Context.BIND_AUTO_CREATE, - new UserHandle(mUserId))) { - userState.mBindingServices.add(mComponentName); - } + if (mService == null && mContext.bindServiceAsUser( + mIntent, this, Context.BIND_AUTO_CREATE, new UserHandle(mUserId))) { + userState.mBindingServices.add(mComponentName); } } else { userState.mBindingServices.add(mComponentName); @@ -1697,14 +1693,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (mService == null) { return false; } + UserState userState = getUserStateLocked(mUserId); if (!mIsAutomation) { mContext.unbindService(this); } else { - UserState userState = getUserStateLocked(mUserId); userState.mUiAutomationService = null; userState.mUiAutomationServiceClient = null; } - removeServiceLocked(this); + removeServiceLocked(this, userState); + dispose(); return true; } @@ -1750,11 +1747,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { mService = service; mServiceInterface = IAccessibilityServiceClient.Stub.asInterface(service); UserState userState = getUserStateLocked(mUserId); + addServiceLocked(this, userState); if (!userState.mBindingServices.contains(mComponentName)) { binderDied(); } else { userState.mBindingServices.remove(mComponentName); - addServiceLocked(this, userState); onUserStateChangedLocked(userState); } } @@ -2106,9 +2103,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { public void binderDied() { synchronized (mLock) { - // The death recipient is unregistered in tryRemoveServiceLocked - removeServiceLocked(this); UserState userState = getUserStateLocked(mUserId); + // The death recipient is unregistered in removeServiceLocked + removeServiceLocked(this, userState); + dispose(); if (mIsAutomation) { // We no longer have an automation service, so restore // the state based on values in the settings database.