Search in sources :

Example 6 with MmsDatabase

use of org.thoughtcrime.securesms.database.MmsDatabase 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 7 with MmsDatabase

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

the class PushGroupSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws MmsException, IOException, NoSuchMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        deliver(masterSecret, message, filterRecipientId);
        database.markAsSent(messageId, true);
        markAttachmentsUploaded(messageId, message.getAttachments());
        if (message.getExpiresIn() > 0 && !message.isExpirationUpdate()) {
            database.markExpireStarted(messageId);
            ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpiresIn());
        }
    } catch (InvalidNumberException | RecipientFormattingException | UndeliverableMessageException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (EncapsulatedExceptions e) {
        Log.w(TAG, e);
        List<NetworkFailure> failures = new LinkedList<>();
        for (NetworkFailureException nfe : e.getNetworkExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, nfe.getE164number(), false).getPrimaryRecipient();
            failures.add(new NetworkFailure(recipient.getRecipientId()));
        }
        for (UntrustedIdentityException uie : e.getUntrustedIdentityExceptions()) {
            Recipient recipient = RecipientFactory.getRecipientsFromString(context, uie.getE164Number(), false).getPrimaryRecipient();
            database.addMismatchedIdentity(messageId, recipient.getRecipientId(), uie.getIdentityKey());
        }
        database.addFailures(messageId, failures);
        if (e.getNetworkExceptions().isEmpty() && e.getUntrustedIdentityExceptions().isEmpty()) {
            database.markAsSent(messageId, true);
            markAttachmentsUploaded(messageId, message.getAttachments());
        } else {
            database.markAsSentFailed(messageId);
            notifyMediaMessageDeliveryFailed(context, messageId);
        }
    }
}
Also used : EncapsulatedExceptions(org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions) UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) LinkedList(java.util.LinkedList) List(java.util.List) NetworkFailureException(org.whispersystems.signalservice.api.push.exceptions.NetworkFailureException) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 8 with MmsDatabase

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

the class GroupMessageProcessor method storeMessage.

@Nullable
private static Long storeMessage(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupContext storage, boolean outgoing) {
    if (group.getAvatar().isPresent()) {
        ApplicationContext.getInstance(context).getJobManager().add(new AvatarDownloadJob(context, group.getGroupId()));
    }
    try {
        if (outgoing) {
            MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
            Recipients recipients = RecipientFactory.getRecipientsFromString(context, GroupUtil.getEncodedId(group.getGroupId()), false);
            OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(recipients, storage, null, envelope.getTimestamp(), 0);
            long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
            long messageId = mmsDatabase.insertMessageOutbox(masterSecret, outgoingMessage, threadId, false);
            mmsDatabase.markAsSent(messageId, true);
            return threadId;
        } else {
            EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
            String body = Base64.encodeBytes(storage.toByteArray());
            IncomingTextMessage incoming = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), body, Optional.of(group), 0);
            IncomingGroupMessage groupMessage = new IncomingGroupMessage(incoming, storage, body);
            Optional<InsertResult> insertResult = smsDatabase.insertMessageInbox(masterSecret, groupMessage);
            if (insertResult.isPresent()) {
                MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
                return insertResult.get().getThreadId();
            } else {
                return null;
            }
        }
    } catch (MmsException e) {
        Log.w(TAG, e);
    }
    return null;
}
Also used : IncomingGroupMessage(org.thoughtcrime.securesms.sms.IncomingGroupMessage) InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) MmsException(ws.com.google.android.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) AvatarDownloadJob(org.thoughtcrime.securesms.jobs.AvatarDownloadJob) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) ByteString(com.google.protobuf.ByteString) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Nullable(android.support.annotation.Nullable)

Example 9 with MmsDatabase

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

the class MmsSendJob method onSend.

@Override
public void onSend(MasterSecret masterSecret) throws MmsException, NoSuchMessageException, IOException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(masterSecret, messageId);
    try {
        SendReq pdu = constructSendPdu(masterSecret, message);
        validateDestinations(message, pdu);
        final byte[] pduBytes = getPduBytes(pdu);
        final SendConf sendConf = new CompatMmsConnection(context).send(pduBytes, message.getSubscriptionId());
        final MmsSendResult result = getSendResult(sendConf, pdu);
        database.markAsSent(messageId, false);
        markAttachmentsUploaded(messageId, message.getAttachments());
    } catch (UndeliverableMessageException | IOException e) {
        Log.w(TAG, e);
        database.markAsSentFailed(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(messageId);
        notifyMediaMessageDeliveryFailed(context, messageId);
    }
}
Also used : SendConf(ws.com.google.android.mms.pdu.SendConf) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsSendResult(org.thoughtcrime.securesms.mms.MmsSendResult) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) IOException(java.io.IOException) SendReq(ws.com.google.android.mms.pdu.SendReq) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 10 with MmsDatabase

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

Aggregations

MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)17 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)4 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)3 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)3 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)3 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)3 MmsException (ws.com.google.android.mms.MmsException)3 Nullable (android.support.annotation.Nullable)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 Uri (android.net.Uri)1