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

Commit 262c678d authored by Antoan Angelov's avatar Antoan Angelov Committed by Android (Google) Code Review
Browse files

Merge "Copy the device manager role holder to the other profile during provisioning"

parents 0644eeef e01f8960
Loading
Loading
Loading
Loading
+45 −1
Original line number Diff line number Diff line
@@ -215,6 +215,7 @@ import android.app.admin.SystemUpdatePolicy;
import android.app.admin.UnsafeStateException;
import android.app.backup.IBackupManager;
import android.app.compat.CompatChanges;
import android.app.role.RoleManager;
import android.app.trust.TrustManager;
import android.app.usage.UsageStatsManagerInternal;
import android.compat.annotation.ChangeId;
@@ -10857,6 +10858,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        final int userHandle = user.getIdentifier();
        final long id = mInjector.binderClearCallingIdentity();
        try {
            maybeInstallDeviceManagerRoleHolderInUser(userHandle);
            manageUserUnchecked(admin, profileOwner, userHandle, adminExtras,
                    /* showDisclaimer= */ true);
@@ -17696,6 +17699,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            }
            final long startTime = SystemClock.elapsedRealtime();
            onCreateAndProvisionManagedProfileStarted(provisioningParams);
            final Set<String> nonRequiredApps = provisioningParams.isLeaveAllSystemAppsEnabled()
                    ? Collections.emptySet()
                    : mOverlayPackagesProvider.getNonRequiredApps(
@@ -17707,6 +17713,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    Slogf.i(LOG_TAG, "Disallowed package [" + packageName + "]");
                }
            }
            userInfo = mUserManager.createProfileForUserEvenWhenDisallowed(
                    provisioningParams.getProfileName(),
                    UserManager.USER_TYPE_PROFILE_MANAGED,
@@ -17725,7 +17732,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    startTime,
                    callerPackage);
            onCreateAndProvisionManagedProfileStarted(provisioningParams);
            maybeInstallDeviceManagerRoleHolderInUser(userInfo.id);
            installExistingAdminPackage(userInfo.id, admin.getPackageName());
            if (!enableAdminAndSetProfileOwner(
@@ -17793,6 +17800,43 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private void onCreateAndProvisionManagedProfileCompleted(
            ManagedProfileProvisioningParams provisioningParams) {}
    private void maybeInstallDeviceManagerRoleHolderInUser(int targetUserId) {
        String deviceManagerRoleHolderPackageName = getDeviceManagerRoleHolderPackageName(mContext);
        if (deviceManagerRoleHolderPackageName == null) {
            Slogf.d(LOG_TAG, "No device manager role holder specified.");
            return;
        }
        try {
            if (mIPackageManager.isPackageAvailable(
                    deviceManagerRoleHolderPackageName, targetUserId)) {
                Slogf.d(LOG_TAG, "The device manager role holder "
                        + deviceManagerRoleHolderPackageName + " is already installed in "
                        + "user " + targetUserId);
                return;
            }
            Slogf.d(LOG_TAG, "Installing the device manager role holder "
                    + deviceManagerRoleHolderPackageName + " in user " + targetUserId);
            mIPackageManager.installExistingPackageAsUser(
                    deviceManagerRoleHolderPackageName,
                    targetUserId,
                    PackageManager.INSTALL_ALL_WHITELIST_RESTRICTED_PERMISSIONS,
                    PackageManager.INSTALL_REASON_POLICY,
                    /* whiteListedPermissions= */ null);
        } catch (RemoteException e) {
            // Does not happen, same process
        }
    }
    private String getDeviceManagerRoleHolderPackageName(Context context) {
        RoleManager roleManager = context.getSystemService(RoleManager.class);
        List<String> roleHolders =
                roleManager.getRoleHolders(RoleManager.ROLE_DEVICE_MANAGER);
        if (roleHolders.isEmpty()) {
            return null;
        }
        return roleHolders.get(0);
    }
    private void resetInteractAcrossProfilesAppOps() {
        mInjector.getCrossProfileApps().clearInteractAcrossProfilesAppOps();
        pregrantDefaultInteractAcrossProfilesAppOps();