Search in sources :

Example 16 with SmsDatabase

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

the class PushDecryptJob method handleSynchronizeSentEndSessionMessage.

private long handleSynchronizeSentEndSessionMessage(@NonNull SentTranscriptMessage message) {
    SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
    Recipient recipient = getSyncMessageDestination(message);
    OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, "", -1);
    OutgoingEndSessionMessage outgoingEndSessionMessage = new OutgoingEndSessionMessage(outgoingTextMessage);
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    if (!recipient.isGroupRecipient()) {
        SessionStore sessionStore = new TextSecureSessionStore(context);
        sessionStore.deleteAllSessions(recipient.getAddress().toPhoneString());
        SecurityEvent.broadcastSecurityUpdateEvent(context);
        long messageId = database.insertMessageOutbox(threadId, outgoingEndSessionMessage, false, message.getTimestamp(), null);
        database.markAsSent(messageId, true);
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingEndSessionMessage(org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 17 with SmsDatabase

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

the class PushDecryptJob method handleUntrustedIdentityMessage.

private void handleUntrustedIdentityMessage(@NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    try {
        SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
        Address sourceAddress = Address.fromExternal(context, envelope.getSource());
        byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage() : envelope.getContent();
        PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
        IdentityKey identityKey = whisperMessage.getIdentityKey();
        String encoded = Base64.encodeBytes(serialized);
        IncomingTextMessage textMessage = new IncomingTextMessage(sourceAddress, envelope.getSourceDevice(), envelope.getTimestamp(), encoded, Optional.absent(), 0);
        if (!smsMessageId.isPresent()) {
            IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
            Optional<InsertResult> insertResult = database.insertMessageInbox(bundleMessage);
            if (insertResult.isPresent()) {
                database.setMismatchedIdentity(insertResult.get().getMessageId(), sourceAddress, identityKey);
                MessageNotifier.updateNotification(context, insertResult.get().getThreadId());
            }
        } else {
            database.updateMessageBody(smsMessageId.get(), encoded);
            database.markAsPreKeyBundle(smsMessageId.get());
            database.setMismatchedIdentity(smsMessageId.get(), sourceAddress, identityKey);
        }
    } catch (InvalidMessageException | InvalidVersionException e) {
        throw new AssertionError(e);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IdentityKey(org.whispersystems.libsignal.IdentityKey) Address(org.thoughtcrime.securesms.database.Address) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) IncomingPreKeyBundleMessage(org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage) PreKeySignalMessage(org.whispersystems.libsignal.protocol.PreKeySignalMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase)

Example 18 with SmsDatabase

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

the class PushDecryptJob method handleCallOfferMessage.

private void handleCallOfferMessage(@NonNull SignalServiceEnvelope envelope, @NonNull OfferMessage message, @NonNull Optional<Long> smsMessageId) {
    Log.w(TAG, "handleCallOfferMessage...");
    if (smsMessageId.isPresent()) {
        SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
        database.markAsMissedCall(smsMessageId.get());
    } else {
        Intent intent = new Intent(context, WebRtcCallService.class);
        intent.setAction(WebRtcCallService.ACTION_INCOMING_CALL);
        intent.putExtra(WebRtcCallService.EXTRA_CALL_ID, message.getId());
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, Address.fromExternal(context, envelope.getSource()));
        intent.putExtra(WebRtcCallService.EXTRA_REMOTE_DESCRIPTION, message.getDescription());
        intent.putExtra(WebRtcCallService.EXTRA_TIMESTAMP, envelope.getTimestamp());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
            context.startForegroundService(intent);
        else
            context.startService(intent);
    }
}
Also used : SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 19 with SmsDatabase

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

the class PushDecryptJob method handleLegacyMessage.

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

Example 20 with SmsDatabase

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

the class MessageDetailsActivity method getMessageRecord.

@Nullable
private MessageRecord getMessageRecord(Context context, Cursor cursor, String type) {
    switch(type) {
        case MmsSmsDatabase.SMS_TRANSPORT:
            SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
            SmsDatabase.Reader reader = smsDatabase.readerFor(cursor);
            return reader.getNext();
        case MmsSmsDatabase.MMS_TRANSPORT:
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            MmsDatabase.Reader mmsReader = mmsDatabase.readerFor(cursor);
            return mmsReader.getNext();
        default:
            throw new AssertionError("no valid message type specified");
    }
}
Also used : MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) 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