Search in sources :

Example 6 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage 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 7 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage 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 8 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleSynchronizeSentMediaMessage.

private long handleSynchronizeSentMediaMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Recipients recipients = getSyncMessageDestination(message);
    OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(recipients, message.getMessage().getBody().orNull(), PointerAttachment.forPointers(masterSecret, message.getMessage().getAttachments()), message.getTimestamp(), -1, message.getMessage().getExpiresInSeconds() * 1000, ThreadDatabase.DistributionTypes.DEFAULT);
    mediaMessage = new OutgoingSecureMediaMessage(mediaMessage);
    if (recipients.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(masterSecret, message, Optional.<Long>absent());
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
    long messageId = database.insertMessageOutbox(masterSecret, mediaMessage, threadId, false);
    database.markAsSent(messageId, true);
    for (DatabaseAttachment attachment : DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageId)) {
        ApplicationContext.getInstance(context).getJobManager().add(new AttachmentDownloadJob(context, messageId, attachment.getAttachmentId()));
    }
    if (smsMessageId.isPresent()) {
        DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }
    if (message.getMessage().getExpiresInSeconds() > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, true, message.getExpirationStartTimestamp(), message.getMessage().getExpiresInSeconds());
    }
    return threadId;
}
Also used : OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 9 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage in project Signal-Android by WhisperSystems.

the class MmsDatabase method copyMessageInbox.

public long copyMessageInbox(MasterSecret masterSecret, long messageId) throws MmsException {
    try {
        OutgoingMediaMessage request = getOutgoingMessage(masterSecret, messageId);
        ContentValues contentValues = new ContentValues();
        contentValues.put(ADDRESS, request.getRecipients().getPrimaryRecipient().getNumber());
        contentValues.put(DATE_SENT, request.getSentTimeMillis());
        contentValues.put(MESSAGE_BOX, Types.BASE_INBOX_TYPE | Types.SECURE_MESSAGE_BIT | Types.ENCRYPTION_SYMMETRIC_BIT);
        contentValues.put(THREAD_ID, getThreadIdForMessage(messageId));
        contentValues.put(READ, 1);
        contentValues.put(DATE_RECEIVED, contentValues.getAsLong(DATE_SENT));
        contentValues.put(EXPIRES_IN, request.getExpiresIn());
        List<Attachment> attachments = new LinkedList<>();
        for (Attachment attachment : request.getAttachments()) {
            DatabaseAttachment databaseAttachment = (DatabaseAttachment) attachment;
            attachments.add(new DatabaseAttachment(databaseAttachment.getAttachmentId(), databaseAttachment.getMmsId(), databaseAttachment.hasData(), databaseAttachment.hasThumbnail(), databaseAttachment.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_DONE, databaseAttachment.getSize(), databaseAttachment.getLocation(), databaseAttachment.getKey(), databaseAttachment.getRelay(), databaseAttachment.getDigest()));
        }
        return insertMediaMessage(new MasterSecretUnion(masterSecret), MmsAddresses.forTo(request.getRecipients().toNumberStringList(false)), request.getBody(), attachments, contentValues);
    } catch (NoSuchMessageException e) {
        throw new MmsException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) MmsException(ws.com.google.android.mms.MmsException) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) LinkedList(java.util.LinkedList)

Example 10 with OutgoingMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingMediaMessage in project Signal-Android by WhisperSystems.

the class MmsDatabase method getOutgoingMessage.

public OutgoingMediaMessage getOutgoingMessage(MasterSecret masterSecret, long messageId) throws MmsException, NoSuchMessageException {
    MmsAddressDatabase addr = DatabaseFactory.getMmsAddressDatabase(context);
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    Cursor cursor = null;
    try {
        cursor = rawQuery(RAW_ID_WHERE, new String[] { String.valueOf(messageId) });
        if (cursor != null && cursor.moveToNext()) {
            long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
            String messageText = cursor.getString(cursor.getColumnIndexOrThrow(BODY));
            long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT));
            int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID));
            long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
            List<Attachment> attachments = new LinkedList<Attachment>(attachmentDatabase.getAttachmentsForMessage(messageId));
            MmsAddresses addresses = addr.getAddressesForId(messageId);
            List<String> destinations = new LinkedList<>();
            String body = getDecryptedBody(masterSecret, messageText, outboxType);
            destinations.addAll(addresses.getBcc());
            destinations.addAll(addresses.getCc());
            destinations.addAll(addresses.getTo());
            Recipients recipients = RecipientFactory.getRecipientsFromStrings(context, destinations, false);
            if (body != null && (Types.isGroupQuit(outboxType) || Types.isGroupUpdate(outboxType))) {
                return new OutgoingGroupMediaMessage(recipients, body, attachments, timestamp, 0);
            } else if (Types.isExpirationTimerUpdate(outboxType)) {
                return new OutgoingExpirationUpdateMessage(recipients, timestamp, expiresIn);
            }
            OutgoingMediaMessage message = new OutgoingMediaMessage(recipients, body, attachments, timestamp, subscriptionId, expiresIn, !addresses.getBcc().isEmpty() ? ThreadDatabase.DistributionTypes.BROADCAST : ThreadDatabase.DistributionTypes.DEFAULT);
            if (Types.isSecureType(outboxType)) {
                return new OutgoingSecureMediaMessage(message);
            }
            return message;
        }
        throw new NoSuchMessageException("No record found for id: " + messageId);
    } catch (IOException e) {
        throw new MmsException(e);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) IOException(java.io.IOException) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) MmsException(ws.com.google.android.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage)

Aggregations

OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)10 Recipients (org.thoughtcrime.securesms.recipients.Recipients)6 LinkedList (java.util.LinkedList)5 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)4 List (java.util.List)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)3 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)3 Bundle (android.os.Bundle)2 IOException (java.io.IOException)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)2 Optional (org.whispersystems.libsignal.util.guava.Optional)2 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)2 MmsException (ws.com.google.android.mms.MmsException)2 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Cursor (android.database.Cursor)1