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

Commit e88e2665 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Update accessibility to be encryption-aware.

Look for both EA and non-EA accessibility services, but when the user
is locked only bind to EA services.  Once the user is unlocked, we
take another pass and bind to any non-EA services.

We only consider disabling accessibility once the user is unlocked,
since there could be non-EA services waiting in the wings.

Bug: 25860579
Change-Id: I97bd019661457c3577d629ba12290d02f026011a
parent 413573ac
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -686,6 +686,11 @@ public class AccessibilityServiceInfo implements Parcelable {
        return null;
    }

    /** {@hide} */
    public boolean isEncryptionAware() {
        return mResolveInfo.serviceInfo.encryptionAware;
    }

    /**
     * {@inheritDoc}
     */
+22 −3
Original line number Diff line number Diff line
@@ -351,6 +351,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        // user change and unlock
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
        intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
        intentFilter.addAction(Intent.ACTION_USER_REMOVED);
        intentFilter.addAction(Intent.ACTION_USER_PRESENT);
        intentFilter.addAction(Intent.ACTION_SETTING_RESTORED);
@@ -361,6 +362,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                String action = intent.getAction();
                if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                    switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_USER_UNLOCKED.equals(action)) {
                    unlockUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
                    removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
                } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
@@ -900,6 +903,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
        }
    }

    private void unlockUser(int userId) {
        synchronized (mLock) {
            UserState userState = getUserStateLocked(userId);
            onUserStateChangedLocked(userState);
        }
    }

    private void removeUser(int userId) {
        synchronized (mLock) {
            mUserStates.remove(userId);
@@ -1003,7 +1013,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                new Intent(AccessibilityService.SERVICE_INTERFACE),
                PackageManager.GET_SERVICES
                        | PackageManager.GET_META_DATA
                  | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
                        | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
                        | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE,
                mCurrentUserId);

        for (int i = 0, count = installedServices.size(); i < count; i++) {
@@ -1236,6 +1247,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
    private void manageServicesLocked(UserState userState) {
        Map<ComponentName, Service> componentNameToServiceMap =
                userState.mComponentNameToServiceMap;
        boolean isUnlocked = mContext.getSystemService(UserManager.class)
                .isUserUnlocked(userState.mUserId);
        boolean isEnabled = userState.mIsAccessibilityEnabled;

        for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) {
@@ -1244,6 +1257,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
                    installedService.getId());
            Service service = componentNameToServiceMap.get(componentName);

            // Ignore non-encryption-aware services until user is unlocked
            if (!isUnlocked && !installedService.isEncryptionAware()) {
                Slog.d(LOG_TAG, "Ignoring non-encryption-aware service " + componentName);
                continue;
            }

            if (isEnabled) {
                // Wait for the binding if it is in process.
                if (userState.mBindingServices.contains(componentName)) {
@@ -1272,7 +1291,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {

        // No enabled installed services => disable accessibility to avoid
        // sending accessibility events with no recipient across processes.
        if (isEnabled && userState.mBoundServices.isEmpty()
        if (isEnabled && isUnlocked && userState.mBoundServices.isEmpty()
                && userState.mBindingServices.isEmpty()) {
            userState.mIsAccessibilityEnabled = false;
            final long identity = Binder.clearCallingIdentity();