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

Commit b13a21e3 authored by Eduard Dumitrescul's avatar Eduard Dumitrescul Committed by Bruno Martins
Browse files

Do not allow to set device owner while accounts present

Bug: 417988098
Test: manual
Flag: EXEMPT BUGFIX
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:ebc43259914fe7892c36faaef09c1c1eedb2663f
Merged-In: I51c7253b124ab524b817b17dc0aabbdb5ab12ac7
Change-Id: I51c7253b124ab524b817b17dc0aabbdb5ab12ac7
parent 984b6719
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -364,6 +364,7 @@ import com.android.internal.widget.LockSettingsInternal;
import com.android.internal.widget.LockscreenCredential;
import com.android.internal.widget.PasswordValidationError;
import com.android.net.module.util.ProxyUtils;
import com.android.server.accounts.AccountManagerService;
import com.android.server.LocalServices;
import com.android.server.LockGuard;
import com.android.server.PersistentDataBlockManagerInternal;
@@ -8455,6 +8456,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        // Cannot be called while holding the lock:
        final boolean hasIncompatibleAccountsOrNonAdb =
                hasIncompatibleAccountsOrNonAdbNoLock(caller, userId, admin);
        if (!hasIncompatibleAccountsOrNonAdb) {
            synchronized (getLockObject()) {
                if (!isAdminTestOnlyLocked(admin, userId) && hasAccountsOnAnyUser()) {
                    Slogf.w(LOG_TAG,
                            "Non test-only owner can't be installed with existing accounts.");
                    return false;
                }
            }
        }
        synchronized (getLockObject()) {
            enforceCanSetDeviceOwnerLocked(caller, admin, userId, hasIncompatibleAccountsOrNonAdb);
            Preconditions.checkArgument(isPackageInstalledForUser(admin.getPackageName(), userId),
@@ -18856,6 +18868,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        return accounts.length == 0;
    }
    private boolean hasAccountsOnAnyUser() {
        AccountManagerService accountManagerService = AccountManagerService.getSingleton();
        return accountManagerService.getAllAccountsForSystemProcess().length != 0;
    }
    private void setBypassDevicePolicyManagementRoleQualificationStateInternal(
            String currentRoleHolder, boolean allowBypass) {
        boolean stateChanged = false;