private void authenticate()

in packages/local_auth/local_auth/android/src/main/java/io/flutter/plugins/localauth/LocalAuthPlugin.java [122:221]


  private void authenticate(MethodCall call, final Result result) {
    if (authInProgress.get()) {
      result.error("auth_in_progress", "Authentication in progress", null);
      return;
    }

    if (activity == null || activity.isFinishing()) {
      result.error("no_activity", "local_auth plugin requires a foreground activity", null);
      return;
    }

    if (!(activity instanceof FragmentActivity)) {
      result.error(
          "no_fragment_activity",
          "local_auth plugin requires activity to be a FragmentActivity.",
          null);
      return;
    }

    if (!isDeviceSupported()) {
      authInProgress.set(false);
      result.error("NotAvailable", "Required security features not enabled", null);
      return;
    }

    authInProgress.set(true);
    AuthCompletionHandler completionHandler =
        new AuthCompletionHandler() {
          @Override
          public void onSuccess() {
            authenticateSuccess(result);
          }

          @Override
          public void onFailure() {
            authenticateFail(result);
          }

          @Override
          public void onError(String code, String error) {
            if (authInProgress.compareAndSet(true, false)) {
              result.error(code, error, null);
            }
          }
        };

    // if is biometricOnly try biometric prompt - might not work
    boolean isBiometricOnly = call.argument("biometricOnly");
    if (isBiometricOnly) {
      if (!canAuthenticateWithBiometrics()) {
        if (!hasBiometricHardware()) {
          completionHandler.onError("NoHardware", "No biometric hardware found");
        }
        completionHandler.onError("NotEnrolled", "No biometrics enrolled on this device.");
        return;
      }
      authHelper =
          new AuthenticationHelper(
              lifecycle, (FragmentActivity) activity, call, completionHandler, false);
      authHelper.authenticate();
      return;
    }

    // API 29 and above
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
      authHelper =
          new AuthenticationHelper(
              lifecycle, (FragmentActivity) activity, call, completionHandler, true);
      authHelper.authenticate();
      return;
    }

    // API 23 - 28 with fingerprint
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager != null) {
      if (fingerprintManager.hasEnrolledFingerprints()) {
        authHelper =
            new AuthenticationHelper(
                lifecycle, (FragmentActivity) activity, call, completionHandler, false);
        authHelper.authenticate();
        return;
      }
    }

    // API 23 or higher with device credentials
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
        && keyguardManager != null
        && keyguardManager.isDeviceSecure()) {
      String title = call.argument("signInTitle");
      String reason = call.argument("localizedReason");
      Intent authIntent = keyguardManager.createConfirmDeviceCredentialIntent(title, reason);

      // save result for async response
      lockRequestResult = result;
      activity.startActivityForResult(authIntent, LOCK_REQUEST_CODE);
      return;
    }

    // Unable to authenticate
    result.error("NotSupported", "This device does not support required security features", null);
  }