Skip to content

Commit

Permalink
handle fingerprint changed more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
dkunzler committed Aug 28, 2017
1 parent edc529f commit ffb58d2
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "de.devland.masterpassword"
minSdkVersion 15
targetSdkVersion 25
versionCode 45
versionName "1.13.0"
versionCode 47
versionName "1.13.1"
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ public void onAuthenticationFailed() {
}
}, null);
} catch (FingerprintException e) {
SnackbarUtil.showLong(getActivity(), e.getMessage());
Throwable cause = e.getCause();
if (cause.getClass().getSimpleName().equals("KeyPermanentlyInvalidatedException")) {
FingerprintUtil.resetFingerprintSettings();
SnackbarUtil.showLong(getActivity(), R.string.msg_fingerprint_changed);
} else {
SnackbarUtil.showLong(getActivity(), e.getMessage());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.hardware.fingerprint.FingerprintManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
Expand All @@ -23,6 +25,9 @@
import android.widget.ImageView;
import android.widget.TextView;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.crypto.Cipher;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -153,6 +158,41 @@ public void onShow(DialogInterface unused) {
dismiss();
defaultPrefs.fingerprintEnabled(false);
SnackbarUtil.showLong(App.get().getCurrentForegroundActivity(), e.getMessage());
Throwable cause = e;
String stacktrace = "";
do {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
cause.printStackTrace(pw);
stacktrace += sw.toString();
cause = cause.getCause();
} while (cause != null && cause != e);

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "[email protected]", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Master Password Feedback");
String mailTemplate = "\n\n\n-----\n" +
"App Version: %s\n" +
"App Version Code: %d\n" +
"OS Version: %s\n" +
"API Level: %d\n" +
"Android Version: %s\n" +
"Device Manufacturer: %s\n" +
"Device Codename: %s\n" +
"Device Model: %s\n" +
"Stacktrace: %s";
String mailText = String.format(mailTemplate,
defaultPrefs.versionName(),
defaultPrefs.versionCode(),
System.getProperty("os.version"),
Build.VERSION.SDK_INT,
Build.VERSION.RELEASE,
Build.MANUFACTURER,
Build.DEVICE,
Build.MODEL,
stacktrace);
emailIntent.putExtra(Intent.EXTRA_TEXT, mailText);
getContext().startActivity(Intent.createChooser(emailIntent, getContext().getString(R.string.title_feedback)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((Boolean) newValue) {
if (!FingerprintUtil.canUseFingerprint(true)) {
this.setChecked(false);
FingerprintUtil.resetFingerprintSettings();
} else {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(settingsActivity, new String[]{Manifest.permission.USE_FINGERPRINT}, 42);
Expand All @@ -72,13 +73,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
this.setChecked(false);
FingerprintUtil.resetFingerprintSettings();
} else {
UnlockFingerprintDialog verifyPasswordDialog = new UnlockFingerprintDialog();
verifyPasswordDialog.show(settingsActivity.getSupportFragmentManager(), null);
}
}
} else {
defaultPrefs.masterPasswordHash(null);
FingerprintUtil.resetFingerprintSettings();
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;

import de.devland.esperandro.Esperandro;
import de.devland.masterpassword.App;
import de.devland.masterpassword.R;
import de.devland.masterpassword.base.ui.BaseActivity;
import de.devland.masterpassword.base.util.SnackbarUtil;
import de.devland.masterpassword.prefs.DefaultPrefs;

import static android.content.Context.KEYGUARD_SERVICE;

Expand Down Expand Up @@ -227,4 +229,10 @@ private static Cipher getCipher(int mode, KeyStore keyStore, String ivString) th
}
}

public static void resetFingerprintSettings() {
DefaultPrefs defaultPrefs = Esperandro.getPreferences(DefaultPrefs.class, App.get());
defaultPrefs.fingerprintEnabled(false);
defaultPrefs.encrypted(null);
defaultPrefs.encryptionIV(null);
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@
<string name="fingerprint_permission">Bitte aktivieren Sie die Fingerabdruck Berechtigung</string>
<string name="fingerprint_scanNeeded">Sie müssen Ihren Fingerabdruck scannen bevor Sie weitermachen können.</string>
<string name="fingerprint_unconfigured">Keine Fingerabdrücke hinterlegt. Bitte registrieren Sie Ihren Fingerabdruck in den Geräte Einstellungen.</string>
<string name="msg_fingerprint_changed">Fingerabdrücke wurden geändert, bitte in den Einstellungen wieder aktivieren.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@
<string name="fingerprint_hint">Enter required information and then scan your fingerprint.</string>
<string name="fingerprint_scanNeeded">You need to provide your fingerprint before proceeding.</string>
<string name="fingerprint_dialog_success">Fingerprint provided. Confirm after entering your password.</string>
<string name="msg_fingerprint_changed">Fingerprints changed, re-enable fingerprint in settings.</string>
</resources>

0 comments on commit ffb58d2

Please sign in to comment.