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

Commit 3729573a authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Don't count DMRH as admin on non managed users.

Don't treat DMRH as an active admin if the user isn't organization
managed. This will allow uninstalling DMRH package if it isn't
preinstalled and uninstalling updates when it is preinstalled on
unmanaged users. Devices managed by Financed DO are not considered
organization managed.

Starting from U DMRH has the tools to protect itself if necessary,
e.g. via DPM.setUserControlDisabledPackages().

Bug: 360807442
Test: btest a.d.c.DevicePolicyManagementRoleHolderTest
Flag: EXEMPT bugfix
Change-Id: I99d86bbe9e7160db9274a5d6bc4ee325d4010f79
parent 992ffb63
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.app.ApplicationExitInfo;
import android.app.ApplicationPackageManager;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.IDevicePolicyManager;
import android.app.admin.SecurityLog;
import android.app.backup.IBackupManager;
@@ -3372,8 +3373,10 @@ public class PackageManagerService implements PackageSender, TestUtilityService
    // TODO(b/261957226): centralise this logic in DPM
    boolean isPackageDeviceAdmin(String packageName, int userId) {
        final IDevicePolicyManager dpm = getDevicePolicyManager();
        final DevicePolicyManagerInternal dpmi =
                mInjector.getLocalService(DevicePolicyManagerInternal.class);
        try {
            if (dpm != null) {
            if (dpm != null && dpmi != null) {
                final ComponentName deviceOwnerComponentName = dpm.getDeviceOwnerComponent(
                        /* callingUserOnly =*/ false);
                final String deviceOwnerPackageName = deviceOwnerComponentName == null ? null
@@ -3396,7 +3399,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                    if (dpm.packageHasActiveAdmins(packageName, users[i])) {
                        return true;
                    }
                    if (isDeviceManagementRoleHolder(packageName, users[i])) {
                    if (isDeviceManagementRoleHolder(packageName, users[i])
                            && dpmi.isUserOrganizationManaged(users[i])) {
                        return true;
                    }
                }