Search in sources :

Example 6 with SmsDatabase

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

the class PushDecryptJob method handleNoSessionMessage.

private void handleNoSessionMessage(@NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsNoSession(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsNoSession(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 7 with SmsDatabase

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

the class PushDecryptJob method handleEndSessionMessage.

private void handleEndSessionMessage(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) {
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    IncomingTextMessage incomingTextMessage = new IncomingTextMessage(Address.fromExternal(context, envelope.getSource()), envelope.getSourceDevice(), message.getTimestamp(), "", Optional.absent(), 0);
    Long threadId;
    if (!smsMessageId.isPresent()) {
        IncomingEndSessionMessage incomingEndSessionMessage = new IncomingEndSessionMessage(incomingTextMessage);
        Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(incomingEndSessionMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
    } else {
        smsDatabase.markAsEndSession(smsMessageId.get());
        threadId = smsDatabase.getThreadIdForMessage(smsMessageId.get());
    }
    if (threadId != null) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(envelope.getSource());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        MessageNotifier.updateNotification(context, threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) IncomingEndSessionMessage(org.thoughtcrime.securesms.sms.IncomingEndSessionMessage) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 8 with SmsDatabase

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

the class PushDecryptJob method handleInvalidVersionMessage.

private void handleInvalidVersionMessage(@NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsInvalidVersionKeyExchange(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsInvalidVersionKeyExchange(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 9 with SmsDatabase

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

the class SmsSendJob method onSend.

@Override
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
    } catch (UndeliverableMessageException ude) {
        Log.w(TAG, ude);
        DatabaseFactory.getSmsDatabase(context).markAsSentFailed(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipient(), record.getThreadId());
    }
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 10 with SmsDatabase

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

the class MessageDetailsActivity method getMessageRecord.

@Nullable
private MessageRecord getMessageRecord(Context context, Cursor cursor, String type) {
    switch(type) {
        case MmsSmsDatabase.SMS_TRANSPORT:
            EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
            SmsDatabase.Reader reader = smsDatabase.readerFor(masterSecret, cursor);
            return reader.getNext();
        case MmsSmsDatabase.MMS_TRANSPORT:
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            MmsDatabase.Reader mmsReader = mmsDatabase.readerFor(masterSecret, cursor);
            return mmsReader.getNext();
        default:
            throw new AssertionError("no valid message type specified");
    }
}
Also used : EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Nullable(android.support.annotation.Nullable)

Aggregations

SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)20 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)8 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)5 Nullable (android.support.annotation.Nullable)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)3 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)3 Intent (android.content.Intent)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 Address (org.thoughtcrime.securesms.database.Address)2 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SessionStore (org.whispersystems.libsignal.state.SessionStore)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 AlertDialog (android.support.v7.app.AlertDialog)1 ByteString (com.google.protobuf.ByteString)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1