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

Commit 17c5e79f authored by Sandy Pan's avatar Sandy Pan
Browse files

Update accessibility policy to handle supervising profile as a child profile of any current user.

Context: When starting the supervising profile with talkback on, it
cannot recognize the keyboard as the userId does not belong the the same
profile of the current user.

Change-Id: I32e135e0eda71455a7b545e9d3aff98b3fb871ec
Bug: 430955186
Test: AccessibilitySecurityPolicyTest
Flag: android.multiuser.allow_supervising_profile
parent 85e714a0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -440,6 +440,10 @@ public class AccessibilitySecurityPolicy {
    /**
     * Returns the parent userId of the profile according to the specified userId.
     *
     * <p>For accessibility purposes, a supervising profile, which is a shell profile used for
     * setting up parental controls and doesn't have its own accessibility settings, is viewed as a
     * child of the current user.
     *
     * @param userId The userId to check
     * @return the parent userId of the profile, or self if no parent exist
     */
@@ -447,6 +451,12 @@ public class AccessibilitySecurityPolicy {
        if (userId != mAccessibilityUserManager.getCurrentUserIdLocked()) {
            final long identity = Binder.clearCallingIdentity();
            try {
                if (android.multiuser.Flags.allowSupervisingProfile()) {
                    UserInfo userInfo = mUserManager.getUserInfo(userId);
                    if (userInfo != null && userInfo.isSupervisingProfile()) {
                        return mAccessibilityUserManager.getCurrentUserIdLocked();
                    }
                }
                UserInfo parent = mUserManager.getProfileParent(userId);
                if (parent != null) {
                    return parent.getUserHandle().getIdentifier();
+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.accessibility;

import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.os.UserManager.USER_TYPE_PROFILE_SUPERVISING;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

@@ -49,9 +50,11 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.testing.DexmakerShareClassLoaderRule;
import android.testing.TestableContext;
import android.util.ArraySet;
@@ -458,6 +461,19 @@ public class AccessibilitySecurityPolicyTest {
                currentUserId);
    }

    @Test
    @RequiresFlagsEnabled(android.multiuser.Flags.FLAG_ALLOW_SUPERVISING_PROFILE)
    public void resolveProfileParent_userIdNotCurrentUser_isSupervising_returnCurrentUser() {
        final int userId = 15;
        final int currentUserId = 20;
        when(mMockA11yUserManager.getCurrentUserIdLocked()).thenReturn(currentUserId);
        when(mMockUserManager.getUserInfo(userId))
                .thenReturn(
                        new UserInfo(
                                userId, "Supervising", null, 0, USER_TYPE_PROFILE_SUPERVISING));
        assertEquals(mA11ySecurityPolicy.resolveProfileParentLocked(userId), currentUserId);
    }

    @Test
    public void resolveProfileParent_userIdNotCurrentUser_shouldGetProfileParent() {
        final int userId = 15;