Skip to content

Commit

Permalink
Merge pull request #10 from Isaacel97/fix
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
riderx authored Apr 23, 2024
2 parents f8427d4 + bb72265 commit 48aeb2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
18 changes: 9 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
}

buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'com.android.tools.build:gradle:8.0.2'
}
}

Expand Down Expand Up @@ -39,20 +40,19 @@ android {

repositories {
google()
jcenter()
mavenCentral()
}


dependencies {
implementation 'androidx.biometric:biometric:1.0.1'
implementation 'androidx.biometric:biometric:1.1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
Expand Down
28 changes: 11 additions & 17 deletions android/src/main/java/ee/forgr/biometric/AuthActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.biometric.BiometricConstants;
import androidx.biometric.BiometricPrompt;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import ee.forgr.biometric.capacitornativebiometric.R;
import java.util.concurrent.Executor;

Expand Down Expand Up @@ -136,29 +130,29 @@ void finishActivity(String result, Integer errorCode, String errorDetails) {
* Convert Auth Error Codes to plugin expected Biometric Auth Errors (in README.md)
* This way both iOS and Android return the same error codes for the same authentication failure reasons.
* !!IMPORTANT!!: Whenever this is modified, check if similar function in iOS Plugin.swift needs to be modified as well
* @see https://developer.android.com/reference/androidx/biometric/BiometricPrompt#constants
* @see <a href="https://developer.android.com/reference/androidx/biometric/BiometricPrompt#constants">...</a>
* @return BiometricAuthError
*/
public static int convertToPluginErrorCode(int errorCode) {
switch (errorCode) {
case BiometricConstants.ERROR_HW_UNAVAILABLE:
case BiometricConstants.ERROR_HW_NOT_PRESENT:
case BiometricPrompt.ERROR_HW_UNAVAILABLE:
case BiometricPrompt.ERROR_HW_NOT_PRESENT:
return 1;
case BiometricConstants.ERROR_LOCKOUT_PERMANENT:
case BiometricPrompt.ERROR_LOCKOUT_PERMANENT:
return 2;
case BiometricConstants.ERROR_NO_BIOMETRICS:
case BiometricPrompt.ERROR_NO_BIOMETRICS:
return 3;
case BiometricConstants.ERROR_LOCKOUT:
case BiometricPrompt.ERROR_LOCKOUT:
return 4;
// Authentication Failure (10) Handled by `onAuthenticationFailed`.
// App Cancel (11), Invalid Context (12), and Not Interactive (13) are not valid error codes for Android.
case BiometricConstants.ERROR_NO_DEVICE_CREDENTIAL:
case BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL:
return 14;
case BiometricConstants.ERROR_TIMEOUT:
case BiometricConstants.ERROR_CANCELED:
case BiometricPrompt.ERROR_TIMEOUT:
case BiometricPrompt.ERROR_CANCELED:
return 15;
case BiometricConstants.ERROR_USER_CANCELED:
case BiometricConstants.ERROR_NEGATIVE_BUTTON:
case BiometricPrompt.ERROR_USER_CANCELED:
case BiometricPrompt.ERROR_NEGATIVE_BUTTON:
return 16;
default:
return 0;
Expand Down
9 changes: 6 additions & 3 deletions android/src/main/java/ee/forgr/biometric/NativeBiometric.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.security.keystore.StrongBoxUnavailableException;
import android.util.Base64;
import androidx.activity.result.ActivityResult;
import androidx.biometric.BiometricConstants;
import androidx.biometric.BiometricManager;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
Expand Down Expand Up @@ -124,7 +123,7 @@ public void isAvailable(PluginCall call) {
// @see https://developer.android.com/reference/androidx/biometric/BiometricManager#canAuthenticate(int)
boolean fallbackAvailable = useFallback && this.deviceHasCredentials();
if (useFallback && !fallbackAvailable) {
canAuthenticateResult = BiometricConstants.ERROR_NO_DEVICE_CREDENTIAL;
canAuthenticateResult = BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE;
}

boolean isAvailable =
Expand Down Expand Up @@ -496,6 +495,10 @@ private boolean deviceHasCredentials() {
KeyguardManager keyguardManager = (KeyguardManager) getActivity()
.getSystemService(Context.KEYGUARD_SERVICE);
// Can only use fallback if the device has a pin/pattern/password lockscreen.
return keyguardManager.isDeviceSecure();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return keyguardManager.isDeviceSecure();
} else {
return keyguardManager.isKeyguardSecure();
}
}
}

0 comments on commit 48aeb2b

Please sign in to comment.