use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class PlaintextBackupImporter method importPlaintextFromSd.
public static void importPlaintextFromSd(Context context) throws NoExternalStorageException, IOException {
Log.w("PlaintextBackupImporter", "importPlaintext()");
SmsDatabase db = DatabaseFactory.getSmsDatabase(context);
SQLiteDatabase transaction = db.beginTransaction();
try {
ThreadDatabase threads = DatabaseFactory.getThreadDatabase(context);
XmlBackup backup = new XmlBackup(getPlaintextExportFile().getAbsolutePath());
Set<Long> modifiedThreads = new HashSet<>();
XmlBackup.XmlBackupItem item;
while ((item = backup.getNext()) != null) {
Recipient recipient = Recipient.from(context, Address.fromExternal(context, item.getAddress()), false);
long threadId = threads.getThreadIdFor(recipient);
SQLiteStatement statement = db.createInsertStatement(transaction);
if (item.getAddress() == null || item.getAddress().equals("null"))
continue;
if (!isAppropriateTypeForImport(item.getType()))
continue;
addStringToStatement(statement, 1, item.getAddress());
addNullToStatement(statement, 2);
addLongToStatement(statement, 3, item.getDate());
addLongToStatement(statement, 4, item.getDate());
addLongToStatement(statement, 5, item.getProtocol());
addLongToStatement(statement, 6, item.getRead());
addLongToStatement(statement, 7, item.getStatus());
addTranslatedTypeToStatement(statement, 8, item.getType());
addNullToStatement(statement, 9);
addStringToStatement(statement, 10, item.getSubject());
addStringToStatement(statement, 11, item.getBody());
addStringToStatement(statement, 12, item.getServiceCenter());
addLongToStatement(statement, 13, threadId);
modifiedThreads.add(threadId);
statement.execute();
}
for (long threadId : modifiedThreads) {
threads.update(threadId, true);
}
Log.w("PlaintextBackupImporter", "Exited loop");
} catch (XmlPullParserException e) {
Log.w("PlaintextBackupImporter", e);
throw new IOException("XML Parsing error!");
} finally {
db.endTransaction(transaction);
}
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class RecipientDatabase method updateOrInsert.
private void updateOrInsert(Address address, ContentValues contentValues) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
database.beginTransaction();
int updated = database.update(TABLE_NAME, contentValues, ADDRESS + " = ?", new String[] { address.serialize() });
if (updated < 1) {
contentValues.put(ADDRESS, address.serialize());
database.insert(TABLE_NAME, null, contentValues);
}
database.setTransactionSuccessful();
database.endTransaction();
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class RecipientDatabase method getSystemContacts.
public List<Address> getSystemContacts() {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
List<Address> results = new LinkedList<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS }, SYSTEM_DISPLAY_NAME + " IS NOT NULL AND " + SYSTEM_DISPLAY_NAME + " != \"\"", null, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
results.add(Address.fromSerialized(cursor.getString(0)));
}
}
return results;
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class RecipientDatabase method getAllAddresses.
public Set<Address> getAllAddresses() {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Set<Address> results = new HashSet<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS }, null, null, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
results.add(Address.fromExternal(context, cursor.getString(0)));
}
}
return results;
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class RecipientDatabase method getRegistered.
public List<Address> getRegistered() {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
List<Address> results = new LinkedList<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] { ADDRESS }, REGISTERED + " = ?", new String[] { "1" }, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
results.add(Address.fromSerialized(cursor.getString(0)));
}
}
return results;
}
Aggregations