Allow doing Conversations-compatible backups

Stephen Paul Weber created

Change summary

src/main/java/eu/siacs/conversations/services/ExportBackupService.java |  6 
src/main/java/eu/siacs/conversations/ui/SettingsActivity.java          | 16 
2 files changed, 18 insertions(+), 4 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/services/ExportBackupService.java 🔗

@@ -227,7 +227,7 @@ public class ExportBackupService extends Service {
                 boolean success;
                 List<File> files;
                 try {
-                    files = export();
+                    files = export(intent.getBooleanExtra("cheogram_db", true));
                     success = true;
                 } catch (final Exception e) {
                     Log.d(Config.LOGTAG, "unable to create backup", e);
@@ -296,7 +296,7 @@ public class ExportBackupService extends Service {
         }
     }
 
-    private List<File> export() throws Exception {
+    private List<File> export(boolean withCheogramDb) throws Exception {
         NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getBaseContext(), "backup");
         mBuilder.setContentTitle(getString(R.string.notification_create_backup_title))
                 .setSmallIcon(R.drawable.ic_archive_white_24dp)
@@ -345,7 +345,7 @@ public class ExportBackupService extends Service {
             accountExport(db, uuid, writer);
             simpleExport(db, Conversation.TABLENAME, Conversation.ACCOUNT, uuid, writer);
             messageExport(db, uuid, writer, progress);
-            messageExportCheogram(db, uuid, writer, progress);
+            if (withCheogramDb) messageExportCheogram(db, uuid, writer, progress);
             for (String table : Arrays.asList(SQLiteAxolotlStore.PREKEY_TABLENAME, SQLiteAxolotlStore.SIGNED_PREKEY_TABLENAME, SQLiteAxolotlStore.SESSION_TABLENAME, SQLiteAxolotlStore.IDENTITIES_TABLENAME)) {
                 simpleExport(db, table, SQLiteAxolotlStore.ACCOUNT, uuid, writer);
             }

src/main/java/eu/siacs/conversations/ui/SettingsActivity.java 🔗

@@ -523,7 +523,21 @@ public class SettingsActivity extends XmppActivity implements OnSharedPreference
     }
 
     private void createBackup() {
-        ContextCompat.startForegroundService(this, new Intent(this, ExportBackupService.class));
+        new AlertDialog.Builder(this)
+            .setTitle("Create Backup")
+            .setMessage("Export extra Cheogram-only data (backup will not import into other apps then)?")
+            .setPositiveButton(R.string.yes, (dialog, whichButton) -> {
+                createBackup(true);
+            })
+            .setNegativeButton(R.string.no, (dialog, whichButton) -> {
+                createBackup(false);
+            }).show();
+    }
+
+    private void createBackup(boolean withCheogramDb) {
+        Intent intent = new Intent(this, ExportBackupService.class);
+        intent.putExtra("cheogram_db", withCheogramDb);
+        ContextCompat.startForegroundService(this, intent);
         final AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setMessage(R.string.backup_started_message);
         builder.setPositiveButton(R.string.ok, null);