Search in sources :

Example 1 with PduParser

use of com.google.android.mms.pdu_alt.PduParser in project Signal-Android by signalapp.

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(com.google.android.mms.pdu_alt.PduParser) IOException(java.io.IOException) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf)

Example 2 with PduParser

use of com.google.android.mms.pdu_alt.PduParser in project Signal-Android by signalapp.

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();
        // + Hex.dump(baos.toByteArray()));
        Log.w(TAG, baos.size() + "-byte response: ");
        RetrieveConf retrieved = (RetrieveConf) new PduParser(baos.toByteArray()).parse();
        if (retrieved == null)
            return null;
        sendRetrievedAcknowledgement(transactionId, retrieved.getMmsVersion(), subscriptionId);
        return retrieved;
    } catch (IOException | TimeoutException e) {
        Log.w(TAG, e);
        throw new MmsException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) PduParser(com.google.android.mms.pdu_alt.PduParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RetrieveConf(com.google.android.mms.pdu_alt.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 com.google.android.mms.pdu_alt.PduParser in project Signal-Android by signalapp.

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();
        }
        Bundle configOverrides = new Bundle();
        configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, true);
        MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(getContext(), subscriptionId);
        if (mmsConfig != null) {
            MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle());
            configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, overridden.getHttpParams());
            configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, overridden.getMaxMessageSize());
        }
        smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, configOverrides, 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(com.google.android.mms.pdu_alt.SendConf) PduParser(com.google.android.mms.pdu_alt.PduParser) Bundle(android.os.Bundle) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) MmsConfig(com.android.mms.service_alt.MmsConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(android.support.annotation.Nullable)

Example 4 with PduParser

use of com.google.android.mms.pdu_alt.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)) {
        MessageDatabase database = SignalDatabase.mms();
        Pair<Long, Long> messageAndThreadId = database.insertMessageInbox((NotificationInd) pdu, subscriptionId);
        Log.i(TAG, "Inserted received MMS notification...");
        ApplicationDependencies.getJobManager().add(new MmsDownloadJob(messageAndThreadId.first(), messageAndThreadId.second(), true));
    } else if (isNotification(pdu)) {
        Log.w(TAG, "*** Received blocked MMS, ignoring...");
    }
}
Also used : PduParser(com.google.android.mms.pdu_alt.PduParser) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu)

Example 5 with PduParser

use of com.google.android.mms.pdu_alt.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());
        final String transactionIdString = Util.toIsoString(transactionId);
        Log.i(TAG, String.format(Locale.ENGLISH, "Downloading subscriptionId=%s multimedia from '%s' [transactionId='%s'] to '%s'", subscriptionId, contentLocation, transactionIdString, pointer.getUri()));
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        final Bundle configOverrides = smsManager.getCarrierConfigValues();
        if (configOverrides.getBoolean(SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID)) {
            if (!contentLocation.contains(transactionIdString)) {
                Log.i(TAG, "Appending transactionId to contentLocation at the direction of CarrierConfigValues. New location: " + contentLocation);
                contentLocation += transactionIdString;
            } else {
                Log.i(TAG, "Skipping 'append transaction id' as contentLocation already contains it");
            }
        }
        if (TextUtils.isEmpty(configOverrides.getString(SmsManager.MMS_CONFIG_USER_AGENT))) {
            configOverrides.remove(SmsManager.MMS_CONFIG_USER_AGENT);
        }
        if (TextUtils.isEmpty(configOverrides.getString(SmsManager.MMS_CONFIG_UA_PROF_URL))) {
            configOverrides.remove(SmsManager.MMS_CONFIG_UA_PROF_URL);
        }
        smsManager.downloadMultimediaMessage(getContext(), contentLocation, pointer.getUri(), configOverrides, getPendingIntent());
        waitForResult();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StreamUtil.copy(pointer.getInputStream(), baos);
        pointer.close();
        // + Hex.dump(baos.toByteArray()));
        Log.i(TAG, baos.size() + "-byte response: ");
        Bundle configValues = smsManager.getCarrierConfigValues();
        boolean parseContentDisposition = configValues.getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION);
        RetrieveConf retrieved;
        try {
            retrieved = (RetrieveConf) new PduParser(baos.toByteArray(), parseContentDisposition).parse();
        } catch (NullPointerException e) {
            Log.w(TAG, "Badly formatted MMS message caused the parser to fail.", e);
            throw new MmsException(e);
        }
        if (retrieved == null)
            return null;
        sendRetrievedAcknowledgement(transactionId, retrieved.getMmsVersion(), subscriptionId);
        return retrieved;
    } catch (IOException | TimeoutException e) {
        Log.w(TAG, e);
        throw new MmsException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) PduParser(com.google.android.mms.pdu_alt.PduParser) Bundle(android.os.Bundle) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(androidx.annotation.Nullable)

Aggregations

PduParser (com.google.android.mms.pdu_alt.PduParser)13 RetrieveConf (com.google.android.mms.pdu_alt.RetrieveConf)8 IOException (java.io.IOException)8 GenericPdu (com.google.android.mms.pdu_alt.GenericPdu)5 TargetApi (android.annotation.TargetApi)4 ContentValues (android.content.ContentValues)4 Uri (android.net.Uri)4 SmsManager (android.telephony.SmsManager)4 MmsException (com.google.android.mms.MmsException)4 PduPersister (com.google.android.mms.pdu_alt.PduPersister)4 TimeoutException (java.util.concurrent.TimeoutException)4 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)4 Bundle (android.os.Bundle)3 MmsConfig (com.android.mms.service_alt.MmsConfig)3 SendConf (com.google.android.mms.pdu_alt.SendConf)3 Intent (android.content.Intent)2 Nullable (android.support.annotation.Nullable)2 Nullable (androidx.annotation.Nullable)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2