summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Olivier Nshimiye <onshimiye@google.com> 2024-03-27 12:06:18 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-03-27 12:06:18 +0000
commitfc7c11e09f60e9cc7026d07be861d12d3e241ece (patch)
tree6d162d6a420849ab3970ecc74a3a17fbf324cd14
parent64ea8781e76722d69219f21c2969eb4f7680f20a (diff)
parent470fef025b6c98df453a939ea127af5cca51897b (diff)
Merge "Fix the getUserBadge test failure" into main
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java67
1 files changed, 37 insertions, 30 deletions
diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
index 1591a963a406..4405a20cb059 100644
--- a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
@@ -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)