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

Commit 61873aab authored by Olivier Nshimiye's avatar Olivier Nshimiye Committed by Android (Google) Code Review
Browse files

Merge "Add tests for blocking hidden profile visibility in CPA Apis" into main

parents c8c3a324 6ebfc1f0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1466,7 +1466,7 @@ public class UserManagerService extends IUserManager.Stub {
            if (userType != null && !userType.equals(profile.userType)) {
                continue;
            }
            if (excludeHidden && isProfileHidden(userId)) {
            if (excludeHidden && isProfileHidden(profile.id)) {
                continue;
            }
            result.add(profile.id);
+11 −0
Original line number Diff line number Diff line
@@ -722,6 +722,17 @@ public final class UserManagerServiceTest {
        Mockito.verify(mKeyguardManager, never()).addKeyguardLockedStateListener(any(), any());
    }

    @Test
    public void testGetProfileIdsExcludingHidden() {
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_HIDING_PROFILES);
        UserInfo privateProfileUser =
                mUms.createProfileForUserEvenWhenDisallowedWithThrow("TestPrivateProfile",
                        USER_TYPE_PROFILE_PRIVATE, 0, 0, null);
        for (int id : mUms.getProfileIdsExcludingHidden(0, true)) {
            assertThat(id).isNotEqualTo(privateProfileUser.id);
        }
    }

    /**
     * Returns true if the user's XML file has Default restrictions
     * @param userId Id of the user.
+15 −0
Original line number Diff line number Diff line
@@ -1729,6 +1729,21 @@ public final class UserManagerTest {
        mUserManager.removeUser(userInfo.id);
    }

    @Test
    @RequiresFlagsEnabled(android.multiuser.Flags.FLAG_ENABLE_HIDING_PROFILES)
    public void testGetProfileIdsExcludingHidden() throws Exception {
        int mainUserId = mUserManager.getMainUser().getIdentifier();
        final UserInfo profile = createProfileForUser("Profile",
                UserManager.USER_TYPE_PROFILE_PRIVATE, mainUserId);

        final int[] allProfiles = mUserManager.getProfileIds(mainUserId, /* enabledOnly */ false);
        final int[] profilesExcludingHidden = mUserManager.getProfileIdsExcludingHidden(
                mainUserId, /* enabledOnly */ false);

        assertThat(allProfiles).asList().contains(profile.id);
        assertThat(profilesExcludingHidden).asList().doesNotContain(profile.id);
    }

    private String generateLongString() {
        String partialString = "Test Name Test Name Test Name Test Name Test Name Test Name Test "
                + "Name Test Name Test Name Test Name "; //String of length 100