Search in sources :

Example 11 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class MmsDatabase method getThreadIdFor.

private long getThreadIdFor(IncomingMediaMessage retrieved) throws RecipientFormattingException, MmsException {
    if (retrieved.getGroupId() != null) {
        Recipients groupRecipients = RecipientFactory.getRecipientsFromString(context, retrieved.getGroupId(), true);
        return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(groupRecipients);
    }
    String localNumber;
    Set<String> group = new HashSet<>();
    if (retrieved.getAddresses().getFrom() == null) {
        throw new MmsException("FROM value in PduHeaders did not exist.");
    }
    group.add(retrieved.getAddresses().getFrom());
    if (TextSecurePreferences.isPushRegistered(context)) {
        localNumber = TextSecurePreferences.getLocalNumber(context);
    } else {
        localNumber = ServiceUtil.getTelephonyManager(context).getLine1Number();
    }
    for (String cc : retrieved.getAddresses().getCc()) {
        PhoneNumberUtil.MatchType match;
        if (localNumber == null)
            match = PhoneNumberUtil.MatchType.NO_MATCH;
        else
            match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, cc);
        if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) {
            group.add(cc);
        }
    }
    if (retrieved.getAddresses().getTo().size() > 1) {
        for (String to : retrieved.getAddresses().getTo()) {
            PhoneNumberUtil.MatchType match;
            if (localNumber == null)
                match = PhoneNumberUtil.MatchType.NO_MATCH;
            else
                match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, to);
            if (match == PhoneNumberUtil.MatchType.NO_MATCH || match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) {
                group.add(to);
            }
        }
    }
    String recipientsList = Util.join(group, ",");
    Recipients recipients = RecipientFactory.getRecipientsFromString(context, recipientsList, false);
    return DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
}
Also used : MmsException(ws.com.google.android.mms.MmsException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) HashSet(java.util.HashSet)

Example 12 with MmsException

use of ws.com.google.android.mms.MmsException 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)

Example 13 with MmsException

use of ws.com.google.android.mms.MmsException 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 14 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class SendJob method scaleAttachments.

protected List<Attachment> scaleAttachments(@NonNull MasterSecret masterSecret, @NonNull MediaConstraints constraints, @NonNull List<Attachment> attachments) throws UndeliverableMessageException {
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    List<Attachment> results = new LinkedList<>();
    for (Attachment attachment : attachments) {
        try {
            if (constraints.isSatisfied(context, masterSecret, attachment)) {
                results.add(attachment);
            } else if (constraints.canResize(attachment)) {
                MediaStream resized = constraints.getResizedMedia(context, masterSecret, attachment);
                results.add(attachmentDatabase.updateAttachmentData(masterSecret, attachment, resized));
            } else {
                throw new UndeliverableMessageException("Size constraints could not be met!");
            }
        } catch (IOException | MmsException e) {
            throw new UndeliverableMessageException(e);
        }
    }
    return results;
}
Also used : MmsException(ws.com.google.android.mms.MmsException) MediaStream(org.thoughtcrime.securesms.mms.MediaStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) LinkedList(java.util.LinkedList)

Example 15 with MmsException

use of ws.com.google.android.mms.MmsException in project Signal-Android by WhisperSystems.

the class MessageSender method send.

public static long send(final Context context, final MasterSecret masterSecret, final OutgoingMediaMessage message, final long threadId, final boolean forceSms) {
    try {
        ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
        MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
        long allocatedThreadId;
        if (threadId == -1) {
            allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipients(), message.getDistributionType());
        } else {
            allocatedThreadId = threadId;
        }
        Recipients recipients = message.getRecipients();
        long messageId = database.insertMessageOutbox(new MasterSecretUnion(masterSecret), message, allocatedThreadId, forceSms);
        sendMediaMessage(context, masterSecret, recipients, forceSms, messageId, message.getExpiresIn());
        return allocatedThreadId;
    } catch (MmsException e) {
        Log.w(TAG, e);
        return threadId;
    }
}
Also used : MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) MmsException(ws.com.google.android.mms.MmsException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

MmsException (ws.com.google.android.mms.MmsException)15 IOException (java.io.IOException)5 Recipients (org.thoughtcrime.securesms.recipients.Recipients)5 ContentValues (android.content.ContentValues)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)3 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)3 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)3 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 Pair (android.util.Pair)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)2 LegacyMessageException (org.whispersystems.libsignal.LegacyMessageException)2