Search in sources :

Example 86 with MmsException

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

the class WorkingMessage method sendMmsWorker.

private void sendMmsWorker(Conversation conv, Uri mmsUri, PduPersister persister, SlideshowModel slideshow, SendReq sendReq, boolean textOnly) {
    long threadId = 0;
    Cursor cursor = null;
    boolean newMessage = false;
    try {
        // Put a placeholder message in the database first
        DraftCache.getInstance().setSavingDraft(true);
        mStatusListener.onPreMessageSent();
        // Make sure we are still using the correct thread ID for our
        // recipient set.
        threadId = conv.ensureThreadId();
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            LogTag.debug("sendMmsWorker: update draft MMS message " + mmsUri + " threadId: " + threadId);
        }
        // One last check to verify the address of the recipient.
        String[] dests = conv.getRecipients().getNumbers(true);
        if (dests.length == 1) {
            // verify the single address matches what's in the database. If we get a different
            // address back, jam the new value back into the SendReq.
            String newAddress = Conversation.verifySingleRecipient(mActivity, conv.getThreadId(), dests[0]);
            if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                LogTag.debug("sendMmsWorker: newAddress " + newAddress + " dests[0]: " + dests[0]);
            }
            if (!newAddress.equals(dests[0])) {
                dests[0] = newAddress;
                EncodedStringValue[] encodedNumbers = EncodedStringValue.encodeStrings(dests);
                if (encodedNumbers != null) {
                    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                        LogTag.debug("sendMmsWorker: REPLACING number!!!");
                    }
                    sendReq.setTo(encodedNumbers);
                }
            }
        }
        newMessage = mmsUri == null;
        if (newMessage) {
            // Write something in the database so the new message will appear as sending
            ContentValues values = new ContentValues();
            values.put(Mms.MESSAGE_BOX, Mms.MESSAGE_BOX_OUTBOX);
            values.put(Mms.THREAD_ID, threadId);
            values.put(Mms.MESSAGE_TYPE, PduHeaders.MESSAGE_TYPE_SEND_REQ);
            if (textOnly) {
                values.put(Mms.TEXT_ONLY, 1);
            }
            mmsUri = SqliteWrapper.insert(mActivity, mContentResolver, Mms.Outbox.CONTENT_URI, values);
        }
        mStatusListener.onMessageSent();
        // If user tries to send the message, it's a signal the inputted text is
        // what they wanted.
        UserHappinessSignals.userAcceptedImeText(mActivity);
        // First make sure we don't have too many outstanding unsent message.
        cursor = SqliteWrapper.query(mActivity, mContentResolver, Mms.Outbox.CONTENT_URI, MMS_OUTBOX_PROJECTION, null, null, null);
        if (cursor != null) {
            long maxMessageSize = MmsConfig.getMaxSizeScaleForPendingMmsAllowed() * MmsConfig.getMaxMessageSize();
            long totalPendingSize = 0;
            while (cursor.moveToNext()) {
                totalPendingSize += cursor.getLong(MMS_MESSAGE_SIZE_INDEX);
            }
            if (totalPendingSize >= maxMessageSize) {
                // it wasn't successfully sent. Allow it to be saved as a draft.
                unDiscard();
                mStatusListener.onMaxPendingMessagesReached();
                markMmsMessageWithError(mmsUri);
                return;
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    try {
        if (newMessage) {
            // Create a new MMS message if one hasn't been made yet.
            mmsUri = createDraftMmsMessage(persister, sendReq, slideshow, mmsUri, mActivity, null);
        } else {
            // Otherwise, sync the MMS message in progress to disk.
            updateDraftMmsMessage(mmsUri, persister, slideshow, sendReq, null);
        }
        // Be paranoid and clean any draft SMS up.
        deleteDraftSmsMessage(threadId);
    } finally {
        DraftCache.getInstance().setSavingDraft(false);
    }
    // Resize all the resizeable attachments (e.g. pictures) to fit
    // in the remaining space in the slideshow.
    int error = 0;
    try {
        slideshow.finalResize(mmsUri);
    } catch (ExceedMessageSizeException e1) {
        error = MESSAGE_SIZE_EXCEEDED;
    } catch (MmsException e1) {
        error = UNKNOWN_ERROR;
    }
    if (error != 0) {
        markMmsMessageWithError(mmsUri);
        mStatusListener.onAttachmentError(error);
        return;
    }
    MessageSender sender = new MmsMessageSender(mActivity, mmsUri, slideshow.getCurrentMessageSize());
    try {
        if (!sender.sendMessage(threadId)) {
            // The message was sent through SMS protocol, we should
            // delete the copy which was previously saved in MMS drafts.
            SqliteWrapper.delete(mActivity, mContentResolver, mmsUri, null, null);
        }
        // Make sure this thread isn't over the limits in message count
        Recycler.getMmsRecycler().deleteOldMessagesByThreadId(mActivity, threadId);
    } catch (Exception e) {
        Log.e(TAG, "Failed to send message: " + mmsUri + ", threadId=" + threadId, e);
    }
    MmsWidgetProvider.notifyDatasetChanged(mActivity);
}
Also used : ContentValues(android.content.ContentValues) MmsMessageSender(com.android.mms.transaction.MmsMessageSender) EncodedStringValue(com.google.android.mms.pdu.EncodedStringValue) SmsMessageSender(com.android.mms.transaction.SmsMessageSender) MmsMessageSender(com.android.mms.transaction.MmsMessageSender) MessageSender(com.android.mms.transaction.MessageSender) Cursor(android.database.Cursor) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException) ResolutionException(com.android.mms.ResolutionException) UnsupportContentTypeException(com.android.mms.UnsupportContentTypeException) MmsException(com.google.android.mms.MmsException) ContentRestrictionException(com.android.mms.ContentRestrictionException) IOException(java.io.IOException) MmsException(com.google.android.mms.MmsException) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException)

