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
This commit is contained in:
Svetoslav
2013-02-20 16:28:39 -08:00
parent ab8e936e85
commit 6f8218a442

View File

@@ -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.