Cache the encryption key when recreating the settings activity after settings changes

This commit is contained in:
Jakob Nixdorf 2020-05-25 17:01:11 +02:00
parent cdc54028b3
commit c1d6c6b2b8
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC

View file

@ -85,6 +85,15 @@ public class SettingsActivity extends BaseActivity
if (keyMaterial != null && keyMaterial.length > 0)
encryptionKey = EncryptionHelper.generateSymmetricKey(keyMaterial);
if (savedInstanceState != null) {
encryptionChanged = savedInstanceState.getBoolean(Constants.EXTRA_SETTINGS_ENCRYPTION_CHANGED, false);
byte[] encKey = savedInstanceState.getByteArray(Constants.EXTRA_SETTINGS_ENCRYPTION_KEY);
if (encKey != null) {
encryptionKey = EncryptionHelper.generateSymmetricKey(encKey);
}
}
fragment = new SettingsFragment();
getFragmentManager().beginTransaction()
@ -95,6 +104,14 @@ public class SettingsActivity extends BaseActivity
sharedPref.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(Constants.EXTRA_SETTINGS_ENCRYPTION_CHANGED, encryptionChanged);
outState.putByteArray(Constants.EXTRA_SETTINGS_ENCRYPTION_KEY, encryptionKey.getEncoded());
}
public void finishWithResult() {
Intent data = new Intent();