Example 87 with MmsException

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

the class ComposeMessageActivity method isForwardable.

/**
 * Returns true if all drm'd parts are forwardable.
 * @param msgId
 * @return true if all drm'd parts are forwardable.
 */
private boolean isForwardable(long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "getDrmMimeType can't load pdu body: " + msgId);
    }
    if (body == null) {
        return false;
    }
    int partNum = body.getPartsNum();
    for (int i = 0; i < partNum; i++) {
        PduPart part = body.getPart(i);
        String type = new String(part.getContentType());
        if (DrmUtils.isDrmType(type) && !DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.TRANSFER)) {
            return false;
        }
    }
    return true;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart) SpannableString(android.text.SpannableString)

Example 88 with MmsException

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

the class ComposeMessageActivity method haveSomethingToCopyToSDCard.

/**
 * Looks to see if there are any valid parts of the attachment that can be copied to a SD card.
 * @param msgId
 */
private boolean haveSomethingToCopyToSDCard(long msgId) {
    PduBody body = null;
    try {
        body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId));
    } catch (MmsException e) {
        Log.e(TAG, "haveSomethingToCopyToSDCard can't load pdu body: " + msgId);
    }
    if (body == null) {
        return false;
    }
    boolean result = false;
    int partNum = body.getPartsNum();
    for (int i = 0; i < partNum; i++) {
        PduPart part = body.getPart(i);
        String type = new String(part.getContentType());
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            log("[CMA] haveSomethingToCopyToSDCard: part[" + i + "] contentType=" + type);
        }
        if (ContentType.isImageType(type) || ContentType.isVideoType(type) || ContentType.isAudioType(type) || DrmUtils.isDrmType(type)) {
            result = true;
            break;
        }
    }
    return result;
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) PduPart(com.google.android.mms.pdu.PduPart) SpannableString(android.text.SpannableString)

Aggregations

MmsException (com.google.android.mms.MmsException)88 Uri (android.net.Uri)32 ContentValues (android.content.ContentValues)27 Cursor (android.database.Cursor)21 IOException (java.io.IOException)18 Intent (android.content.Intent)12 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)9 PduBody (com.google.android.mms.pdu.PduBody)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ContentResolver (android.content.ContentResolver)8 InputStream (java.io.InputStream)8 PduPersister (com.google.android.mms.pdu.PduPersister)7 PduPersister (com.google.android.mms.pdu_alt.PduPersister)7 Entry (java.util.Map.Entry)7 SpannableString (android.text.SpannableString)6 PduBody (com.google.android.mms.pdu_alt.PduBody)6 PduPart (com.google.android.mms.pdu_alt.PduPart)6 FileNotFoundException (java.io.FileNotFoundException)6 InvalidHeaderValueException (com.google.android.mms.InvalidHeaderValueException)5 PduPart (com.google.android.mms.pdu.PduPart)5