Skip to content

Commit

Permalink
Improve fingerprint error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bpellin committed May 8, 2018
1 parent 0dd1513 commit c6926fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
52 changes: 32 additions & 20 deletions app/src/main/java/com/keepassdroid/PasswordActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,9 @@ public void onAuthenticationError(
final int errorCode,
final CharSequence errString) {

// this is triggered on stop/start listening done by helper to switch between modes so don't restart here
// errorCode = 5
// errString = "Fingerprint operation canceled."
//onException();
//confirmationView.setText(errString);
// true false fingerprint readings are handled otherwise with the toast messages, see below in code
if (errorCode != 5) { // FINGERPRINT_ERROR_CANCELLED (not defined in support library)
onException(errString);
}
}

@Override
Expand Down Expand Up @@ -347,7 +344,7 @@ public void onAuthenticationSucceeded(final FingerprintManagerCompat.Authenticat

@Override
public void onAuthenticationFailed() {
onException();
onException(R.string.fingerprint_notrecognized);
}
});
}
Expand All @@ -363,17 +360,23 @@ private String getPreferenceKeyIvSpec() {
}

private int toggleMode(final int newMode) {
mode = newMode;
switch (mode) {
case Cipher.ENCRYPT_MODE:
fingerPrintHelper.initEncryptData();
break;
case Cipher.DECRYPT_MODE:
final String ivSpecValue = prefsNoBackup.getString(getPreferenceKeyIvSpec(), null);
if (ivSpecValue != null) {
fingerPrintHelper.initDecryptData(ivSpecValue);
}
break;
if (mode != newMode) {
mode = newMode;
switch (mode) {
case Cipher.ENCRYPT_MODE:
fingerPrintHelper.initEncryptData();
break;
case Cipher.DECRYPT_MODE:
final String ivSpecValue = prefsNoBackup.getString(getPreferenceKeyIvSpec(), null);
if (ivSpecValue != null) {
fingerPrintHelper.initDecryptData(ivSpecValue);
}
break;
}
}
else {
fingerPrintHelper.stopListening();
fingerPrintHelper.startListening();
}

return mode;
Expand Down Expand Up @@ -467,7 +470,6 @@ public void handleDecryptedResult(final String value) {
@Override
public void onInvalidKeyException() {
Toast.makeText(this, R.string.fingerprint_invalid_key, Toast.LENGTH_SHORT).show();
checkAvailability(); // restarts listening
}

@Override
Expand All @@ -478,10 +480,20 @@ public void onException() {
@Override
public void onException(boolean showMessage) {
if (showMessage) {
Toast.makeText(this, R.string.fingerprint_error, Toast.LENGTH_SHORT).show();
onException(R.string.fingerprint_error);
}
}

@Override
public void onException(int resId) {
Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
}

@Override
public void onException(CharSequence message) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

private class DefaultCheckChange implements CompoundButton.OnCheckedChangeListener {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public interface FingerPrintCallback {

void onException(boolean showWarningMessage);

void onException(CharSequence message);

void onException(int resId);
}

public FingerPrintHelper(
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2009-2017 Brian Pellin.
Copyright 2009-2018 Brian Pellin.
This file is part of KeePassDroid.
Expand Down Expand Up @@ -203,6 +203,7 @@
<string name="fingerprint_error">Fingerprint problem</string>
<string name="store_with_fingerprint">Use fingerprint to store this password</string>
<string name="no_password_stored">No password stored yet for this database</string>
<string name="fingerprint_notrecognized">Fingerprint not recognized</string>

<string-array name="clipboard_timeout_options">
<item>30 seconds</item>
Expand Down

0 comments on commit c6926fb

Please sign in to comment.