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

Commit 1b2137cf authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Deprecate CC and add BP#buildIntent()

To ensure future BP builder changes don't require a 1:1 addition to the
CC API, we're deprecating CC and moving the API to BP.

Since CDC is an activity, and BP can't receive onActivityResult from CDC,
we need to have BiometricService launch CDC. CDC will return auth/reject
results to BiometricService using a private protected aidl method, which
can then forward the reuslt to BP/app.

Bug: 111461540

Test: builds
Test: demo app, receives correct callbacks

Change-Id: I7111ca2842534a596302fe0eb7338fbfaca72eec
parent 6a212176
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5101,7 +5101,7 @@ package android.app {
  }
  public class KeyguardManager {
    method public android.content.Intent createConfirmDeviceCredentialIntent(CharSequence, CharSequence);
    method @Deprecated public android.content.Intent createConfirmDeviceCredentialIntent(CharSequence, CharSequence);
    method @Deprecated @RequiresPermission(android.Manifest.permission.DISABLE_KEYGUARD) public void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
    method @Deprecated public boolean inKeyguardRestrictedInputMode();
    method public boolean isDeviceLocked();
@@ -16498,6 +16498,7 @@ package android.hardware.biometrics {
    ctor public BiometricPrompt.Builder(android.content.Context);
    method public android.hardware.biometrics.BiometricPrompt build();
    method public android.hardware.biometrics.BiometricPrompt.Builder setDescription(@NonNull CharSequence);
    method public android.hardware.biometrics.BiometricPrompt.Builder setEnableFallback(boolean);
    method public android.hardware.biometrics.BiometricPrompt.Builder setNegativeButton(@NonNull CharSequence, @NonNull java.util.concurrent.Executor, @NonNull android.content.DialogInterface.OnClickListener);
    method public android.hardware.biometrics.BiometricPrompt.Builder setRequireConfirmation(boolean);
    method public android.hardware.biometrics.BiometricPrompt.Builder setSubtitle(@NonNull CharSequence);
+15 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
@@ -86,6 +87,12 @@ public class KeyguardManager {
    public static final String ACTION_CONFIRM_FRP_CREDENTIAL =
            "android.app.action.CONFIRM_FRP_CREDENTIAL";

    /**
     * @hide
     */
    public static final String EXTRA_BIOMETRIC_PROMPT_BUNDLE =
            "android.app.extra.BIOMETRIC_PROMPT_BUNDLE";

    /**
     * A CharSequence dialog title to show to the user when used with a
     * {@link #ACTION_CONFIRM_DEVICE_CREDENTIAL}.
@@ -118,15 +125,19 @@ public class KeyguardManager {
    public static final int RESULT_ALTERNATE = 1;

    /**
     * Get an intent to prompt the user to confirm credentials (pin, pattern or password)
     * for the current user of the device. The caller is expected to launch this activity using
     * {@link android.app.Activity#startActivityForResult(Intent, int)} and check for
     * @deprecated see {@link BiometricPrompt.Builder#setEnableFallback(boolean)}
     *
     * Get an intent to prompt the user to confirm credentials (pin, pattern, password or biometrics
     * if enrolled) for the current user of the device. The caller is expected to launch this
     * activity using {@link android.app.Activity#startActivityForResult(Intent, int)} and check for
     * {@link android.app.Activity#RESULT_OK} if the user successfully completes the challenge.
     *
     * @return the intent for launching the activity or null if no password is required.
     **/
    @Deprecated
    @RequiresFeature(PackageManager.FEATURE_SECURE_LOCK_SCREEN)
    public Intent createConfirmDeviceCredentialIntent(CharSequence title, CharSequence description) {
    public Intent createConfirmDeviceCredentialIntent(CharSequence title,
            CharSequence description) {
        if (!isDeviceSecure()) return null;
        Intent intent = new Intent(ACTION_CONFIRM_DEVICE_CREDENTIAL);
        intent.putExtra(EXTRA_TITLE, title);
+34 −0
Original line number Diff line number Diff line
@@ -171,5 +171,39 @@ public class BiometricManager {
            Slog.w(TAG, "resetTimeout(): Service not connected");
        }
    }

    /**
     * TODO(b/123378871): Remove when moved.
     * @hide
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void onConfirmDeviceCredentialSuccess() {
        if (mService != null) {
            try {
                mService.onConfirmDeviceCredentialSuccess();
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            Slog.w(TAG, "onConfirmDeviceCredentialSuccess(): Service not connected");
        }
    }

    /**
     * TODO(b/123378871): Remove when moved.
     * @hide
     */
    @RequiresPermission(USE_BIOMETRIC_INTERNAL)
    public void onConfirmDeviceCredentialError(int error, String message) {
        if (mService != null) {
            try {
                mService.onConfirmDeviceCredentialError(error, message);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        } else {
            Slog.w(TAG, "onConfirmDeviceCredentialError(): Service not connected");
        }
    }
}
+24 −1
Original line number Diff line number Diff line
@@ -77,6 +77,10 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     * @hide
     */
    public static final String KEY_REQUIRE_CONFIRMATION = "require_confirmation";
    /**
     * @hide
     */
    public static final String KEY_ENABLE_FALLBACK = "enable_fallback";

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

        /**
         * The user will first be prompted to authenticate with biometrics, but also given the
         * option to authenticate with their device PIN, pattern, or password.
         * @param enable When true, the prompt will fall back to ask for the user's device
         *               credentials (PIN, pattern, or password).
         * @return
         */
        public Builder setEnableFallback(boolean enable) {
            mBundle.putBoolean(KEY_ENABLE_FALLBACK, enable);
            return this;
        }

        /**
         * Creates a {@link BiometricPrompt}.
         * @return a {@link BiometricPrompt}
@@ -250,11 +266,15 @@ 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_ENABLE_FALLBACK);

            if (TextUtils.isEmpty(title) && !useDefaultTitle) {
                throw new IllegalArgumentException("Title must be set and non-empty");
            } else if (TextUtils.isEmpty(negative)) {
            } else if (TextUtils.isEmpty(negative) && !enableFallback) {
                throw new IllegalArgumentException("Negative text must be set and non-empty");
            } else if (!TextUtils.isEmpty(negative) && enableFallback) {
                throw new IllegalArgumentException("Can't have both negative button behavior"
                        + " and fallback enabled");
            }
            return new BiometricPrompt(mContext, mBundle, mPositiveButtonInfo, mNegativeButtonInfo);
        }
@@ -514,6 +534,9 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        if (callback == null) {
            throw new IllegalArgumentException("Must supply a callback");
        }
        if (mBundle.getBoolean(KEY_ENABLE_FALLBACK)) {
            throw new IllegalArgumentException("Fallback not supported with crypto");
        }
        authenticateInternal(crypto, cancel, executor, callback, mContext.getUserId());
    }

+8 −0
Original line number Diff line number Diff line
@@ -51,4 +51,12 @@ interface IBiometricService {

    // Reset the timeout when user authenticates with strong auth (e.g. PIN, pattern or password)
    void resetTimeout(in byte [] token);

    // TODO(b/123378871): Remove when moved.
    // CDCA needs to send results to BiometricService if it was invoked using BiometricPrompt's
    // setEnableFallback method, since there's no way for us to intercept onActivityResult.
    // CDCA is launched from BiometricService (startActivityAsUser) instead of *ForResult.
    void onConfirmDeviceCredentialSuccess();
    // TODO(b/123378871): Remove when moved.
    void onConfirmDeviceCredentialError(int error, String message);
}
Loading