mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
parent
72064d8827
commit
3d651ef29a
@ -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;
|
||||
|
@ -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<Long> modifiedThreads = new HashSet<Long>();
|
||||
XmlBackup.XmlBackupItem item;
|
||||
|
@ -144,7 +144,7 @@ public class XmlBackup {
|
||||
public static class Writer {
|
||||
|
||||
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
|
||||
private static final String CREATED_BY = "<!-- File Created By TextSecure -->";
|
||||
private static final String CREATED_BY = "<!-- File Created By Signal -->";
|
||||
private static final String OPEN_TAG_SMSES = "<smses count=\"%d\">";
|
||||
private static final String CLOSE_TAG_SMSES = "</smses>";
|
||||
private static final String OPEN_TAG_SMS = " <sms ";
|
||||
|
Loading…
Reference in New Issue
Block a user