From d708f08f0215e1fd65ec5d785c3475af46605878 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Thu, 5 Oct 2017 10:06:02 +0200 Subject: [PATCH] Keep authentication settings when receiving a Panic trigger Fixes #50 --- .../Activities/PanicResponderActivity.java | 2 +- .../flocke/andotp/Utilities/Settings.java | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/PanicResponderActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/PanicResponderActivity.java index e2343d9b..c927e17e 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/PanicResponderActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/PanicResponderActivity.java @@ -51,7 +51,7 @@ public class PanicResponderActivity extends Activity { DatabaseHelper.saveDatabase(this, new ArrayList()); if (response.contains("settings")) - settings.clear(); + settings.clear(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java index e7ac6a5e..01681c49 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java @@ -109,8 +109,30 @@ public class Settings { .apply(); } - public void clear() { - settings.edit().clear().commit(); + public void clear(boolean keep_auth) { + String authMethod = getAuthMethod().toString().toLowerCase(); + String authPassword = getAuthPasswordHash(); + String authPIN = getAuthPINHash(); + + boolean warningShown = getFirstTimeWarningShown(); + + SharedPreferences.Editor editor = settings.edit(); + editor.clear(); + + editor.putBoolean(getResString(R.string.settings_key_security_backup_warning), warningShown); + + if (keep_auth) { + editor.putString(getResString(R.string.settings_key_auth), authMethod); + + if (!authPassword.isEmpty()) + editor.putString(getResString(R.string.settings_key_auth_password_hash), authPassword); + + if (!authPIN.isEmpty()) + editor.putString(getResString(R.string.settings_key_auth_pin_hash), authPIN); + } + + editor.commit(); + PreferenceManager.setDefaultValues(context, R.xml.preferences, true); }