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

Commit 6d97866f authored by Jason Parks's avatar Jason Parks Committed by Automerger Merge Worker
Browse files

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

Merge "Add method to check to see if the component is the supervison component." into tm-dev am: 4492604d am: 44effc42 am: e2438acb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18815896



Change-Id: I2ab07032c7c3b307247fcc5f1763f48adc9777c4
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a43e0271 e2438acb
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -9262,6 +9262,21 @@ public class DevicePolicyManager {
        return null;
        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
     * @hide
     * @return the human readable name of the organisation associated with this DPM or {@code null}
     * @return the human readable name of the organisation associated with this DPM or {@code null}
+1 −0
Original line number Original line Diff line number Diff line
@@ -178,6 +178,7 @@ interface IDevicePolicyManager {
    boolean setProfileOwner(in ComponentName who, String ownerName, int userHandle);
    boolean setProfileOwner(in ComponentName who, String ownerName, int userHandle);
    ComponentName getProfileOwnerAsUser(int userHandle);
    ComponentName getProfileOwnerAsUser(int userHandle);
    ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(in UserHandle userHandle);
    ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(in UserHandle userHandle);
    boolean isSupervisionComponent(in ComponentName who);
    String getProfileOwnerName(int userHandle);
    String getProfileOwnerName(int userHandle);
    void setProfileEnabled(in ComponentName who);
    void setProfileEnabled(in ComponentName who);
    void setProfileName(in ComponentName who, String profileName);
    void setProfileName(in ComponentName who, String profileName);
+26 −7
Original line number Original line 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.
            // Check profile owner first as that is what most likely is set.
            if (isSupervisionComponent(poComponent)) {
            if (isSupervisionComponentLocked(poComponent)) {
                return poComponent;
                return poComponent;
            }
            }
            if (isSupervisionComponent(doComponent)) {
            if (isSupervisionComponentLocked(doComponent)) {
                return 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) {
        if (who == null) {
            return false;
            return false;
        }
        }
@@ -9508,7 +9527,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    "Cannot set the profile owner on a user which is already set-up");
                    "Cannot set the profile owner on a user which is already set-up");
            if (!mIsWatch) {
            if (!mIsWatch) {
                if (!isSupervisionComponent(owner)) {
                if (!isSupervisionComponentLocked(owner)) {
                    throw new IllegalStateException("Unable to set non-default profile owner"
                    throw new IllegalStateException("Unable to set non-default profile owner"
                            + " post-setup " + owner);
                            + " post-setup " + owner);
                }
                }
@@ -12102,8 +12121,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        synchronized (getLockObject()) {
        synchronized (getLockObject()) {
            // Allow testOnly admins to bypass supervision config requirement.
            // Allow testOnly admins to bypass supervision config requirement.
            Preconditions.checkCallAuthorization(isAdminTestOnlyLocked(who, caller.getUserId())
            Preconditions.checkCallAuthorization(isAdminTestOnlyLocked(who, caller.getUserId())
                    || isSupervisionComponent(caller.getComponentName()), "Admin %s is not the "
                    || isSupervisionComponentLocked(caller.getComponentName()), "Admin %s is not "
                    + "default supervision component", caller.getComponentName());
                    + "the default supervision component", caller.getComponentName());
            DevicePolicyData policy = getUserData(caller.getUserId());
            DevicePolicyData policy = getUserData(caller.getUserId());
            policy.mSecondaryLockscreenEnabled = enabled;
            policy.mSecondaryLockscreenEnabled = enabled;
            saveSettingsLocked(caller.getUserId());
            saveSettingsLocked(caller.getUserId());
@@ -13004,7 +13023,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                    return false;
                    return false;
                }
                }
                return isSupervisionComponent(admin.info.getComponent());
                return isSupervisionComponentLocked(admin.info.getComponent());
            }
            }
        }
        }
+2 −0
Original line number Original line Diff line number Diff line
@@ -3360,9 +3360,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
            assertThat(dpmi.isActiveSupervisionApp(uid)).isTrue();
            assertThat(dpmi.isActiveSupervisionApp(uid)).isTrue();
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user))
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user))
                        .isEqualTo(admin1);
                        .isEqualTo(admin1);
            assertThat(dpm.isSupervisionComponent(admin1)).isTrue();
        } else {
        } else {
            assertThat(dpmi.isActiveSupervisionApp(uid)).isFalse();
            assertThat(dpmi.isActiveSupervisionApp(uid)).isFalse();
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user)).isNull();
            assertThat(dpm.getProfileOwnerOrDeviceOwnerSupervisionComponent(user)).isNull();
            assertThat(dpm.isSupervisionComponent(admin1)).isFalse();
        }
        }
    }
    }