diff options
Diffstat (limited to 'core/java/android/os/UserManager.java')
-rw-r--r-- | core/java/android/os/UserManager.java | 81 |
1 files changed, 59 insertions, 22 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 9c9829fb08e2..af9e592f9036 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -37,6 +37,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.IntentSender; import android.content.pm.UserInfo; +import android.content.pm.UserInfo.UserInfoFlag; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; @@ -2003,18 +2004,20 @@ public class UserManager { /** * Creates a user with the specified name and options. For non-admin users, default user - * restrictions are going to be applied. - * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. + * restrictions will be applied. + * + * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. * * @param name the user's name - * @param flags flags that identify the type of user and other properties. + * @param flags UserInfo flags that identify the type of user and other properties. * @see UserInfo * - * @return the UserInfo object for the created user, or null if the user could not be created. + * @return the UserInfo object for the created user, or {@code null} if the user could not be + * created. * @hide */ @UnsupportedAppUsage - public UserInfo createUser(String name, int flags) { + public @Nullable UserInfo createUser(@Nullable String name, @UserInfoFlag int flags) { UserInfo user = null; try { user = mService.createUser(name, flags); @@ -2031,6 +2034,36 @@ public class UserManager { } /** + * Pre-creates a user with the specified name and options. For non-admin users, default user + * restrictions will be applied. + * + * <p>This method can be used by OEMs to "warm" up the user creation by pre-creating some users + * at the first boot, so they when the "real" user is created (for example, + * by {@link #createUser(String, int)} or {@link #createGuest(Context, String)}), it takes + * less time. + * + * <p>Requires {@link android.Manifest.permission#MANAGE_USERS} permission. + * + * @param flags UserInfo flags that identify the type of user and other properties. + * @see UserInfo + * + * @return the UserInfo object for the created user, or {@code null} if the user could not be + * created. + * + * @throw {@link IllegalArgumentException} if {@code flags} contains + * {@link UserInfo#FLAG_MANAGED_PROFILE}. + * + * @hide + */ + public @Nullable UserInfo preCreateUser(@UserInfoFlag int flags) { + try { + return mService.preCreateUser(flags); + } catch (RemoteException re) { + throw re.rethrowFromSystemServer(); + } + } + + /** * Creates a guest user and configures it. * @param context an application context * @param name the name to set for the user @@ -2346,15 +2379,26 @@ public class UserManager { /** * Returns information for all users on this device, including ones marked for deletion. * To retrieve only users that are alive, use {@link #getUsers(boolean)}. - * <p> - * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. + * * @return the list of users that exist on the device. * @hide */ @UnsupportedAppUsage + @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public List<UserInfo> getUsers() { + return getUsers(/* excludeDying= */ false); + } + + /** + * Returns information for all users on this device, based on the filtering parameters. + * + * @hide + */ + @RequiresPermission(android.Manifest.permission.MANAGE_USERS) + public List<UserInfo> getUsers(boolean excludePartial, boolean excludeDying, + boolean excludePreCreated) { try { - return mService.getUsers(false); + return mService.getUsers(excludePartial, excludeDying, excludePreCreated); } catch (RemoteException re) { throw re.rethrowFromSystemServer(); } @@ -2370,16 +2414,12 @@ public class UserManager { @SystemApi @RequiresPermission(android.Manifest.permission.MANAGE_USERS) public long[] getSerialNumbersOfUsers(boolean excludeDying) { - try { - List<UserInfo> users = mService.getUsers(excludeDying); - long[] result = new long[users.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = users.get(i).serialNumber; - } - return result; - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); + List<UserInfo> users = getUsers(excludeDying); + long[] result = new long[users.size()]; + for (int i = 0; i < result.length; i++) { + result[i] = users.get(i).serialNumber; } + return result; } /** @@ -2765,11 +2805,8 @@ public class UserManager { */ @UnsupportedAppUsage public @NonNull List<UserInfo> getUsers(boolean excludeDying) { - try { - return mService.getUsers(excludeDying); - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); - } + return getUsers(/*excludePartial= */ true, excludeDying, + /* excludePreCreated= */ true); } /** |