Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 661ec471 authored by Adam Connors's avatar Adam Connors
Browse files

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
parent fde7865c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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);
+8 −0
Original line number Diff line number Diff line
@@ -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