Skip to content

Commit

Permalink
Merge pull request #89 from infinum/release/2.2.0
Browse files Browse the repository at this point in the history
Merge release/2.2.0 to master
  • Loading branch information
spasepremcheski authored Sep 3, 2024
2 parents d59f62c + a94426c commit 8c40fa6
Show file tree
Hide file tree
Showing 34 changed files with 191 additions and 136 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ buildscript {
#### Add dependency

```gradle
implementation 'co.infinum:goldfinger:2.1.0'
implementation 'com.infinum:goldfinger:2.2.0'
```

#### Initialize
Expand Down Expand Up @@ -80,8 +80,8 @@ Goldfinger has separate Rx module in case you want to use reactive approach.
#### Add dependencies

```gradle
implementation 'co.infinum:goldfinger:2.1.0'
implementation 'co.infinum:goldfinger-rx:2.1.0'
implementation 'com.infinum:goldfinger:2.2.0'
implementation 'com.infinum:goldfinger-rx:2.2.0'
```

#### Initialize
Expand All @@ -97,7 +97,7 @@ goldfinger.authenticate(params).subscribe(new DisposableObserver<Goldfinger.Resu

@Override
public void onComplete() {
/* Fingerprint authentication is finished */
/* Biometrics authentication is finished */
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ buildscript {

ext.sdk = [
min : 14,
target: 30,
target: 33,
]

ext.versions = [
appcompat : '1.1.0',
biometric : '1.1.0',
goldfinger: '2.1.0',
biometric : '1.2.0-alpha05',
goldfinger: '2.2.0',
junit : '4.12',
mockito : '2.28.2',
rxjava : '2.2.12',
]

ext.releaseConfig = [
"groupId" : 'co.infinum',
"groupId" : 'com.infinum',
]

repositories {
Expand All @@ -26,7 +26,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:7.1.3'
}
}

Expand All @@ -37,7 +37,7 @@ allprojects {
}
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}

Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
testImplementation "junit:junit:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation project(path: ':core')
}

apply from: '../tasks.gradle'
Expand Down
18 changes: 5 additions & 13 deletions core/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apply plugin: "maven-publish"
apply plugin: "signing"

task sourcesJar(type: Jar, dependsOn: assemble) {
classifier = 'sources'
archiveClassifier.set("sources")
from android.sourceSets.main.java.source
}

// Sonatype will not accept a published artifact without at least an empty Javadoc JAR.
task javadocsJar(type: Jar, dependsOn: javadocs) {
classifier = 'javadoc'
archiveClassifier.set("javadoc")
from javadocs.destinationDir
}

Expand All @@ -26,16 +26,18 @@ afterEvaluate {
}
publications {
release(MavenPublication) {
from components.release

groupId = releaseConfig.groupId
version = versions.goldfinger

artifactId = 'goldfinger'

artifact bundleReleaseAar
artifact sourcesJar
artifact javadocsJar

pom {
packaging = "aar"
name = 'Goldfinger'
description = 'Android library to simplify Biometric authentication implementation.'
url = 'https://github.com/infinum/Android-Goldfinger'
Expand All @@ -58,16 +60,6 @@ afterEvaluate {
url = 'https://github.com/infinum/Android-Goldfinger'
}
}
pom.withXml {
def root = asNode()
def dependenciesNode = root.appendNode('dependencies')
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
signing {
sign publishing.publications.release
}
Expand Down
52 changes: 32 additions & 20 deletions core/src/main/java/co/infinum/goldfinger/Goldfinger.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,33 @@ public interface Goldfinger {
boolean hasFingerprintHardware();

/**
* Returns true if user has fingerprint hardware, false otherwise.
* @deprecated Use {@link #hasBiometricHardware(int)} instead.
*/
@Deprecated
boolean hasFingerprintHardware(int authenticators);

/**
* Returns true if user has biometrics hardware, false otherwise.
*/
boolean hasBiometricHardware(int authenticators);

/**
* @deprecated Use {@link #hasEnrolledFingerprint(int)} instead.
*/
@Deprecated
boolean hasEnrolledFingerprint();

/**
* Returns true if user has enrolled fingerprint, false otherwise.
* @deprecated Use {@link #hasEnrolledBiometrics(int)} instead.
*/
@Deprecated
boolean hasEnrolledFingerprint(int authenticators);

/**
* Returns true if user has enrolled biometrics, false otherwise.
*/
boolean hasEnrolledBiometrics(int authenticators);

/**
* @deprecated Use {@link #canAuthenticate(int)} instead.
*/
Expand All @@ -57,22 +69,22 @@ public interface Goldfinger {
boolean canAuthenticate(int authenticators);

/**
* Authenticate user via Fingerprint.
* Authenticate user via Biometrics.
* <p>
* Example - Process payment after successful fingerprint authentication.
* Example - Process payment after successful biometric authentication.
*
* @see PromptParams
*/
void authenticate(@NonNull PromptParams params, @NonNull Callback callback);

/**
* Authenticate user via Fingerprint. If user is successfully authenticated,
* Authenticate user via Biometrics. If user is successfully authenticated,
* {@link CrypterProxy} implementation is used to automatically encrypt given value.
* <p>
* Use it when saving some data that should not be saved as plain text (e.g. password).
* To decrypt the value use {@link Goldfinger#decrypt} method.
* <p>
* Example - Allow auto-login via Fingerprint.
* Example - Allow auto-login via Biometrics.
*
* @param params parameters used to build {@link BiometricPrompt} instance
* @param key unique key identifier, used to store cipher IV internally
Expand All @@ -88,7 +100,7 @@ void encrypt(
);

/**
* Authenticate user via Fingerprint. If user is successfully authenticated,
* Authenticate user via Biometrics. If user is successfully authenticated,
* {@link CrypterProxy} implementation is used to automatically decrypt given value.
* <p>
* Should be used together with {@link Goldfinger#encrypt} to decrypt saved data.
Expand All @@ -104,7 +116,7 @@ void decrypt(
);

/**
* Cancel current active Fingerprint authentication.
* Cancel current active Biometrics authentication.
*/
void cancel();

Expand Down Expand Up @@ -447,7 +459,7 @@ private String getString(@StringRes int resId) {

/**
* Result wrapper class containing all the useful information about
* fingerprint authentication and value for encryption/decryption operations.
* biometric authentication and value for encryption/decryption operations.
*/
class Result {

Expand Down Expand Up @@ -516,20 +528,20 @@ public String value() {
interface Callback {

/**
* Returns fingerprint result and will be invoked multiple times during
* fingerprint authentication as not all fingerprint results complete
* Returns biometric result and will be invoked multiple times during
* biometric authentication as not all biometric results complete
* the authentication.
* <p>
* Result callback invoked for every fingerprint result (success, error or info).
* It can be invoked multiple times during single fingerprint authentication.
* Result callback invoked for every biometric result (success, error or info).
* It can be invoked multiple times during single biometric authentication.
*
* @param result contains fingerprint result information
* @param result contains biometric result information
* @see Goldfinger.Result
*/
void onResult(@NonNull Goldfinger.Result result);

/**
* Critical error happened and fingerprint authentication is stopped.
* Critical error happened and biometric authentication is stopped.
*/
void onError(@NonNull Exception e);
}
Expand Down Expand Up @@ -609,7 +621,7 @@ enum Reason {
SECURITY_UPDATE_REQUIRED,

/**
* Dispatched when Fingerprint authentication is initialized correctly and
* Dispatched when Biometrics authentication is initialized correctly and
* just before actual authentication is started. Can be used to update UI if necessary.
*/
AUTHENTICATION_START,
Expand All @@ -636,20 +648,20 @@ enum Reason {
enum Type {

/**
* Fingerprint authentication is successfully finished. {@link Goldfinger.Result}
* Biometrics authentication is successfully finished. {@link Goldfinger.Result}
* will contain value in case of {@link PromptParams.Builder#decrypt} or
* {@link PromptParams.Builder#encrypt} invocation.
*/
SUCCESS,

/**
* Fingerprint authentication is still active. {@link Goldfinger.Result} contains
* additional information about currently active fingerprint authentication.
* Biometrics authentication is still active. {@link Goldfinger.Result} contains
* additional information about currently active biometric authentication.
*/
INFO,

/**
* Fingerprint authentication is unsuccessfully finished. {@link Goldfinger.Result}
* Biometrics authentication is unsuccessfully finished. {@link Goldfinger.Result}
* contains the reason why the authentication failed.
*/
ERROR
Expand Down
22 changes: 18 additions & 4 deletions core/src/main/java/co/infinum/goldfinger/GoldfingerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void authenticate(
}

log("Starting authentication");
startNativeFingerprintAuthentication(params, Mode.AUTHENTICATION, null, null, callback, null);
startNativeBiometricAuthentication(params, Mode.AUTHENTICATION, null, null, callback, null);
}

@Override
Expand Down Expand Up @@ -126,6 +126,13 @@ public boolean hasEnrolledFingerprint(int authenticators) {
&& authenticationStatus != BiometricManager.BIOMETRIC_STATUS_UNKNOWN;
}

@Override
public boolean hasEnrolledBiometrics(int authenticators) {
int authenticationStatus = biometricManager.canAuthenticate(authenticators);
return authenticationStatus != BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED
&& authenticationStatus != BiometricManager.BIOMETRIC_STATUS_UNKNOWN;
}

@Override
public boolean hasFingerprintHardware() {
int authenticationStatus = biometricManager.canAuthenticate();
Expand All @@ -140,6 +147,13 @@ public boolean hasFingerprintHardware(int authenticators) {
&& authenticationStatus != BiometricManager.BIOMETRIC_STATUS_UNKNOWN;
}

@Override
public boolean hasBiometricHardware(int authenticators) {
int authenticationStatus = biometricManager.canAuthenticate(authenticators);
return authenticationStatus != BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE
&& authenticationStatus != BiometricManager.BIOMETRIC_STATUS_UNKNOWN;
}

private void initializeCryptoObject(
@NonNull final PromptParams params,
@NonNull final Mode mode,
Expand All @@ -153,7 +167,7 @@ private void initializeCryptoObject(
void onCryptoObjectCreated(@Nullable BiometricPrompt.CryptoObject cryptoObject) {
creatingCryptoObject = false;
if (cryptoObject != null) {
startNativeFingerprintAuthentication(params, mode, key, value, callback, cryptoObject);
startNativeBiometricAuthentication(params, mode, key, value, callback, cryptoObject);
} else {
log("Failed to create CryptoObject");
callback.onError(new CryptoObjectInitException());
Expand All @@ -176,7 +190,7 @@ private boolean preconditionsInvalid(PromptParams params, Mode mode, String key,
}

if (!hasEnrolledFingerprint(params.allowedAuthenticators())) {
callback.onError(new NoEnrolledFingerprintException());
callback.onError(new NoEnrolledBiometricsException());
return true;
}

Expand All @@ -196,7 +210,7 @@ private boolean preconditionsInvalid(PromptParams params, Mode mode, String key,
}

@SuppressWarnings("ConstantConditions")
private void startNativeFingerprintAuthentication(
private void startNativeBiometricAuthentication(
@NonNull final PromptParams params,
@NonNull final Mode mode,
@Nullable final String key,
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/co/infinum/goldfinger/GoldfingerMock.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public boolean hasEnrolledFingerprint(int authenticators) {
return false;
}

@Override
public boolean hasEnrolledBiometrics(int authenticators) {
return false;
}

@Override
public boolean hasEnrolledFingerprint() {
return false;
Expand All @@ -52,4 +57,9 @@ public boolean hasEnrolledFingerprint() {
public boolean hasFingerprintHardware(int authenticators) {
return false;
}

@Override
public boolean hasBiometricHardware(int authenticators) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package co.infinum.goldfinger;

/**
* Thrown if the device is missing fingerprint authentication hardware.
* Thrown if the device is missing biometric authentication hardware.
*/
@SuppressWarnings("WeakerAccess")
public class MissingHardwareException extends Exception {

MissingHardwareException() {
super("Device has no fingerprint hardware.");
super("Device has no biometric hardware.");
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/co/infinum/goldfinger/Mode.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.infinum.goldfinger;

/**
* Internal enum used to differentiate Fingerprint authentication modes.
* Internal enum used to differentiate Biometric authentication modes.
* Authentication does not have to work with cipher, while both
* Decryption and Encryption should.
* <p>
Expand Down
Loading

0 comments on commit 8c40fa6

Please sign in to comment.