Added debug option to disable emergency file

pull/212/head
M66B 2 years ago
parent 4267aa92f9
commit 495412c16c

@ -267,35 +267,42 @@ public abstract class DB extends RoomDatabase {
} }
static void createEmergencyBackup(Context context) { static void createEmergencyBackup(Context context) {
Log.i("Creating emergency backup"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try { boolean emergency_file = prefs.getBoolean("emergency_file", true);
DB db = DB.getInstance(context);
JSONArray jaccounts = new JSONArray();
List<EntityAccount> accounts = db.account().getAccounts();
for (EntityAccount account : accounts) {
JSONObject jaccount = account.toJSON();
JSONArray jfolders = new JSONArray(); File emergency = new File(context.getFilesDir(), "emergency.json");
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);
for (EntityFolder folder : folders)
jfolders.put(folder.toJSON());
jaccount.put("folders", jfolders);
JSONArray jidentities = new JSONArray(); if (emergency_file) {
List<EntityIdentity> identities = db.identity().getIdentities(account.id); Log.i("Creating emergency backup");
for (EntityIdentity identity : identities) try {
jidentities.put(identity.toJSON()); DB db = DB.getInstance(context);
jaccount.put("identities", jidentities);
JSONArray jaccounts = new JSONArray();
List<EntityAccount> accounts = db.account().getAccounts();
for (EntityAccount account : accounts) {
JSONObject jaccount = account.toJSON();
JSONArray jfolders = new JSONArray();
List<EntityFolder> 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<EntityIdentity> 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);
} }
} else
File emergency = new File(context.getFilesDir(), "emergency.json"); emergency.delete();
Helper.writeText(emergency, jaccounts.toString(2));
} catch (Throwable ex) {
Log.e(ex);
}
} }
private static void checkEmergencyBackup(Context context) { private static void checkEmergencyBackup(Context context) {

@ -176,6 +176,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private Button btnRepair; private Button btnRepair;
private Button btnDaily; private Button btnDaily;
private SwitchCompat swAutostart; private SwitchCompat swAutostart;
private SwitchCompat swEmergency;
private SwitchCompat swWorkManager; private SwitchCompat swWorkManager;
private SwitchCompat swExternalStorage; private SwitchCompat swExternalStorage;
private TextView tvExternalStorageFolder; private TextView tvExternalStorageFolder;
@ -262,7 +263,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"crash_reports", "cleanup_attachments", "crash_reports", "cleanup_attachments",
"watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary", "watchdog", "experiments", "main_log", "main_log_memory", "protocol", "log_level", "debug", "leak_canary",
"test1", "test2", "test3", "test4", "test5", "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", "sqlite_integrity_check", "wal", "sqlite_checkpoints", "sqlite_analyze", "sqlite_auto_vacuum", "sqlite_sync_extra", "sqlite_cache",
"chunk_size", "thread_range", "undo_manager", "chunk_size", "thread_range", "undo_manager",
"browser_zoom", "fake_dark", "browser_zoom", "fake_dark",
@ -395,6 +396,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
btnRepair = view.findViewById(R.id.btnRepair); btnRepair = view.findViewById(R.id.btnRepair);
btnDaily = view.findViewById(R.id.btnDaily); btnDaily = view.findViewById(R.id.btnDaily);
swAutostart = view.findViewById(R.id.swAutostart); swAutostart = view.findViewById(R.id.swAutostart);
swEmergency = view.findViewById(R.id.swEmergency);
swWorkManager = view.findViewById(R.id.swWorkManager); swWorkManager = view.findViewById(R.id.swWorkManager);
swExternalStorage = view.findViewById(R.id.swExternalStorage); swExternalStorage = view.findViewById(R.id.swExternalStorage);
tvExternalStorageFolder = view.findViewById(R.id.tvExternalStorageFolder); 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() { swWorkManager.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -2205,6 +2214,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swTest5.setChecked(prefs.getBoolean("test5", false)); swTest5.setChecked(prefs.getBoolean("test5", false));
swAutostart.setChecked(Helper.isComponentEnabled(getContext(), ReceiverAutoStart.class)); swAutostart.setChecked(Helper.isComponentEnabled(getContext(), ReceiverAutoStart.class));
swEmergency.setChecked(prefs.getBoolean("emergency_file", true));
swWorkManager.setChecked(prefs.getBoolean("work_manager", true)); swWorkManager.setChecked(prefs.getBoolean("work_manager", true));
swExternalStorage.setChecked(prefs.getBoolean("external_storage", false)); swExternalStorage.setChecked(prefs.getBoolean("external_storage", false));

@ -1149,6 +1149,18 @@
app:layout_constraintTop_toBottomOf="@id/btnDaily" app:layout_constraintTop_toBottomOf="@id/btnDaily"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEmergency"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_emergency"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutostart"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWorkManager" android:id="@+id/swWorkManager"
android:layout_width="0dp" android:layout_width="0dp"
@ -1158,7 +1170,7 @@
android:text="@string/title_advanced_work_manager" android:text="@string/title_advanced_work_manager"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutostart" app:layout_constraintTop_toBottomOf="@id/swEmergency"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -808,6 +808,7 @@
<string name="title_advanced_repair" translatable="false">Repair</string> <string name="title_advanced_repair" translatable="false">Repair</string>
<string name="title_advanced_daily" translatable="false">Daily</string> <string name="title_advanced_daily" translatable="false">Daily</string>
<string name="title_advanced_autostart" translatable="false">Autostart app</string> <string name="title_advanced_autostart" translatable="false">Autostart app</string>
<string name="title_advanced_emergency" translatable="false">Write emergency file</string>
<string name="title_advanced_work_manager" translatable="false">Initialize work manager</string> <string name="title_advanced_work_manager" translatable="false">Initialize work manager</string>
<string name="title_advanced_external_storage" translatable="false">Use external storage</string> <string name="title_advanced_external_storage" translatable="false">Use external storage</string>
<string name="title_advanced_integrity" translatable="false">sqlite integrity check</string> <string name="title_advanced_integrity" translatable="false">sqlite integrity check</string>

Loading…
Cancel
Save