Search in sources :

Example 1 with RetrieveConf

use of com.google.android.mms.pdu.RetrieveConf in project android-aosp-mms by slvn.

the class MessageUtils method getMultimediaMessageDetails.

private static String getMultimediaMessageDetails(Context context, Cursor cursor, int size) {
    int type = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_TYPE);
    if (type == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND) {
        return getNotificationIndDetails(context, cursor);
    }
    StringBuilder details = new StringBuilder();
    Resources res = context.getResources();
    long id = cursor.getLong(MessageListAdapter.COLUMN_ID);
    Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, id);
    MultimediaMessagePdu msg;
    try {
        msg = (MultimediaMessagePdu) PduPersister.getPduPersister(context).load(uri);
    } catch (MmsException e) {
        Log.e(TAG, "Failed to load the message: " + uri, e);
        return context.getResources().getString(R.string.cannot_get_details);
    }
    // Message Type: Text message.
    details.append(res.getString(R.string.message_type_label));
    details.append(res.getString(R.string.multimedia_message));
    if (msg instanceof RetrieveConf) {
        // From: ***
        String from = extractEncStr(context, ((RetrieveConf) msg).getFrom());
        details.append('\n');
        details.append(res.getString(R.string.from_label));
        details.append(!TextUtils.isEmpty(from) ? from : res.getString(R.string.hidden_sender_address));
    }
    // To: ***
    details.append('\n');
    details.append(res.getString(R.string.to_address_label));
    EncodedStringValue[] to = msg.getTo();
    if (to != null) {
        details.append(EncodedStringValue.concat(to));
    } else {
        Log.w(TAG, "recipient list is empty!");
    }
    // Bcc: ***
    if (msg instanceof SendReq) {
        EncodedStringValue[] values = ((SendReq) msg).getBcc();
        if ((values != null) && (values.length > 0)) {
            details.append('\n');
            details.append(res.getString(R.string.bcc_label));
            details.append(EncodedStringValue.concat(values));
        }
    }
    // Date: ***
    details.append('\n');
    int msgBox = cursor.getInt(MessageListAdapter.COLUMN_MMS_MESSAGE_BOX);
    if (msgBox == Mms.MESSAGE_BOX_DRAFTS) {
        details.append(res.getString(R.string.saved_label));
    } else if (msgBox == Mms.MESSAGE_BOX_INBOX) {
        details.append(res.getString(R.string.received_label));
    } else {
        details.append(res.getString(R.string.sent_label));
    }
    details.append(MessageUtils.formatTimeStampString(context, msg.getDate() * 1000L, true));
    // Subject: ***
    details.append('\n');
    details.append(res.getString(R.string.subject_label));
    EncodedStringValue subject = msg.getSubject();
    if (subject != null) {
        String subStr = subject.getString();
        // Message size should include size of subject.
        size += subStr.length();
        details.append(subStr);
    }
    // Priority: High/Normal/Low
    details.append('\n');
    details.append(res.getString(R.string.priority_label));
    details.append(getPriorityDescription(context, msg.getPriority()));
    // Message size: *** KB
    details.append('\n');
    details.append(res.getString(R.string.message_size_label));
    details.append((size - 1) / 1000 + 1);
    details.append(" KB");
    return details.toString();
}
Also used : MmsException(com.google.android.mms.MmsException) EncodedStringValue(com.google.android.mms.pdu.EncodedStringValue) MultimediaMessagePdu(com.google.android.mms.pdu.MultimediaMessagePdu) Resources(android.content.res.Resources) Uri(android.net.Uri) SendReq(com.google.android.mms.pdu.SendReq) RetrieveConf(com.google.android.mms.pdu.RetrieveConf)

Example 2 with RetrieveConf

use of com.google.android.mms.pdu.RetrieveConf in project android-aosp-mms by slvn.

the class RetrieveTransaction method run.

public void run() {
    try {
        // Change the downloading state of the M-Notification.ind.
        DownloadManager.getInstance().markState(mUri, DownloadManager.STATE_DOWNLOADING);
        // Send GET request to MMSC and retrieve the response data.
        byte[] resp = getPdu(mContentLocation);
        // Parse M-Retrieve.conf
        RetrieveConf retrieveConf = (RetrieveConf) new PduParser(resp).parse();
        if (null == retrieveConf) {
            throw new MmsException("Invalid M-Retrieve.conf PDU.");
        }
        Uri msgUri = null;
        if (isDuplicateMessage(mContext, retrieveConf)) {
            // Mark this transaction as failed to prevent duplicate
            // notification to user.
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
        } else {
            // Store M-Retrieve.conf into Inbox
            PduPersister persister = PduPersister.getPduPersister(mContext);
            msgUri = persister.persist(retrieveConf, Inbox.CONTENT_URI, true, MessagingPreferenceActivity.getIsGroupMmsEnabled(mContext), 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(), msgUri, values, null, null);
            // The M-Retrieve.conf has been successfully downloaded.
            mTransactionState.setState(TransactionState.SUCCESS);
            mTransactionState.setContentUri(msgUri);
            // Remember the location the message was downloaded from.
            // Since it's not critical, it won't fail the transaction.
            // Copy over the locked flag from the M-Notification.ind in case
            // the user locked the message before activating the download.
            updateContentLocation(mContext, msgUri, mContentLocation, mLocked);
        }
        // Delete the corresponding M-Notification.ind.
        SqliteWrapper.delete(mContext, mContext.getContentResolver(), mUri, null, null);
        if (msgUri != null) {
            // Have to delete messages over limit *after* the delete above. Otherwise,
            // it would be counted as part of the total.
            Recycler.getMmsRecycler().deleteOldMessagesInSameThreadAsMessage(mContext, msgUri);
            MmsWidgetProvider.notifyDatasetChanged(mContext);
        }
        // Send ACK to the Proxy-Relay to indicate we have fetched the
        // MM successfully.
        // Don't mark the transaction as failed if we failed to send it.
        sendAcknowledgeInd(retrieveConf);
    } catch (Throwable t) {
        Log.e(TAG, Log.getStackTraceString(t));
    } finally {
        if (mTransactionState.getState() != TransactionState.SUCCESS) {
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mUri);
            Log.e(TAG, "Retrieval failed.");
        }
        notifyObservers();
    }
}
Also used : ContentValues(android.content.ContentValues) PduParser(com.google.android.mms.pdu.PduParser) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu.PduPersister) Uri(android.net.Uri) RetrieveConf(com.google.android.mms.pdu.RetrieveConf)

Aggregations

Uri (android.net.Uri)2 MmsException (com.google.android.mms.MmsException)2 RetrieveConf (com.google.android.mms.pdu.RetrieveConf)2 ContentValues (android.content.ContentValues)1 Resources (android.content.res.Resources)1 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)1 MultimediaMessagePdu (com.google.android.mms.pdu.MultimediaMessagePdu)1 PduParser (com.google.android.mms.pdu.PduParser)1 PduPersister (com.google.android.mms.pdu.PduPersister)1 SendReq (com.google.android.mms.pdu.SendReq)1