Search in sources :

Example 1 with SendReq

use of ws.com.google.android.mms.pdu.SendReq 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 2 with SendReq

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

the class MmsSendJob method constructSendPdu.

private SendReq constructSendPdu(MasterSecret masterSecret, OutgoingMediaMessage message) throws UndeliverableMessageException {
    SendReq sendReq = new SendReq();
    PduBody body = new PduBody();
    List<String> numbers = message.getRecipients().toNumberStringList(true);
    for (String number : numbers) {
        if (message.getDistributionType() == DistributionTypes.CONVERSATION) {
            sendReq.addTo(new EncodedStringValue(Util.toIsoBytes(number)));
        } else {
            sendReq.addBcc(new EncodedStringValue(Util.toIsoBytes(number)));
        }
    }
    sendReq.setDate(message.getSentTimeMillis() / 1000L);
    if (!TextUtils.isEmpty(message.getBody())) {
        PduPart part = new PduPart();
        part.setData(Util.toUtf8Bytes(message.getBody()));
        part.setCharset(CharacterSets.UTF_8);
        part.setContentType(ContentType.TEXT_PLAIN.getBytes());
        part.setContentId((System.currentTimeMillis() + "").getBytes());
        part.setName(("Text" + System.currentTimeMillis()).getBytes());
        body.addPart(part);
    }
    List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.MMS_CONSTRAINTS, message.getAttachments());
    for (Attachment attachment : scaledAttachments) {
        try {
            if (attachment.getDataUri() == null)
                throw new IOException("Assertion failed, attachment for outgoing MMS has no data!");
            PduPart part = new PduPart();
            part.setData(Util.readFully(PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri())));
            part.setContentType(Util.toIsoBytes(attachment.getContentType()));
            part.setContentId((System.currentTimeMillis() + "").getBytes());
            part.setName((System.currentTimeMillis() + "").getBytes());
            body.addPart(part);
        } catch (IOException e) {
            Log.w(TAG, e);
        }
    }
    sendReq.setBody(body);
    return sendReq;
}
Also used : EncodedStringValue(ws.com.google.android.mms.pdu.EncodedStringValue) PduBody(ws.com.google.android.mms.pdu.PduBody) PduPart(ws.com.google.android.mms.pdu.PduPart) Attachment(org.thoughtcrime.securesms.attachments.Attachment) IOException(java.io.IOException) SendReq(ws.com.google.android.mms.pdu.SendReq)

Aggregations

IOException (java.io.IOException)2 SendReq (ws.com.google.android.mms.pdu.SendReq)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)1 MmsSendResult (org.thoughtcrime.securesms.mms.MmsSendResult)1 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)1 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)1 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)1 EncodedStringValue (ws.com.google.android.mms.pdu.EncodedStringValue)1 PduBody (ws.com.google.android.mms.pdu.PduBody)1 PduPart (ws.com.google.android.mms.pdu.PduPart)1 SendConf (ws.com.google.android.mms.pdu.SendConf)1