mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-20 05:58:27 +00:00
parent
72064d8827
commit
3d651ef29a
@ -12,6 +12,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class PlaintextBackupExporter {
|
public class PlaintextBackupExporter {
|
||||||
|
|
||||||
|
private static final String FILENAME = "SignalPlaintextBackup.xml";
|
||||||
|
|
||||||
public static void exportPlaintextToSd(Context context, MasterSecret masterSecret)
|
public static void exportPlaintextToSd(Context context, MasterSecret masterSecret)
|
||||||
throws NoExternalStorageException, IOException
|
throws NoExternalStorageException, IOException
|
||||||
{
|
{
|
||||||
@ -24,16 +26,15 @@ public class PlaintextBackupExporter {
|
|||||||
throw new NoExternalStorageException();
|
throw new NoExternalStorageException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlaintextExportDirectoryPath() {
|
public static File getPlaintextExportFile() {
|
||||||
File sdDirectory = Environment.getExternalStorageDirectory();
|
return new File(Environment.getExternalStorageDirectory(), FILENAME);
|
||||||
return sdDirectory.getAbsolutePath() + File.separator + "TextSecurePlaintextBackup.xml";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void exportPlaintext(Context context, MasterSecret masterSecret)
|
private static void exportPlaintext(Context context, MasterSecret masterSecret)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
int count = DatabaseFactory.getSmsDatabase(context).getMessageCount();
|
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;
|
SmsMessageRecord record;
|
||||||
|
@ -9,7 +9,6 @@ import android.util.Log;
|
|||||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
@ -30,14 +29,18 @@ public class PlaintextBackupImporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyExternalStorageForPlaintextImport() throws NoExternalStorageException {
|
private static void verifyExternalStorageForPlaintextImport() throws NoExternalStorageException {
|
||||||
if (!Environment.getExternalStorageDirectory().canRead() ||
|
if (!Environment.getExternalStorageDirectory().canRead() || !getPlaintextExportFile().exists())
|
||||||
!(new File(getPlaintextExportDirectoryPath()).exists()))
|
|
||||||
throw new NoExternalStorageException();
|
throw new NoExternalStorageException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPlaintextExportDirectoryPath() {
|
private static File getPlaintextExportFile() {
|
||||||
File sdDirectory = Environment.getExternalStorageDirectory();
|
File backup = PlaintextBackupExporter.getPlaintextExportFile();
|
||||||
return sdDirectory.getAbsolutePath() + File.separator + "TextSecurePlaintextBackup.xml";
|
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)
|
private static void importPlaintext(Context context, MasterSecret masterSecret)
|
||||||
@ -49,7 +52,7 @@ public class PlaintextBackupImporter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
|
ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
|
||||||
XmlBackup backup = new XmlBackup(getPlaintextExportDirectoryPath());
|
XmlBackup backup = new XmlBackup(getPlaintextExportFile().getAbsolutePath());
|
||||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||||
Set<Long> modifiedThreads = new HashSet<Long>();
|
Set<Long> modifiedThreads = new HashSet<Long>();
|
||||||
XmlBackup.XmlBackupItem item;
|
XmlBackup.XmlBackupItem item;
|
||||||
|
@ -144,7 +144,7 @@ public class XmlBackup {
|
|||||||
public static class Writer {
|
public static class Writer {
|
||||||
|
|
||||||
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
|
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 OPEN_TAG_SMSES = "<smses count=\"%d\">";
|
||||||
private static final String CLOSE_TAG_SMSES = "</smses>";
|
private static final String CLOSE_TAG_SMSES = "</smses>";
|
||||||
private static final String OPEN_TAG_SMS = " <sms ";
|
private static final String OPEN_TAG_SMS = " <sms ";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user