diff options
| author | Amith Yamasani <yamasani@google.com> | 2014-07-01 10:09:39 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-06-26 23:19:11 +0000 |
| commit | 374041a63dffb49dae89ab9959c96b50f4db98e9 (patch) | |
| tree | 86a97dd147e4fe09cb73bbf3f92910cc5954340a /core/java/android | |
| parent | aeaf87fe452353371b36da42e5beccca3150ab08 (diff) | |
| parent | aba4f1b54a2b7b2aefc840dcb3b46459aa1bde23 (diff) | |
Merge "Add a method to set a profile owner and active admin at once"
Diffstat (limited to 'core/java/android')
| -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. |
