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

Commit 1b7f9845 authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixed DPMS.setDeviceOwner() permission check.

It was not clearing the caller's identity before calling
manageUserUnchecked().

Test: atest com.android.bedstead.nene.devicepolicy.DevicePolicyTest#setDeviceOwner_deviceOwnerIsAlreadySet_throwsException

Fixes: 200810234

Change-Id: I3f96e1bf477f310d0c8eee935839cf401df44e02
parent 292c4941
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -8414,17 +8414,19 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            mDeviceAdminServiceController.startServiceForOwner(
                    admin.getPackageName(), userId, "set-device-owner");
            Slogf.i(LOG_TAG, "Device owner set: " + admin + " on user " + userId);
            Slogf.i(LOG_TAG, "Device owner set: %s on user %d", admin.flattenToShortString(),
                    userId);
            if (mInjector.userManagerIsHeadlessSystemUserMode()) {
                int currentForegroundUser = getCurrentForegroundUserId();
                Slogf.i(LOG_TAG, "setDeviceOwner(): setting " + admin
                        + " as profile owner on user " + currentForegroundUser);
                Slogf.i(LOG_TAG, "setDeviceOwner(): setting %s as profile owner on user %d",
                        admin.flattenToShortString(), currentForegroundUser);
                // Sets profile owner on current foreground user since
                // the human user will complete the DO setup workflow from there.
                manageUserUnchecked(/* deviceOwner= */ admin, /* profileOwner= */ admin,
                mInjector.binderWithCleanCallingIdentity(() -> manageUserUnchecked(
                        /* deviceOwner= */ admin, /* profileOwner= */ admin,
                        /* managedUser= */ currentForegroundUser, /* adminExtras= */ null,
                        /* showDisclaimer= */ false);
                        /* showDisclaimer= */ false));
            }
            return true;
        }