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

Commit d7693917 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

Check if the profile password would comply as the device lock

Bug: 26801330
Change-Id: Ide31464dd0292ca97b03abe08cdde5b41d517b66
parent d1f722d9
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -1732,7 +1732,7 @@ public class DevicePolicyManager {
    /**
     * Determine whether the current password the user has set is sufficient
     * to meet the policy requirements (quality, minimum length) that have been
     * requested by the admins of this user and its profiles.
     * requested by the admins of this user and its profiles that don't have a separate challenge.
     *
     * <p>The calling device admin must have requested
     * {@link DeviceAdminInfo#USES_POLICY_LIMIT_PASSWORD} to be able to call
@@ -1751,6 +1751,26 @@ public class DevicePolicyManager {
        return false;
    }

    /**
     * Determine whether the current profile password the user has set is sufficient
     * to meet the policy requirements (quality, minimum length) that have been
     * requested by the admins of the parent user and its profiles.
     *
     * @param userHandle the userId of the profile to check the password for.
     * @return Returns true if the password would meet the current requirements, else false.
     * @hide
     */
    public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
        if (mService != null) {
            try {
                return mService.isProfileActivePasswordSufficientForParent(userHandle);
            } catch (RemoteException e) {
                Log.w(TAG, REMOTE_EXCEPTION_MESSAGE, e);
            }
        }
        return false;
    }

    /**
     * Retrieve the number of times the user has failed at entering a
     * password since that last successful password entry.
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ interface IDevicePolicyManager {
    long getPasswordExpiration(in ComponentName who, int userHandle, boolean parent);

    boolean isActivePasswordSufficient(int userHandle, boolean parent);
    boolean isProfileActivePasswordSufficientForParent(int userHandle);
    int getCurrentFailedPasswordAttempts(int userHandle, boolean parent);
    int getProfileWithMinimumFailedPasswordsForWipe(int userHandle, boolean parent);

+7 −0
Original line number Diff line number Diff line
@@ -935,6 +935,13 @@ public class LockPatternUtils {
        return getDevicePolicyManager().isSeparateProfileChallengeAllowed(userHandle);
    }

    /**
     * Retrieves whether the current profile and device locks can be unified.
     */
    public boolean isSeparateProfileChallengeAllowedToUnify(int userHandle) {
        return getDevicePolicyManager().isProfileActivePasswordSufficientForParent(userHandle);
    }

    /**
     * Deserialize a pattern.
     * @param string The pattern serialized with {@link #patternToString}
+41 −23
Original line number Diff line number Diff line
@@ -3382,10 +3382,29 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
        synchronized (this) {
            // This API can only be called by an active device admin,
            // so try to retrieve it to check that the caller is one.
            getActiveAdminForCallerLocked(
                    null, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, parent);

            getActiveAdminForCallerLocked(null, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, parent);
            DevicePolicyData policy = getUserDataUnchecked(getCredentialOwner(userHandle, parent));
            return isActivePasswordSufficientForUserLocked(policy, userHandle, parent);
        }
    }

    @Override
    public boolean isProfileActivePasswordSufficientForParent(int userHandle) {
        if (!mHasFeature) {
            return true;
        }
        enforceFullCrossUsersPermission(userHandle);
        enforceManagedProfile(userHandle, "call APIs refering to the parent profile");

        synchronized (this) {
            int targetUser = getProfileParentId(userHandle);
            DevicePolicyData policy = getUserDataUnchecked(getCredentialOwner(userHandle, false));
            return isActivePasswordSufficientForUserLocked(policy, targetUser, false);
        }
    }

    private boolean isActivePasswordSufficientForUserLocked(
            DevicePolicyData policy, int userHandle, boolean parent) {
        if (policy.mActivePasswordQuality < getPasswordQuality(null, userHandle, parent)
                || policy.mActivePasswordLength < getPasswordMinimumLength(
                        null, userHandle, parent)) {
@@ -3407,7 +3426,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
                && policy.mActivePasswordNonLetter >= getPasswordMinimumNonLetter(
                        null, userHandle, parent);
    }
    }

    @Override
    public int getCurrentFailedPasswordAttempts(int userHandle, boolean parent) {