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

Commit fb4a4606 authored by Jason Parks's avatar Jason Parks
Browse files

Add method to check to see if the component is the supervison component.

Bug: 219025233
Test: manual && atest --no-bazel-mode FrameworksServicesTests:DevicePolicyManagerTest
Change-Id: Icfa6ba0b7300261d49d62fc8b7840fbb964a255a
parent 4ad09b9b
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -9262,6 +9262,21 @@ public class DevicePolicyManager {
        return null;
    }
    /**
     * Checks if the specified component is the supervision component.
     * @hide
     */
    public boolean isSupervisionComponent(@NonNull ComponentName who) {
        if (mService != null) {
            try {
                return getService().isSupervisionComponent(who);
            } catch (RemoteException re) {
                throw re.rethrowFromSystemServer();
            }
        }
        return false;
    }
    /**
     * @hide
     * @return the human readable name of the organisation associated with this DPM or {@code null}
+1 −0
Original line number Diff line number Diff line
@@ -178,6 +178,7 @@ interface IDevicePolicyManager {
    boolean setProfileOwner(in ComponentName who, String ownerName, int userHandle);
    ComponentName getProfileOwnerAsUser(int userHandle);
    ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(in UserHandle userHandle);
    boolean isSupervisionComponent(in ComponentName who);
    String getProfileOwnerName(int userHandle);
    void setProfileEnabled(in ComponentName who);
    void setProfileName(in ComponentName who, String profileName);
+26 −7
Original line number Diff line number Diff line
@@ -9292,11 +9292,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            }
            // Check profile owner first as that is what most likely is set.
            if (isSupervisionComponent(poComponent)) {
            if (isSupervisionComponentLocked(poComponent)) {
                return poComponent;
            }
            if (isSupervisionComponent(doComponent)) {
            if (isSupervisionComponentLocked(doComponent)) {
                return doComponent;
            }
@@ -9304,7 +9304,26 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
    }
    private boolean isSupervisionComponent(@Nullable ComponentName who) {
    /**
     * Returns if the specified component is the supervision component.
     */
    @Override
    public boolean isSupervisionComponent(@NonNull ComponentName who) {
        if (!mHasFeature) {
            return false;
        }
        synchronized (getLockObject()) {
            if (mConstants.USE_TEST_ADMIN_AS_SUPERVISION_COMPONENT) {
                final CallerIdentity caller = getCallerIdentity();
                if (isAdminTestOnlyLocked(who, caller.getUserId())) {
                    return true;
                }
            }
            return isSupervisionComponentLocked(who);
        }
    }
    private boolean isSupervisionComponentLocked(@Nullable ComponentName who) {
        if (who == null) {
            return false;
        }
@@ -9508,7 +9527,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    "Cannot set the profile owner on a user which is already set-up");
            if (!mIsWatch) {
                if (!isSupervisionComponent(owner)) {
                if (!isSupervisionComponentLocked(owner)) {
                    throw new IllegalStateException("Unable to set non-default profile owner"
                            + " post-setup " + owner);
                }
@@ -12102,8 +12121,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        synchronized (getLockObject()) {
            // Allow testOnly admins to bypass supervision config requirement.
            Preconditions.checkCallAuthorization(isAdminTestOnlyLocked(who, caller.getUserId())
                    || isSupervisionComponent(caller.getComponentName()), "Admin %s is not the "
                    + "default supervision component", caller.getComponentName());
                    || isSupervisionComponentLocked(caller.getComponentName()), "Admin %s is not "
                    + "the default supervision component", caller.getComponentName());
            DevicePolicyData policy = getUserData(caller.getUserId());
            policy.mSecondaryLockscreenEnabled = enabled;
            saveSettingsLocked(caller.getUserId());
@@ -13004,7 +13023,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    return false;
                }
                return isSupervisionComponent(admin.info.getComponent());
                return isSupervisionComponentLocked(admin.info.getComponent());
            }
        }
+2 −0
Original line number Diff line number Diff line
@@ -3360,9 +3360,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
            assertThat(dpmi.isActiveSupervisionApp(uid)).isTrue();
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user))
                        .isEqualTo(admin1);
            assertThat(dpm.isSupervisionComponent(admin1)).isTrue();
        } else {
            assertThat(dpmi.isActiveSupervisionApp(uid)).isFalse();
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user)).isNull();
            assertThat(dpm.isSupervisionComponent(admin1)).isFalse();
        }
    }