diff --git a/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java b/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java index 453dab4763..7f1178ad40 100644 --- a/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java +++ b/src/org/thoughtcrime/securesms/database/PlaintextBackupExporter.java @@ -12,6 +12,8 @@ import java.io.IOException; public class PlaintextBackupExporter { + private static final String FILENAME = "SignalPlaintextBackup.xml"; + public static void exportPlaintextToSd(Context context, MasterSecret masterSecret) throws NoExternalStorageException, IOException { @@ -24,16 +26,15 @@ public class PlaintextBackupExporter { throw new NoExternalStorageException(); } - private static String getPlaintextExportDirectoryPath() { - File sdDirectory = Environment.getExternalStorageDirectory(); - return sdDirectory.getAbsolutePath() + File.separator + "TextSecurePlaintextBackup.xml"; + public static File getPlaintextExportFile() { + return new File(Environment.getExternalStorageDirectory(), FILENAME); } private static void exportPlaintext(Context context, MasterSecret masterSecret) throws IOException { int count = DatabaseFactory.getSmsDatabase(context).getMessageCount(); - XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportDirectoryPath(), count); + XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportFile().getAbsolutePath(), count); SmsMessageRecord record; diff --git a/src/org/thoughtcrime/securesms/database/PlaintextBackupImporter.java b/src/org/thoughtcrime/securesms/database/PlaintextBackupImporter.java index c1cf58c30d..87b187cac9 100644 --- a/src/org/thoughtcrime/securesms/database/PlaintextBackupImporter.java +++ b/src/org/thoughtcrime/securesms/database/PlaintextBackupImporter.java @@ -9,7 +9,6 @@ import android.util.Log; import org.thoughtcrime.securesms.crypto.MasterCipher; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.recipients.RecipientFactory; -import org.thoughtcrime.securesms.recipients.RecipientFormattingException; import org.thoughtcrime.securesms.recipients.Recipients; import org.xmlpull.v1.XmlPullParserException; @@ -30,14 +29,18 @@ public class PlaintextBackupImporter { } private static void verifyExternalStorageForPlaintextImport() throws NoExternalStorageException { - if (!Environment.getExternalStorageDirectory().canRead() || - !(new File(getPlaintextExportDirectoryPath()).exists())) + if (!Environment.getExternalStorageDirectory().canRead() || !getPlaintextExportFile().exists()) throw new NoExternalStorageException(); } - private static String getPlaintextExportDirectoryPath() { - File sdDirectory = Environment.getExternalStorageDirectory(); - return sdDirectory.getAbsolutePath() + File.separator + "TextSecurePlaintextBackup.xml"; + private static File getPlaintextExportFile() { + File backup = PlaintextBackupExporter.getPlaintextExportFile(); + File oldBackup = new File(Environment.getExternalStorageDirectory(), "TextSecurePlaintextBackup.xml"); + + if (!backup.exists() && oldBackup.exists()) { + return oldBackup; + } + return backup; } private static void importPlaintext(Context context, MasterSecret masterSecret) @@ -49,7 +52,7 @@ public class PlaintextBackupImporter { try { ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context); - XmlBackup backup = new XmlBackup(getPlaintextExportDirectoryPath()); + XmlBackup backup = new XmlBackup(getPlaintextExportFile().getAbsolutePath()); MasterCipher masterCipher = new MasterCipher(masterSecret); Set modifiedThreads = new HashSet(); XmlBackup.XmlBackupItem item; diff --git a/src/org/thoughtcrime/securesms/database/XmlBackup.java b/src/org/thoughtcrime/securesms/database/XmlBackup.java index bc467f78c3..3bf178af14 100644 --- a/src/org/thoughtcrime/securesms/database/XmlBackup.java +++ b/src/org/thoughtcrime/securesms/database/XmlBackup.java @@ -144,7 +144,7 @@ public class XmlBackup { public static class Writer { private static final String XML_HEADER = ""; - private static final String CREATED_BY = ""; + private static final String CREATED_BY = ""; private static final String OPEN_TAG_SMSES = ""; private static final String CLOSE_TAG_SMSES = ""; private static final String OPEN_TAG_SMS = "