Search in sources :

Example 1 with PduParser

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

the class MmsReceiveJob method onRun.

@Override
public void onRun() {
    if (data == null) {
        Log.w(TAG, "Received NULL pdu, ignoring...");
        return;
    }
    PduParser parser = new PduParser(data);
    GenericPdu pdu = null;
    try {
        pdu = parser.parse();
    } catch (RuntimeException e) {
        Log.w(TAG, e);
    }
    if (isNotification(pdu) && !isBlocked(pdu)) {
        MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
        Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
        Log.w(TAG, "Inserted received MMS notification...");
        ApplicationContext.getInstance(context).getJobManager().add(new MmsDownloadJob(context, messageAndThreadId.first, messageAndThreadId.second, true));
    } else if (isNotification(pdu)) {
        Log.w(TAG, "*** Received blocked MMS, ignoring...");
    }
}
Also used : PduParser(ws.com.google.android.mms.pdu.PduParser) GenericPdu(ws.com.google.android.mms.pdu.GenericPdu) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 2 with PduParser

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

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

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

PduParser (ws.com.google.android.mms.pdu.PduParser)4 IOException (java.io.IOException)3 TargetApi (android.annotation.TargetApi)2 Nullable (android.support.annotation.Nullable)2 SmsManager (android.telephony.SmsManager)2 TimeoutException (java.util.concurrent.TimeoutException)2 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)2 RetrieveConf (ws.com.google.android.mms.pdu.RetrieveConf)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 UndeliverableMessageException (org.thoughtcrime.securesms.transport.UndeliverableMessageException)1 MmsException (ws.com.google.android.mms.MmsException)1 GenericPdu (ws.com.google.android.mms.pdu.GenericPdu)1 SendConf (ws.com.google.android.mms.pdu.SendConf)1