Loading apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -516,7 +516,7 @@ public class UserLifecycleTests { /** Creates a managed (work) profile under the current user, returning its userId. */ /** Creates a managed (work) profile under the current user, returning its userId. */ private int createManagedProfile() { private int createManagedProfile() { final UserInfo userInfo = mUm.createProfileForUser("TestProfile", final UserInfo userInfo = mUm.createProfileForUser("TestProfile", UserInfo.FLAG_MANAGED_PROFILE, mAm.getCurrentUser()); UserManager.USER_TYPE_PROFILE_MANAGED, /* flags */ 0, mAm.getCurrentUser()); if (userInfo == null) { if (userInfo == null) { throw new IllegalStateException("Creating managed profile failed. Most likely there is " throw new IllegalStateException("Creating managed profile failed. Most likely there is " + "already a pre-existing profile on the device."); + "already a pre-existing profile on the device."); Loading core/java/android/app/ApplicationPackageManager.java +14 −25 Original line number Original line Diff line number Diff line Loading @@ -92,7 +92,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.ArraySet; import android.util.ArraySet; import android.util.DebugUtils; import android.util.DebugUtils; import android.util.IconDrawableFactory; import android.util.LauncherIcons; import android.util.LauncherIcons; import android.util.Log; import android.util.Log; import android.view.Display; import android.view.Display; Loading Loading @@ -1474,11 +1473,11 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { if (!isManagedProfile(user.getIdentifier())) { if (!hasUserBadge(user.getIdentifier())) { return icon; return icon; } } Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( com.android.internal.R.drawable.ic_corp_icon_badge_case, getUserManager().getUserIconBadgeResId(user.getIdentifier()), getUserBadgeColor(user)); getUserBadgeColor(user)); return getBadgedDrawable(icon, badge, null, true); return getBadgedDrawable(icon, badge, null, true); } } Loading @@ -1493,26 +1492,21 @@ public class ApplicationPackageManager extends PackageManager { return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true); return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true); } } @VisibleForTesting /** Returns the color of the user's actual badge (not the badge's shadow). */ public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] { com.android.internal.R.string.managed_profile_label_badge, com.android.internal.R.string.managed_profile_label_badge_2, com.android.internal.R.string.managed_profile_label_badge_3 }; private int getUserBadgeColor(UserHandle user) { private int getUserBadgeColor(UserHandle user) { return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier()); return getUserManager().getUserBadgeColor(user.getIdentifier()); } } @Override @Override public Drawable getUserBadgeForDensity(UserHandle user, int density) { public Drawable getUserBadgeForDensity(UserHandle user, int density) { Drawable badgeColor = getManagedProfileIconForDensity(user, // This is part of the shadow, not the main color, and is not actually corp-specific. Drawable badgeColor = getProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge_color, density); com.android.internal.R.drawable.ic_corp_badge_color, density); if (badgeColor == null) { if (badgeColor == null) { return null; return null; } } Drawable badgeForeground = getDrawableForDensity( Drawable badgeForeground = getDrawableForDensity( com.android.internal.R.drawable.ic_corp_badge_case, density); getUserManager().getUserBadgeResId(user.getIdentifier()), density); badgeForeground.setTint(getUserBadgeColor(user)); badgeForeground.setTint(getUserBadgeColor(user)); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); return badge; return badge; Loading @@ -1520,8 +1514,8 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { Drawable badge = getManagedProfileIconForDensity(user, Drawable badge = getProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge_no_background, density); getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); if (badge != null) { if (badge != null) { badge.setTint(getUserBadgeColor(user)); badge.setTint(getUserBadgeColor(user)); } } Loading @@ -1535,8 +1529,8 @@ public class ApplicationPackageManager extends PackageManager { return mContext.getResources().getDrawableForDensity(drawableId, density); return mContext.getResources().getDrawableForDensity(drawableId, density); } } private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) { private Drawable getProfileIconForDensity(UserHandle user, int drawableId, int density) { if (isManagedProfile(user.getIdentifier())) { if (hasUserBadge(user.getIdentifier())) { return getDrawableForDensity(drawableId, density); return getDrawableForDensity(drawableId, density); } } return null; return null; Loading @@ -1544,12 +1538,7 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { if (isManagedProfile(user.getIdentifier())) { return getUserManager().getBadgedLabelForUser(label, user); int badge = getUserManager().getManagedProfileBadge(user.getIdentifier()); int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length]; return Resources.getSystem().getString(resourceId, label); } return label; } } @Override @Override Loading Loading @@ -2865,8 +2854,8 @@ public class ApplicationPackageManager extends PackageManager { return drawable; return drawable; } } private boolean isManagedProfile(int userId) { private boolean hasUserBadge(int userId) { return getUserManager().isManagedProfile(userId); return getUserManager().hasBadge(userId); } } /** /** Loading core/java/android/content/pm/UserInfo.java +95 −29 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.content.pm; package android.content.pm; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage; import android.annotation.UserIdInt; import android.annotation.UserIdInt; import android.os.Parcel; import android.os.Parcel; Loading @@ -25,6 +26,8 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.util.DebugUtils; import android.util.DebugUtils; import com.android.server.pm.UserTypeDetails; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading @@ -32,13 +35,13 @@ import java.lang.annotation.RetentionPolicy; * Per-user information. * Per-user information. * * * <p>There are 3 base properties of users: {@link #FLAG_SYSTEM}, {@link #FLAG_FULL}, and * <p>There are 3 base properties of users: {@link #FLAG_SYSTEM}, {@link #FLAG_FULL}, and * {@link #FLAG_MANAGED_PROFILE}. Every user must have one of the following combination of these * {@link #FLAG_PROFILE}. Every user must have one of the following combination of these * flags: * flags: * <ul> * <ul> * <li>FLAG_SYSTEM (user {@link UserHandle#USER_SYSTEM} on a headless-user-0 device)</li> * <li>FLAG_SYSTEM (user {@link UserHandle#USER_SYSTEM} on a headless-user-0 device)</li> * <li>FLAG_SYSTEM and FLAG_FULL (user {@link UserHandle#USER_SYSTEM} on a regular device)</li> * <li>FLAG_SYSTEM and FLAG_FULL (user {@link UserHandle#USER_SYSTEM} on a regular device)</li> * <li>FLAG_FULL (non-profile secondary user)</li> * <li>FLAG_FULL (non-profile secondary user)</li> * <li>FLAG_MANAGED_PROFILE (profile users)</li> * <li>FLAG_PROFILE (profile users)</li> * </ul> * </ul> * Users can have also have additional flags (such as FLAG_GUEST) as appropriate. * Users can have also have additional flags (such as FLAG_GUEST) as appropriate. * * Loading Loading @@ -70,13 +73,17 @@ public class UserInfo implements Parcelable { /** /** * Indicates a guest user that may be transient. * Indicates a guest user that may be transient. * @deprecated Use {@link UserManager#USER_TYPE_FULL_GUEST} instead. */ */ @Deprecated public static final int FLAG_GUEST = 0x00000004; public static final int FLAG_GUEST = 0x00000004; /** /** * Indicates the user has restrictions in privileges, in addition to those for normal users. * Indicates the user has restrictions in privileges, in addition to those for normal users. * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. * @deprecated Use {@link UserManager#USER_TYPE_FULL_RESTRICTED} instead. */ */ @Deprecated public static final int FLAG_RESTRICTED = 0x00000008; public static final int FLAG_RESTRICTED = 0x00000008; /** /** Loading @@ -87,7 +94,9 @@ public class UserInfo implements Parcelable { /** /** * Indicates that this user is a profile of another user, for example holding a users * Indicates that this user is a profile of another user, for example holding a users * corporate data. * corporate data. * @deprecated Use {@link UserManager#USER_TYPE_PROFILE_MANAGED} instead. */ */ @Deprecated public static final int FLAG_MANAGED_PROFILE = 0x00000020; public static final int FLAG_MANAGED_PROFILE = 0x00000020; /** /** Loading @@ -108,14 +117,16 @@ public class UserInfo implements Parcelable { /** /** * User is for demo purposes only and can be removed at any time. * User is for demo purposes only and can be removed at any time. * @deprecated Use {@link UserManager#USER_TYPE_FULL_DEMO} instead. */ */ @Deprecated public static final int FLAG_DEMO = 0x00000200; public static final int FLAG_DEMO = 0x00000200; /** /** * Indicates that this user is a non-profile human user. * Indicates that this user is a non-profile human user. * * * <p>When creating a new (non-system) user, this flag will always be forced true unless the * <p>When creating a new (non-system) user, this flag will always be forced true unless the * user is a {@link #FLAG_MANAGED_PROFILE}. If user {@link UserHandle#USER_SYSTEM} is also a * user is a {@link #FLAG_PROFILE}. If user {@link UserHandle#USER_SYSTEM} is also a * human user, it must also be flagged as FULL. * human user, it must also be flagged as FULL. */ */ public static final int FLAG_FULL = 0x00000400; public static final int FLAG_FULL = 0x00000400; Loading @@ -126,11 +137,10 @@ public class UserInfo implements Parcelable { public static final int FLAG_SYSTEM = 0x00000800; public static final int FLAG_SYSTEM = 0x00000800; /** /** * Indicates that this user is some sort of profile. Right now, the only profile type is * Indicates that this user is a profile human user, such as a managed profile. * {@link #FLAG_MANAGED_PROFILE}, but this can include other types of profiles too if any * Mutually exclusive with {@link #FLAG_FULL}. * are created in the future. This is therefore not a flag, but an OR of several flags. */ */ public static final int PROFILE_FLAGS_MASK = FLAG_MANAGED_PROFILE; public static final int FLAG_PROFILE = 0x00001000; /** /** * @hide * @hide Loading @@ -147,7 +157,8 @@ public class UserInfo implements Parcelable { FLAG_EPHEMERAL, FLAG_EPHEMERAL, FLAG_DEMO, FLAG_DEMO, FLAG_FULL, FLAG_FULL, FLAG_SYSTEM FLAG_SYSTEM, FLAG_PROFILE }) }) @Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE) public @interface UserInfoFlag { public @interface UserInfoFlag { Loading @@ -170,6 +181,13 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public long lastLoggedInTime; public long lastLoggedInTime; public String lastLoggedInFingerprint; public String lastLoggedInFingerprint; /** * Type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}, corresponding to * {@link UserTypeDetails#getName()}. */ public String userType; /** /** * If this user is a parent user, it would be its own user id. * If this user is a parent user, it would be its own user id. * If this user is a child user, it would be its parent user id. * If this user is a child user, it would be its parent user id. Loading @@ -178,7 +196,12 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public int profileGroupId; public int profileGroupId; public int restrictedProfileParentId; public int restrictedProfileParentId; /** Which profile badge color/label to use. */ /** * Which badge color/label to use within a particular {@link UserTypeDetails}, i.e. * the badgeIndex. * This is an index for distinguishing different profiles with the same parent and user type. */ public int profileBadge; public int profileBadge; /** User is only partially created. */ /** User is only partially created. */ Loading @@ -199,21 +222,68 @@ public class UserInfo implements Parcelable { */ */ public boolean preCreated; public boolean preCreated; /** * Creates a UserInfo whose user type is determined automatically by the flags according to * {@link #getDefaultUserType}; can only be used for user types handled there. */ @UnsupportedAppUsage @UnsupportedAppUsage public UserInfo(int id, String name, int flags) { public UserInfo(int id, String name, int flags) { this(id, name, null, flags); this(id, name, null, flags); } } /** * Creates a UserInfo whose user type is determined automatically by the flags according to * {@link #getDefaultUserType}; can only be used for user types handled there. */ @UnsupportedAppUsage @UnsupportedAppUsage public UserInfo(int id, String name, String iconPath, int flags) { public UserInfo(int id, String name, String iconPath, int flags) { this(id, name, iconPath, flags, getDefaultUserType(flags)); } public UserInfo(int id, String name, String iconPath, int flags, String userType) { this.id = id; this.id = id; this.name = name; this.name = name; this.flags = flags; this.flags = flags; this.userType = userType; this.iconPath = iconPath; this.iconPath = iconPath; this.profileGroupId = NO_PROFILE_GROUP_ID; this.profileGroupId = NO_PROFILE_GROUP_ID; this.restrictedProfileParentId = NO_PROFILE_GROUP_ID; this.restrictedProfileParentId = NO_PROFILE_GROUP_ID; } } /** * Get the user type (such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}) that corresponds to * the given {@link UserInfoFlag}s. * <p>The userInfoFlag can contain GUEST, RESTRICTED, MANAGED_PROFILE, DEMO, or else be * interpreted as a regular "secondary" user. It cannot contain more than one of these. * It can contain other UserInfoFlag properties (like EPHEMERAL), which will be ignored here. * * @throws IllegalArgumentException if userInfoFlag is more than one type of user or if it * is a SYSTEM user. * * @hide */ public static @NonNull String getDefaultUserType(@UserInfoFlag int userInfoFlag) { if ((userInfoFlag & FLAG_SYSTEM) != 0) { throw new IllegalArgumentException("Cannot getDefaultUserType for flags " + Integer.toHexString(userInfoFlag) + " because it corresponds to a " + "SYSTEM user type."); } final int supportedFlagTypes = FLAG_GUEST | FLAG_RESTRICTED | FLAG_MANAGED_PROFILE | FLAG_DEMO; switch (userInfoFlag & supportedFlagTypes) { case 0 : return UserManager.USER_TYPE_FULL_SECONDARY; case FLAG_GUEST: return UserManager.USER_TYPE_FULL_GUEST; case FLAG_RESTRICTED: return UserManager.USER_TYPE_FULL_RESTRICTED; case FLAG_MANAGED_PROFILE: return UserManager.USER_TYPE_PROFILE_MANAGED; case FLAG_DEMO: return UserManager.USER_TYPE_FULL_DEMO; default: throw new IllegalArgumentException("Cannot getDefaultUserType for flags " + Integer.toHexString(userInfoFlag) + " because it doesn't correspond to a " + "valid user type."); } } @UnsupportedAppUsage @UnsupportedAppUsage public boolean isPrimary() { public boolean isPrimary() { return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; Loading @@ -226,31 +296,21 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public boolean isGuest() { public boolean isGuest() { return isGuest(flags); return UserManager.isUserTypeGuest(userType); } /** * Checks if the flag denotes a guest user. */ public static boolean isGuest(@UserInfoFlag int flags) { return (flags & FLAG_GUEST) == FLAG_GUEST; } } @UnsupportedAppUsage @UnsupportedAppUsage public boolean isRestricted() { public boolean isRestricted() { return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED; return UserManager.isUserTypeRestricted(userType); } } @UnsupportedAppUsage public boolean isProfile() { public boolean isManagedProfile() { return (flags & FLAG_PROFILE) != 0; return isManagedProfile(flags); } } /** @UnsupportedAppUsage * Checks if the flag denotes a managed profile. public boolean isManagedProfile() { */ return UserManager.isUserTypeManagedProfile(userType); public static boolean isManagedProfile(@UserInfoFlag int flags) { return (flags & FLAG_MANAGED_PROFILE) == FLAG_MANAGED_PROFILE; } } @UnsupportedAppUsage @UnsupportedAppUsage Loading @@ -271,7 +331,7 @@ public class UserInfo implements Parcelable { } } public boolean isDemo() { public boolean isDemo() { return (flags & FLAG_DEMO) == FLAG_DEMO; return UserManager.isUserTypeDemo(userType); } } public boolean isFull() { public boolean isFull() { Loading Loading @@ -304,7 +364,7 @@ public class UserInfo implements Parcelable { // Don't support switching to an ephemeral user with removal in progress. // Don't support switching to an ephemeral user with removal in progress. return false; return false; } } return !isManagedProfile(); return !isProfile(); } } /** /** Loading @@ -316,9 +376,10 @@ public class UserInfo implements Parcelable { return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } } // TODO(b/142482943): Make this logic more specific and customizable. (canHaveProfile(userType)) /* @hide */ /* @hide */ public boolean canHaveProfile() { public boolean canHaveProfile() { if (isManagedProfile() || isGuest() || isRestricted()) { if (isProfile() || isGuest() || isRestricted()) { return false; return false; } } if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) { if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) { Loading @@ -336,6 +397,7 @@ public class UserInfo implements Parcelable { iconPath = orig.iconPath; iconPath = orig.iconPath; id = orig.id; id = orig.id; flags = orig.flags; flags = orig.flags; userType = orig.userType; serialNumber = orig.serialNumber; serialNumber = orig.serialNumber; creationTime = orig.creationTime; creationTime = orig.creationTime; lastLoggedInTime = orig.lastLoggedInTime; lastLoggedInTime = orig.lastLoggedInTime; Loading @@ -353,6 +415,7 @@ public class UserInfo implements Parcelable { return UserHandle.of(id); return UserHandle.of(id); } } // TODO(b/142482943): Probably include mUserType here, which means updating TestDevice, etc. @Override @Override public String toString() { public String toString() { // NOTE: do not change this string, it's used by 'pm list users', which in turn is // NOTE: do not change this string, it's used by 'pm list users', which in turn is Loading @@ -365,6 +428,7 @@ public class UserInfo implements Parcelable { public String toFullString() { public String toFullString() { return "UserInfo[id=" + id return "UserInfo[id=" + id + ", name=" + name + ", name=" + name + ", type=" + userType + ", flags=" + flagsToString(flags) + ", flags=" + flagsToString(flags) + (preCreated ? " (pre-created)" : "") + (preCreated ? " (pre-created)" : "") + (partial ? " (partial)" : "") + (partial ? " (partial)" : "") Loading @@ -387,6 +451,7 @@ public class UserInfo implements Parcelable { dest.writeString(name); dest.writeString(name); dest.writeString(iconPath); dest.writeString(iconPath); dest.writeInt(flags); dest.writeInt(flags); dest.writeString(userType); dest.writeInt(serialNumber); dest.writeInt(serialNumber); dest.writeLong(creationTime); dest.writeLong(creationTime); dest.writeLong(lastLoggedInTime); dest.writeLong(lastLoggedInTime); Loading Loading @@ -415,6 +480,7 @@ public class UserInfo implements Parcelable { name = source.readString(); name = source.readString(); iconPath = source.readString(); iconPath = source.readString(); flags = source.readInt(); flags = source.readInt(); userType = source.readString(); serialNumber = source.readInt(); serialNumber = source.readInt(); creationTime = source.readLong(); creationTime = source.readLong(); lastLoggedInTime = source.readLong(); lastLoggedInTime = source.readLong(); Loading core/java/android/os/IUserManager.aidl +46 −39 Original line number Original line Diff line number Diff line Loading @@ -35,77 +35,84 @@ interface IUserManager { /* /* * DO NOT MOVE - UserManager.h depends on the ordering of this function. * DO NOT MOVE - UserManager.h depends on the ordering of this function. */ */ int getCredentialOwnerProfile(int userHandle); int getCredentialOwnerProfile(int userId); int getProfileParentId(int userHandle); int getProfileParentId(int userId); /* /* * END OF DO NOT MOVE * END OF DO NOT MOVE */ */ UserInfo createUser(in String name, int flags); UserInfo createUser(in String name, in String userType, int flags); UserInfo preCreateUser(int flags); UserInfo preCreateUser(in String userType); UserInfo createProfileForUser(in String name, int flags, int userHandle, UserInfo createProfileForUser(in String name, in String userType, int flags, int userId, in String[] disallowedPackages); in String[] disallowedPackages); UserInfo createRestrictedProfile(String name, int parentUserHandle); UserInfo createRestrictedProfile(String name, int parentUserHandle); void setUserEnabled(int userHandle); void setUserEnabled(int userId); void setUserAdmin(int userId); void setUserAdmin(int userId); void evictCredentialEncryptionKey(int userHandle); void evictCredentialEncryptionKey(int userId); boolean removeUser(int userHandle); boolean removeUser(int userId); boolean removeUserEvenWhenDisallowed(int userHandle); boolean removeUserEvenWhenDisallowed(int userId); void setUserName(int userHandle, String name); void setUserName(int userId, String name); void setUserIcon(int userHandle, in Bitmap icon); void setUserIcon(int userId, in Bitmap icon); ParcelFileDescriptor getUserIcon(int userHandle); ParcelFileDescriptor getUserIcon(int userId); UserInfo getPrimaryUser(); UserInfo getPrimaryUser(); List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getProfiles(int userHandle, boolean enabledOnly); List<UserInfo> getProfiles(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); boolean canAddMoreManagedProfiles(int userHandle, boolean allowedToRemoveOne); boolean canAddMoreProfilesToUser(in String userType, int userId, boolean allowedToRemoveOne); UserInfo getProfileParent(int userHandle); boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne); boolean isSameProfileGroup(int userHandle, int otherUserHandle); UserInfo getProfileParent(int userId); boolean isSameProfileGroup(int userId, int otherUserHandle); String getUserTypeForUser(int userId); @UnsupportedAppUsage @UnsupportedAppUsage UserInfo getUserInfo(int userHandle); UserInfo getUserInfo(int userId); String getUserAccount(int userHandle); String getUserAccount(int userId); void setUserAccount(int userHandle, String accountName); void setUserAccount(int userId, String accountName); long getUserCreationTime(int userHandle); long getUserCreationTime(int userId); boolean isRestricted(); boolean isRestricted(); boolean canHaveRestrictedProfile(int userHandle); boolean canHaveRestrictedProfile(int userId); int getUserSerialNumber(int userHandle); int getUserSerialNumber(int userId); int getUserHandle(int userSerialNumber); int getUserHandle(int userSerialNumber); int getUserRestrictionSource(String restrictionKey, int userHandle); int getUserRestrictionSource(String restrictionKey, int userId); List<UserManager.EnforcingUser> getUserRestrictionSources(String restrictionKey, int userHandle); List<UserManager.EnforcingUser> getUserRestrictionSources(String restrictionKey, int userId); Bundle getUserRestrictions(int userHandle); Bundle getUserRestrictions(int userId); boolean hasBaseUserRestriction(String restrictionKey, int userHandle); boolean hasBaseUserRestriction(String restrictionKey, int userId); boolean hasUserRestriction(in String restrictionKey, int userHandle); boolean hasUserRestriction(in String restrictionKey, int userId); boolean hasUserRestrictionOnAnyUser(in String restrictionKey); boolean hasUserRestrictionOnAnyUser(in String restrictionKey); boolean isSettingRestrictedForUser(in String setting, int userId, in String value, int callingUid); boolean isSettingRestrictedForUser(in String setting, int userId, in String value, int callingUid); void addUserRestrictionsListener(IUserRestrictionsListener listener); void addUserRestrictionsListener(IUserRestrictionsListener listener); void setUserRestriction(String key, boolean value, int userHandle); void setUserRestriction(String key, boolean value, int userId); void setApplicationRestrictions(in String packageName, in Bundle restrictions, void setApplicationRestrictions(in String packageName, in Bundle restrictions, int userId); int userHandle); Bundle getApplicationRestrictions(in String packageName); Bundle getApplicationRestrictions(in String packageName); Bundle getApplicationRestrictionsForUser(in String packageName, int userHandle); Bundle getApplicationRestrictionsForUser(in String packageName, int userId); void setDefaultGuestRestrictions(in Bundle restrictions); void setDefaultGuestRestrictions(in Bundle restrictions); Bundle getDefaultGuestRestrictions(); Bundle getDefaultGuestRestrictions(); boolean markGuestForDeletion(int userHandle); boolean markGuestForDeletion(int userId); boolean isQuietModeEnabled(int userHandle); boolean isQuietModeEnabled(int userId); void setSeedAccountData(int userHandle, in String accountName, void setSeedAccountData(int userId, in String accountName, in String accountType, in PersistableBundle accountOptions, boolean persist); in String accountType, in PersistableBundle accountOptions, boolean persist); String getSeedAccountName(); String getSeedAccountName(); String getSeedAccountType(); String getSeedAccountType(); PersistableBundle getSeedAccountOptions(); PersistableBundle getSeedAccountOptions(); void clearSeedAccountData(); void clearSeedAccountData(); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean isProfile(int userId); boolean isManagedProfile(int userId); boolean isManagedProfile(int userId); boolean isDemoUser(int userId); boolean isDemoUser(int userId); boolean isPreCreated(int userId); boolean isPreCreated(int userId); UserInfo createProfileForUserEvenWhenDisallowed(in String name, int flags, int userHandle, UserInfo createProfileForUserEvenWhenDisallowed(in String name, in String userType, int flags, in String[] disallowedPackages); int userId, in String[] disallowedPackages); boolean isUserUnlockingOrUnlocked(int userId); boolean isUserUnlockingOrUnlocked(int userId); int getManagedProfileBadge(int userId); int getUserIconBadgeResId(int userId); int getUserBadgeResId(int userId); int getUserBadgeNoBackgroundResId(int userId); int getUserBadgeLabelResId(int userId); int getUserBadgeColorResId(int userId); boolean hasBadge(int userId); boolean isUserUnlocked(int userId); boolean isUserUnlocked(int userId); boolean isUserRunning(int userId); boolean isUserRunning(int userId); boolean isUserNameSet(int userHandle); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(); boolean hasRestrictedProfiles(); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userHandle, in IntentSender target); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target); String getUserName(); String getUserName(); long getUserStartRealtime(); long getUserStartRealtime(); long getUserUnlockRealtime(); long getUserUnlockRealtime(); Loading core/java/android/os/UserManager.java +383 −51 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -516,7 +516,7 @@ public class UserLifecycleTests { /** Creates a managed (work) profile under the current user, returning its userId. */ /** Creates a managed (work) profile under the current user, returning its userId. */ private int createManagedProfile() { private int createManagedProfile() { final UserInfo userInfo = mUm.createProfileForUser("TestProfile", final UserInfo userInfo = mUm.createProfileForUser("TestProfile", UserInfo.FLAG_MANAGED_PROFILE, mAm.getCurrentUser()); UserManager.USER_TYPE_PROFILE_MANAGED, /* flags */ 0, mAm.getCurrentUser()); if (userInfo == null) { if (userInfo == null) { throw new IllegalStateException("Creating managed profile failed. Most likely there is " throw new IllegalStateException("Creating managed profile failed. Most likely there is " + "already a pre-existing profile on the device."); + "already a pre-existing profile on the device."); Loading
core/java/android/app/ApplicationPackageManager.java +14 −25 Original line number Original line Diff line number Diff line Loading @@ -92,7 +92,6 @@ import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArrayMap; import android.util.ArraySet; import android.util.ArraySet; import android.util.DebugUtils; import android.util.DebugUtils; import android.util.IconDrawableFactory; import android.util.LauncherIcons; import android.util.LauncherIcons; import android.util.Log; import android.util.Log; import android.view.Display; import android.view.Display; Loading Loading @@ -1474,11 +1473,11 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { if (!isManagedProfile(user.getIdentifier())) { if (!hasUserBadge(user.getIdentifier())) { return icon; return icon; } } Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( Drawable badge = new LauncherIcons(mContext).getBadgeDrawable( com.android.internal.R.drawable.ic_corp_icon_badge_case, getUserManager().getUserIconBadgeResId(user.getIdentifier()), getUserBadgeColor(user)); getUserBadgeColor(user)); return getBadgedDrawable(icon, badge, null, true); return getBadgedDrawable(icon, badge, null, true); } } Loading @@ -1493,26 +1492,21 @@ public class ApplicationPackageManager extends PackageManager { return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true); return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true); } } @VisibleForTesting /** Returns the color of the user's actual badge (not the badge's shadow). */ public static final int[] CORP_BADGE_LABEL_RES_ID = new int[] { com.android.internal.R.string.managed_profile_label_badge, com.android.internal.R.string.managed_profile_label_badge_2, com.android.internal.R.string.managed_profile_label_badge_3 }; private int getUserBadgeColor(UserHandle user) { private int getUserBadgeColor(UserHandle user) { return IconDrawableFactory.getUserBadgeColor(getUserManager(), user.getIdentifier()); return getUserManager().getUserBadgeColor(user.getIdentifier()); } } @Override @Override public Drawable getUserBadgeForDensity(UserHandle user, int density) { public Drawable getUserBadgeForDensity(UserHandle user, int density) { Drawable badgeColor = getManagedProfileIconForDensity(user, // This is part of the shadow, not the main color, and is not actually corp-specific. Drawable badgeColor = getProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge_color, density); com.android.internal.R.drawable.ic_corp_badge_color, density); if (badgeColor == null) { if (badgeColor == null) { return null; return null; } } Drawable badgeForeground = getDrawableForDensity( Drawable badgeForeground = getDrawableForDensity( com.android.internal.R.drawable.ic_corp_badge_case, density); getUserManager().getUserBadgeResId(user.getIdentifier()), density); badgeForeground.setTint(getUserBadgeColor(user)); badgeForeground.setTint(getUserBadgeColor(user)); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); Drawable badge = new LayerDrawable(new Drawable[] {badgeColor, badgeForeground }); return badge; return badge; Loading @@ -1520,8 +1514,8 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { Drawable badge = getManagedProfileIconForDensity(user, Drawable badge = getProfileIconForDensity(user, com.android.internal.R.drawable.ic_corp_badge_no_background, density); getUserManager().getUserBadgeNoBackgroundResId(user.getIdentifier()), density); if (badge != null) { if (badge != null) { badge.setTint(getUserBadgeColor(user)); badge.setTint(getUserBadgeColor(user)); } } Loading @@ -1535,8 +1529,8 @@ public class ApplicationPackageManager extends PackageManager { return mContext.getResources().getDrawableForDensity(drawableId, density); return mContext.getResources().getDrawableForDensity(drawableId, density); } } private Drawable getManagedProfileIconForDensity(UserHandle user, int drawableId, int density) { private Drawable getProfileIconForDensity(UserHandle user, int drawableId, int density) { if (isManagedProfile(user.getIdentifier())) { if (hasUserBadge(user.getIdentifier())) { return getDrawableForDensity(drawableId, density); return getDrawableForDensity(drawableId, density); } } return null; return null; Loading @@ -1544,12 +1538,7 @@ public class ApplicationPackageManager extends PackageManager { @Override @Override public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { if (isManagedProfile(user.getIdentifier())) { return getUserManager().getBadgedLabelForUser(label, user); int badge = getUserManager().getManagedProfileBadge(user.getIdentifier()); int resourceId = CORP_BADGE_LABEL_RES_ID[badge % CORP_BADGE_LABEL_RES_ID.length]; return Resources.getSystem().getString(resourceId, label); } return label; } } @Override @Override Loading Loading @@ -2865,8 +2854,8 @@ public class ApplicationPackageManager extends PackageManager { return drawable; return drawable; } } private boolean isManagedProfile(int userId) { private boolean hasUserBadge(int userId) { return getUserManager().isManagedProfile(userId); return getUserManager().hasBadge(userId); } } /** /** Loading
core/java/android/content/pm/UserInfo.java +95 −29 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,7 @@ package android.content.pm; package android.content.pm; import android.annotation.IntDef; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.UnsupportedAppUsage; import android.annotation.UnsupportedAppUsage; import android.annotation.UserIdInt; import android.annotation.UserIdInt; import android.os.Parcel; import android.os.Parcel; Loading @@ -25,6 +26,8 @@ import android.os.UserHandle; import android.os.UserManager; import android.os.UserManager; import android.util.DebugUtils; import android.util.DebugUtils; import com.android.server.pm.UserTypeDetails; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading @@ -32,13 +35,13 @@ import java.lang.annotation.RetentionPolicy; * Per-user information. * Per-user information. * * * <p>There are 3 base properties of users: {@link #FLAG_SYSTEM}, {@link #FLAG_FULL}, and * <p>There are 3 base properties of users: {@link #FLAG_SYSTEM}, {@link #FLAG_FULL}, and * {@link #FLAG_MANAGED_PROFILE}. Every user must have one of the following combination of these * {@link #FLAG_PROFILE}. Every user must have one of the following combination of these * flags: * flags: * <ul> * <ul> * <li>FLAG_SYSTEM (user {@link UserHandle#USER_SYSTEM} on a headless-user-0 device)</li> * <li>FLAG_SYSTEM (user {@link UserHandle#USER_SYSTEM} on a headless-user-0 device)</li> * <li>FLAG_SYSTEM and FLAG_FULL (user {@link UserHandle#USER_SYSTEM} on a regular device)</li> * <li>FLAG_SYSTEM and FLAG_FULL (user {@link UserHandle#USER_SYSTEM} on a regular device)</li> * <li>FLAG_FULL (non-profile secondary user)</li> * <li>FLAG_FULL (non-profile secondary user)</li> * <li>FLAG_MANAGED_PROFILE (profile users)</li> * <li>FLAG_PROFILE (profile users)</li> * </ul> * </ul> * Users can have also have additional flags (such as FLAG_GUEST) as appropriate. * Users can have also have additional flags (such as FLAG_GUEST) as appropriate. * * Loading Loading @@ -70,13 +73,17 @@ public class UserInfo implements Parcelable { /** /** * Indicates a guest user that may be transient. * Indicates a guest user that may be transient. * @deprecated Use {@link UserManager#USER_TYPE_FULL_GUEST} instead. */ */ @Deprecated public static final int FLAG_GUEST = 0x00000004; public static final int FLAG_GUEST = 0x00000004; /** /** * Indicates the user has restrictions in privileges, in addition to those for normal users. * Indicates the user has restrictions in privileges, in addition to those for normal users. * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. * Exact meaning TBD. For instance, maybe they can't install apps or administer WiFi access pts. * @deprecated Use {@link UserManager#USER_TYPE_FULL_RESTRICTED} instead. */ */ @Deprecated public static final int FLAG_RESTRICTED = 0x00000008; public static final int FLAG_RESTRICTED = 0x00000008; /** /** Loading @@ -87,7 +94,9 @@ public class UserInfo implements Parcelable { /** /** * Indicates that this user is a profile of another user, for example holding a users * Indicates that this user is a profile of another user, for example holding a users * corporate data. * corporate data. * @deprecated Use {@link UserManager#USER_TYPE_PROFILE_MANAGED} instead. */ */ @Deprecated public static final int FLAG_MANAGED_PROFILE = 0x00000020; public static final int FLAG_MANAGED_PROFILE = 0x00000020; /** /** Loading @@ -108,14 +117,16 @@ public class UserInfo implements Parcelable { /** /** * User is for demo purposes only and can be removed at any time. * User is for demo purposes only and can be removed at any time. * @deprecated Use {@link UserManager#USER_TYPE_FULL_DEMO} instead. */ */ @Deprecated public static final int FLAG_DEMO = 0x00000200; public static final int FLAG_DEMO = 0x00000200; /** /** * Indicates that this user is a non-profile human user. * Indicates that this user is a non-profile human user. * * * <p>When creating a new (non-system) user, this flag will always be forced true unless the * <p>When creating a new (non-system) user, this flag will always be forced true unless the * user is a {@link #FLAG_MANAGED_PROFILE}. If user {@link UserHandle#USER_SYSTEM} is also a * user is a {@link #FLAG_PROFILE}. If user {@link UserHandle#USER_SYSTEM} is also a * human user, it must also be flagged as FULL. * human user, it must also be flagged as FULL. */ */ public static final int FLAG_FULL = 0x00000400; public static final int FLAG_FULL = 0x00000400; Loading @@ -126,11 +137,10 @@ public class UserInfo implements Parcelable { public static final int FLAG_SYSTEM = 0x00000800; public static final int FLAG_SYSTEM = 0x00000800; /** /** * Indicates that this user is some sort of profile. Right now, the only profile type is * Indicates that this user is a profile human user, such as a managed profile. * {@link #FLAG_MANAGED_PROFILE}, but this can include other types of profiles too if any * Mutually exclusive with {@link #FLAG_FULL}. * are created in the future. This is therefore not a flag, but an OR of several flags. */ */ public static final int PROFILE_FLAGS_MASK = FLAG_MANAGED_PROFILE; public static final int FLAG_PROFILE = 0x00001000; /** /** * @hide * @hide Loading @@ -147,7 +157,8 @@ public class UserInfo implements Parcelable { FLAG_EPHEMERAL, FLAG_EPHEMERAL, FLAG_DEMO, FLAG_DEMO, FLAG_FULL, FLAG_FULL, FLAG_SYSTEM FLAG_SYSTEM, FLAG_PROFILE }) }) @Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE) public @interface UserInfoFlag { public @interface UserInfoFlag { Loading @@ -170,6 +181,13 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public long lastLoggedInTime; public long lastLoggedInTime; public String lastLoggedInFingerprint; public String lastLoggedInFingerprint; /** * Type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}, corresponding to * {@link UserTypeDetails#getName()}. */ public String userType; /** /** * If this user is a parent user, it would be its own user id. * If this user is a parent user, it would be its own user id. * If this user is a child user, it would be its parent user id. * If this user is a child user, it would be its parent user id. Loading @@ -178,7 +196,12 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public int profileGroupId; public int profileGroupId; public int restrictedProfileParentId; public int restrictedProfileParentId; /** Which profile badge color/label to use. */ /** * Which badge color/label to use within a particular {@link UserTypeDetails}, i.e. * the badgeIndex. * This is an index for distinguishing different profiles with the same parent and user type. */ public int profileBadge; public int profileBadge; /** User is only partially created. */ /** User is only partially created. */ Loading @@ -199,21 +222,68 @@ public class UserInfo implements Parcelable { */ */ public boolean preCreated; public boolean preCreated; /** * Creates a UserInfo whose user type is determined automatically by the flags according to * {@link #getDefaultUserType}; can only be used for user types handled there. */ @UnsupportedAppUsage @UnsupportedAppUsage public UserInfo(int id, String name, int flags) { public UserInfo(int id, String name, int flags) { this(id, name, null, flags); this(id, name, null, flags); } } /** * Creates a UserInfo whose user type is determined automatically by the flags according to * {@link #getDefaultUserType}; can only be used for user types handled there. */ @UnsupportedAppUsage @UnsupportedAppUsage public UserInfo(int id, String name, String iconPath, int flags) { public UserInfo(int id, String name, String iconPath, int flags) { this(id, name, iconPath, flags, getDefaultUserType(flags)); } public UserInfo(int id, String name, String iconPath, int flags, String userType) { this.id = id; this.id = id; this.name = name; this.name = name; this.flags = flags; this.flags = flags; this.userType = userType; this.iconPath = iconPath; this.iconPath = iconPath; this.profileGroupId = NO_PROFILE_GROUP_ID; this.profileGroupId = NO_PROFILE_GROUP_ID; this.restrictedProfileParentId = NO_PROFILE_GROUP_ID; this.restrictedProfileParentId = NO_PROFILE_GROUP_ID; } } /** * Get the user type (such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}) that corresponds to * the given {@link UserInfoFlag}s. * <p>The userInfoFlag can contain GUEST, RESTRICTED, MANAGED_PROFILE, DEMO, or else be * interpreted as a regular "secondary" user. It cannot contain more than one of these. * It can contain other UserInfoFlag properties (like EPHEMERAL), which will be ignored here. * * @throws IllegalArgumentException if userInfoFlag is more than one type of user or if it * is a SYSTEM user. * * @hide */ public static @NonNull String getDefaultUserType(@UserInfoFlag int userInfoFlag) { if ((userInfoFlag & FLAG_SYSTEM) != 0) { throw new IllegalArgumentException("Cannot getDefaultUserType for flags " + Integer.toHexString(userInfoFlag) + " because it corresponds to a " + "SYSTEM user type."); } final int supportedFlagTypes = FLAG_GUEST | FLAG_RESTRICTED | FLAG_MANAGED_PROFILE | FLAG_DEMO; switch (userInfoFlag & supportedFlagTypes) { case 0 : return UserManager.USER_TYPE_FULL_SECONDARY; case FLAG_GUEST: return UserManager.USER_TYPE_FULL_GUEST; case FLAG_RESTRICTED: return UserManager.USER_TYPE_FULL_RESTRICTED; case FLAG_MANAGED_PROFILE: return UserManager.USER_TYPE_PROFILE_MANAGED; case FLAG_DEMO: return UserManager.USER_TYPE_FULL_DEMO; default: throw new IllegalArgumentException("Cannot getDefaultUserType for flags " + Integer.toHexString(userInfoFlag) + " because it doesn't correspond to a " + "valid user type."); } } @UnsupportedAppUsage @UnsupportedAppUsage public boolean isPrimary() { public boolean isPrimary() { return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; return (flags & FLAG_PRIMARY) == FLAG_PRIMARY; Loading @@ -226,31 +296,21 @@ public class UserInfo implements Parcelable { @UnsupportedAppUsage @UnsupportedAppUsage public boolean isGuest() { public boolean isGuest() { return isGuest(flags); return UserManager.isUserTypeGuest(userType); } /** * Checks if the flag denotes a guest user. */ public static boolean isGuest(@UserInfoFlag int flags) { return (flags & FLAG_GUEST) == FLAG_GUEST; } } @UnsupportedAppUsage @UnsupportedAppUsage public boolean isRestricted() { public boolean isRestricted() { return (flags & FLAG_RESTRICTED) == FLAG_RESTRICTED; return UserManager.isUserTypeRestricted(userType); } } @UnsupportedAppUsage public boolean isProfile() { public boolean isManagedProfile() { return (flags & FLAG_PROFILE) != 0; return isManagedProfile(flags); } } /** @UnsupportedAppUsage * Checks if the flag denotes a managed profile. public boolean isManagedProfile() { */ return UserManager.isUserTypeManagedProfile(userType); public static boolean isManagedProfile(@UserInfoFlag int flags) { return (flags & FLAG_MANAGED_PROFILE) == FLAG_MANAGED_PROFILE; } } @UnsupportedAppUsage @UnsupportedAppUsage Loading @@ -271,7 +331,7 @@ public class UserInfo implements Parcelable { } } public boolean isDemo() { public boolean isDemo() { return (flags & FLAG_DEMO) == FLAG_DEMO; return UserManager.isUserTypeDemo(userType); } } public boolean isFull() { public boolean isFull() { Loading Loading @@ -304,7 +364,7 @@ public class UserInfo implements Parcelable { // Don't support switching to an ephemeral user with removal in progress. // Don't support switching to an ephemeral user with removal in progress. return false; return false; } } return !isManagedProfile(); return !isProfile(); } } /** /** Loading @@ -316,9 +376,10 @@ public class UserInfo implements Parcelable { return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); return (!hideSystemUser || id != UserHandle.USER_SYSTEM) && supportsSwitchTo(); } } // TODO(b/142482943): Make this logic more specific and customizable. (canHaveProfile(userType)) /* @hide */ /* @hide */ public boolean canHaveProfile() { public boolean canHaveProfile() { if (isManagedProfile() || isGuest() || isRestricted()) { if (isProfile() || isGuest() || isRestricted()) { return false; return false; } } if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) { if (UserManager.isSplitSystemUser() || UserManager.isHeadlessSystemUserMode()) { Loading @@ -336,6 +397,7 @@ public class UserInfo implements Parcelable { iconPath = orig.iconPath; iconPath = orig.iconPath; id = orig.id; id = orig.id; flags = orig.flags; flags = orig.flags; userType = orig.userType; serialNumber = orig.serialNumber; serialNumber = orig.serialNumber; creationTime = orig.creationTime; creationTime = orig.creationTime; lastLoggedInTime = orig.lastLoggedInTime; lastLoggedInTime = orig.lastLoggedInTime; Loading @@ -353,6 +415,7 @@ public class UserInfo implements Parcelable { return UserHandle.of(id); return UserHandle.of(id); } } // TODO(b/142482943): Probably include mUserType here, which means updating TestDevice, etc. @Override @Override public String toString() { public String toString() { // NOTE: do not change this string, it's used by 'pm list users', which in turn is // NOTE: do not change this string, it's used by 'pm list users', which in turn is Loading @@ -365,6 +428,7 @@ public class UserInfo implements Parcelable { public String toFullString() { public String toFullString() { return "UserInfo[id=" + id return "UserInfo[id=" + id + ", name=" + name + ", name=" + name + ", type=" + userType + ", flags=" + flagsToString(flags) + ", flags=" + flagsToString(flags) + (preCreated ? " (pre-created)" : "") + (preCreated ? " (pre-created)" : "") + (partial ? " (partial)" : "") + (partial ? " (partial)" : "") Loading @@ -387,6 +451,7 @@ public class UserInfo implements Parcelable { dest.writeString(name); dest.writeString(name); dest.writeString(iconPath); dest.writeString(iconPath); dest.writeInt(flags); dest.writeInt(flags); dest.writeString(userType); dest.writeInt(serialNumber); dest.writeInt(serialNumber); dest.writeLong(creationTime); dest.writeLong(creationTime); dest.writeLong(lastLoggedInTime); dest.writeLong(lastLoggedInTime); Loading Loading @@ -415,6 +480,7 @@ public class UserInfo implements Parcelable { name = source.readString(); name = source.readString(); iconPath = source.readString(); iconPath = source.readString(); flags = source.readInt(); flags = source.readInt(); userType = source.readString(); serialNumber = source.readInt(); serialNumber = source.readInt(); creationTime = source.readLong(); creationTime = source.readLong(); lastLoggedInTime = source.readLong(); lastLoggedInTime = source.readLong(); Loading
core/java/android/os/IUserManager.aidl +46 −39 Original line number Original line Diff line number Diff line Loading @@ -35,77 +35,84 @@ interface IUserManager { /* /* * DO NOT MOVE - UserManager.h depends on the ordering of this function. * DO NOT MOVE - UserManager.h depends on the ordering of this function. */ */ int getCredentialOwnerProfile(int userHandle); int getCredentialOwnerProfile(int userId); int getProfileParentId(int userHandle); int getProfileParentId(int userId); /* /* * END OF DO NOT MOVE * END OF DO NOT MOVE */ */ UserInfo createUser(in String name, int flags); UserInfo createUser(in String name, in String userType, int flags); UserInfo preCreateUser(int flags); UserInfo preCreateUser(in String userType); UserInfo createProfileForUser(in String name, int flags, int userHandle, UserInfo createProfileForUser(in String name, in String userType, int flags, int userId, in String[] disallowedPackages); in String[] disallowedPackages); UserInfo createRestrictedProfile(String name, int parentUserHandle); UserInfo createRestrictedProfile(String name, int parentUserHandle); void setUserEnabled(int userHandle); void setUserEnabled(int userId); void setUserAdmin(int userId); void setUserAdmin(int userId); void evictCredentialEncryptionKey(int userHandle); void evictCredentialEncryptionKey(int userId); boolean removeUser(int userHandle); boolean removeUser(int userId); boolean removeUserEvenWhenDisallowed(int userHandle); boolean removeUserEvenWhenDisallowed(int userId); void setUserName(int userHandle, String name); void setUserName(int userId, String name); void setUserIcon(int userHandle, in Bitmap icon); void setUserIcon(int userId, in Bitmap icon); ParcelFileDescriptor getUserIcon(int userHandle); ParcelFileDescriptor getUserIcon(int userId); UserInfo getPrimaryUser(); UserInfo getPrimaryUser(); List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, boolean excludePreCreated); List<UserInfo> getProfiles(int userHandle, boolean enabledOnly); List<UserInfo> getProfiles(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); int[] getProfileIds(int userId, boolean enabledOnly); boolean canAddMoreManagedProfiles(int userHandle, boolean allowedToRemoveOne); boolean canAddMoreProfilesToUser(in String userType, int userId, boolean allowedToRemoveOne); UserInfo getProfileParent(int userHandle); boolean canAddMoreManagedProfiles(int userId, boolean allowedToRemoveOne); boolean isSameProfileGroup(int userHandle, int otherUserHandle); UserInfo getProfileParent(int userId); boolean isSameProfileGroup(int userId, int otherUserHandle); String getUserTypeForUser(int userId); @UnsupportedAppUsage @UnsupportedAppUsage UserInfo getUserInfo(int userHandle); UserInfo getUserInfo(int userId); String getUserAccount(int userHandle); String getUserAccount(int userId); void setUserAccount(int userHandle, String accountName); void setUserAccount(int userId, String accountName); long getUserCreationTime(int userHandle); long getUserCreationTime(int userId); boolean isRestricted(); boolean isRestricted(); boolean canHaveRestrictedProfile(int userHandle); boolean canHaveRestrictedProfile(int userId); int getUserSerialNumber(int userHandle); int getUserSerialNumber(int userId); int getUserHandle(int userSerialNumber); int getUserHandle(int userSerialNumber); int getUserRestrictionSource(String restrictionKey, int userHandle); int getUserRestrictionSource(String restrictionKey, int userId); List<UserManager.EnforcingUser> getUserRestrictionSources(String restrictionKey, int userHandle); List<UserManager.EnforcingUser> getUserRestrictionSources(String restrictionKey, int userId); Bundle getUserRestrictions(int userHandle); Bundle getUserRestrictions(int userId); boolean hasBaseUserRestriction(String restrictionKey, int userHandle); boolean hasBaseUserRestriction(String restrictionKey, int userId); boolean hasUserRestriction(in String restrictionKey, int userHandle); boolean hasUserRestriction(in String restrictionKey, int userId); boolean hasUserRestrictionOnAnyUser(in String restrictionKey); boolean hasUserRestrictionOnAnyUser(in String restrictionKey); boolean isSettingRestrictedForUser(in String setting, int userId, in String value, int callingUid); boolean isSettingRestrictedForUser(in String setting, int userId, in String value, int callingUid); void addUserRestrictionsListener(IUserRestrictionsListener listener); void addUserRestrictionsListener(IUserRestrictionsListener listener); void setUserRestriction(String key, boolean value, int userHandle); void setUserRestriction(String key, boolean value, int userId); void setApplicationRestrictions(in String packageName, in Bundle restrictions, void setApplicationRestrictions(in String packageName, in Bundle restrictions, int userId); int userHandle); Bundle getApplicationRestrictions(in String packageName); Bundle getApplicationRestrictions(in String packageName); Bundle getApplicationRestrictionsForUser(in String packageName, int userHandle); Bundle getApplicationRestrictionsForUser(in String packageName, int userId); void setDefaultGuestRestrictions(in Bundle restrictions); void setDefaultGuestRestrictions(in Bundle restrictions); Bundle getDefaultGuestRestrictions(); Bundle getDefaultGuestRestrictions(); boolean markGuestForDeletion(int userHandle); boolean markGuestForDeletion(int userId); boolean isQuietModeEnabled(int userHandle); boolean isQuietModeEnabled(int userId); void setSeedAccountData(int userHandle, in String accountName, void setSeedAccountData(int userId, in String accountName, in String accountType, in PersistableBundle accountOptions, boolean persist); in String accountType, in PersistableBundle accountOptions, boolean persist); String getSeedAccountName(); String getSeedAccountName(); String getSeedAccountType(); String getSeedAccountType(); PersistableBundle getSeedAccountOptions(); PersistableBundle getSeedAccountOptions(); void clearSeedAccountData(); void clearSeedAccountData(); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean someUserHasSeedAccount(in String accountName, in String accountType); boolean isProfile(int userId); boolean isManagedProfile(int userId); boolean isManagedProfile(int userId); boolean isDemoUser(int userId); boolean isDemoUser(int userId); boolean isPreCreated(int userId); boolean isPreCreated(int userId); UserInfo createProfileForUserEvenWhenDisallowed(in String name, int flags, int userHandle, UserInfo createProfileForUserEvenWhenDisallowed(in String name, in String userType, int flags, in String[] disallowedPackages); int userId, in String[] disallowedPackages); boolean isUserUnlockingOrUnlocked(int userId); boolean isUserUnlockingOrUnlocked(int userId); int getManagedProfileBadge(int userId); int getUserIconBadgeResId(int userId); int getUserBadgeResId(int userId); int getUserBadgeNoBackgroundResId(int userId); int getUserBadgeLabelResId(int userId); int getUserBadgeColorResId(int userId); boolean hasBadge(int userId); boolean isUserUnlocked(int userId); boolean isUserUnlocked(int userId); boolean isUserRunning(int userId); boolean isUserRunning(int userId); boolean isUserNameSet(int userHandle); boolean isUserNameSet(int userId); boolean hasRestrictedProfiles(); boolean hasRestrictedProfiles(); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userHandle, in IntentSender target); boolean requestQuietModeEnabled(String callingPackage, boolean enableQuietMode, int userId, in IntentSender target); String getUserName(); String getUserName(); long getUserStartRealtime(); long getUserStartRealtime(); long getUserUnlockRealtime(); long getUserUnlockRealtime(); Loading
core/java/android/os/UserManager.java +383 −51 File changed.Preview size limit exceeded, changes collapsed. Show changes