Loading core/api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -10555,6 +10555,7 @@ package android.os { method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public android.os.PersistableBundle getSeedAccountOptions(); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public String getSeedAccountType(); method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public long[] getSerialNumbersOfUsers(boolean); method @NonNull public android.graphics.drawable.Drawable getUserBadge(); method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.os.UserHandle> getUserHandles(boolean); method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) public android.graphics.Bitmap getUserIcon(); method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public android.content.pm.UserProperties getUserProperties(@NonNull android.os.UserHandle); core/java/android/os/UserManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.os; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Strings.Core.WORK_PROFILE_BADGED_LABEL; import static android.app.admin.DevicePolicyResources.UNDEFINED; Loading Loading @@ -5651,6 +5652,38 @@ public class UserManager { badgeLocation, badgeDensity); } /** * Retrieves a user badge associated with the current context user. This is only * applicable to profile users since non-profile users do not have badges. * * @return A {@link Drawable} user badge corresponding to the context user * @throws android.content.res.Resources.NotFoundException if the user is not a profile or * does not have a badge defined. * @hide */ @SystemApi @UserHandleAware( requiresAnyOfPermissionsIfNotCallerProfileGroup = { Manifest.permission.MANAGE_USERS, Manifest.permission.INTERACT_ACROSS_USERS}) @SuppressLint("UnflaggedApi") // b/306636213 public @NonNull Drawable getUserBadge() { if (!isProfile(mUserId)) { throw new Resources.NotFoundException("No badge found for this user."); } if (isManagedProfile(mUserId)) { DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); return dpm.getResources().getDrawable( android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE, SOLID_COLORED, () -> getDefaultUserBadge(mUserId)); } return getDefaultUserBadge(mUserId); } private Drawable getDefaultUserBadge(@UserIdInt int userId){ return mContext.getResources().getDrawable(getUserBadgeResId(userId), mContext.getTheme()); } /** * If the target user is a profile of the calling user or the caller * is itself a profile, then this returns a copy of the label with Loading services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +14 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertThrows; import static org.testng.Assert.assertTrue; import android.annotation.UserIdInt; import android.app.ActivityManager; Loading @@ -31,6 +32,7 @@ import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.content.pm.UserProperties; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -219,6 +221,8 @@ public final class UserManagerTest { .isEqualTo(cloneUserProperties.isCredentialShareableWithParent()); assertThrows(SecurityException.class, cloneUserProperties::getDeleteAppWithParent); assertThrows(SecurityException.class, cloneUserProperties::getAlwaysVisible); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); // Verify clone user parent assertThat(mUserManager.getProfileParent(mainUserId)).isNull(); Loading Loading @@ -335,7 +339,8 @@ public final class UserManagerTest { .isEqualTo(privateProfileUserProperties .isAuthAlwaysRequiredToDisableQuietMode()); assertThrows(SecurityException.class, privateProfileUserProperties::getDeleteAppWithParent); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); // Verify private profile parent assertThat(mUserManager.getProfileParent(mainUserId)).isNull(); UserInfo parentProfileInfo = mUserManager.getProfileParent(userInfo.id); Loading Loading @@ -955,6 +960,8 @@ public final class UserManagerTest { .isEqualTo(userTypeDetails.getBadgeNoBackground()); assertThat(mUserManager.getUserStatusBarIconResId(userId)) .isEqualTo(userTypeDetails.getStatusBarIcon()); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); final int badgeIndex = userInfo.profileBadge; assertThat(mUserManager.getUserBadgeColor(userId)).isEqualTo( Loading Loading @@ -1762,4 +1769,10 @@ public final class UserManagerTest { .getBoolean(com.android.internal.R.bool.config_isMainUserPermanentAdmin); } private void compareDrawables(Drawable actual, Drawable expected){ assertEquals(actual.getIntrinsicWidth(), expected.getIntrinsicWidth()); assertEquals(actual.getIntrinsicHeight(), expected.getIntrinsicHeight()); assertEquals(actual.getLevel(), expected.getLevel()); } } Loading
core/api/system-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -10555,6 +10555,7 @@ package android.os { method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public android.os.PersistableBundle getSeedAccountOptions(); method @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public String getSeedAccountType(); method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public long[] getSerialNumbersOfUsers(boolean); method @NonNull public android.graphics.drawable.Drawable getUserBadge(); method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.os.UserHandle> getUserHandles(boolean); method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) public android.graphics.Bitmap getUserIcon(); method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public android.content.pm.UserProperties getUserProperties(@NonNull android.os.UserHandle);
core/java/android/os/UserManager.java +33 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.os; import static android.app.admin.DevicePolicyResources.Drawables.Style.SOLID_COLORED; import static android.app.admin.DevicePolicyResources.Strings.Core.WORK_PROFILE_BADGED_LABEL; import static android.app.admin.DevicePolicyResources.UNDEFINED; Loading Loading @@ -5651,6 +5652,38 @@ public class UserManager { badgeLocation, badgeDensity); } /** * Retrieves a user badge associated with the current context user. This is only * applicable to profile users since non-profile users do not have badges. * * @return A {@link Drawable} user badge corresponding to the context user * @throws android.content.res.Resources.NotFoundException if the user is not a profile or * does not have a badge defined. * @hide */ @SystemApi @UserHandleAware( requiresAnyOfPermissionsIfNotCallerProfileGroup = { Manifest.permission.MANAGE_USERS, Manifest.permission.INTERACT_ACROSS_USERS}) @SuppressLint("UnflaggedApi") // b/306636213 public @NonNull Drawable getUserBadge() { if (!isProfile(mUserId)) { throw new Resources.NotFoundException("No badge found for this user."); } if (isManagedProfile(mUserId)) { DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); return dpm.getResources().getDrawable( android.app.admin.DevicePolicyResources.Drawables.WORK_PROFILE_ICON_BADGE, SOLID_COLORED, () -> getDefaultUserBadge(mUserId)); } return getDefaultUserBadge(mUserId); } private Drawable getDefaultUserBadge(@UserIdInt int userId){ return mContext.getResources().getDrawable(getUserBadgeResId(userId), mContext.getTheme()); } /** * If the target user is a profile of the calling user or the caller * is itself a profile, then this returns a copy of the label with Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java +14 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertThrows; import static org.testng.Assert.assertTrue; import android.annotation.UserIdInt; import android.app.ActivityManager; Loading @@ -31,6 +32,7 @@ import android.content.pm.PackageManager; import android.content.pm.UserInfo; import android.content.pm.UserProperties; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; Loading Loading @@ -219,6 +221,8 @@ public final class UserManagerTest { .isEqualTo(cloneUserProperties.isCredentialShareableWithParent()); assertThrows(SecurityException.class, cloneUserProperties::getDeleteAppWithParent); assertThrows(SecurityException.class, cloneUserProperties::getAlwaysVisible); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); // Verify clone user parent assertThat(mUserManager.getProfileParent(mainUserId)).isNull(); Loading Loading @@ -335,7 +339,8 @@ public final class UserManagerTest { .isEqualTo(privateProfileUserProperties .isAuthAlwaysRequiredToDisableQuietMode()); assertThrows(SecurityException.class, privateProfileUserProperties::getDeleteAppWithParent); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); // Verify private profile parent assertThat(mUserManager.getProfileParent(mainUserId)).isNull(); UserInfo parentProfileInfo = mUserManager.getProfileParent(userInfo.id); Loading Loading @@ -955,6 +960,8 @@ public final class UserManagerTest { .isEqualTo(userTypeDetails.getBadgeNoBackground()); assertThat(mUserManager.getUserStatusBarIconResId(userId)) .isEqualTo(userTypeDetails.getStatusBarIcon()); compareDrawables(mUserManager.getUserBadge(), Resources.getSystem().getDrawable(userTypeDetails.getBadgePlain())); final int badgeIndex = userInfo.profileBadge; assertThat(mUserManager.getUserBadgeColor(userId)).isEqualTo( Loading Loading @@ -1762,4 +1769,10 @@ public final class UserManagerTest { .getBoolean(com.android.internal.R.bool.config_isMainUserPermanentAdmin); } private void compareDrawables(Drawable actual, Drawable expected){ assertEquals(actual.getIntrinsicWidth(), expected.getIntrinsicWidth()); assertEquals(actual.getIntrinsicHeight(), expected.getIntrinsicHeight()); assertEquals(actual.getLevel(), expected.getLevel()); } }