private EncryptingSmsDatabase.Reader getSmsReader() { if (smsReader == null) { if (masterSecret.isPresent()) smsReader = DatabaseFactory.getEncryptingSmsDatabase(context) .readerFor(masterSecret.get(), cursor); else smsReader = DatabaseFactory.getSmsDatabase(context).readerFor(cursor); } return smsReader; }
private static void exportPlaintext(Context context, MasterSecret masterSecret) throws IOException { int count = DatabaseFactory.getSmsDatabase(context).getMessageCount(); XmlBackup.Writer writer = new XmlBackup.Writer(getPlaintextExportDirectoryPath(), count); 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 = new XmlBackup.XmlBackupItem( 0, record.getIndividualRecipient().getNumber(), 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(); }