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

Commit af5d0765 authored by Phil Weaver's avatar Phil Weaver
Browse files

Change users without crashing a11y services.

Accessibility services crash when changing users for several
reasons. we were looking up permissions for the current
user, which wasn't the user who created the service. We also
end up resetting the accessibility state, which reads user-
specific settings and thus must be done with the calling
identity cleared.

Bug: 27594523
Change-Id: I2b910d77704a6054b3a591c38f54d3ed3a2dc427
parent dc81d34d
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -1315,8 +1315,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
    private void updateServicesLocked(UserState userState) {
        Map<ComponentName, Service> componentNameToServiceMap =
                userState.mComponentNameToServiceMap;
        boolean isUnlockingOrUnlocked = mContext.getSystemService(UserManager.class)
        boolean isUnlockingOrUnlocked;
        final long identity = Binder.clearCallingIdentity();
        try {
            isUnlockingOrUnlocked = mContext.getSystemService(UserManager.class)
                    .isUserUnlockingOrUnlocked(userState.mUserId);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }

        for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) {
            AccessibilityServiceInfo installedService = userState.mInstalledServices.get(i);
@@ -2531,7 +2537,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub {
            // share the accessibility state of the parent. The call below
            // performs the current profile parent resolution.
            final int resolvedUserId = mSecurityPolicy
                    .resolveCallingUserIdEnforcingPermissionsLocked(UserHandle.USER_CURRENT);
                    .resolveCallingUserIdEnforcingPermissionsLocked(UserHandle.getCallingUserId());
            return resolvedUserId == mCurrentUserId;
        }

+19 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.accessibility;

import android.content.ContentResolver;
import android.content.Context;
import android.os.Binder;
import android.provider.Settings.Secure;
import android.view.accessibility.AccessibilityManager;

@@ -60,11 +61,16 @@ class DisplayAdjustmentUtils {
        final DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class);

        int daltonizerMode = AccessibilityManager.DALTONIZER_DISABLED;
        long identity = Binder.clearCallingIdentity();
        try {
            if (Secure.getIntForUser(cr,
                    Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, 0, userId) != 0) {
                daltonizerMode = Secure.getIntForUser(cr,
                        Secure.ACCESSIBILITY_DISPLAY_DALTONIZER, DEFAULT_DISPLAY_DALTONIZER, userId);
            }
        } finally {
            Binder.restoreCallingIdentity(identity);
        }

        float[] grayscaleMatrix = null;
        if (daltonizerMode == AccessibilityManager.DALTONIZER_SIMULATE_MONOCHROMACY) {
@@ -83,9 +89,14 @@ class DisplayAdjustmentUtils {
        final ContentResolver cr = context.getContentResolver();
        final DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class);

        long identity = Binder.clearCallingIdentity();
        try {
            final boolean invertColors = Secure.getIntForUser(cr,
                    Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, 0, userId) != 0;
            dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_INVERT_COLOR,
                    invertColors ? MATRIX_INVERT_COLOR : null);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
    }
}