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

Commit 2f44f8fe authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Clear calling identity before calling into UserManager

Currently "adb shell dpm set-profile-owner" fails because shell
lacks MANAGE_USERS.

Bug: 147655081
Test: atest ManagedProfileTest
Change-Id: I2d09d6bd9f95b63cc4d124363aaabff7d5f63c64
parent eeb90fec
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -8336,13 +8336,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                throw new IllegalArgumentException("Not active admin: " + who);
            }
            UserInfo parentUser = mUserManager.getProfileParent(userHandle);
            final int parentUserId = getProfileParentId(userHandle);
            // When trying to set a profile owner on a new user, it may be that this user is
            // a profile - but it may not be a managed profile if there's a restriction on the
            // parent to add managed profiles (e.g. if the device has a device owner).
            if (parentUser != null && mUserManager.hasUserRestriction(
            if (parentUserId != userHandle && mUserManager.hasUserRestriction(
                    UserManager.DISALLOW_ADD_MANAGED_PROFILE,
                    UserHandle.of(parentUser.id))) {
                    UserHandle.of(parentUserId))) {
                Slog.i(LOG_TAG, "Cannot set profile owner because of restriction.");
                return false;
            }