Search in sources :

Example 1 with GenericPdu

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

the class MmsMessageSender method sendMessage.

public boolean sendMessage(long token) throws Throwable {
    // Load the MMS from the message uri
    PduPersister p = PduPersister.getPduPersister(mContext);
    GenericPdu pdu = p.load(mMessageUri);
    if (pdu.getMessageType() != PduHeaders.MESSAGE_TYPE_SEND_REQ) {
        throw new MmsException("Invalid message: " + pdu.getMessageType());
    }
    SendReq sendReq = (SendReq) pdu;
    // Update headers.
    updatePreferencesHeaders(sendReq);
    // MessageClass.
    sendReq.setMessageClass(DEFAULT_MESSAGE_CLASS.getBytes());
    // Update the 'date' field of the message before sending it.
    sendReq.setDate(System.currentTimeMillis() / 1000L);
    sendReq.setMessageSize(mMessageSize);
    p.updateHeaders(mMessageUri, sendReq);
    long messageId = ContentUris.parseId(mMessageUri);
    // Move the message into MMS Outbox.
    if (!mMessageUri.toString().startsWith(Uri.parse("content://mms/drafts").toString())) {
        try {
            // If the message is already in the outbox (most likely because we created a "primed"
            // message in the outbox when the user hit send), then we have to manually put an
            // entry in the pending_msgs table which is where TransacationService looks for
            // messages to send. Normally, the entry in pending_msgs is created by the trigger:
            // insert_mms_pending_on_update, when a message is moved from drafts to the outbox.
            ContentValues values = new ContentValues(7);
            values.put(Telephony.MmsSms.PendingMessages.PROTO_TYPE, 1);
            values.put(Telephony.MmsSms.PendingMessages.MSG_ID, messageId);
            values.put(Telephony.MmsSms.PendingMessages.MSG_TYPE, pdu.getMessageType());
            values.put(Telephony.MmsSms.PendingMessages.ERROR_TYPE, 0);
            values.put(Telephony.MmsSms.PendingMessages.ERROR_CODE, 0);
            values.put(Telephony.MmsSms.PendingMessages.RETRY_INDEX, 0);
            values.put(Telephony.MmsSms.PendingMessages.DUE_TIME, 0);
            SqliteWrapper.insert(mContext, mContext.getContentResolver(), Telephony.MmsSms.PendingMessages.CONTENT_URI, values);
        } catch (Throwable e) {
            p.move(mMessageUri, Telephony.Mms.Outbox.CONTENT_URI);
        }
    } else {
        p.move(mMessageUri, Telephony.Mms.Outbox.CONTENT_URI);
    }
    // Start MMS transaction service
    try {
        SendingProgressTokenManager.put(messageId, token);
        Intent service = new Intent(TransactionService.HANDLE_PENDING_TRANSACTIONS_ACTION, null, mContext, TransactionService.class);
        mContext.startService(service);
    } catch (Exception e) {
        throw new Exception("transaction service not registered in manifest");
    }
    return true;
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) Intent(android.content.Intent) SendReq(com.google.android.mms.pdu_alt.SendReq) MmsException(com.google.android.mms.MmsException) InvalidHeaderValueException(com.google.android.mms.InvalidHeaderValueException)

Example 2 with GenericPdu

use of com.google.android.mms.pdu_alt.GenericPdu 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 3 with GenericPdu

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

the class SlideshowModel method getPduBody.

public static PduBody getPduBody(Context context, Uri msg) throws MmsException {
    PduPersister p = PduPersister.getPduPersister(context);
    GenericPdu pdu = p.load(msg);
    int msgType = pdu.getMessageType();
    if ((msgType == PduHeaders.MESSAGE_TYPE_SEND_REQ) || (msgType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF)) {
        return ((MultimediaMessagePdu) pdu).getBody();
    } else {
        throw new MmsException();
    }
}
Also used : MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu_alt.PduPersister) GenericPdu(com.google.android.mms.pdu_alt.GenericPdu) MultimediaMessagePdu(com.google.android.mms.pdu_alt.MultimediaMessagePdu)

Example 4 with GenericPdu

use of com.google.android.mms.pdu_alt.GenericPdu 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

GenericPdu (com.google.android.mms.pdu_alt.GenericPdu)4 MmsException (com.google.android.mms.MmsException)3 PduPersister (com.google.android.mms.pdu_alt.PduPersister)3 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2 PduParser (com.google.android.mms.pdu_alt.PduParser)2 Uri (android.net.Uri)1 DownloadManager (com.android.mms.util.DownloadManager)1 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)1 MultimediaMessagePdu (com.google.android.mms.pdu_alt.MultimediaMessagePdu)1 SendReq (com.google.android.mms.pdu_alt.SendReq)1 IOException (java.io.IOException)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1