Add new API function createAndManageUser
This is a reduced version of the (deprecated) function
createAndInitializeUser, that allows the device owner to create a
new user and pass a bundle with information for initialization. The
new version of the function has the same functionality, but the
profile owner of the new user is always the device owner.
A flag can be specified to skip the setup wizard for the new user.
The new user is not started in the background, as opposed to how
createAndInitializeUser did it. Instead, the bundle with
initialization information is stored and will be broadcast when the
user is started for the first time.
Bug: 25288732, 25860170
Change-Id: I4e1aea6d2b7821b412c131e88454dff5934192aa
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 53f7b29..9fe0ec4 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -4120,6 +4120,47 @@
}
/**
+ * Flag used by {@link createAndManageUser} to skip setup wizard after creating a new user.
+ * @hide
+ */
+ public static final int SKIP_SETUP_WIZARD = 0x0001;
+
+ /**
+ * Called by a device owner to create a user with the specified name and the caller as profile
+ * owner. The UserHandle returned by this method should not be persisted as user handles are
+ * recycled as users are removed and created. If you need to persist an identifier for this
+ * user, use {@link UserManager#getSerialNumberForUser}. The new user will not be started in the
+ * background.
+ *
+ * <p> admin is the {@link DeviceAdminReceiver} which is the device owner, and will become the
+ * profile owner and will be registered as an active admin on the new user. The profile owner
+ * package will be installed on the new user.
+ *
+ * <p>If the adminExtras are not null, they will be stored on the device until the user is
+ * started for the first time. Then the extras will be passed to the admin when
+ * onEnable is called.
+ *
+ * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
+ * @param name The user's name.
+ * @param adminExtras Extras that will be passed to onEnable of the admin receiver on the new
+ * user.
+ * @param flags {@link SKIP_SETUP_WIZARD} is supported.
+ * @see UserHandle
+ * @return the {@link android.os.UserHandle} object for the created user, or {@code null} if the
+ * user could not be created.
+ * @hide
+ */
+ public UserHandle createAndManageUser(@NonNull ComponentName admin, @NonNull String name,
+ @Nullable PersistableBundle adminExtras, int flags) {
+ try {
+ return mService.createAndManageUser(admin, name, adminExtras, flags);
+ } catch (RemoteException re) {
+ Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, re);
+ }
+ return null;
+ }
+
+ /**
* Called by a device owner to remove a user and all associated data. The primary user can
* not be removed.
*