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

Commit 26687b11 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Logs state on DPMS.setUserProvisioningState() when it fails." into tm-dev am: 8546fdc9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17038228

Change-Id: Ie841afe4a24754dd4a72d7e258764dc341fcf2f7
parents 71ed199b 8546fdc9
Loading
Loading
Loading
Loading
+23 −11
Original line number Original line Diff line number Diff line
@@ -9183,10 +9183,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    }
    @Override
    @Override
    public void setUserProvisioningState(int newState, int userHandle) {
    public void setUserProvisioningState(int newState, int userId) {
        if (!mHasFeature) {
        if (!mHasFeature) {
            logMissingFeatureAction("Cannot set provisioning state " + newState + " for user "
            logMissingFeatureAction("Cannot set provisioning state " + newState + " for user "
                    + userHandle);
                    + userId);
            return;
            return;
        }
        }
@@ -9196,12 +9196,24 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        final CallerIdentity caller = getCallerIdentity();
        final CallerIdentity caller = getCallerIdentity();
        final long id = mInjector.binderClearCallingIdentity();
        final long id = mInjector.binderClearCallingIdentity();
        try {
        try {
            if (userHandle != mOwners.getDeviceOwnerUserId() && !mOwners.hasProfileOwner(userHandle)
            int deviceOwnerUserId = mOwners.getDeviceOwnerUserId();
                    && getManagedUserId(userHandle) == -1
            // NOTE: multiple if statements are nested below so it can log more info on error
                    && newState != STATE_USER_UNMANAGED) {
            if (userId != deviceOwnerUserId) {
                // No managed device, user or profile, so setting provisioning state makes no sense.
                boolean hasProfileOwner = mOwners.hasProfileOwner(userId);
                throw new IllegalStateException("Not allowed to change provisioning state unless a "
                if (!hasProfileOwner) {
                        + "device or profile owner is set.");
                    int managedUserId = getManagedUserId(userId);
                    if (managedUserId == -1 && newState != STATE_USER_UNMANAGED) {
                        // No managed device, user or profile, so setting provisioning state makes
                        // no sense.
                        String error = "Not allowed to change provisioning state unless a "
                                + "device or profile owner is set.";
                        Slogf.w(LOG_TAG, "setUserProvisioningState(newState=%d, userId=%d) failed: "
                                + "deviceOwnerId=%d, hasProfileOwner=%b, managedUserId=%d, err=%s",
                                newState, userId, deviceOwnerUserId, hasProfileOwner,
                                managedUserId, error);
                        throw new IllegalStateException(error);
                    }
                }
            }
            }
            synchronized (getLockObject()) {
            synchronized (getLockObject()) {
@@ -9211,7 +9223,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                if (isAdb(caller)) {
                if (isAdb(caller)) {
                    // ADB shell can only move directly from un-managed to finalized as part of
                    // ADB shell can only move directly from un-managed to finalized as part of
                    // directly setting profile-owner or device-owner.
                    // directly setting profile-owner or device-owner.
                    if (getUserProvisioningState(userHandle)
                    if (getUserProvisioningState(userId)
                            != DevicePolicyManager.STATE_USER_UNMANAGED
                            != DevicePolicyManager.STATE_USER_UNMANAGED
                            || newState != DevicePolicyManager.STATE_USER_SETUP_FINALIZED) {
                            || newState != DevicePolicyManager.STATE_USER_SETUP_FINALIZED) {
                        throw new IllegalStateException("Not allowed to change provisioning state "
                        throw new IllegalStateException("Not allowed to change provisioning state "
@@ -9221,14 +9233,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    transitionCheckNeeded = false;
                    transitionCheckNeeded = false;
                }
                }
                final DevicePolicyData policyData = getUserData(userHandle);
                final DevicePolicyData policyData = getUserData(userId);
                if (transitionCheckNeeded) {
                if (transitionCheckNeeded) {
                    // Optional state transition check for non-ADB case.
                    // Optional state transition check for non-ADB case.
                    checkUserProvisioningStateTransition(policyData.mUserProvisioningState,
                    checkUserProvisioningStateTransition(policyData.mUserProvisioningState,
                            newState);
                            newState);
                }
                }
                policyData.mUserProvisioningState = newState;
                policyData.mUserProvisioningState = newState;
                saveSettingsLocked(userHandle);
                saveSettingsLocked(userId);
            }
            }
        } finally {
        } finally {
            mInjector.binderRestoreCallingIdentity(id);
            mInjector.binderRestoreCallingIdentity(id);