Search in sources :

Example 76 with SQLiteDatabase

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);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 77 with SQLiteDatabase

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;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Pair(android.util.Pair)

Example 78 with SQLiteDatabase

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) });
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 79 with SQLiteDatabase

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);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 80 with SQLiteDatabase

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;
}
Also used : ECPrivateKey(org.whispersystems.libsignal.ecc.ECPrivateKey) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) PreKeyRecord(org.whispersystems.libsignal.state.PreKeyRecord) IOException(java.io.IOException) Cursor(android.database.Cursor) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) Nullable(android.support.annotation.Nullable)

Aggregations

SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)124 Cursor (android.database.Cursor)37 ContentValues (android.content.ContentValues)32 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)12 NonNull (android.support.annotation.NonNull)7 MergeCursor (android.database.MergeCursor)6 Nullable (android.support.annotation.Nullable)6 Pair (android.util.Pair)6 File (java.io.File)5 SQLiteConstraintException (net.sqlcipher.database.SQLiteConstraintException)5 FileNotFoundException (java.io.FileNotFoundException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AudioClipTable (org.storymaker.app.model.AudioClipTable)4 AuthTable (org.storymaker.app.model.AuthTable)4 JobTable (org.storymaker.app.model.JobTable)4 LessonTable (org.storymaker.app.model.LessonTable)4 MediaTable (org.storymaker.app.model.MediaTable)4 ProjectTable (org.storymaker.app.model.ProjectTable)4