Search in sources :

Example 1 with UndeliverableMessageException

use of org.thoughtcrime.securesms.transport.UndeliverableMessageException 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 2 with UndeliverableMessageException

use of org.thoughtcrime.securesms.transport.UndeliverableMessageException in project Signal-Android by WhisperSystems.

the class OutgoingLollipopMmsConnection method send.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        Util.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, null, getPendingIntent());
        waitForResult();
        Log.w(TAG, "MMS broadcast received and processed.");
        pointer.close();
        if (response == null) {
            throw new UndeliverableMessageException("Null response.");
        }
        return (SendConf) new PduParser(response).parse();
    } catch (IOException | TimeoutException e) {
        throw new UndeliverableMessageException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) SendConf(ws.com.google.android.mms.pdu.SendConf) PduParser(ws.com.google.android.mms.pdu.PduParser) ByteArrayInputStream(java.io.ByteArrayInputStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(android.support.annotation.Nullable)

Example 3 with UndeliverableMessageException

use of org.thoughtcrime.securesms.transport.UndeliverableMessageException 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 4 with UndeliverableMessageException

use of org.thoughtcrime.securesms.transport.UndeliverableMessageException in project Signal-Android by WhisperSystems.

the class PushMediaSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message) throws RetryLaterException, InsecureFallbackApprovalException, UntrustedIdentityException, UndeliverableMessageException {
    if (message.getRecipients() == null || message.getRecipients().getPrimaryRecipient() == null || message.getRecipients().getPrimaryRecipient().getNumber() == null) {
        throw new UndeliverableMessageException("No destination address.");
    }
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    try {
        SignalServiceAddress address = getPushAddress(message.getRecipients().getPrimaryRecipient().getNumber());
        List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
        List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
        SignalServiceDataMessage mediaMessage = SignalServiceDataMessage.newBuilder().withBody(message.getBody()).withAttachments(attachmentStreams).withTimestamp(message.getSentTimeMillis()).withExpiration((int) (message.getExpiresIn() / 1000)).asExpirationUpdate(message.isExpirationUpdate()).build();
        messageSender.sendMessage(address, mediaMessage);
    } catch (InvalidNumberException | UnregisteredUserException e) {
        Log.w(TAG, e);
        throw new InsecureFallbackApprovalException(e);
    } catch (FileNotFoundException e) {
        Log.w(TAG, e);
        throw new UndeliverableMessageException(e);
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new RetryLaterException(e);
    }
}
Also used : UnregisteredUserException(org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) FileNotFoundException(java.io.FileNotFoundException) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException)

Example 5 with UndeliverableMessageException

use of org.thoughtcrime.securesms.transport.UndeliverableMessageException in project Signal-Android by WhisperSystems.

the class MmsSendJob method getPduBytes.

private byte[] getPduBytes(SendReq message) throws IOException, UndeliverableMessageException, InsecureFallbackApprovalException {
    String number = TelephonyUtil.getManager(context).getLine1Number();
    message.setBody(SmilUtil.getSmilBody(message.getBody()));
    if (!TextUtils.isEmpty(number)) {
        message.setFrom(new EncodedStringValue(number));
    }
    byte[] pduBytes = new PduComposer(context, message).make();
    if (pduBytes == null) {
        throw new UndeliverableMessageException("PDU composition failed, null payload");
    }
    return pduBytes;
}
Also used : EncodedStringValue(ws.com.google.android.mms.pdu.EncodedStringValue) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) PduComposer(ws.com.google.android.mms.pdu.PduComposer)

Aggregations

UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)8 IOException (java.io.IOException)5 Nullable (android.support.annotation.Nullable)2 LinkedList (java.util.LinkedList)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)2 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)2 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)2 SendConf (ws.com.google.android.mms.pdu.SendConf)2 TargetApi (android.annotation.TargetApi)1 SmsManager (android.telephony.SmsManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 AttachmentDatabase (org.thoughtcrime.securesms.database.AttachmentDatabase)1 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)1 NetworkFailure (org.thoughtcrime.securesms.database.documents.NetworkFailure)1 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)1