Revert "Move backup function to any saveDatabase call"

This reverts commit 7c60a06532.
This commit is contained in:
Jakob Nixdorf 2019-10-30 11:35:25 +01:00
parent 7c60a06532
commit 3516b7b90d
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 17 additions and 16 deletions

View file

@ -25,7 +25,6 @@ package org.shadowice.flocke.andotp.Utilities;
import android.app.backup.BackupManager;
import android.content.Context;
import android.net.Uri;
import android.widget.Toast;
import org.json.JSONArray;
@ -110,21 +109,6 @@ public class DatabaseHelper {
byte[] data = EncryptionHelper.encrypt(encryptionKey, jsonString.getBytes());
FileHelper.writeBytesToFile(new File(context.getFilesDir() + "/" + Constants.FILENAME_DATABASE), data);
Settings settings = new Settings(context);
if(settings.getAutoBackupEncryptedPasswordsEnabled()) {
Constants.BackupType backupType = BackupHelper.autoBackupType(context);
if (backupType == Constants.BackupType.ENCRYPTED) {
Uri backupFilename = Tools.buildUri(settings.getBackupDir(), BackupHelper.backupFilename(context, Constants.BackupType.ENCRYPTED));
boolean success = BackupHelper.backupToFile(context, backupFilename, settings.getBackupPasswordEnc(), encryptionKey);
if (success) {
Toast.makeText(context, R.string.backup_toast_export_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, R.string.backup_toast_export_failed, Toast.LENGTH_LONG).show();
}
}
}
}
} catch (Exception error) {
error.printStackTrace();

View file

@ -136,6 +136,23 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
public void saveEntries() {
DatabaseHelper.saveDatabase(context, entries, encryptionKey);
if(settings.getAutoBackupEncryptedPasswordsEnabled()) {
Constants.BackupType backupType = BackupHelper.autoBackupType(context);
if (backupType == Constants.BackupType.ENCRYPTED) {
Uri backupFilename = Tools.buildUri(settings.getBackupDir(), BackupHelper.backupFilename(context, Constants.BackupType.ENCRYPTED));
byte[] keyMaterial = encryptionKey.getEncoded();
SecretKey encryptionKey = EncryptionHelper.generateSymmetricKey(keyMaterial);
boolean success = BackupHelper.backupToFile(context, backupFilename, settings.getBackupPasswordEnc(), encryptionKey);
if (success) {
Toast.makeText(context, R.string.backup_toast_export_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, R.string.backup_toast_export_failed, Toast.LENGTH_LONG).show();
}
}
}
}
public void loadEntries() {