Search in sources :

Example 1 with CompatMmsConnection

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

the class MmsDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Optional<Pair<NotificationInd, Integer>> notification = database.getNotification(messageId);
    if (!notification.isPresent()) {
        Log.w(TAG, "No notification for ID: " + messageId);
        return;
    }
    try {
        if (notification.get().first.getContentLocation() == null) {
            throw new MmsException("Notification content location was null.");
        }
        database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_CONNECTING);
        String contentLocation = new String(notification.get().first.getContentLocation());
        byte[] transactionId = notification.get().first.getTransactionId();
        Log.w(TAG, "Downloading mms at " + Uri.parse(contentLocation).getHost());
        RetrieveConf retrieveConf = new CompatMmsConnection(context).retrieve(contentLocation, transactionId, notification.get().second);
        if (retrieveConf == null) {
            throw new MmsException("RetrieveConf was null");
        }
        storeRetrievedMms(masterSecret, contentLocation, messageId, threadId, retrieveConf, notification.get().second);
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE, automatic);
    } catch (MmsException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_HARD_FAILURE, automatic);
    } catch (MmsRadioException | IOException e) {
        Log.w(TAG, e);
        handleDownloadError(masterSecret, messageId, threadId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE, automatic);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptDuplicate(messageId, threadId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        database.markAsLegacyVersion(messageId, threadId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        database.markAsNoSession(messageId, threadId);
    } catch (InvalidMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptFailed(messageId, threadId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IOException(java.io.IOException) NoSessionException(org.whispersystems.libsignal.NoSessionException) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsException(ws.com.google.android.mms.MmsException) ApnUnavailableException(org.thoughtcrime.securesms.mms.ApnUnavailableException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) MmsRadioException(org.thoughtcrime.securesms.mms.MmsRadioException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) RetrieveConf(ws.com.google.android.mms.pdu.RetrieveConf) Pair(android.util.Pair)

Example 2 with CompatMmsConnection

use of org.thoughtcrime.securesms.mms.CompatMmsConnection in project Signal-Android by signalapp.

the class MmsDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    Optional<MmsDatabase.MmsNotificationInfo> notification = database.getNotification(messageId);
    if (!notification.isPresent()) {
        Log.w(TAG, "No notification for ID: " + messageId);
        return;
    }
    try {
        if (notification.get().getContentLocation() == null) {
            throw new MmsException("Notification content location was null.");
        }
        if (!TextSecurePreferences.isPushRegistered(context)) {
            throw new MmsException("Not registered");
        }
        database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_CONNECTING);
        String contentLocation = notification.get().getContentLocation();
        byte[] transactionId = new byte[0];
        try {
            if (notification.get().getTransactionId() != null) {
                transactionId = notification.get().getTransactionId().getBytes(CharacterSets.MIMENAME_ISO_8859_1);
            } else {
                Log.w(TAG, "No transaction ID!");
            }
        } catch (UnsupportedEncodingException e) {
            Log.w(TAG, e);
        }
        Log.w(TAG, "Downloading mms at " + Uri.parse(contentLocation).getHost() + ", subscription ID: " + notification.get().getSubscriptionId());
        RetrieveConf retrieveConf = new CompatMmsConnection(context).retrieve(contentLocation, transactionId, notification.get().getSubscriptionId());
        if (retrieveConf == null) {
            throw new MmsException("RetrieveConf was null");
        }
        storeRetrievedMms(contentLocation, messageId, threadId, retrieveConf, notification.get().getSubscriptionId(), notification.get().getFrom());
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE, automatic);
    } catch (MmsException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_HARD_FAILURE, automatic);
    } catch (MmsRadioException | IOException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE, automatic);
    } catch (DuplicateMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptDuplicate(messageId, threadId);
    } catch (LegacyMessageException e) {
        Log.w(TAG, e);
        database.markAsLegacyVersion(messageId, threadId);
    } catch (NoSessionException e) {
        Log.w(TAG, e);
        database.markAsNoSession(messageId, threadId);
    } catch (InvalidMessageException e) {
        Log.w(TAG, e);
        database.markAsDecryptFailed(messageId, threadId);
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) NoSessionException(org.whispersystems.libsignal.NoSessionException) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsException(org.thoughtcrime.securesms.mms.MmsException) ApnUnavailableException(org.thoughtcrime.securesms.mms.ApnUnavailableException) DuplicateMessageException(org.whispersystems.libsignal.DuplicateMessageException) MmsRadioException(org.thoughtcrime.securesms.mms.MmsRadioException) LegacyMessageException(org.whispersystems.libsignal.LegacyMessageException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Example 3 with CompatMmsConnection

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

use of org.thoughtcrime.securesms.mms.CompatMmsConnection in project Signal-Android by signalapp.

the class MmsSendJob method onSend.

@Override
public void onSend(MasterSecret masterSecret) throws MmsException, NoSuchMessageException, IOException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
    try {
        SendReq pdu = constructSendPdu(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(com.google.android.mms.pdu_alt.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(com.google.android.mms.pdu_alt.SendReq) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 5 with CompatMmsConnection

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

the class MmsDownloadJob method onRun.

@Override
public void onRun() {
    if (SignalStore.account().getE164() == null) {
        throw new NotReadyException();
    }
    MessageDatabase database = SignalDatabase.mms();
    Optional<MmsDatabase.MmsNotificationInfo> notification = database.getNotification(messageId);
    if (!notification.isPresent()) {
        Log.w(TAG, "No notification for ID: " + messageId);
        return;
    }
    try {
        if (notification.get().getContentLocation() == null) {
            throw new MmsException("Notification content location was null.");
        }
        if (!SignalStore.account().isRegistered()) {
            throw new MmsException("Not registered");
        }
        database.markDownloadState(messageId, MmsDatabase.Status.DOWNLOAD_CONNECTING);
        String contentLocation = notification.get().getContentLocation();
        byte[] transactionId = new byte[0];
        try {
            if (notification.get().getTransactionId() != null) {
                transactionId = notification.get().getTransactionId().getBytes(CharacterSets.MIMENAME_ISO_8859_1);
            } else {
                Log.w(TAG, "No transaction ID!");
            }
        } catch (UnsupportedEncodingException e) {
            Log.w(TAG, e);
        }
        Log.i(TAG, "Downloading mms at " + Uri.parse(contentLocation).getHost() + ", subscription ID: " + notification.get().getSubscriptionId());
        RetrieveConf retrieveConf = new CompatMmsConnection(context).retrieve(contentLocation, transactionId, notification.get().getSubscriptionId());
        if (retrieveConf == null) {
            throw new MmsException("RetrieveConf was null");
        }
        storeRetrievedMms(contentLocation, messageId, threadId, retrieveConf, notification.get().getSubscriptionId(), notification.get().getFrom());
    } catch (ApnUnavailableException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_APN_UNAVAILABLE, automatic);
    } catch (MmsException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_HARD_FAILURE, automatic);
    } catch (MmsRadioException | IOException e) {
        Log.w(TAG, e);
        handleDownloadError(messageId, threadId, MmsDatabase.Status.DOWNLOAD_SOFT_FAILURE, automatic);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) CompatMmsConnection(org.thoughtcrime.securesms.mms.CompatMmsConnection) MmsException(org.thoughtcrime.securesms.mms.MmsException) ApnUnavailableException(org.thoughtcrime.securesms.mms.ApnUnavailableException) MmsRadioException(org.thoughtcrime.securesms.mms.MmsRadioException) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Aggregations

IOException (java.io.IOException)6 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)6 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)4 ApnUnavailableException (org.thoughtcrime.securesms.mms.ApnUnavailableException)3 MmsRadioException (org.thoughtcrime.securesms.mms.MmsRadioException)3 MmsSendResult (org.thoughtcrime.securesms.mms.MmsSendResult)3 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)3 InsecureFallbackApprovalException (org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)3 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)3 RetrieveConf (com.google.android.mms.pdu_alt.RetrieveConf)2 SendConf (com.google.android.mms.pdu_alt.SendConf)2 SendReq (com.google.android.mms.pdu_alt.SendReq)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)2 MmsException (org.thoughtcrime.securesms.mms.MmsException)2 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 LegacyMessageException (org.whispersystems.libsignal.LegacyMessageException)2 NoSessionException (org.whispersystems.libsignal.NoSessionException)2 Pair (android.util.Pair)1