diff options
| author | Amith Yamasani <yamasani@google.com> | 2014-07-01 15:36:12 +0530 |
|---|---|---|
| committer | Amith Yamasani <yamasani@google.com> | 2014-07-01 15:36:12 +0530 |
| commit | aba4f1b54a2b7b2aefc840dcb3b46459aa1bde23 (patch) | |
| tree | 4ea1175b9d02f4afca6d3d04f0d6c7fa60196f7b /core/java | |
| parent | f2d4fa8c7851cac0be9e65cefc49834da15e9b69 (diff) | |
Add a method to set a profile owner and active admin at once
This can be used by system apps to register a profile owner during setup
Bug: 15922051
Change-Id: Iee1b5adeb47d7e40ab36df18e3a057d8ee430f46
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/admin/DevicePolicyManager.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index d313cac23b4c..d18647a3622a 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -2062,6 +2062,37 @@ public class DevicePolicyManager { /** * @hide + * @SystemApi + * Sets the given component as an active admin and registers the package as the profile + * owner for this user. The package must already be installed and there shouldn't be + * an existing profile owner registered for this user. Also, this method must be called + * before the user setup has been completed. + * <p> + * This method can only be called by system apps that hold MANAGE_USERS permission and + * MANAGE_DEVICE_ADMINS permission. + * @param admin The component to register as an active admin and profile owner. + * @param ownerName The user-visible name of the entity that is managing this user. + * @return whether the admin was successfully registered as the profile owner. + * @throws IllegalArgumentException if packageName is null, the package isn't installed, or + * the user has already been set up. + */ + public boolean setActiveProfileOwner(ComponentName admin, String ownerName) + throws IllegalArgumentException { + if (mService != null) { + try { + final int myUserId = UserHandle.myUserId(); + mService.setActiveAdmin(admin, false, myUserId); + return mService.setProfileOwner(admin.getPackageName(), ownerName, myUserId); + } catch (RemoteException re) { + Log.w(TAG, "Failed to set profile owner " + re); + throw new IllegalArgumentException("Couldn't set profile owner.", re); + } + } + return false; + } + + /** + * @hide * Sets the given package as the profile owner of the given user profile. The package must * already be installed and there shouldn't be an existing profile owner registered for this * user. Also, this method must be called before the user has been used for the first time. |
