Search in sources :

Example 86 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SignedPreKeyDatabase method getSignedPreKey.

@Nullable
public SignedPreKeyRecord getSignedPreKey(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))));
                byte[] signature = Base64.decode(cursor.getString(cursor.getColumnIndexOrThrow(SIGNATURE)));
                long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP));
                return new SignedPreKeyRecord(keyId, timestamp, new ECKeyPair(publicKey, privateKey), signature);
            } 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) IOException(java.io.IOException) Cursor(android.database.Cursor) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) SignedPreKeyRecord(org.whispersystems.libsignal.state.SignedPreKeyRecord) Nullable(android.support.annotation.Nullable)

Example 87 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SignedPreKeyDatabase method removeSignedPreKey.

public void removeSignedPreKey(int keyId) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.delete(TABLE_NAME, KEY_ID + " = ? AND " + SIGNATURE + " IS NOT NULL", new String[] { String.valueOf(keyId) });
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 88 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SmsDatabase method deleteThreads.

/*package*/
void deleteThreads(Set<Long> threadIds) {
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    String where = "";
    for (long threadId : threadIds) {
        where += THREAD_ID + " = '" + threadId + "' OR ";
    }
    where = where.substring(0, where.length() - 4);
    db.delete(TABLE_NAME, where, null);
}
Also used : SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 89 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SmsDatabase method markStatus.

public void markStatus(long id, int status) {
    Log.w("MessageDatabase", "Updating ID: " + id + " to status: " + status);
    ContentValues contentValues = new ContentValues();
    contentValues.put(STATUS, status);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] { id + "" });
    long threadId = getThreadIdForMessage(id);
    DatabaseFactory.getThreadDatabase(context).update(threadId, false);
    notifyConversationListeners(threadId);
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase)

Example 90 with SQLiteDatabase

use of net.sqlcipher.database.SQLiteDatabase in project Signal-Android by signalapp.

the class SmsDatabase method insertCallLog.

@NonNull
private Pair<Long, Long> insertCallLog(@NonNull Address address, long type, boolean unread) {
    Recipient recipient = Recipient.from(context, address, true);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    ContentValues values = new ContentValues(6);
    values.put(ADDRESS, address.serialize());
    values.put(ADDRESS_DEVICE_ID, 1);
    values.put(DATE_RECEIVED, System.currentTimeMillis());
    values.put(DATE_SENT, System.currentTimeMillis());
    values.put(READ, unread ? 0 : 1);
    values.put(TYPE, type);
    values.put(THREAD_ID, threadId);
    SQLiteDatabase db = databaseHelper.getWritableDatabase();
    long messageId = db.insert(TABLE_NAME, null, values);
    DatabaseFactory.getThreadDatabase(context).update(threadId, true);
    notifyConversationListeners(threadId);
    jobManager.add(new TrimThreadJob(context, threadId));
    if (unread) {
        DatabaseFactory.getThreadDatabase(context).incrementUnread(threadId, 1);
    }
    return new Pair<>(messageId, threadId);
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Pair(android.util.Pair) NonNull(android.support.annotation.NonNull)

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