Search in sources :

Example 6 with PduParser

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

the class NotificationTransaction method run.

public void run() {
    try {
        Looper.prepare();
    } catch (Exception e) {
        Log.e(TAG, "exception thrown", e);
    }
    DownloadManager.init(mContext);
    DownloadManager downloadManager = DownloadManager.getInstance();
    boolean autoDownload = allowAutoDownload(mContext);
    try {
        if (LOCAL_LOGV)
            Log.v(TAG, "Notification transaction launched: " + this);
        // By default, we set status to STATUS_DEFERRED because we
        // should response MMSC with STATUS_DEFERRED when we cannot
        // download a MM immediately.
        int status = STATUS_DEFERRED;
        // Don't try to download when data is suspended, as it will fail, so defer download
        if (!autoDownload) {
            downloadManager.markState(mUri, DownloadManager.STATE_UNSTARTED);
            sendNotifyRespInd(status);
            return;
        }
        downloadManager.markState(mUri, DownloadManager.STATE_DOWNLOADING);
        if (LOCAL_LOGV)
            Log.v(TAG, "Content-Location: " + mContentLocation);
        byte[] retrieveConfData = null;
        // with STATUS_DEFERRED.
        try {
            retrieveConfData = getPdu(mContentLocation);
        } catch (IOException e) {
            mTransactionState.setState(FAILED);
        }
        if (retrieveConfData != null) {
            GenericPdu pdu = new PduParser(retrieveConfData).parse();
            if ((pdu == null) || (pdu.getMessageType() != MESSAGE_TYPE_RETRIEVE_CONF)) {
                Log.e(TAG, "Invalid M-RETRIEVE.CONF PDU. " + (pdu != null ? "message type: " + pdu.getMessageType() : "null pdu"));
                mTransactionState.setState(FAILED);
                status = STATUS_UNRECOGNIZED;
            } else {
                // Save the received PDU (must be a M-RETRIEVE.CONF).
                PduPersister p = PduPersister.getPduPersister(mContext);
                Uri uri = p.persist(pdu, Inbox.CONTENT_URI, true, com.moez.QKSMS.mmssms.Transaction.settings.getGroup(), null);
                // Use local time instead of PDU time
                ContentValues values = new ContentValues(1);
                values.put(Mms.DATE, System.currentTimeMillis() / 1000L);
                SqliteWrapper.update(mContext, mContext.getContentResolver(), uri, values, null, null);
                // We have successfully downloaded the new MM. Delete the
                // M-NotifyResp.ind from Inbox.
                SqliteWrapper.delete(mContext, mContext.getContentResolver(), mUri, null, null);
                Log.v(TAG, "NotificationTransaction received new mms message: " + uri);
                // Delete obsolete threads
                SqliteWrapper.delete(mContext, mContext.getContentResolver(), Threads.OBSOLETE_THREADS_URI, null, null);
                // Notify observers with newly received MM.
                mUri = uri;
                status = STATUS_RETRIEVED;
                mContext.sendBroadcast(new Intent(com.moez.QKSMS.mmssms.Transaction.NOTIFY_OF_MMS));
            }
        }
        if (LOCAL_LOGV)
            Log.v(TAG, "status=0x" + Integer.toHexString(status));
        // Check the status and update the result state of this Transaction.
        switch(status) {
            case STATUS_RETRIEVED:
                mTransactionState.setState(SUCCESS);
                break;
            case STATUS_DEFERRED:
                // STATUS_DEFERRED, may be a failed immediate retrieval.
                if (mTransactionState.getState() == INITIALIZED) {
                    mTransactionState.setState(SUCCESS);
                }
                break;
        }
        sendNotifyRespInd(status);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    } finally {
        mTransactionState.setContentUri(mUri);
        if (!autoDownload) {
            // Always mark the transaction successful for deferred
            // download since any error here doesn't make sense.
            mTransactionState.setState(SUCCESS);
        }
        if (mTransactionState.getState() != SUCCESS) {
            mTransactionState.setState(FAILED);
            Log.e(TAG, "NotificationTransaction failed.");
        }
        notifyObservers();
    }
}
Also used : ContentValues(android.content.ContentValues) PduParser(com.google.android.mms.pdu_alt.PduParser) PduPersister(com.google.android.mms.pdu_alt.PduPersister) Intent(android.content.Intent) IOException(java.io.IOException) DownloadManager(com.android.mms.util.DownloadManager) Uri(android.net.Uri) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu)

Example 7 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)) {
        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(com.google.android.mms.pdu_alt.PduParser) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

PduParser (com.google.android.mms.pdu_alt.PduParser)7 IOException (java.io.IOException)5 ContentValues (android.content.ContentValues)3 Uri (android.net.Uri)3 PduPersister (com.google.android.mms.pdu_alt.PduPersister)3 RetrieveConf (com.google.android.mms.pdu_alt.RetrieveConf)3 TargetApi (android.annotation.TargetApi)2 Intent (android.content.Intent)2 Nullable (android.support.annotation.Nullable)2 SmsManager (android.telephony.SmsManager)2 MmsException (com.google.android.mms.MmsException)2 GenericPdu (com.google.android.mms.pdu_alt.GenericPdu)2 SendConf (com.google.android.mms.pdu_alt.SendConf)2 TimeoutException (java.util.concurrent.TimeoutException)2 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)2 Bundle (android.os.Bundle)1 MmsConfig (com.android.mms.service_alt.MmsConfig)1 DownloadManager (com.android.mms.util.DownloadManager)1 RateController (com.android.mms.util.RateController)1 EncodedStringValue (com.google.android.mms.pdu_alt.EncodedStringValue)1