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

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

Merge "Fix the getUserBadge test failure" into main

parents 64ea8781 470fef02
Loading
Loading
Loading
Loading
+37 −30
Original line number Diff line number Diff line
@@ -180,25 +180,26 @@ public final class UserManagerTest {

        // Test that only one clone user can be created
        final int mainUserId = mainUser.getIdentifier();
        UserInfo userInfo = createProfileForUser("Clone user1",
        UserInfo cloneProfileUser = createProfileForUser("Clone user1",
                UserManager.USER_TYPE_PROFILE_CLONE,
                mainUserId);
        assertThat(userInfo).isNotNull();
        UserInfo userInfo2 = createProfileForUser("Clone user2",
        assertThat(cloneProfileUser).isNotNull();
        UserInfo cloneProfileUser2 = createProfileForUser("Clone user2",
                UserManager.USER_TYPE_PROFILE_CLONE,
                mainUserId);
        assertThat(userInfo2).isNull();
        assertThat(cloneProfileUser2).isNull();

        final Context userContext = mContext.createPackageContextAsUser("system", 0,
                UserHandle.of(userInfo.id));
        assertThat(userContext.getSystemService(
        final Context profileUserContest = mContext.createPackageContextAsUser("system", 0,
                UserHandle.of(cloneProfileUser.id));
        final UserManager profileUM = UserManager.get(profileUserContest);
        assertThat(profileUserContest.getSystemService(
                UserManager.class).isMediaSharedWithParent()).isTrue();
        assertThat(Settings.Secure.getInt(userContext.getContentResolver(),
        assertThat(Settings.Secure.getInt(profileUserContest.getContentResolver(),
                Settings.Secure.USER_SETUP_COMPLETE, 0)).isEqualTo(1);

        List<UserInfo> list = mUserManager.getUsers();
        List<UserInfo> cloneUsers = list.stream().filter(
                user -> (user.id == userInfo.id && user.name.equals("Clone user1")
                user -> (user.id == cloneProfileUser.id && user.name.equals("Clone user1")
                        && user.isCloneProfile()))
                .collect(Collectors.toList());
        assertThat(cloneUsers.size()).isEqualTo(1);
@@ -206,7 +207,7 @@ public final class UserManagerTest {
        // Check that the new clone user has the expected properties (relative to the defaults)
        // provided that the test caller has the necessary permissions.
        UserProperties cloneUserProperties =
                mUserManager.getUserProperties(UserHandle.of(userInfo.id));
                mUserManager.getUserProperties(UserHandle.of(cloneProfileUser.id));
        assertThat(typeProps.getUseParentsContacts())
                .isEqualTo(cloneUserProperties.getUseParentsContacts());
        assertThat(typeProps.getShowInLauncher())
@@ -226,15 +227,15 @@ public final class UserManagerTest {
        assertThrows(SecurityException.class, cloneUserProperties::getAlwaysVisible);
        assertThat(typeProps.getProfileApiVisibility()).isEqualTo(
                cloneUserProperties.getProfileApiVisibility());
        compareDrawables(mUserManager.getUserBadge(),
        compareDrawables(profileUM.getUserBadge(),
                Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain()));

        // Verify clone user parent
        assertThat(mUserManager.getProfileParent(mainUserId)).isNull();
        UserInfo parentProfileInfo = mUserManager.getProfileParent(userInfo.id);
        UserInfo parentProfileInfo = mUserManager.getProfileParent(cloneProfileUser.id);
        assertThat(parentProfileInfo).isNotNull();
        assertThat(mainUserId).isEqualTo(parentProfileInfo.id);
        removeUser(userInfo.id);
        removeUser(cloneProfileUser.id);
        assertThat(mUserManager.getProfileParent(mainUserId)).isNull();
    }

@@ -322,19 +323,22 @@ public final class UserManagerTest {

        // Test that only one private profile  can be created
        final int mainUserId = mainUser.getIdentifier();
        UserInfo userInfo = createProfileForUser("Private profile1",
        UserInfo privateProfileUser = createProfileForUser("Private profile1",
                UserManager.USER_TYPE_PROFILE_PRIVATE,
                mainUserId);
        assertThat(userInfo).isNotNull();
        UserInfo userInfo2 = createProfileForUser("Private profile2",
        assertThat(privateProfileUser).isNotNull();
        UserInfo privateProfileUser2 = createProfileForUser("Private profile2",
                UserManager.USER_TYPE_PROFILE_PRIVATE,
                mainUserId);
        assertThat(userInfo2).isNull();
        assertThat(privateProfileUser2).isNull();
        final UserManager profileUM = UserManager.get(
                mContext.createPackageContextAsUser("android", 0,
                        UserHandle.of(privateProfileUser.id)));

        // Check that the new private profile has the expected properties (relative to the defaults)
        // provided that the test caller has the necessary permissions.
        UserProperties privateProfileUserProperties =
                mUserManager.getUserProperties(UserHandle.of(userInfo.id));
                mUserManager.getUserProperties(UserHandle.of(privateProfileUser.id));
        assertThat(typeProps.getShowInLauncher())
                .isEqualTo(privateProfileUserProperties.getShowInLauncher());
        assertThrows(SecurityException.class, privateProfileUserProperties::getStartWithParent);
@@ -356,17 +360,17 @@ public final class UserManagerTest {
                privateProfileUserProperties.getProfileApiVisibility());
        assertThat(typeProps.areItemsRestrictedOnHomeScreen())
                .isEqualTo(privateProfileUserProperties.areItemsRestrictedOnHomeScreen());
        compareDrawables(mUserManager.getUserBadge(),
        compareDrawables(profileUM.getUserBadge(),
                Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain()));

        // Verify private profile parent
        assertThat(mUserManager.getProfileParent(mainUserId)).isNull();
        UserInfo parentProfileInfo = mUserManager.getProfileParent(userInfo.id);
        UserInfo parentProfileInfo = mUserManager.getProfileParent(privateProfileUser.id);
        assertThat(parentProfileInfo).isNotNull();
        assertThat(mainUserId).isEqualTo(parentProfileInfo.id);
        removeUser(userInfo.id);
        removeUser(privateProfileUser.id);
        assertThat(mUserManager.getProfileParent(mainUserId)).isNull();
        assertThat(mUserManager.getProfileLabel()).isEqualTo(
        assertThat(profileUM.getProfileLabel()).isEqualTo(
                Resources.getSystem().getString(userTypeDetails.getLabel(0)));
    }

@@ -964,10 +968,13 @@ public final class UserManagerTest {
        assertThat(userTypeDetails.getName()).isEqualTo(UserManager.USER_TYPE_PROFILE_MANAGED);

        int mainUserId = mUserManager.getMainUser().getIdentifier();
        UserInfo userInfo = createProfileForUser("Managed",
        UserInfo managedProfileUser = createProfileForUser("Managed",
                UserManager.USER_TYPE_PROFILE_MANAGED, mainUserId);
        assertThat(userInfo).isNotNull();
        final int userId = userInfo.id;
        assertThat(managedProfileUser).isNotNull();
        final int userId = managedProfileUser.id;
        final UserManager profileUM = UserManager.get(
                mContext.createPackageContextAsUser("android", 0,
                        UserHandle.of(managedProfileUser.id)));

        assertThat(mUserManager.hasBadge(userId)).isEqualTo(userTypeDetails.hasBadge());
        assertThat(mUserManager.getUserIconBadgeResId(userId))
@@ -978,10 +985,10 @@ public final class UserManagerTest {
                .isEqualTo(userTypeDetails.getBadgeNoBackground());
        assertThat(mUserManager.getUserStatusBarIconResId(userId))
                .isEqualTo(userTypeDetails.getStatusBarIcon());
        compareDrawables(mUserManager.getUserBadge(),
        compareDrawables(profileUM.getUserBadge(),
                Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain()));

        final int badgeIndex = userInfo.profileBadge;
        final int badgeIndex = managedProfileUser.profileBadge;
        assertThat(mUserManager.getUserBadgeColor(userId)).isEqualTo(
                Resources.getSystem().getColor(userTypeDetails.getBadgeColor(badgeIndex), null));
        assertThat(mUserManager.getUserBadgeDarkColor(userId)).isEqualTo(
@@ -1013,10 +1020,10 @@ public final class UserManagerTest {

        // Create an actual user (of this user type) and get its properties.
        int mainUserId = mUserManager.getMainUser().getIdentifier();
        final UserInfo userInfo = createProfileForUser("Managed",
        final UserInfo managedProfileUser = createProfileForUser("Managed",
                UserManager.USER_TYPE_PROFILE_MANAGED, mainUserId);
        assertThat(userInfo).isNotNull();
        final int userId = userInfo.id;
        assertThat(managedProfileUser).isNotNull();
        final int userId = managedProfileUser.id;
        final UserProperties userProps = mUserManager.getUserProperties(UserHandle.of(userId));

        // Check that this new user has the expected properties (relative to the defaults)