Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.8

* Updates internal implementation to use Kotlin Pigeon.

## 2.0.7

* Updates build files from Groovy to Kotlin.
Expand Down
11 changes: 11 additions & 0 deletions packages/local_auth/local_auth_android/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

group = "io.flutter.plugins.localauth"
version = "1.0-SNAPSHOT"

buildscript {
val kotlinVersion = "2.3.20"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:8.13.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}

Expand All @@ -21,6 +25,13 @@ rootProject.allprojects {

plugins {
id("com.android.library")
id("kotlin-android")
}

kotlin {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(JavaVersion.VERSION_17.toString())
}
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import io.flutter.plugins.localauth.Messages.AuthResult;
import io.flutter.plugins.localauth.Messages.AuthResultCode;
import java.util.concurrent.Executor;

/**
Expand All @@ -37,7 +35,6 @@ interface AuthCompletionHandler {
private final Lifecycle lifecycle;
private final FragmentActivity activity;
private final AuthCompletionHandler completionHandler;
private final Messages.AuthStrings strings;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just an opportunistic fix while I was in the file; the IDE flagged that we never actually read this value (it's used in the constructor where it's passed in, but never outside that, so doesn't need to be stored).

private final BiometricPrompt.PromptInfo promptInfo;
private final boolean isAuthSticky;
private final UiThreadExecutor uiThreadExecutor;
Expand All @@ -47,14 +44,13 @@ interface AuthCompletionHandler {
AuthenticationHelper(
Lifecycle lifecycle,
FragmentActivity activity,
@NonNull Messages.AuthOptions options,
@NonNull Messages.AuthStrings strings,
@NonNull AuthOptions options,
@NonNull AuthStrings strings,
@NonNull AuthCompletionHandler completionHandler,
boolean allowCredentials) {
this.lifecycle = lifecycle;
this.activity = activity;
this.completionHandler = completionHandler;
this.strings = strings;
this.isAuthSticky = options.getSticky();
this.uiThreadExecutor = new UiThreadExecutor();

Expand Down Expand Up @@ -157,14 +153,13 @@ public void onAuthenticationError(int errorCode, @NonNull CharSequence errString
code = AuthResultCode.UNKNOWN_ERROR;
break;
}
completionHandler.complete(
new AuthResult.Builder().setCode(code).setErrorMessage(errString.toString()).build());
completionHandler.complete(new AuthResult(code, errString.toString()));
stop();
}

@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
completionHandler.complete(new AuthResult.Builder().setCode(AuthResultCode.SUCCESS).build());
completionHandler.complete(new AuthResult(AuthResultCode.SUCCESS, null));
stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.biometric.BiometricManager;
import androidx.fragment.app.FragmentActivity;
Expand All @@ -20,16 +21,13 @@
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.embedding.engine.plugins.lifecycle.FlutterLifecycleAdapter;
import io.flutter.plugins.localauth.AuthenticationHelper.AuthCompletionHandler;
import io.flutter.plugins.localauth.Messages.AuthClassification;
import io.flutter.plugins.localauth.Messages.AuthOptions;
import io.flutter.plugins.localauth.Messages.AuthResult;
import io.flutter.plugins.localauth.Messages.AuthResultCode;
import io.flutter.plugins.localauth.Messages.AuthStrings;
import io.flutter.plugins.localauth.Messages.LocalAuthApi;
import io.flutter.plugins.localauth.Messages.Result;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import kotlin.Result;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;

/**
* Flutter plugin providing access to local authentication.
Expand All @@ -54,17 +52,17 @@ public class LocalAuthPlugin implements FlutterPlugin, ActivityAware, LocalAuthA
public LocalAuthPlugin() {}

@Override
public @NonNull Boolean isDeviceSupported() {
public boolean isDeviceSupported() {
return isDeviceSecure() || canAuthenticateWithBiometrics();
}

@Override
public @NonNull Boolean deviceCanSupportBiometrics() {
public boolean deviceCanSupportBiometrics() {
return hasBiometricHardware();
}

@Override
public @NonNull List<AuthClassification> getEnrolledBiometrics() {
public @Nullable List<AuthClassification> getEnrolledBiometrics() {
if (biometricManager == null) {
return null;
}
Expand All @@ -81,7 +79,7 @@ public LocalAuthPlugin() {}
}

@Override
public @NonNull Boolean stopAuthentication() {
public boolean stopAuthentication() {
try {
if (authHelper != null && authInProgress.get()) {
authHelper.stopAuthentication();
Expand All @@ -98,30 +96,32 @@ public LocalAuthPlugin() {}
public void authenticate(
@NonNull AuthOptions options,
@NonNull AuthStrings strings,
@NonNull Result<AuthResult> result) {
@NonNull Function1<? super @NotNull Result<@NotNull AuthResult>, @NotNull Unit> callback) {
if (authInProgress.get()) {
result.success(new AuthResult.Builder().setCode(AuthResultCode.ALREADY_IN_PROGRESS).build());
ResultUtilsKt.completeWithValue(
callback, new AuthResult(AuthResultCode.ALREADY_IN_PROGRESS, null));
return;
}

if (activity == null || activity.isFinishing()) {
result.success(new AuthResult.Builder().setCode(AuthResultCode.NO_ACTIVITY).build());
ResultUtilsKt.completeWithValue(callback, new AuthResult(AuthResultCode.NO_ACTIVITY, null));
return;
}

if (!(activity instanceof FragmentActivity)) {
result.success(
new AuthResult.Builder().setCode(AuthResultCode.NOT_FRAGMENT_ACTIVITY).build());
ResultUtilsKt.completeWithValue(
callback, new AuthResult(AuthResultCode.NOT_FRAGMENT_ACTIVITY, null));
return;
}

if (!isDeviceSupported()) {
result.success(new AuthResult.Builder().setCode(AuthResultCode.NO_CREDENTIALS).build());
ResultUtilsKt.completeWithValue(
callback, new AuthResult(AuthResultCode.NO_CREDENTIALS, null));
return;
}

authInProgress.set(true);
AuthCompletionHandler completionHandler = createAuthCompletionHandler(result);
AuthCompletionHandler completionHandler = createAuthCompletionHandler(callback);

boolean allowCredentials = !options.getBiometricOnly() && canAuthenticateWithDeviceCredential();

Expand All @@ -130,8 +130,8 @@ public void authenticate(

@VisibleForTesting
public @NonNull AuthCompletionHandler createAuthCompletionHandler(
@NonNull final Result<AuthResult> result) {
return authResult -> onAuthenticationCompleted(result, authResult);
@NonNull Function1<? super @NotNull Result<@NotNull AuthResult>, @NotNull Unit> callback) {
return authResult -> onAuthenticationCompleted(callback, authResult);
}

@VisibleForTesting
Expand All @@ -152,9 +152,11 @@ public void sendAuthenticationRequest(
authHelper.authenticate();
}

void onAuthenticationCompleted(Result<AuthResult> result, AuthResult value) {
void onAuthenticationCompleted(
@NonNull Function1<? super @NotNull Result<@NotNull AuthResult>, @NotNull Unit> callback,
AuthResult value) {
if (authInProgress.compareAndSet(true, false)) {
result.success(value);
ResultUtilsKt.completeWithValue(callback, value);
}
}

Expand Down Expand Up @@ -192,12 +194,12 @@ public boolean canAuthenticateWithDeviceCredential() {

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
LocalAuthApi.setUp(binding.getBinaryMessenger(), this);
LocalAuthApi.Companion.setUp(binding.getBinaryMessenger(), this);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
LocalAuthApi.setUp(binding.getBinaryMessenger(), null);
LocalAuthApi.Companion.setUp(binding.getBinaryMessenger(), null);
}

private void setServicesFromActivity(Activity activity) {
Expand Down
Loading
Loading