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 Diff line number Diff line
@@ -379,25 +379,20 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub

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