Change API for setProfileOwner to require userId

Previously the userId of the current process used but it
makes the provisioning process cleaner to be able to pass
it in explicitly.

Change-Id: I670c4cf3638f1340f6d0bf856c3e01045df8c29e
This commit is contained in:
Adam Connors
2014-02-11 13:59:46 +00:00
parent fde7865c16
commit 661ec4710b
2 changed files with 11 additions and 3 deletions

View File

@@ -1690,16 +1690,16 @@ public class DevicePolicyManager {
* user. Also, this method must be called before the user has been used for the first time.
* @param packageName the package name of the application to be registered as profile owner.
* @param ownerName the human readable name of the organisation associated with this DPM.
* @param userHandle the userId to set the profile owner for.
* @return whether the package 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 setProfileOwner(String packageName, String ownerName)
public boolean setProfileOwner(String packageName, String ownerName, int userHandle)
throws IllegalArgumentException {
if (mService != null) {
try {
return mService.setProfileOwner(packageName, ownerName,
Process.myUserHandle().getIdentifier());
return mService.setProfileOwner(packageName, ownerName, userHandle);
} catch (RemoteException re) {
Log.w(TAG, "Failed to set profile owner", re);
throw new IllegalArgumentException("Couldn't set profile owner.", re);

View File

@@ -2830,6 +2830,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return false;
}
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
if (um.getUserInfo(userHandle) == null) {
// User doesn't exist.
throw new IllegalArgumentException(
"Attempted to set profile owner for invalid userId: " + userHandle);
}
if (packageName == null
|| !DeviceOwner.isInstalledForUser(packageName, userHandle)) {
throw new IllegalArgumentException("Package name " + packageName