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

Commit 5ab10177 authored by Alex Johnston's avatar Alex Johnston Committed by Android (Google) Code Review
Browse files

Merge "Call getPasswordComplexity on the parent profile"

parents d583bf29 07cb9f04
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -3499,9 +3499,11 @@ public class DevicePolicyManager {
     * Returns how complex the current user's screen lock is.
     *
     * <p>Note that when called from a profile which uses an unified challenge with its parent, the
     * screen lock complexity of the parent will be returned. However, this API does not support
     * explicitly querying the parent profile screen lock complexity via {@link
     * #getParentProfileInstance}.
     * screen lock complexity of the parent will be returned.
     *
     * <p>This method can be called on the {@link DevicePolicyManager} instance
     * returned by {@link #getParentProfileInstance(ComponentName)} in order to retrieve
     * restrictions on the parent profile.
     *
     * @throws IllegalStateException if the user is not unlocked.
     * @throws SecurityException     if the calling application does not have the permission
@@ -3510,13 +3512,12 @@ public class DevicePolicyManager {
    @PasswordComplexity
    @RequiresPermission(android.Manifest.permission.REQUEST_PASSWORD_COMPLEXITY)
    public int getPasswordComplexity() {
        throwIfParentInstance("getPasswordComplexity");
        if (mService == null) {
            return PASSWORD_COMPLEXITY_NONE;
        }

        try {
            return mService.getPasswordComplexity();
            return mService.getPasswordComplexity(mParentInstance);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -9254,6 +9255,7 @@ public class DevicePolicyManager {
     * <li>{@link #setPasswordExpirationTimeout}</li>
     * <li>{@link #getPasswordExpiration}</li>
     * <li>{@link #getPasswordMaximumLength}</li>
     * <li>{@link #getPasswordComplexity}</li>
     * <li>{@link #isActivePasswordSufficient}</li>
     * <li>{@link #getCurrentFailedPasswordAttempts}</li>
     * <li>{@link #getMaximumFailedPasswordsForWipe}</li>
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ interface IDevicePolicyManager {

    boolean isActivePasswordSufficient(int userHandle, boolean parent);
    boolean isProfileActivePasswordSufficientForParent(int userHandle);
    int getPasswordComplexity();
    int getPasswordComplexity(boolean parent);
    boolean isUsingUnifiedPassword(in ComponentName admin);
    int getCurrentFailedPasswordAttempts(int userHandle, boolean parent);
    int getProfileWithMinimumFailedPasswordsForWipe(int userHandle, boolean parent);
+7 −3
Original line number Diff line number Diff line
@@ -4928,21 +4928,25 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @Override
    @PasswordComplexity
    public int getPasswordComplexity() {
    public int getPasswordComplexity(boolean parent) {
        DevicePolicyEventLogger
                .createEvent(DevicePolicyEnums.GET_USER_PASSWORD_COMPLEXITY_LEVEL)
                .setStrings(mInjector.getPackageManager()
                        .getPackagesForUid(mInjector.binderGetCallingUid()))
                .write();
        final int callingUserId = mInjector.userHandleGetCallingUserId();
        if (parent) {
            enforceProfileOwnerOrSystemUser();
        }
        enforceUserUnlocked(callingUserId);
        mContext.enforceCallingOrSelfPermission(
                REQUEST_PASSWORD_COMPLEXITY,
                "Must have " + REQUEST_PASSWORD_COMPLEXITY + " permission.");
        synchronized (getLockObject()) {
            int targetUserId = getCredentialOwner(callingUserId, /* parent= */ false);
            PasswordMetrics metrics = mLockSettingsInternal.getUserPasswordMetrics(targetUserId);
            final int credentialOwner = getCredentialOwner(callingUserId, parent);
            PasswordMetrics metrics = mLockSettingsInternal.getUserPasswordMetrics(credentialOwner);
            return metrics == null ? PASSWORD_COMPLEXITY_NONE : metrics.determineComplexity();
        }
    }
+11 −7
Original line number Diff line number Diff line
@@ -5295,13 +5295,17 @@ public class DevicePolicyManagerTest extends DpmTestBase {
        });
    }

    public void testGetPasswordComplexity_securityExceptionIfParentInstance() {
        assertThrows(SecurityException.class,
                () -> new DevicePolicyManagerTestable(
    public void testGetPasswordComplexity_securityExceptionNotThrownForParentInstance() {
        mServiceContext.permissions.add(permission.REQUEST_PASSWORD_COMPLEXITY);
        setAsProfileOwner(admin1);

        new DevicePolicyManagerTestable(
                mServiceContext,
                dpms,
                /* parentInstance= */ true)
                        .getPasswordComplexity());
                .getPasswordComplexity();

        assertEquals(PASSWORD_COMPLEXITY_NONE, dpm.getPasswordComplexity());
    }

    public void testGetPasswordComplexity_illegalStateExceptionIfLocked() {