Search in sources :

Example 11 with PduParser

use of com.google.android.mms.pdu_alt.PduParser in project qksms by moezbhatti.

the class DownloadRequest method persist.

public static Uri persist(Context context, byte[] response, MmsConfig.Overridden mmsConfig, String locationUrl, int subId, String creator) {
    // Let any mms apps running as secondary user know that a new mms has been downloaded.
    notifyOfDownload(context);
    Timber.d("DownloadRequest.persistIfRequired");
    if (response == null || response.length < 1) {
        Timber.e("DownloadRequest.persistIfRequired: empty response");
        // Update the retrieve status of the NotificationInd
        final ContentValues values = new ContentValues(1);
        values.put(Telephony.Mms.RETRIEVE_STATUS, PduHeaders.RETRIEVE_STATUS_ERROR_END);
        SqliteWrapper.update(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, values, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl });
        return null;
    }
    final long identity = Binder.clearCallingIdentity();
    try {
        final GenericPdu pdu = (new PduParser(response, mmsConfig.getSupportMmsContentDisposition())).parse();
        if (pdu == null || !(pdu instanceof RetrieveConf)) {
            Timber.e("DownloadRequest.persistIfRequired: invalid parsed PDU");
            // Update the error type of the NotificationInd
            setErrorType(context, locationUrl, Telephony.MmsSms.ERR_TYPE_MMS_PROTO_PERMANENT);
            return null;
        }
        final RetrieveConf retrieveConf = (RetrieveConf) pdu;
        final int status = retrieveConf.getRetrieveStatus();
        // if (status != PduHeaders.RETRIEVE_STATUS_OK) {
        // Timber.e("DownloadRequest.persistIfRequired: retrieve failed "
        // + status);
        // // Update the retrieve status of the NotificationInd
        // final ContentValues values = new ContentValues(1);
        // values.put(Telephony.Mms.RETRIEVE_STATUS, status);
        // SqliteWrapper.update(
        // context,
        // context.getContentResolver(),
        // Telephony.Mms.CONTENT_URI,
        // values,
        // LOCATION_SELECTION,
        // new String[]{
        // Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND),
        // mLocationUrl
        // });
        // return null;
        // }
        // Store the downloaded message
        final PduPersister persister = PduPersister.getPduPersister(context);
        final Uri messageUri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, PduPersister.DUMMY_THREAD_ID, true, true, null);
        if (messageUri == null) {
            Timber.e("DownloadRequest.persistIfRequired: can not persist message");
            return null;
        }
        // Update some of the properties of the message
        final ContentValues values = new ContentValues();
        values.put(Telephony.Mms.DATE, System.currentTimeMillis() / 1000L);
        try {
            values.put(Telephony.Mms.DATE_SENT, retrieveConf.getDate());
        } catch (Exception ignored) {
        }
        values.put(Telephony.Mms.READ, 0);
        values.put(Telephony.Mms.SEEN, 0);
        if (!TextUtils.isEmpty(creator)) {
            values.put(Telephony.Mms.CREATOR, creator);
        }
        if (SubscriptionIdChecker.getInstance(context).canUseSubscriptionId()) {
            values.put(Telephony.Mms.SUBSCRIPTION_ID, subId);
        }
        try {
            context.getContentResolver().update(messageUri, values, null, null);
        } catch (SQLiteException e) {
            // in advance that it will fail, and we have to just try again
            if (values.containsKey(Telephony.Mms.SUBSCRIPTION_ID)) {
                values.remove(Telephony.Mms.SUBSCRIPTION_ID);
                context.getContentResolver().update(messageUri, values, null, null);
            } else {
                throw e;
            }
        }
        // Delete the corresponding NotificationInd
        SqliteWrapper.delete(context, context.getContentResolver(), Telephony.Mms.CONTENT_URI, LOCATION_SELECTION, new String[] { Integer.toString(PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND), locationUrl });
        return messageUri;
    } catch (MmsException e) {
        Timber.e(e, "DownloadRequest.persistIfRequired: can not persist message");
    } catch (SQLiteException e) {
        Timber.e(e, "DownloadRequest.persistIfRequired: can not update message");
    } catch (RuntimeException e) {
        Timber.e(e, "DownloadRequest.persistIfRequired: can not parse response");
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    return null;
}
Also used : ContentValues(android.content.ContentValues) PduParser(com.google.android.mms.pdu_alt.PduParser) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) SQLiteException(android.database.sqlite.SQLiteException) Uri(android.net.Uri) RetrieveConf(com.google.android.mms.pdu_alt.RetrieveConf) MmsException(com.google.android.mms.MmsException) MmsHttpException(com.android.mms.service_alt.exception.MmsHttpException) SQLiteException(android.database.sqlite.SQLiteException)

Example 12 with PduParser

use of com.google.android.mms.pdu_alt.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.i(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 13 with PduParser

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

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 14 with PduParser

use of com.google.android.mms.pdu_alt.PduParser in project cadpage-cadpage by cadpage.

the class MMSParser method parseMsg.

private static void parseMsg(String data) {
    byte[] byteData = cvtHexString(data);
    GenericPdu pdu;
    try {
        PduParser parser = new PduParser(byteData);
        pdu = parser.parse();
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }
    if (null == pdu) {
        System.err.println("Invalid PUSH data");
        return;
    }
    System.out.println("PDU:" + pdu.getClass().getName());
    SmsMmsMessage message = MmsUtil.getMessage(pdu);
    if (message == null) {
        System.err.println("Empty MMS message");
        return;
    }
    System.out.println("Parse succeeded");
    System.out.println("Subject:" + message.getSubject());
    System.out.println("ContentLoc:" + message.getContentLoc());
    System.out.println("MmsMsgId:" + message.getMmsMsgId());
}
Also used : PduParser(com.google.android.mms.pdu_alt.PduParser) SmsMmsMessage(net.anei.cadpage.SmsMmsMessage) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu)

Aggregations

PduParser (com.google.android.mms.pdu_alt.PduParser)14 RetrieveConf (com.google.android.mms.pdu_alt.RetrieveConf)8 IOException (java.io.IOException)8 GenericPdu (com.google.android.mms.pdu_alt.GenericPdu)6 TargetApi (android.annotation.TargetApi)4 ContentValues (android.content.ContentValues)4 Uri (android.net.Uri)4 Bundle (android.os.Bundle)4 SmsManager (android.telephony.SmsManager)4 Nullable (androidx.annotation.Nullable)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 MmsConfig (com.android.mms.service_alt.MmsConfig)3 SendConf (com.google.android.mms.pdu_alt.SendConf)3 Intent (android.content.Intent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)2