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

Commit 85c9cc89 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Fix bad state for clouddpc users" into main

parents 4dde7ca3 99ed4259
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -243,3 +243,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
    name: "headless_single_user_bad_device_admin_state_fix"
    namespace: "enterprise"
    description: "Fix the bad state in DPMS caused by an earlier bug related to the headless single user change"
    bug: "332477138"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}
+30 −0
Original line number Diff line number Diff line
@@ -2253,11 +2253,41 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                if (userHandle == UserHandle.USER_SYSTEM) {
                    mStateCache.setDeviceProvisioned(policy.mUserSetupComplete);
                }
                if (Flags.headlessSingleUserBadDeviceAdminStateFix()) {
                    fixBadDeviceAdminStateForInternalUsers(userHandle, policy);
                }
            }
            return policy;
        }
    }
    private void fixBadDeviceAdminStateForInternalUsers(int userId, DevicePolicyData policy) {
        ComponentName component = mOwners.getDeviceOwnerComponent();
        int doUserId = mOwners.getDeviceOwnerUserId();
        ComponentName cloudDpc = new ComponentName(
                "com.google.android.apps.work.clouddpc",
                "com.google.android.apps.work.clouddpc.receivers.CloudDeviceAdminReceiver");
        if (component == null || doUserId != userId || !component.equals(cloudDpc)) {
            return;
        }
        Slogf.i(LOG_TAG, "Attempting to apply a temp fix for cloudpc internal users' bad state.");
        final int n = policy.mAdminList.size();
        for (int i = 0; i < n; i++) {
            ActiveAdmin admin = policy.mAdminList.get(i);
            if (component.equals(admin.info.getComponent())) {
                Slogf.i(LOG_TAG, "An ActiveAdmin already exists, fix not required.");
                return;
            }
        }
        DeviceAdminInfo dai = findAdmin(component, userId, /* throwForMissingPermission= */ false);
        if (dai != null) {
            ActiveAdmin ap = new ActiveAdmin(dai, /* parent */ false);
            policy.mAdminMap.put(ap.info.getComponent(), ap);
            policy.mAdminList.add(ap);
            Slogf.i(LOG_TAG, "Fix applied, an ActiveAdmin has been added.");
        }
    }
    /**
     * Creates and loads the policy data from xml for data that is shared between
     * various profiles of a user. In contrast to {@link #getUserData(int)}