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

Commit 86f1b8e3 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

15/n: Allow Auth UI to start in credential UI

If the user is locked out of biometrics, and
BiometricPrompt#setDeviceCredentialAllowed(true), the user should be
shown the credential UI.

This change gives BiometricService the ability to request SystemUI
to show AuthCredentialView without first showing AuthBiometricView.

Bug: 140127687

Test: atest BiometricServiceTest
Test: atest com.android.systemui.biometrics

Change-Id: Ic26986ba044b7992641676c3d3b99fc1395a45b7
parent 8429da25
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.biometrics;

/**
 * Type of authenticators defined on a granularity that the BiometricManager / BiometricPrompt
 * supports.
 * @hide
 */
public class Authenticator {

    /**
     * Device credential, e.g. Pin/Pattern/Password.
     */
    public static final int TYPE_CREDENTIAL = 1 << 0;
    /**
     * Encompasses all biometrics on the device, e.g. Fingerprint/Iris/Face.
     */
    public static final int TYPE_BIOMETRIC = 1 << 1;

}
+13 −31
Original line number Diff line number Diff line
@@ -66,10 +66,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     * @hide
     */
    public static final String KEY_DESCRIPTION = "description";
    /**
     * @hide
     */
    public static final String KEY_POSITIVE_TEXT = "positive_text";
    /**
     * @hide
     */
@@ -79,9 +75,15 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     */
    public static final String KEY_REQUIRE_CONFIRMATION = "require_confirmation";
    /**
     * This is deprecated. Internally we should use {@link #KEY_AUTHENTICATORS_ALLOWED}
     * @hide
     */
    public static final String KEY_ALLOW_DEVICE_CREDENTIAL = "allow_device_credential";
    /**
     * If this key is set, we will ignore {@link #KEY_ALLOW_DEVICE_CREDENTIAL}
     * @hide
     */
    public static final String KEY_AUTHENTICATORS_ALLOWED = "authenticators_allowed";

    /**
     * Error/help message will show for this amount of time.
@@ -202,30 +204,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            return this;
        }

        /**
         * Optional: Set the text for the positive button. If not set, the positive button
         * will not show.
         * @param text
         * @return
         * @hide
         */
        @NonNull public Builder setPositiveButton(@NonNull CharSequence text,
                @NonNull @CallbackExecutor Executor executor,
                @NonNull DialogInterface.OnClickListener listener) {
            if (TextUtils.isEmpty(text)) {
                throw new IllegalArgumentException("Text must be set and non-empty");
            }
            if (executor == null) {
                throw new IllegalArgumentException("Executor must not be null");
            }
            if (listener == null) {
                throw new IllegalArgumentException("Listener must not be null");
            }
            mBundle.putCharSequence(KEY_POSITIVE_TEXT, text);
            mPositiveButtonInfo = new ButtonInfo(executor, listener);
            return this;
        }

        /**
         * Required: Set the text for the negative button. This would typically be used as a
         * "Cancel" button, but may be also used to show an alternative method for authentication,
@@ -306,15 +284,19 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            final CharSequence title = mBundle.getCharSequence(KEY_TITLE);
            final CharSequence negative = mBundle.getCharSequence(KEY_NEGATIVE_TEXT);
            final boolean useDefaultTitle = mBundle.getBoolean(KEY_USE_DEFAULT_TITLE);
            final boolean enableFallback = mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL);
            final boolean allowCredential = mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL);
            final Object authenticatorsAllowed = mBundle.get(KEY_AUTHENTICATORS_ALLOWED);

            if (TextUtils.isEmpty(title) && !useDefaultTitle) {
                throw new IllegalArgumentException("Title must be set and non-empty");
            } else if (TextUtils.isEmpty(negative) && !enableFallback) {
            } else if (TextUtils.isEmpty(negative) && !allowCredential) {
                throw new IllegalArgumentException("Negative text must be set and non-empty");
            } else if (!TextUtils.isEmpty(negative) && enableFallback) {
            } else if (!TextUtils.isEmpty(negative) && allowCredential) {
                throw new IllegalArgumentException("Can't have both negative button behavior"
                        + " and device credential enabled");
            } else if (authenticatorsAllowed != null && allowCredential) {
                throw new IllegalArgumentException("setAuthenticatorsAllowed and"
                        + " setDeviceCredentialAllowed should not be used simultaneously");
            }
            return new BiometricPrompt(mContext, mBundle, mPositiveButtonInfo, mNegativeButtonInfo);
        }
+6 −6
Original line number Diff line number Diff line
@@ -151,17 +151,17 @@ oneway interface IStatusBar

    void showShutdownUi(boolean isReboot, String reason);

    // Used to show the dialog when BiometricService starts authentication
    void showBiometricDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver, int type,
            boolean requireConfirmation, int userId, String opPackageName);
    // Used to hide the dialog when a biometric is authenticated
    // Used to show the authentication dialog (Biometrics, Device Credential)
    void showAuthenticationDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver,
            int biometricModality, boolean requireConfirmation, int userId, String opPackageName);
    // Used to notify the authentication dialog that a biometric has been authenticated or rejected
    void onBiometricAuthenticated(boolean authenticated, String failureReason);
    // Used to set a temporary message, e.g. fingerprint not recognized, finger moved too fast, etc
    void onBiometricHelp(String message);
    // Used to set a message - the dialog will dismiss after a certain amount of time
    void onBiometricError(int errorCode, String error);
    // Used to hide the biometric dialog when the AuthenticationClient is stopped
    void hideBiometricDialog();
    // Used to hide the authentication dialog, e.g. when the application cancels authentication
    void hideAuthenticationDialog();

    /**
     * Notifies System UI that the display is ready to show system decorations.
+6 −6
Original line number Diff line number Diff line
@@ -99,15 +99,15 @@ interface IStatusBarService
    void showPinningEnterExitToast(boolean entering);
    void showPinningEscapeToast();

    // Used to show the dialog when BiometricService starts authentication
    void showBiometricDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver, int type,
            boolean requireConfirmation, int userId, String opPackageName);
    // Used to hide the dialog when a biometric is authenticated
    // Used to show the authentication dialog (Biometrics, Device Credential)
    void showAuthenticationDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver,
            int biometricModality, boolean requireConfirmation, int userId, String opPackageName);
    // Used to notify the authentication dialog that a biometric has been authenticated or rejected
    void onBiometricAuthenticated(boolean authenticated, String failureReason);
    // Used to set a temporary message, e.g. fingerprint not recognized, finger moved too fast, etc
    void onBiometricHelp(String message);
    // Used to set a message - the dialog will dismiss after a certain amount of time
    void onBiometricError(int errorCode, String error);
    // Used to hide the biometric dialog when the AuthenticationClient is stopped
    void hideBiometricDialog();
    // Used to hide the authentication dialog, e.g. when the application cancels authentication
    void hideAuthenticationDialog();
}
+1 −1
Original line number Diff line number Diff line
@@ -754,6 +754,6 @@ public abstract class AuthBiometricView extends LinearLayout {
    }

    private boolean isDeviceCredentialAllowed() {
        return mBiometricPromptBundle.getBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL);
        return Utils.isDeviceCredentialAllowed(mBiometricPromptBundle);
    }
}
Loading