Search in sources :

Example 6 with EncryptingSmsDatabase

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

the class SmsSendJob method onSend.

@Override
public void onSend(MasterSecret masterSecret) throws NoSuchMessageException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, 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.getRecipients(), record.getThreadId());
    }
}
Also used : SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException)

Example 7 with EncryptingSmsDatabase

use of org.thoughtcrime.securesms.database.EncryptingSmsDatabase 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)

Example 8 with EncryptingSmsDatabase

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

the class PushDecryptJob method handleTextMessage.

private void handleTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    Recipients recipients = getMessageDestination(envelope, message);
    if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
        handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
    }
    Long threadId;
    if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
        threadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body).second;
    } else {
        IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000);
        textMessage = new IncomingEncryptedMessage(textMessage, body);
        Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, textMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
        if (smsMessageId.isPresent())
            database.deleteMessage(smsMessageId.get());
    }
    if (threadId != null) {
        MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 9 with EncryptingSmsDatabase

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

the class PushDecryptJob method handleInvalidVersionMessage.

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

Example 10 with EncryptingSmsDatabase

use of org.thoughtcrime.securesms.database.EncryptingSmsDatabase 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)

Aggregations

EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)19 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)9 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)4 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 Nullable (android.support.annotation.Nullable)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SessionStore (org.whispersystems.libsignal.state.SessionStore)2 ByteString (com.google.protobuf.ByteString)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)1 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)1