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

Commit 179b83ac authored by Joshua Mccloskey's avatar Joshua Mccloskey Committed by Android (Google) Code Review
Browse files

Merge "SUW enrolls FP before Face" into tm-d1-dev

parents eb60f311 1dd4f54d
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.BiometricManager.Authenticators;
import android.hardware.biometrics.BiometricManager.BiometricError;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.hardware.fingerprint.FingerprintManager;
@@ -211,12 +210,6 @@ public class BiometricEnrollActivity extends InstrumentedActivity {
                // required check if setup has completed instead.
                final boolean isSettingUp = isSetupWizard || (mParentalOptionsRequired
                        && !WizardManagerHelper.isUserSetupComplete(this));
                if (isSettingUp && isMultiSensor && mIsFaceEnrollable) {
                    if (props.sensorStrength == SensorProperties.STRENGTH_CONVENIENCE) {
                        Log.i(TAG, "Excluding face from SuW enrollment (STRENGTH_CONVENIENCE)");
                        mIsFaceEnrollable = false;
                    }
                }
            }
        }
        if (mHasFeatureFingerprint) {
+1 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity {
        intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, mFromSettingsSummary);
        intent.putExtra(EXTRA_KEY_CHALLENGE, mChallenge);
        intent.putExtra(EXTRA_KEY_SENSOR_ID, mSensorId);
        BiometricUtils.copyMultiBiometricExtras(getIntent(), intent);
        if (mUserId != UserHandle.USER_NULL) {
            intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
        }
+35 −7
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.hardware.biometrics.BiometricAuthenticator;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

@@ -303,9 +302,17 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        final boolean cameFromMultiBioFpAuthAddAnother =
                requestCode == BiometricUtils.REQUEST_ADD_ANOTHER
                && BiometricUtils.isMultiBiometricFingerprintEnrollmentFlow(this);
        if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST) {
            if (isResultSkipOrFinished(resultCode)) {
            if (isResultFinished(resultCode)) {
                handleBiometricResultSkipOrFinished(resultCode, data);
            } else if (isResultSkipped(resultCode)) {
                if (!BiometricUtils.tryStartingNextBiometricEnroll(this,
                        ENROLL_NEXT_BIOMETRIC_REQUEST, "BIOMETRIC_FIND_SENSOR_SKIPPED")) {
                    handleBiometricResultSkipOrFinished(resultCode, data);
                }
            } else if (resultCode == RESULT_TIMEOUT) {
                setResult(resultCode, data);
                finish();
@@ -353,10 +360,22 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
            }
        } else if (requestCode == LEARN_MORE_REQUEST) {
            overridePendingTransition(R.anim.sud_slide_back_in, R.anim.sud_slide_back_out);
        } else if (requestCode == ENROLL_NEXT_BIOMETRIC_REQUEST) {
            Log.d(TAG, "ENROLL_NEXT_BIOMETRIC_REQUEST, result: " + resultCode);
            if (isResultSkipOrFinished(resultCode)) {
        } else if (requestCode == ENROLL_NEXT_BIOMETRIC_REQUEST
                || cameFromMultiBioFpAuthAddAnother) {
            if (isResultFinished(resultCode)) {
                handleBiometricResultSkipOrFinished(resultCode, data);
            } else if (isResultSkipped(resultCode)) {
                if (requestCode == BiometricUtils.REQUEST_ADD_ANOTHER) {
                    // If we came from an add another request, it still might
                    // be possible to add another biometric. Check if we can.
                    if (checkMaxEnrolled() != 0) {
                        // If we can't enroll any more biometrics, than skip
                        // this one.
                        handleBiometricResultSkipOrFinished(resultCode, data);
                    }
                } else {
                    handleBiometricResultSkipOrFinished(resultCode, data);
                }
            } else if (resultCode != RESULT_CANCELED) {
                setResult(resultCode, data);
                finish();
@@ -365,9 +384,17 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
        super.onActivityResult(requestCode, resultCode, data);
    }

    private static boolean isResultSkipped(int resultCode) {
        return resultCode == RESULT_SKIP
                || resultCode == SetupSkipDialog.RESULT_SKIP;
    }

    private static boolean isResultFinished(int resultCode) {
        return resultCode == RESULT_FINISHED;
    }

    private static boolean isResultSkipOrFinished(int resultCode) {
        return resultCode == RESULT_SKIP || resultCode == SetupSkipDialog.RESULT_SKIP
                || resultCode == RESULT_FINISHED;
        return isResultSkipped(resultCode) || isResultFinished(resultCode);
    }

    private void handleBiometricResultSkipOrFinished(int resultCode, @Nullable Intent data) {
@@ -375,6 +402,7 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
                && data.getBooleanExtra(
                        MultiBiometricEnrollHelper.EXTRA_SKIP_PENDING_ENROLL, false)) {
            getIntent().removeExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE);
            getIntent().removeExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FINGERPRINT);
        }

        if (resultCode == RESULT_SKIP) {
+45 −11
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
 */
public class BiometricUtils {
    private static final String TAG = "BiometricUtils";

    /**
     * Request was sent for starting another enrollment of a previously
     * enrolled biometric of the same type.
     */
    public static int REQUEST_ADD_ANOTHER = 7;
    /**
     * Given the result from confirming or choosing a credential, request Gatekeeper to generate
     * a HardwareAuthToken with the Gatekeeper Password together with a biometric challenge.
@@ -223,38 +229,66 @@ public class BiometricUtils {
    }

    /**
     * Used for checking if a multi-biometric enrollment flow starts with Face and
     * ends with Fingerprint.
     *
     * @param activity Activity that we want to check
     * @return True if the activity is going through a multi-biometric enrollment flow.
     * @return True if the activity is going through a multi-biometric enrollment flow, that starts
     * with Face.
     */
    public static boolean isMultiBiometricEnrollmentFlow(@NonNull Activity activity) {
    public static boolean isMultiBiometricFaceEnrollmentFlow(@NonNull Activity activity) {
        return activity.getIntent().hasExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE);
    }


    /**
     * Used for checking if a multi-biometric enrollment flowstarts with Fingerprint
     * and ends with Face.
     *
     * @param activity Activity that we want to check
     * @return True if the activity is going through a multi-biometric enrollment flow, that starts
     * with Fingerprint.
     */
    public static boolean isMultiBiometricFingerprintEnrollmentFlow(@NonNull Activity activity) {
        return activity.getIntent().hasExtra(
                MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FINGERPRINT);
    }

    public static void copyMultiBiometricExtras(@NonNull Intent fromIntent,
            @NonNull Intent toIntent) {
        final PendingIntent pendingIntent = (PendingIntent) fromIntent.getExtra(
        PendingIntent pendingIntent = (PendingIntent) fromIntent.getExtra(
                MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE, null);
        if (pendingIntent != null) {
            toIntent.putExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE, pendingIntent);
            toIntent.putExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE,
                    pendingIntent);
        }

        pendingIntent = (PendingIntent) fromIntent.getExtra(
                MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FINGERPRINT, null);
        if (pendingIntent != null) {
            toIntent.putExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FINGERPRINT,
                    pendingIntent);
        }
    }

    /**
     * If the current biometric enrollment (e.g. face) should be followed by another one (e.g.
     * fingerprint) (see {@link #isMultiBiometricEnrollmentFlow(Activity)}), retrieves the
     * PendingIntent pointing to the next enrollment and starts it. The caller will receive the
     * result in onActivityResult.
     * If the current biometric enrollment (e.g. face/fingerprint) should be followed by another
     * one (e.g. fingerprint/face) retrieves the PendingIntent pointing to the next enrollment
     * and starts it. The caller will receive the result in onActivityResult.
     * @return true if the next enrollment was started
     */
    public static boolean tryStartingNextBiometricEnroll(@NonNull Activity activity,
            int requestCode, String debugReason) {

        Log.d(TAG, "tryStartingNextBiometricEnroll, debugReason: " + debugReason);
        final PendingIntent pendingIntent = (PendingIntent) activity.getIntent()
        PendingIntent pendingIntent = (PendingIntent) activity.getIntent()
                .getExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FACE);
        if (pendingIntent == null) {
            pendingIntent = (PendingIntent) activity.getIntent()
                .getExtra(MultiBiometricEnrollHelper.EXTRA_ENROLL_AFTER_FINGERPRINT);
        }

        if (pendingIntent != null) {
            try {
                Log.d(TAG, "Starting pendingIntent: " + pendingIntent);
                IntentSender intentSender = pendingIntent.getIntentSender();
                activity.startIntentSenderForResult(intentSender, requestCode,
                        null /* fillInIntent */, 0 /* flagMask */, 0 /* flagValues */,
+17 −17
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class MultiBiometricEnrollHelper {
    private static final int REQUEST_FINGERPRINT_ENROLL = 3001;

    public static final String EXTRA_ENROLL_AFTER_FACE = "enroll_after_face";
    public static final String EXTRA_ENROLL_AFTER_FINGERPRINT = "enroll_after_finger";
    public static final String EXTRA_SKIP_PENDING_ENROLL = "skip_pending_enroll";

    @NonNull private final FragmentActivity mActivity;
@@ -55,10 +56,10 @@ public class MultiBiometricEnrollHelper {
    }

    void startNextStep() {
        if (mRequestEnrollFace) {
            launchFaceEnroll();
        } else if (mRequestEnrollFingerprint) {
        if (mRequestEnrollFingerprint) {
            launchFingerprintEnroll();
        } else if (mRequestEnrollFace) {
            launchFaceEnroll();
        } else {
            mActivity.setResult(BiometricEnrollIntroduction.RESULT_SKIP);
            mActivity.finish();
@@ -74,20 +75,6 @@ public class MultiBiometricEnrollHelper {
                    mActivity.getIntent());
            faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId);
            faceIntent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);

            if (mRequestEnrollFingerprint) {
                // Give FaceEnroll a pendingIntent pointing to fingerprint enrollment, so that it
                // can be started when user skips or finishes face enrollment. FLAG_UPDATE_CURRENT
                // ensures it is launched with the most recent values.
                final Intent fpIntent = BiometricUtils.getFingerprintIntroIntent(mActivity,
                        mActivity.getIntent());
                fpIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, mGkPwHandle);
                final PendingIntent fpAfterFaceIntent = PendingIntent.getActivity(mActivity,
                        0 /* requestCode */, fpIntent,
                        PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
                faceIntent.putExtra(EXTRA_ENROLL_AFTER_FACE, fpAfterFaceIntent);
            }

            BiometricUtils.launchEnrollForResult(mActivity, faceIntent, REQUEST_FACE_ENROLL,
                    hardwareAuthToken, mGkPwHandle, mUserId);
        });
@@ -103,6 +90,19 @@ public class MultiBiometricEnrollHelper {
                    mActivity.getIntent());
            intent.putExtra(BiometricEnrollBase.EXTRA_KEY_SENSOR_ID, sensorId);
            intent.putExtra(BiometricEnrollBase.EXTRA_KEY_CHALLENGE, challenge);
            if (mRequestEnrollFace) {
                // Give FingerprintEnroll a pendingIntent pointing to face enrollment, so that it
                // can be started when user skips or finishes fingerprint enrollment.
                // FLAG_UPDATE_CURRENT ensures it is launched with the most recent values.
                final Intent faceIntent = BiometricUtils.getFaceIntroIntent(mActivity,
                        mActivity.getIntent());
                faceIntent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_GK_PW_HANDLE, mGkPwHandle);
                final PendingIntent faceAfterFp = PendingIntent.getActivity(mActivity,
                        0 /* requestCode */, faceIntent,
                        PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
                intent.putExtra(EXTRA_ENROLL_AFTER_FINGERPRINT, faceAfterFp);
            }

            BiometricUtils.launchEnrollForResult(mActivity, intent, REQUEST_FINGERPRINT_ENROLL,
                    hardwareAuthToken, mGkPwHandle, mUserId);
        }));
Loading