Search in sources :

Example 11 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.

the class EncryptingSmsDatabase method getMessage.

public SmsMessageRecord getMessage(MasterSecret masterSecret, long messageId) throws NoSuchMessageException {
    Cursor cursor = super.getMessage(messageId);
    DecryptingReader reader = new DecryptingReader(masterSecret, cursor);
    SmsMessageRecord record = reader.getNext();
    reader.close();
    if (record == null)
        throw new NoSuchMessageException("No message for ID: " + messageId);
    else
        return record;
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Cursor(android.database.Cursor)

Example 12 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.

the class SmsSentJob method handleSentResult.

private void handleSentResult(MasterSecret masterSecret, long messageId, int result) {
    try {
        EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
        SmsMessageRecord record = database.getMessage(masterSecret, messageId);
        switch(result) {
            case Activity.RESULT_OK:
                database.markAsSent(messageId, false);
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Log.w(TAG, "Service connectivity problem, requeuing...");
                ApplicationContext.getInstance(context).getJobManager().add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
                break;
            default:
                database.markAsSentFailed(messageId);
                MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        }
    } catch (NoSuchMessageException e) {
        Log.w(TAG, e);
    }
}
Also used : NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 13 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by WhisperSystems.

the class MasterSecretDecryptJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsDatabase.Reader smsReader = smsDatabase.getDecryptInProgressMessages(masterSecret);
    SmsMessageRecord smsRecord;
    while ((smsRecord = smsReader.getNext()) != null) {
        try {
            String body = getAsymmetricDecryptedBody(masterSecret, smsRecord.getBody().getBody());
            smsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), smsRecord.getId(), body);
        } catch (InvalidMessageException e) {
            Log.w(TAG, e);
        }
    }
    MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
    MmsDatabase.Reader mmsReader = mmsDatabase.getDecryptInProgressMessages(masterSecret);
    MessageRecord mmsRecord;
    while ((mmsRecord = mmsReader.getNext()) != null) {
        try {
            String body = getAsymmetricDecryptedBody(masterSecret, mmsRecord.getBody().getBody());
            mmsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), mmsRecord.getId(), body);
        } catch (InvalidMessageException e) {
            Log.w(TAG, e);
        }
    }
    smsReader.close();
    mmsReader.close();
    MessageNotifier.updateNotification(context, masterSecret);
}
Also used : MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 14 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.

the class SmsDatabase method copyMessageInbox.

public Pair<Long, Long> copyMessageInbox(long messageId) {
    try {
        SmsMessageRecord record = getMessage(messageId);
        ContentValues contentValues = new ContentValues();
        contentValues.put(TYPE, (record.getType() & ~Types.BASE_TYPE_MASK) | Types.BASE_INBOX_TYPE);
        contentValues.put(ADDRESS, record.getIndividualRecipient().getAddress().serialize());
        contentValues.put(ADDRESS_DEVICE_ID, record.getRecipientDeviceId());
        contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
        contentValues.put(DATE_SENT, record.getDateSent());
        contentValues.put(PROTOCOL, 31337);
        contentValues.put(READ, 0);
        contentValues.put(BODY, record.getBody());
        contentValues.put(THREAD_ID, record.getThreadId());
        contentValues.put(EXPIRES_IN, record.getExpiresIn());
        SQLiteDatabase db = databaseHelper.getWritableDatabase();
        long newMessageId = db.insert(TABLE_NAME, null, contentValues);
        DatabaseFactory.getThreadDatabase(context).update(record.getThreadId(), true);
        notifyConversationListeners(record.getThreadId());
        jobManager.add(new TrimThreadJob(context, record.getThreadId()));
        return new Pair<>(newMessageId, record.getThreadId());
    } catch (NoSuchMessageException e) {
        throw new AssertionError(e);
    }
}
Also used : ContentValues(android.content.ContentValues) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Pair(android.util.Pair)

Example 15 with SmsMessageRecord

use of org.thoughtcrime.securesms.database.model.SmsMessageRecord in project Signal-Android by signalapp.

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend() throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context, false));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        database.addMismatchedIdentity(record.getId(), Address.fromSerialized(e.getE164Number()), e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Aggregations

SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)17 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)4 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)4 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)4 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)4 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)4 Cursor (android.database.Cursor)3 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)3 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)3 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)3 ContentValues (android.content.ContentValues)2 Pair (android.util.Pair)2 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)2 SyncMessageId (org.thoughtcrime.securesms.database.MessageDatabase.SyncMessageId)2 TrimThreadJob (org.thoughtcrime.securesms.jobs.TrimThreadJob)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 UnidentifiedAccessMode (org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode)1