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

Commit 3a018719 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Add protected BiometricPrompt API to allow default title

ConfirmDeviceCredentials sometimes shows up without a title. Since CC
is now using BiometricPrompt, we need at least a private API that allows
the client to have the dialog show a default title.

Bug: 111461540

Test: Manual test with modified BiometricPromptDemo, to launch CC with
      empty string

Change-Id: I02a3c9327635c04f201f76754f7c0e1135e5ff36
parent bf830a37
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.biometrics;

import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
@@ -52,6 +53,10 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     * @hide
     */
    public static final String KEY_TITLE = "title";
    /**
     * @hide
     */
    public static final String KEY_USE_DEFAULT_TITLE = "use_default_title";
    /**
     * @hide
     */
@@ -130,6 +135,17 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            return this;
        }

        /**
         * For internal use currently. Only takes effect if title is null/empty. Shows a default
         * modality-specific title.
         * @hide
         */
        @RequiresPermission(USE_BIOMETRIC_INTERNAL)
        public Builder setUseDefaultTitle() {
            mBundle.putBoolean(KEY_USE_DEFAULT_TITLE, true);
            return this;
        }

        /**
         * Optional: Set the subtitle to display.
         * @param subtitle
@@ -206,8 +222,9 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        public BiometricPrompt build() {
            final CharSequence title = mBundle.getCharSequence(KEY_TITLE);
            final CharSequence negative = mBundle.getCharSequence(KEY_NEGATIVE_TEXT);
            final boolean useDefaultTitle = mBundle.getBoolean(KEY_USE_DEFAULT_TITLE);

            if (TextUtils.isEmpty(title)) {
            if (TextUtils.isEmpty(title) && !useDefaultTitle) {
                throw new IllegalArgumentException("Title must be set and non-empty");
            } else if (TextUtils.isEmpty(negative)) {
                throw new IllegalArgumentException("Negative text must be set and non-empty");
+3 −0
Original line number Diff line number Diff line
@@ -1418,6 +1418,9 @@
    <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
    <string name="permdesc_mediaLocation">Allows the app to read locations from your media collection.</string>

    <!-- Title shown when the system-provided biometric dialog is shown, asking the user to authenticate. [CHAR LIMIT=40] -->
    <string name="biometric_dialog_default_title">Application <xliff:g id="app" example="Gmail">%s</xliff:g> wants to authenticate.</string>

    <!-- Message shown when biometric hardware is not available [CHAR LIMIT=50] -->
    <string name="biometric_error_hw_unavailable">Biometric hardware unavailable</string>

+1 −0
Original line number Diff line number Diff line
@@ -2394,6 +2394,7 @@
  <java-symbol type="string" name="config_keyguardComponent" />

  <!-- Biometric messages -->
  <java-symbol type="string" name="biometric_dialog_default_title" />
  <java-symbol type="string" name="biometric_error_hw_unavailable" />
  <java-symbol type="string" name="biometric_not_recognized" />

+3 −1
Original line number Diff line number Diff line
@@ -200,7 +200,9 @@ public abstract class BiometricDialogView extends LinearLayout {
        mLastState = STATE_NONE;
        updateState(STATE_AUTHENTICATING);

        title.setText(mBundle.getCharSequence(BiometricPrompt.KEY_TITLE));
        CharSequence titleText = mBundle.getCharSequence(BiometricPrompt.KEY_TITLE);

        title.setText(titleText);
        title.setSelected(true);

        positive.setVisibility(View.INVISIBLE);
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.security.KeyStore;
import android.text.TextUtils;
import android.util.Slog;

import com.android.internal.statusbar.IStatusBarService;
@@ -205,6 +206,16 @@ public abstract class AuthenticationClient extends ClientMonitor {
        return super.onError(deviceId, error, vendorCode);
    }

    public void setTitleIfEmpty(CharSequence title) {
        if (TextUtils.isEmpty(mBundle.getCharSequence(BiometricPrompt.KEY_TITLE))) {
            mBundle.putCharSequence(BiometricPrompt.KEY_TITLE, title);
        }
    }

    public boolean isBiometricPrompt() {
        return mBundle != null;
    }

    private void notifyClientAuthenticationSucceeded(BiometricAuthenticator.Identifier identifier)
            throws RemoteException {
        final BiometricServiceBase.ServiceListener listener = getListener();
Loading