use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.
the class ThemedActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
settings = new Settings(this);
setTheme();
setLocale();
super.onCreate(savedInstanceState);
}
use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.
the class BackupBroadcastReceiver method canSaveBackup.
protected boolean canSaveBackup(Context context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_read_permission_failed);
return false;
}
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_write_permission_failed);
return false;
}
Settings settings = new Settings(context);
File backupDir = new File(settings.getBackupDir());
if (!backupDir.exists())
backupDir.mkdirs();
return true;
}
use of org.shadowice.flocke.andotp.Utilities.Settings in project andOTP by andOTP.
the class EncryptedBackupBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
Settings settings = new Settings(context);
if (settings.isEncryptedBackupBroadcastEnabled()) {
if (!canSaveBackup(context))
return;
Uri savePath = Tools.buildUri(settings.getBackupDir(), FileHelper.backupFilename(context, Constants.BackupType.ENCRYPTED));
String password = settings.getBackupPasswordEnc();
if (password.isEmpty()) {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_crypt_password_not_set);
return;
}
SecretKey encryptionKey = null;
if (settings.getEncryption() == Constants.EncryptionType.KEYSTORE) {
encryptionKey = KeyStoreHelper.loadEncryptionKeyFromKeyStore(context, false);
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_custom_encryption_failed);
return;
}
if (Tools.isExternalStorageWritable()) {
ArrayList<Entry> entries = DatabaseHelper.loadDatabase(context, encryptionKey);
String plain = DatabaseHelper.entriesToString(entries);
try {
SecretKey key = EncryptionHelper.generateSymmetricKeyFromPassword(password);
byte[] encrypted = EncryptionHelper.encrypt(key, plain.getBytes(StandardCharsets.UTF_8));
FileHelper.writeBytesToFile(context, savePath, encrypted);
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_SUCCESS, R.string.backup_receiver_title_backup_success, savePath.getPath());
} catch (Exception e) {
e.printStackTrace();
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_export_failed);
}
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_toast_storage_not_accessible);
}
} else {
NotificationHelper.notify(context, Constants.NotificationChannel.BACKUP_FAILED, R.string.backup_receiver_title_backup_failed, R.string.backup_receiver_encrypted_disabled);
}
}
Aggregations