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

Commit 936e6c35 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Fix bug in retrieving headless system user mode

Fixes: 325141266
Test: btest android.devicepolicy.cts.ProvisioningTest
Test: btest android.devicepolicy.cts.CreateAndManageUserTest
Change-Id: I5fb259cfed5bd83b16b69ceeac3d427aaf1c90d3
parent 3092a907
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ import static android.app.AppOpsManager.OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTI
import static android.app.AppOpsManager.OPSTR_SYSTEM_EXEMPT_FROM_SUSPENSION;
import static android.app.admin.DeviceAdminInfo.HEADLESS_DEVICE_OWNER_MODE_AFFILIATED;
import static android.app.admin.DeviceAdminInfo.HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER;
import static android.app.admin.DeviceAdminInfo.HEADLESS_DEVICE_OWNER_MODE_UNSUPPORTED;
import static android.app.admin.DeviceAdminInfo.USES_POLICY_FORCE_LOCK;
import static android.app.admin.DeviceAdminInfo.USES_POLICY_WIPE_DATA;
import static android.app.admin.DeviceAdminReceiver.ACTION_COMPLIANCE_ACKNOWLEDGEMENT_REQUIRED;
@@ -9524,7 +9525,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private int getHeadlessDeviceOwnerMode() {
        synchronized (getLockObject()) {
            return getDeviceOwnerAdminLocked().info.getHeadlessDeviceOwnerMode();
            ActiveAdmin deviceOwner = getDeviceOwnerAdminLocked();
            if (deviceOwner == null) {
                return HEADLESS_DEVICE_OWNER_MODE_UNSUPPORTED;
            }
            return deviceOwner.info.getHeadlessDeviceOwnerMode();
        }
    }
@@ -12281,17 +12286,18 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
        final CallerIdentity caller = getCallerIdentity(admin);
        // Only allow the system user to use this method
        Preconditions.checkCallAuthorization(caller.getUserHandle().isSystem(),
                "createAndManageUser was called from non-system user");
        Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
        checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_CREATE_AND_MANAGE_USER);
        if (headlessDeviceOwnerSingleUserEnabled()) {
            // Block this method if the device is in headless main user mode
            Preconditions.checkCallAuthorization(
                    getHeadlessDeviceOwnerMode() != HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER,
                    "createAndManageUser was called while in headless single user mode");
        }
        // Only allow the system user to use this method
        Preconditions.checkCallAuthorization(caller.getUserHandle().isSystem(),
                "createAndManageUser was called from non-system user");
        Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller));
        checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_CREATE_AND_MANAGE_USER);
        final boolean ephemeral = (flags & DevicePolicyManager.MAKE_USER_EPHEMERAL) != 0;
        final boolean demo = (flags & DevicePolicyManager.MAKE_USER_DEMO) != 0