Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Commit 35b5082

Browse files
authored
Merge pull request #72 from infinum/release/2.1.0
Release/2.1.0
2 parents b9bc5fb + 5500469 commit 35b5082

File tree

16 files changed

+485
-123
lines changed

16 files changed

+485
-123
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ buildscript {
2323
#### Add dependency
2424

2525
```gradle
26-
implementation 'co.infinum:goldfinger:2.0.1'
26+
implementation 'co.infinum:goldfinger:2.1.0'
2727
```
2828

2929
#### Initialize
@@ -35,7 +35,7 @@ Goldfinger.Builder(context).build()
3535
#### Check prerequisites
3636

3737
```java
38-
if (goldfinger.canAuthenticate()) {
38+
if (goldfinger.canAuthenticate(@AuthenticatorTypes int authenticators)) {
3939
/* Authenticate */
4040
}
4141
```
@@ -80,8 +80,8 @@ Goldfinger has separate Rx module in case you want to use reactive approach.
8080
#### Add dependencies
8181

8282
```gradle
83-
implementation 'co.infinum:goldfinger:2.0.1'
84-
implementation 'co.infinum:goldfinger-rx:2.0.1'
83+
implementation 'co.infinum:goldfinger:2.1.0'
84+
implementation 'co.infinum:goldfinger-rx:2.1.0'
8585
```
8686

8787
#### Initialize

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ buildscript {
44

55
ext.sdk = [
66
min : 14,
7-
target: 29,
7+
target: 30,
88
]
99

1010
ext.versions = [
1111
appcompat : '1.1.0',
12-
biometric : '1.0.1',
13-
goldfinger: '2.0.1',
12+
biometric : '1.1.0',
13+
goldfinger: '2.1.0',
1414
junit : '4.12',
1515
mockito : '2.28.2',
1616
rxjava : '2.2.12',

core/src/main/java/co/infinum/goldfinger/EnumConverter.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package co.infinum.goldfinger;
22

3-
import androidx.biometric.BiometricConstants;
3+
import androidx.biometric.BiometricPrompt;
44

55
/**
66
* Internal class used to convert Biometric constants into meaningful enum.
@@ -12,32 +12,34 @@ private EnumConverter() {
1212

1313
static Goldfinger.Reason errorToReason(int errorId) {
1414
switch (errorId) {
15-
case BiometricConstants.ERROR_HW_UNAVAILABLE:
15+
case BiometricPrompt.ERROR_HW_UNAVAILABLE:
1616
return Goldfinger.Reason.HARDWARE_UNAVAILABLE;
17-
case BiometricConstants.ERROR_UNABLE_TO_PROCESS:
17+
case BiometricPrompt.ERROR_UNABLE_TO_PROCESS:
1818
return Goldfinger.Reason.UNABLE_TO_PROCESS;
19-
case BiometricConstants.ERROR_TIMEOUT:
19+
case BiometricPrompt.ERROR_TIMEOUT:
2020
return Goldfinger.Reason.TIMEOUT;
21-
case BiometricConstants.ERROR_NO_SPACE:
21+
case BiometricPrompt.ERROR_NO_SPACE:
2222
return Goldfinger.Reason.NO_SPACE;
23-
case BiometricConstants.ERROR_CANCELED:
23+
case BiometricPrompt.ERROR_CANCELED:
2424
return Goldfinger.Reason.CANCELED;
25-
case BiometricConstants.ERROR_LOCKOUT:
25+
case BiometricPrompt.ERROR_LOCKOUT:
2626
return Goldfinger.Reason.LOCKOUT;
27-
case BiometricConstants.ERROR_VENDOR:
27+
case BiometricPrompt.ERROR_VENDOR:
2828
return Goldfinger.Reason.VENDOR;
29-
case BiometricConstants.ERROR_LOCKOUT_PERMANENT:
29+
case BiometricPrompt.ERROR_LOCKOUT_PERMANENT:
3030
return Goldfinger.Reason.LOCKOUT_PERMANENT;
31-
case BiometricConstants.ERROR_USER_CANCELED:
31+
case BiometricPrompt.ERROR_USER_CANCELED:
3232
return Goldfinger.Reason.USER_CANCELED;
33-
case BiometricConstants.ERROR_NO_BIOMETRICS:
33+
case BiometricPrompt.ERROR_NO_BIOMETRICS:
3434
return Goldfinger.Reason.NO_BIOMETRICS;
35-
case BiometricConstants.ERROR_HW_NOT_PRESENT:
35+
case BiometricPrompt.ERROR_HW_NOT_PRESENT:
3636
return Goldfinger.Reason.HW_NOT_PRESENT;
37-
case BiometricConstants.ERROR_NEGATIVE_BUTTON:
37+
case BiometricPrompt.ERROR_NEGATIVE_BUTTON:
3838
return Goldfinger.Reason.NEGATIVE_BUTTON;
39-
case BiometricConstants.ERROR_NO_DEVICE_CREDENTIAL:
39+
case BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL:
4040
return Goldfinger.Reason.NO_DEVICE_CREDENTIAL;
41+
case BiometricPrompt.ERROR_SECURITY_UPDATE_REQUIRED:
42+
return Goldfinger.Reason.SECURITY_UPDATE_REQUIRED;
4143
default:
4244
return Goldfinger.Reason.UNKNOWN;
4345
}

core/src/main/java/co/infinum/goldfinger/Goldfinger.java

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,38 @@
2424
public interface Goldfinger {
2525

2626
/**
27-
* Returns true if user has fingerprint hardware, false otherwise.
27+
* @deprecated Use {@link #hasFingerprintHardware(int)} instead.
2828
*/
29+
@Deprecated
2930
boolean hasFingerprintHardware();
3031

3132
/**
32-
* Returns true if user has enrolled fingerprint, false otherwise.
33+
* Returns true if user has fingerprint hardware, false otherwise.
34+
*/
35+
boolean hasFingerprintHardware(int authenticators);
36+
37+
/**
38+
* @deprecated Use {@link #hasEnrolledFingerprint(int)} instead.
3339
*/
40+
@Deprecated
3441
boolean hasEnrolledFingerprint();
3542

3643
/**
37-
* @see BiometricManager#canAuthenticate()
44+
* Returns true if user has enrolled fingerprint, false otherwise.
45+
*/
46+
boolean hasEnrolledFingerprint(int authenticators);
47+
48+
/**
49+
* @deprecated Use {@link #canAuthenticate(int)} instead.
3850
*/
51+
@Deprecated
3952
boolean canAuthenticate();
4053

54+
/**
55+
* @see BiometricManager#canAuthenticate(int)
56+
*/
57+
boolean canAuthenticate(int authenticators);
58+
4159
/**
4260
* Authenticate user via Fingerprint.
4361
* <p>
@@ -103,7 +121,6 @@ class Builder {
103121
@Nullable private CipherCrypter cipherCrypter;
104122
@Nullable private MacCrypter macCrypter;
105123
@Nullable private SignatureCrypter signatureCrypter;
106-
@NonNull private Mode mode = Mode.AUTHENTICATION;
107124
@Nullable private String key;
108125
@Nullable private String value;
109126

@@ -210,6 +227,7 @@ class PromptParams {
210227
@Nullable private final String title;
211228
private final boolean confirmationRequired;
212229
private final boolean deviceCredentialsAllowed;
230+
private final int allowedAuthenticators;
213231

214232
private PromptParams(
215233
@NonNull Object dialogOwner,
@@ -218,7 +236,8 @@ private PromptParams(
218236
@Nullable String negativeButtonText,
219237
@Nullable String subtitle,
220238
boolean confirmationRequired,
221-
boolean deviceCredentialsAllowed
239+
boolean deviceCredentialsAllowed,
240+
int allowedAuthenticators
222241
) {
223242
this.dialogOwner = dialogOwner;
224243
this.title = title;
@@ -227,24 +246,22 @@ private PromptParams(
227246
this.subtitle = subtitle;
228247
this.confirmationRequired = confirmationRequired;
229248
this.deviceCredentialsAllowed = deviceCredentialsAllowed;
249+
this.allowedAuthenticators = allowedAuthenticators;
230250
}
231251

232-
public boolean confirmationRequired() {
233-
return confirmationRequired;
252+
@NonNull
253+
public Object dialogOwner() {
254+
return dialogOwner;
234255
}
235256

236257
@Nullable
237-
public String description() {
238-
return description;
239-
}
240-
241-
public boolean deviceCredentialsAllowed() {
242-
return deviceCredentialsAllowed;
258+
public String title() {
259+
return title;
243260
}
244261

245-
@NonNull
246-
public Object dialogOwner() {
247-
return dialogOwner;
262+
@Nullable
263+
public String description() {
264+
return description;
248265
}
249266

250267
@Nullable
@@ -257,9 +274,16 @@ public String subtitle() {
257274
return subtitle;
258275
}
259276

260-
@Nullable
261-
public String title() {
262-
return title;
277+
public boolean confirmationRequired() {
278+
return confirmationRequired;
279+
}
280+
281+
public boolean deviceCredentialsAllowed() {
282+
return deviceCredentialsAllowed;
283+
}
284+
285+
public int allowedAuthenticators() {
286+
return allowedAuthenticators;
263287
}
264288

265289
/**
@@ -274,26 +298,23 @@ BiometricPrompt.PromptInfo buildPromptInfo() {
274298
.setTitle(title)
275299
.setSubtitle(subtitle)
276300
.setDescription(description)
277-
.setDeviceCredentialAllowed(deviceCredentialsAllowed)
301+
.setAllowedAuthenticators(allowedAuthenticators)
302+
.setNegativeButtonText(negativeButtonText)
278303
.setConfirmationRequired(confirmationRequired);
279304

280-
if (!deviceCredentialsAllowed) {
281-
builder.setNegativeButtonText(negativeButtonText);
282-
}
283305
return builder.build();
284306
}
285307

286308
public static class Builder {
287309

288310
/* Dialog dialogOwner can be either Fragment or FragmentActivity */
289311
@NonNull private Object dialogOwner;
290-
@NonNull private Mode mode = Mode.AUTHENTICATION;
291312
@Nullable private String description;
292313
@Nullable private String negativeButtonText;
293314
@Nullable private String subtitle;
294315
@Nullable private String title;
295316
private boolean confirmationRequired;
296-
private boolean deviceCredentialsAllowed;
317+
private int allowedAuthenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK;
297318

298319
public Builder(@NonNull FragmentActivity activity) {
299320
this.dialogOwner = activity;
@@ -305,50 +326,53 @@ public Builder(@NonNull Fragment fragment) {
305326

306327
@NonNull
307328
public PromptParams build() {
329+
boolean deviceCredentialAllowed = (allowedAuthenticators & BiometricManager.Authenticators.DEVICE_CREDENTIAL) != 0;
330+
308331
return new PromptParams(
309332
dialogOwner,
310333
title,
311334
description,
312335
negativeButtonText,
313336
subtitle,
314337
confirmationRequired,
315-
deviceCredentialsAllowed
338+
deviceCredentialAllowed,
339+
allowedAuthenticators
316340
);
317341
}
318342

319343
/**
320-
* @see BiometricPrompt.PromptInfo.Builder#setConfirmationRequired
344+
* @see BiometricPrompt.PromptInfo.Builder#setTitle
321345
*/
322346
@NonNull
323-
public Builder confirmationRequired(boolean confirmationRequired) {
324-
this.confirmationRequired = confirmationRequired;
347+
public Builder title(@NonNull String title) {
348+
this.title = title;
325349
return this;
326350
}
327351

328352
/**
329-
* @see BiometricPrompt.PromptInfo.Builder#setDescription
353+
* @see BiometricPrompt.PromptInfo.Builder#setTitle
330354
*/
331355
@NonNull
332-
public Builder description(@Nullable String description) {
333-
this.description = description;
356+
public Builder title(@StringRes int resId) {
357+
this.title = getString(resId);
334358
return this;
335359
}
336360

337361
/**
338362
* @see BiometricPrompt.PromptInfo.Builder#setDescription
339363
*/
340364
@NonNull
341-
public Builder description(@StringRes int resId) {
342-
this.description = getString(resId);
365+
public Builder description(@Nullable String description) {
366+
this.description = description;
343367
return this;
344368
}
345369

346370
/**
347-
* @see BiometricPrompt.PromptInfo.Builder#setDeviceCredentialAllowed
371+
* @see BiometricPrompt.PromptInfo.Builder#setDescription
348372
*/
349373
@NonNull
350-
public Builder deviceCredentialsAllowed(boolean deviceCredentialsAllowed) {
351-
this.deviceCredentialsAllowed = deviceCredentialsAllowed;
374+
public Builder description(@StringRes int resId) {
375+
this.description = getString(resId);
352376
return this;
353377
}
354378

@@ -389,20 +413,20 @@ public Builder subtitle(@StringRes int resId) {
389413
}
390414

391415
/**
392-
* @see BiometricPrompt.PromptInfo.Builder#setTitle
416+
* @see BiometricPrompt.PromptInfo.Builder#setConfirmationRequired
393417
*/
394418
@NonNull
395-
public Builder title(@NonNull String title) {
396-
this.title = title;
419+
public Builder confirmationRequired(boolean confirmationRequired) {
420+
this.confirmationRequired = confirmationRequired;
397421
return this;
398422
}
399423

400424
/**
401-
* @see BiometricPrompt.PromptInfo.Builder#setTitle
425+
* @see BiometricPrompt.PromptInfo.Builder#setAllowedAuthenticators(int)
402426
*/
403427
@NonNull
404-
public Builder title(@StringRes int resId) {
405-
this.title = getString(resId);
428+
public Builder allowedAuthenticators(int allowedAuthenticators) {
429+
this.allowedAuthenticators = allowedAuthenticators;
406430
return this;
407431
}
408432

@@ -579,6 +603,11 @@ enum Reason {
579603
*/
580604
NO_DEVICE_CREDENTIAL,
581605

606+
/**
607+
* @see BiometricPrompt#ERROR_SECURITY_UPDATE_REQUIRED
608+
*/
609+
SECURITY_UPDATE_REQUIRED,
610+
582611
/**
583612
* Dispatched when Fingerprint authentication is initialized correctly and
584613
* just before actual authentication is started. Can be used to update UI if necessary.

0 commit comments

Comments
 (0)