use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class MmsDatabase method markExpireStarted.
@Override
public void markExpireStarted(long messageId, long startedTimestamp) {
ContentValues contentValues = new ContentValues();
contentValues.put(EXPIRE_STARTED, startedTimestamp);
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { String.valueOf(messageId) });
long threadId = getThreadIdForMessage(messageId);
notifyConversationListeners(threadId);
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class MmsDatabase method setTimestampRead.
public List<Pair<Long, Long>> setTimestampRead(SyncMessageId messageId, long expireStarted) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
List<Pair<Long, Long>> expiring = new LinkedList<>();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, MESSAGE_BOX, EXPIRES_IN, ADDRESS }, DATE_SENT + " = ?", new String[] { String.valueOf(messageId.getTimetamp()) }, null, null, null, null);
while (cursor.moveToNext()) {
Address theirAddress = Address.fromSerialized(cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS)));
Address ourAddress = messageId.getAddress();
if (ourAddress.equals(theirAddress) || theirAddress.isGroup()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
ContentValues values = new ContentValues();
values.put(READ, 1);
if (expiresIn > 0) {
values.put(EXPIRE_STARTED, expireStarted);
expiring.add(new Pair<>(id, expiresIn));
}
database.update(TABLE_NAME, values, ID_WHERE, new String[] { String.valueOf(id) });
DatabaseFactory.getThreadDatabase(context).updateReadState(threadId);
DatabaseFactory.getThreadDatabase(context).setLastSeen(threadId);
notifyConversationListeners(threadId);
}
}
} finally {
if (cursor != null)
cursor.close();
}
return expiring;
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class OneTimePreKeyDatabase method removePreKey.
public void removePreKey(int keyId) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
database.delete(TABLE_NAME, KEY_ID + " = ?", new String[] { String.valueOf(keyId) });
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class OneTimePreKeyDatabase method insertPreKey.
public void insertPreKey(int keyId, PreKeyRecord record) {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ID, keyId);
contentValues.put(PUBLIC_KEY, Base64.encodeBytes(record.getKeyPair().getPublicKey().serialize()));
contentValues.put(PRIVATE_KEY, Base64.encodeBytes(record.getKeyPair().getPrivateKey().serialize()));
database.replace(TABLE_NAME, null, contentValues);
}
use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.
the class OneTimePreKeyDatabase method getPreKey.
@Nullable
public PreKeyRecord getPreKey(int keyId) {
SQLiteDatabase database = databaseHelper.getReadableDatabase();
try (Cursor cursor = database.query(TABLE_NAME, null, KEY_ID + " = ?", new String[] { String.valueOf(keyId) }, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
try {
ECPublicKey publicKey = Curve.decodePoint(Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(PUBLIC_KEY))), 0);
ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(PRIVATE_KEY))));
return new PreKeyRecord(keyId, new ECKeyPair(publicKey, privateKey));
} catch (InvalidKeyException | IOException e) {
Log.w(TAG, e);
}
}
}
return null;
}
Aggregations