2013-06-25 04:02:30 +00:00
|
|
|
package org.thoughtcrime.securesms.database;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2013-06-25 04:02:30 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
2017-03-28 22:20:35 +00:00
|
|
|
import org.thoughtcrime.securesms.util.StorageUtil;
|
2013-06-25 04:02:30 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class PlaintextBackupExporter {
|
|
|
|
|
2016-02-19 11:14:17 +00:00
|
|
|
private static final String FILENAME = "SignalPlaintextBackup.xml";
|
|
|
|
|
2013-06-25 04:02:30 +00:00
|
|
|
public static void exportPlaintextToSd(Context context, MasterSecret masterSecret)
|
|
|
|
throws NoExternalStorageException, IOException
|
|
|
|
{
|
|
|
|
exportPlaintext(context, masterSecret);
|
|
|
|
}
|
|
|
|
|
2017-03-28 22:20:35 +00:00
|
|
|
public static File getPlaintextExportFile() throws NoExternalStorageException {
|
|
|
|
return new File(StorageUtil.getBackupDir(), FILENAME);
|
2013-06-25 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void exportPlaintext(Context context, MasterSecret masterSecret)
|
2017-03-28 22:20:35 +00:00
|
|
|
throws NoExternalStorageException, IOException
|
2013-06-25 04:02:30 +00:00
|
|
|
{
|
|
|
|
int count = DatabaseFactory.getSmsDatabase(context).getMessageCount();
|
2016-02-19 11:14:17 +00:00
|
|
|
XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportFile().getAbsolutePath(), count);
|
2013-06-25 04:02:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
SmsMessageRecord record;
|
|
|
|
EncryptingSmsDatabase.Reader reader = null;
|
|
|
|
int skip = 0;
|
|
|
|
int ROW_LIMIT = 500;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (reader != null)
|
|
|
|
reader.close();
|
|
|
|
|
|
|
|
reader = DatabaseFactory.getEncryptingSmsDatabase(context).getMessages(masterSecret, skip, ROW_LIMIT);
|
|
|
|
|
|
|
|
while ((record = reader.getNext()) != null) {
|
|
|
|
XmlBackup.XmlBackupItem item =
|
2017-07-26 16:59:15 +00:00
|
|
|
new XmlBackup.XmlBackupItem(0, record.getIndividualRecipient().getAddress().serialize(),
|
2017-03-27 22:41:16 +00:00
|
|
|
record.getIndividualRecipient().getName(),
|
2013-06-25 04:02:30 +00:00
|
|
|
record.getDateReceived(),
|
|
|
|
MmsSmsColumns.Types.translateToSystemBaseType(record.getType()),
|
|
|
|
null, record.getDisplayBody().toString(), null,
|
|
|
|
1, record.getDeliveryStatus());
|
|
|
|
|
|
|
|
writer.writeItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
skip += ROW_LIMIT;
|
|
|
|
} while (reader.getCount() > 0);
|
|
|
|
|
|
|
|
writer.close();
|
|
|
|
}
|
|
|
|
}
|