Search in sources :

Example 6 with Settings

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);
}
Also used : Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 7 with Settings

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;
}
Also used : File(java.io.File) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Example 8 with Settings

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);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) Entry(org.shadowice.flocke.andotp.Database.Entry) Uri(android.net.Uri) Settings(org.shadowice.flocke.andotp.Utilities.Settings)

Aggregations

Settings (org.shadowice.flocke.andotp.Utilities.Settings)8 Uri (android.net.Uri)2 SecretKey (javax.crypto.SecretKey)2 Entry (org.shadowice.flocke.andotp.Database.Entry)2 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ColorFilter (android.graphics.ColorFilter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 OnNavigationBlockedListener (com.heinrichreimersoftware.materialintro.app.OnNavigationBlockedListener)1 FragmentSlide (com.heinrichreimersoftware.materialintro.slide.FragmentSlide)1 SimpleSlide (com.heinrichreimersoftware.materialintro.slide.SimpleSlide)1 File (java.io.File)1 Constants (org.shadowice.flocke.andotp.Utilities.Constants)1