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

Commit 6e6a735e authored by Kevin Chyn's avatar Kevin Chyn
Browse files

2/n: Remove unnecessary RequestThrottledException for verify paths

verifyCredential and verifyTiedProfileChallenge return a
VerifyCredentialResponse object instead of a byte[] now. Thus,
any/all information regarding the authentication attempt is
received by callers. We no longer need to use exceptions as a
method of returning an alternate non-byte[] result.

The RequestThrottledException cannot be completely removed yet
because checkCredential returns a boolean and has no way of
returning a timeout yet. See b/161956762

Bug: 161765592

Test: Accept/Reject/Lockout the following
      1) Owner profile
      2) Managed profile with separate challenge
      3) Managed profile with unified challenge
Change-Id: Ia61c71bdde42dec34d8f2eac86d7ea964b1485c2
parent e7694cc5
Loading
Loading
Loading
Loading
+2 −11
Original line number Original line Diff line number Diff line
@@ -71,11 +71,7 @@ public final class LockPatternChecker {
                new AsyncTask<Void, Void, VerifyCredentialResponse>() {
                new AsyncTask<Void, Void, VerifyCredentialResponse>() {
            @Override
            @Override
            protected VerifyCredentialResponse doInBackground(Void... args) {
            protected VerifyCredentialResponse doInBackground(Void... args) {
                try {
                return utils.verifyCredential(credentialCopy, challenge, userId, flags);
                return utils.verifyCredential(credentialCopy, challenge, userId, flags);
                } catch (RequestThrottledException ex) {
                    return VerifyCredentialResponse.fromTimeout(ex.getTimeoutMs());
                }
            }
            }


            @Override
            @Override
@@ -159,12 +155,7 @@ public final class LockPatternChecker {
                new AsyncTask<Void, Void, VerifyCredentialResponse>() {
                new AsyncTask<Void, Void, VerifyCredentialResponse>() {
            @Override
            @Override
            protected VerifyCredentialResponse doInBackground(Void... args) {
            protected VerifyCredentialResponse doInBackground(Void... args) {
                try {
                return utils.verifyTiedProfileChallenge(credentialCopy, challenge, userId, flags);
                    return utils.verifyTiedProfileChallenge(credentialCopy, challenge, userId,
                            flags);
                } catch (RequestThrottledException ex) {
                    return VerifyCredentialResponse.fromTimeout(ex.getTimeoutMs());
                }
            }
            }


            @Override
            @Override
+4 −26
Original line number Original line Diff line number Diff line
@@ -389,30 +389,19 @@ public class LockPatternUtils {
     * @param challenge The challenge to verify against the credential
     * @param challenge The challenge to verify against the credential
     * @param userId The user whose credential is being verified
     * @param userId The user whose credential is being verified
     * @param flags See {@link VerifyFlag}
     * @param flags See {@link VerifyFlag}
     * @throws RequestThrottledException if credential verification is being throttled due to
     *         to many incorrect attempts.
     * @throws IllegalStateException if called on the main thread.
     * @throws IllegalStateException if called on the main thread.
     *
     * TODO: This probably doesn't need to throw RequestThrottledException anymore, since the
     * method now returns a VerifyCredentialResponse object, which contains the timeout
     */
     */
    @NonNull
    @NonNull
    public VerifyCredentialResponse verifyCredential(@NonNull LockscreenCredential credential,
    public VerifyCredentialResponse verifyCredential(@NonNull LockscreenCredential credential,
            long challenge, int userId, @VerifyFlag int flags) throws RequestThrottledException {
            long challenge, int userId, @VerifyFlag int flags) {
        throwIfCalledOnMainThread();
        throwIfCalledOnMainThread();
        try {
        try {
            final VerifyCredentialResponse response = getLockSettings().verifyCredential(
            final VerifyCredentialResponse response = getLockSettings().verifyCredential(
                    credential, challenge, userId, flags);
                    credential, challenge, userId, flags);
            if (response == null) {
            if (response == null) {
                return VerifyCredentialResponse.ERROR;
                return VerifyCredentialResponse.ERROR;
            }

            if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_OK) {
                return response;
            } else if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_RETRY) {
                throw new RequestThrottledException(response.getTimeout());
            } else {
            } else {
                return VerifyCredentialResponse.ERROR;
                return response;
            }
            }
        } catch (RemoteException re) {
        } catch (RemoteException re) {
            Log.e(TAG, "failed to verify credential", re);
            Log.e(TAG, "failed to verify credential", re);
@@ -485,31 +474,20 @@ public class LockPatternUtils {
     * @return the attestation that the challenge was verified, or null
     * @return the attestation that the challenge was verified, or null
     * @param userId The managed profile user id
     * @param userId The managed profile user id
     * @param flags See {@link VerifyFlag}
     * @param flags See {@link VerifyFlag}
     * @throws RequestThrottledException if credential verification is being throttled due to
     *         to many incorrect attempts.
     * @throws IllegalStateException if called on the main thread.
     * @throws IllegalStateException if called on the main thread.
     *
     * TODO: This probably doesn't need to throw RequestThrottledException anymore, since the
     * method now returns a VerifyCredentialResponse object, which contains the timeout
     */
     */
    @NonNull
    @NonNull
    public VerifyCredentialResponse verifyTiedProfileChallenge(
    public VerifyCredentialResponse verifyTiedProfileChallenge(
            @NonNull LockscreenCredential credential,
            @NonNull LockscreenCredential credential,
            long challenge, int userId, @VerifyFlag int flags) throws RequestThrottledException {
            long challenge, int userId, @VerifyFlag int flags) {
        throwIfCalledOnMainThread();
        throwIfCalledOnMainThread();
        try {
        try {
            final VerifyCredentialResponse response = getLockSettings()
            final VerifyCredentialResponse response = getLockSettings()
                    .verifyTiedProfileChallenge(credential, challenge, userId, flags);
                    .verifyTiedProfileChallenge(credential, challenge, userId, flags);
            if (response == null) {
            if (response == null) {
                return VerifyCredentialResponse.ERROR;
                return VerifyCredentialResponse.ERROR;
            }

            if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_OK) {
                return response;
            } else if (response.getResponseCode() == VerifyCredentialResponse.RESPONSE_RETRY) {
                throw new RequestThrottledException(response.getTimeout());
            } else {
            } else {
                return VerifyCredentialResponse.ERROR;
                return response;
            }
            }
        } catch (RemoteException re) {
        } catch (RemoteException re) {
            Log.e(TAG, "failed to verify tied profile credential", re);
            Log.e(TAG, "failed to verify tied profile credential", re);