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

Commit 5495e89c authored by Jeroen Dhollander's avatar Jeroen Dhollander
Browse files

Fix installing of DEVICE_POLICY_MANAGEMENT Role holder in work profile

When a work profile is created, the 'DEVICE_POLICY_MANAGEMENT' role
holder app must be installed in that new profile.
To do that, the code must figure out who holds that role *on the current
user*, so that same app can be installed in the work profile.

The old code erroneously checked who had the role in the *work profile*.
This only worked because CloudDPC was always already installed.

Bug: 408993396
Flag: EXEMPT bugfix
Test: Manually created work account and verified it didn't crash.
Change-Id: I8e3159734200bfd592591566a3bd57e0d9dc3851
parent 0ef7279a
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -12665,7 +12665,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        final int userHandle = user.getIdentifier();
        final long id = mInjector.binderClearCallingIdentity();
        try {
            maybeInstallDevicePolicyManagementRoleHolderInUser(userHandle);
            maybeInstallDevicePolicyManagementRoleHolderInUser(userHandle,
                    caller);
            manageUserUnchecked(admin, profileOwner, userHandle, adminExtras,
                    /* showDisclaimer= */ true);
@@ -21514,7 +21515,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                    startTime,
                    callerPackage);
            maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id);
            maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id,
                    caller);
            installExistingAdminPackage(userInfo.id, admin.getPackageName());
            if (!enableAdminAndSetProfileOwner(userInfo.id, caller.getUserId(), admin)) {
@@ -21607,7 +21609,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                    startTime,
                    caller.getPackageName());
            maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id);
            maybeInstallDevicePolicyManagementRoleHolderInUser(userInfo.id, caller);
            installExistingAdminPackage(userInfo.id, admin.getPackageName());
            if (!enableAdminAndSetProfileOwner(userInfo.id, caller.getUserId(), admin)) {
@@ -21735,9 +21737,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    private void onCreateAndProvisionManagedProfileCompleted(
            ManagedProfileProvisioningParams provisioningParams) {}
    private void maybeInstallDevicePolicyManagementRoleHolderInUser(int targetUserId) {
    private void maybeInstallDevicePolicyManagementRoleHolderInUser(@UserIdInt int targetUserId,
            CallerIdentity caller) {
        String devicePolicyManagerRoleHolderPackageName =
                getRoleHolderPackageName(mContext, RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT);
                getRoleHolderPackageNameOnUser(mContext, RoleManager.ROLE_DEVICE_POLICY_MANAGEMENT,
                        caller.getUserHandle());
        if (devicePolicyManagerRoleHolderPackageName == null) {
            Slogf.d(LOG_TAG, "No device policy management role holder specified.");
            return;
@@ -21763,14 +21767,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        }
    }
    /**
     * If multiple packages hold the role, returns the first package in the list.
     */
    @Nullable
    private String getRoleHolderPackageName(Context context, String role) {
        return getRoleHolderPackageNameOnUser(context, role, Process.myUserHandle());
    }
    /**
     * If multiple packages hold the role, returns the first package in the list.
     */