Search in sources :

Example 1 with RetrieveConf

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

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

the class IncomingLollipopMmsConnection method retrieve.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized RetrieveConf retrieve(@NonNull String contentLocation, byte[] transactionId, int subscriptionId) throws MmsException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        smsManager.downloadMultimediaMessage(getContext(), contentLocation, pointer.getUri(), null, getPendingIntent());
        waitForResult();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Util.copy(pointer.getInputStream(), baos);
        pointer.close();
        Log.w(TAG, baos.size() + "-byte response: " + Hex.dump(baos.toByteArray()));
        return (RetrieveConf) new PduParser(baos.toByteArray()).parse();
    } catch (IOException | TimeoutException e) {
        Log.w(TAG, e);
        throw new MmsException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) PduParser(ws.com.google.android.mms.pdu.PduParser) MmsException(ws.com.google.android.mms.MmsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RetrieveConf(ws.com.google.android.mms.pdu.RetrieveConf) SmsManager(android.telephony.SmsManager) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(android.support.annotation.Nullable)

Example 3 with RetrieveConf

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

the class IncomingLegacyMmsConnection method retrieve.

public RetrieveConf retrieve(Apn contentApn, byte[] transactionId, boolean usingMmsRadio, boolean useProxyIfAvailable) throws IOException, ApnUnavailableException {
    byte[] pdu = null;
    final boolean useProxy = useProxyIfAvailable && contentApn.hasProxy();
    final String targetHost = useProxy ? contentApn.getProxy() : Uri.parse(contentApn.getMmsc()).getHost();
    if (checkRouteToHost(context, targetHost, usingMmsRadio)) {
        Log.w(TAG, "got successful route to host " + targetHost);
        pdu = execute(constructRequest(contentApn, useProxy));
    }
    if (pdu == null) {
        throw new IOException("Connection manager could not obtain route to host.");
    }
    RetrieveConf retrieved = (RetrieveConf) new PduParser(pdu).parse();
    if (retrieved == null) {
        Log.w(TAG, "Couldn't parse PDU, byte response: " + Arrays.toString(pdu));
        Log.w(TAG, "Couldn't parse PDU, ASCII:         " + new String(pdu));
        throw new IOException("Bad retrieved PDU");
    }
    sendRetrievedAcknowledgement(transactionId, usingMmsRadio, useProxy);
    return retrieved;
}
Also used : PduParser(ws.com.google.android.mms.pdu.PduParser) IOException(java.io.IOException) RetrieveConf(ws.com.google.android.mms.pdu.RetrieveConf)

Aggregations

IOException (java.io.IOException)3 RetrieveConf (ws.com.google.android.mms.pdu.RetrieveConf)3 MmsException (ws.com.google.android.mms.MmsException)2 PduParser (ws.com.google.android.mms.pdu.PduParser)2 TargetApi (android.annotation.TargetApi)1 Nullable (android.support.annotation.Nullable)1 SmsManager (android.telephony.SmsManager)1 Pair (android.util.Pair)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 ApnUnavailableException (org.thoughtcrime.securesms.mms.ApnUnavailableException)1 CompatMmsConnection (org.thoughtcrime.securesms.mms.CompatMmsConnection)1 MmsRadioException (org.thoughtcrime.securesms.mms.MmsRadioException)1 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)1 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)1 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)1 LegacyMessageException (org.whispersystems.libsignal.LegacyMessageException)1 NoSessionException (org.whispersystems.libsignal.NoSessionException)1