Keep authentication settings when receiving a Panic trigger

Fixes #50
This commit is contained in:
Jakob Nixdorf 2017-10-05 10:06:02 +02:00
parent d856758d15
commit d708f08f02
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 25 additions and 3 deletions

View file

@ -51,7 +51,7 @@ public class PanicResponderActivity extends Activity {
DatabaseHelper.saveDatabase(this, new ArrayList<Entry>()); DatabaseHelper.saveDatabase(this, new ArrayList<Entry>());
if (response.contains("settings")) if (response.contains("settings"))
settings.clear(); settings.clear(true);
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View file

@ -109,8 +109,30 @@ public class Settings {
.apply(); .apply();
} }
public void clear() { public void clear(boolean keep_auth) {
settings.edit().clear().commit(); 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); PreferenceManager.setDefaultValues(context, R.xml.preferences, true);
} }