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

Commit ef4ceb4e authored by Xiqi Ruan's avatar Xiqi Ruan Committed by Android (Google) Code Review
Browse files

Merge "Allowlist provision for retail demo even `device_admin` is disabled" into main

parents ab7464dd c0966c7d
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -1497,6 +1497,16 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                SystemMessage.NOTE_PROFILE_WIPED, notification, UserHandle.of(parentUserId));
    }
    private boolean shouldEnableForRetailDemoPackage(String packageName) {
        if (!Flags.removeDeviceAdminFeatureChecks() || TextUtils.isEmpty(packageName)) {
            return false;
        }
        final String predefinedPkgName = mContext.getString(R.string.config_retailDemoPackage);
        return packageName.equals(predefinedPkgName);
    }
    private final class UserLifecycleListener implements UserManagerInternal.UserLifecycleListener {
        @Override
@@ -4162,7 +4172,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
            int userHandle,
            @Nullable String provisioningContext
    ) {
        if (!mHasFeature) {
        if (!mHasFeature && !shouldEnableForRetailDemoPackage(adminReceiver.getPackageName())) {
            return;
        }
        Preconditions.checkArgumentNonnegative(userHandle, "Invalid userId");
@@ -9939,7 +9949,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    public boolean setDeviceOwner(ComponentName admin, int userId,
            boolean setProfileOwnerOnCurrentUserIfNecessary) {
        if (!mHasFeature) {
        if (!mHasFeature && !shouldEnableForRetailDemoPackage(admin.getPackageName())) {
            logMissingFeatureAction("Cannot set " + ComponentName.flattenToShortString(admin)
                    + " as device owner for user " + userId);
            return false;
@@ -10513,7 +10523,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    @Override
    public boolean setProfileOwner(ComponentName who, int userHandle) {
        if (!mHasFeature) {
        if (!mHasFeature && !shouldEnableForRetailDemoPackage(who.getPackageName())) {
            logMissingFeatureAction("Cannot set " + ComponentName.flattenToShortString(who)
                    + " as profile owner for user " + userHandle);
            return false;
@@ -17725,7 +17735,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private int checkProvisioningPreconditionSkipPermission(
            String action, String packageName, @Nullable ComponentName componentName, int userId) {
        if (!mHasFeature) {
        if (!mHasFeature && !shouldEnableForRetailDemoPackage(packageName)) {
            logMissingFeatureAction("Cannot check provisioning for action " + action);
            return STATUS_DEVICE_ADMIN_NOT_SUPPORTED;
        }
+16 −0
Original line number Diff line number Diff line
@@ -3651,6 +3651,22 @@ public class DevicePolicyManagerTest extends DpmTestBase {
                DevicePolicyManager.STATUS_DEVICE_ADMIN_NOT_SUPPORTED);
    }

    @Test
    public void testCheckProvisioningPreCondition_DeviceAdminFeatureOff_RetailDemo()
            throws Exception {
        setup_DeviceAdminFeatureOff();
        when(mServiceContext.resources
                .getString(R.string.config_retailDemoPackage)).thenReturn(admin1.getPackageName());
        mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
        assertCheckProvisioningPreCondition(DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE,
                DevicePolicyManager.STATUS_OK);
        assertCheckProvisioningPreCondition(DevicePolicyManager.ACTION_PROVISION_FINANCED_DEVICE,
                DevicePolicyManager.STATUS_OK);
        // `managed_user` feature is not enabled.
        assertCheckProvisioningPreCondition(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE,
                DevicePolicyManager.STATUS_MANAGED_USERS_NOT_SUPPORTED);
    }

    private void setup_ManagedProfileFeatureOff() throws Exception {
        when(getServices().ipackageManager
                .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(false);