Search in sources :

Example 6 with PduBody

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

the class WorkingMessage method createDraftMmsMessage.

private static Uri createDraftMmsMessage(PduPersister persister, SendReq sendReq, SlideshowModel slideshow, Uri preUri, Context context, HashMap<Uri, InputStream> preOpenedFiles) {
    if (slideshow == null) {
        return null;
    }
    try {
        PduBody pb = slideshow.toPduBody();
        sendReq.setBody(pb);
        Uri res = persister.persist(sendReq, preUri == null ? Mms.Draft.CONTENT_URI : preUri, true, MessagingPreferenceActivity.getIsGroupMmsEnabled(context), preOpenedFiles);
        slideshow.sync(pb);
        return res;
    } catch (MmsException e) {
        return null;
    }
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody) Uri(android.net.Uri)

Example 7 with PduBody

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

the class WorkingMessage method updateDraftMmsMessage.

private static void updateDraftMmsMessage(Uri uri, PduPersister persister, SlideshowModel slideshow, SendReq sendReq, HashMap<Uri, InputStream> preOpenedFiles) {
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        LogTag.debug("updateDraftMmsMessage uri=%s", uri);
    }
    if (uri == null) {
        Log.e(TAG, "updateDraftMmsMessage null uri");
        return;
    }
    persister.updateHeaders(uri, sendReq);
    final PduBody pb = slideshow.toPduBody();
    try {
        persister.updateParts(uri, pb, preOpenedFiles);
    } catch (MmsException e) {
        Log.e(TAG, "updateDraftMmsMessage: cannot update message " + uri);
    }
    slideshow.sync(pb);
}
Also used : MmsException(com.google.android.mms.MmsException) PduBody(com.google.android.mms.pdu.PduBody)

Example 8 with PduBody

use of com.google.android.mms.pdu.PduBody 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)

Example 9 with PduBody

use of com.google.android.mms.pdu.PduBody 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 10 with PduBody

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

the class SlideshowModel method finalResize.

/**
 * Resize all the resizeable media objects to fit in the remaining size of the slideshow.
 * This should be called off of the UI thread.
 *
 * @throws MmsException, ExceedMessageSizeException
 */
public void finalResize(Uri messageUri) throws MmsException, ExceedMessageSizeException {
    // Figure out if we have any media items that need to be resized and total up the
    // sizes of the items that can't be resized.
    int resizableCnt = 0;
    int fixedSizeTotal = 0;
    for (SlideModel slide : mSlides) {
        for (MediaModel media : slide) {
            if (media.getMediaResizable()) {
                ++resizableCnt;
            } else {
                fixedSizeTotal += media.getMediaSize();
            }
        }
    }
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "finalResize: original message size: " + getCurrentMessageSize() + " getMaxMessageSize: " + MmsConfig.getMaxMessageSize() + " fixedSizeTotal: " + fixedSizeTotal);
    }
    if (resizableCnt > 0) {
        int remainingSize = MmsConfig.getMaxMessageSize() - fixedSizeTotal - SLIDESHOW_SLOP;
        if (remainingSize <= 0) {
            throw new ExceedMessageSizeException("No room for pictures");
        }
        long messageId = ContentUris.parseId(messageUri);
        int bytesPerMediaItem = remainingSize / resizableCnt;
        // Resize the resizable media items to fit within their byte limit.
        for (SlideModel slide : mSlides) {
            for (MediaModel media : slide) {
                if (media.getMediaResizable()) {
                    media.resizeMedia(bytesPerMediaItem, messageId);
                }
            }
        }
        // One last time through to calc the real message size.
        int totalSize = 0;
        for (SlideModel slide : mSlides) {
            for (MediaModel media : slide) {
                totalSize += media.getMediaSize();
            }
        }
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "finalResize: new message size: " + totalSize);
        }
        if (totalSize > MmsConfig.getMaxMessageSize()) {
            throw new ExceedMessageSizeException("After compressing pictures, message too big");
        }
        setCurrentMessageSize(totalSize);
        // clear the cached pdu body
        onModelChanged(this, true);
        PduBody pb = toPduBody();
        // This will write out all the new parts to:
        // /data/data/com.android.providers.telephony/app_parts
        // and at the same time delete the old parts.
        PduPersister.getPduPersister(mContext).updateParts(messageUri, pb, null);
    }
}
Also used : PduBody(com.google.android.mms.pdu.PduBody) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException)

Aggregations

PduBody (com.google.android.mms.pdu.PduBody)11 MmsException (com.google.android.mms.MmsException)9 PduPart (com.google.android.mms.pdu.PduPart)6 SpannableString (android.text.SpannableString)4 Uri (android.net.Uri)1 ExceedMessageSizeException (com.android.mms.ExceedMessageSizeException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1