Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f798d6e7 authored by Jackal Guo's avatar Jackal Guo
Browse files

Correct the state of the accessibility service

When an accessibility service package changes, it would be unbound.
This also causes it's removed from mBoundServices and adding into
mBindingServices currently. Hence, nothing happens since it's not
in mBoundServices in onPackageUpdateFinished(). Also, this service
wouldn't be bound since it is kept in mBindingServices. Remove the
accessibility service from mBindingServices after update, remove,
and force stop.

Bug: 116758044
Test: atest CtsAccessibilityServiceTestCases
Test: atest CtsAccessibilityTestCases
Test: update, remove, and force stop an enabled a11y service, and
      check if it could work again.
Change-Id: I61f8ac3ad92480b296f9970c9bb92af8f6767f1a
parent 27fd83c4
Loading
Loading
Loading
Loading
+10 −13
Original line number Original line Diff line number Diff line
@@ -379,25 +379,20 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub


            @Override
            @Override
            public void onPackageUpdateFinished(String packageName, int uid) {
            public void onPackageUpdateFinished(String packageName, int uid) {
                // Unbind all services from this package, and then update the user state to
                // The package should already be removed from mBoundServices, and added into
                // re-bind new versions of them.
                // mBindingServices in binderDied() during updating. Remove services from  this
                // package from mBindingServices, and then update the user state to re-bind new
                // versions of them.
                synchronized (mLock) {
                synchronized (mLock) {
                    final int userId = getChangingUserId();
                    final int userId = getChangingUserId();
                    if (userId != mCurrentUserId) {
                    if (userId != mCurrentUserId) {
                        return;
                        return;
                    }
                    }
                    UserState userState = getUserStateLocked(userId);
                    UserState userState = getUserStateLocked(userId);
                    boolean unboundAService = false;
                    boolean reboundAService = userState.mBindingServices.removeIf(
                    for (int i = userState.mBoundServices.size() - 1; i >= 0; i--) {
                            component -> component != null
                        AccessibilityServiceConnection boundService =
                                    && component.getPackageName().equals(packageName));
                                userState.mBoundServices.get(i);
                    if (reboundAService) {
                        String servicePkg = boundService.mComponentName.getPackageName();
                        if (servicePkg.equals(packageName)) {
                            boundService.unbindLocked();
                            unboundAService = true;
                        }
                    }
                    if (unboundAService) {
                        onUserStateChangedLocked(userState);
                        onUserStateChangedLocked(userState);
                    }
                    }
                }
                }
@@ -419,6 +414,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                        String compPkg = comp.getPackageName();
                        String compPkg = comp.getPackageName();
                        if (compPkg.equals(packageName)) {
                        if (compPkg.equals(packageName)) {
                            it.remove();
                            it.remove();
                            userState.mBindingServices.remove(comp);
                            // Update the enabled services setting.
                            // Update the enabled services setting.
                            persistComponentNamesToSettingLocked(
                            persistComponentNamesToSettingLocked(
                                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
@@ -457,6 +453,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                                    return true;
                                    return true;
                                }
                                }
                                it.remove();
                                it.remove();
                                userState.mBindingServices.remove(comp);
                                persistComponentNamesToSettingLocked(
                                persistComponentNamesToSettingLocked(
                                        Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                                        Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                                        userState.mEnabledServices, userId);
                                        userState.mEnabledServices, userId);
+1 −1
Original line number Original line Diff line number Diff line
@@ -253,11 +253,11 @@ class AccessibilityServiceConnection extends AbstractAccessibilityServiceConnect
                return;
                return;
            }
            }
            mWasConnectedAndDied = true;
            mWasConnectedAndDied = true;
            mSystemSupport.getKeyEventDispatcher().flush(this);
            UserState userState = mUserStateWeakReference.get();
            UserState userState = mUserStateWeakReference.get();
            if (userState != null) {
            if (userState != null) {
                userState.serviceDisconnectedLocked(this);
                userState.serviceDisconnectedLocked(this);
            }
            }
            resetLocked();
            mSystemSupport.getMagnificationController().resetIfNeeded(mId);
            mSystemSupport.getMagnificationController().resetIfNeeded(mId);
            mSystemSupport.onClientChange(false);
            mSystemSupport.onClientChange(false);
        }
        }