diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index e832656c51..a0d4026f1c 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -267,35 +267,42 @@ public abstract class DB extends RoomDatabase { } static void createEmergencyBackup(Context context) { - Log.i("Creating emergency backup"); - try { - DB db = DB.getInstance(context); - - JSONArray jaccounts = new JSONArray(); - List accounts = db.account().getAccounts(); - for (EntityAccount account : accounts) { - JSONObject jaccount = account.toJSON(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean emergency_file = prefs.getBoolean("emergency_file", true); - JSONArray jfolders = new JSONArray(); - List folders = db.folder().getFolders(account.id, false, true); - for (EntityFolder folder : folders) - jfolders.put(folder.toJSON()); - jaccount.put("folders", jfolders); + File emergency = new File(context.getFilesDir(), "emergency.json"); - JSONArray jidentities = new JSONArray(); - List identities = db.identity().getIdentities(account.id); - for (EntityIdentity identity : identities) - jidentities.put(identity.toJSON()); - jaccount.put("identities", jidentities); + if (emergency_file) { + Log.i("Creating emergency backup"); + try { + DB db = DB.getInstance(context); + + JSONArray jaccounts = new JSONArray(); + List accounts = db.account().getAccounts(); + for (EntityAccount account : accounts) { + JSONObject jaccount = account.toJSON(); + + JSONArray jfolders = new JSONArray(); + List folders = db.folder().getFolders(account.id, false, true); + for (EntityFolder folder : folders) + jfolders.put(folder.toJSON()); + jaccount.put("folders", jfolders); + + JSONArray jidentities = new JSONArray(); + List identities = db.identity().getIdentities(account.id); + for (EntityIdentity identity : identities) + jidentities.put(identity.toJSON()); + jaccount.put("identities", jidentities); + + jaccounts.put(jaccount); + } - jaccounts.put(jaccount); + Helper.writeText(emergency, jaccounts.toString(2)); + } catch (Throwable ex) { + Log.e(ex); } - - File emergency = new File(context.getFilesDir(), "emergency.json"); - Helper.writeText(emergency, jaccounts.toString(2)); - } catch (Throwable ex) { - Log.e(ex); - } + } else + emergency.delete(); } private static void checkEmergencyBackup(Context context) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 78af0e4d18..f62a82a9a3 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -176,6 +176,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private Button btnRepair; private Button btnDaily; private SwitchCompat swAutostart; + private SwitchCompat swEmergency; private SwitchCompat swWorkManager; private SwitchCompat swExternalStorage; private TextView tvExternalStorageFolder; @@ -262,7 +263,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "crash_reports", "cleanup_attachments", "watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary", "test1", "test2", "test3", "test4", "test5", - "work_manager", // "external_storage", + "emergency_file", "work_manager", // "external_storage", "sqlite_integrity_check", "wal", "sqlite_checkpoints", "sqlite_analyze", "sqlite_auto_vacuum", "sqlite_sync_extra", "sqlite_cache", "chunk_size", "thread_range", "undo_manager", "browser_zoom", "fake_dark", @@ -395,6 +396,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc btnRepair = view.findViewById(R.id.btnRepair); btnDaily = view.findViewById(R.id.btnDaily); swAutostart = view.findViewById(R.id.swAutostart); + swEmergency = view.findViewById(R.id.swEmergency); swWorkManager = view.findViewById(R.id.swWorkManager); swExternalStorage = view.findViewById(R.id.swExternalStorage); tvExternalStorageFolder = view.findViewById(R.id.tvExternalStorageFolder); @@ -1197,6 +1199,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swEmergency.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton v, boolean checked) { + prefs.edit().putBoolean("emergency_file", checked).apply(); + } + }); + swWorkManager.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -2205,6 +2214,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swTest5.setChecked(prefs.getBoolean("test5", false)); swAutostart.setChecked(Helper.isComponentEnabled(getContext(), ReceiverAutoStart.class)); + swEmergency.setChecked(prefs.getBoolean("emergency_file", true)); swWorkManager.setChecked(prefs.getBoolean("work_manager", true)); swExternalStorage.setChecked(prefs.getBoolean("external_storage", false)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index cb24127e74..1cb8d69349 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -1149,6 +1149,18 @@ app:layout_constraintTop_toBottomOf="@id/btnDaily" app:switchPadding="12dp" /> + + Repair Daily Autostart app + Write emergency file Initialize work manager Use external storage sqlite integrity check