diff options
4 files changed, 47 insertions, 1 deletions
diff --git a/api/current.txt b/api/current.txt index eeff7537338e..220a1aca4a17 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4953,6 +4953,7 @@ package android.app.admin { method public void setPasswordMinimumSymbols(android.content.ComponentName, int); method public void setPasswordMinimumUpperCase(android.content.ComponentName, int); method public void setPasswordQuality(android.content.ComponentName, int); + method public void setProfileEnabled(android.content.ComponentName); method public int setStorageEncryption(android.content.ComponentName, boolean); method public void wipeData(int); field public static final java.lang.String ACTION_ADD_DEVICE_ADMIN = "android.app.action.ADD_DEVICE_ADMIN"; diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index d8be4393f636..725f8086ced7 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -1756,8 +1756,26 @@ public class DevicePolicyManager { } /** + * Sets the enabled state of the profile. A profile should be enabled only once it is ready to + * be used. Only the profile owner can call this. + * + * @see #isPRofileOwnerApp + * + * @param admin Which {@link DeviceAdminReceiver} this request is associated with. + */ + public void setProfileEnabled(ComponentName admin) { + if (mService != null) { + try { + mService.setProfileEnabled(admin); + } catch (RemoteException e) { + Log.w(TAG, "Failed talking with device policy service", e); + } + } + } + + /** * Used to determine if a particular package is registered as the Profile Owner for the - * current user. A profile owner is a special device admin that has additional priviledges + * current user. A profile owner is a special device admin that has additional privileges * within the managed profile. * * @param packageName The package name of the app to compare with the registered profile owner. diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index 811958550ede..e4b2adc5d611 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -107,6 +107,7 @@ interface IDevicePolicyManager { boolean setProfileOwner(String packageName, String ownerName, int userHandle); String getProfileOwner(int userHandle); String getProfileOwnerName(int userHandle); + void setProfileEnabled(in ComponentName who); boolean installCaCert(in byte[] certBuffer); void uninstallCaCert(in byte[] certBuffer); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 983ca2d032f7..35f93142a420 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -2888,6 +2888,32 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } @Override + public void setProfileEnabled(ComponentName who) { + if (!mHasFeature) { + return; + } + synchronized (this) { + // Check for permissions + if (who == null) { + throw new NullPointerException("ComponentName is null"); + } + // Check if this is the profile owner who is calling + getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); + Slog.d(LOG_TAG, "Enabling the profile for: " + UserHandle.getCallingUserId()); + long id = Binder.clearCallingIdentity(); + + try { + Intent intent = new Intent(Intent.ACTION_MANAGED_PROFILE_ADDED); + intent.putExtra(Intent.EXTRA_USER, new UserHandle(UserHandle.getCallingUserId())); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + mContext.sendBroadcastAsUser(intent, UserHandle.OWNER); + } finally { + restoreCallingIdentity(id); + } + } + } + + @Override public String getProfileOwner(int userHandle) { if (!mHasFeature) { return null; |