Search in sources :

Example 6 with PduPersister

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

the class WorkingMessage method saveAsMms.

/**
 * Force the message to be saved as MMS and return the Uri of the message.
 * Typically used when handing a message off to another activity.
 */
public Uri saveAsMms(boolean notify) {
    if (DEBUG)
        LogTag.debug("saveAsMms mConversation=%s", mConversation);
    // If we have discarded the message, just bail out.
    if (mDiscarded) {
        LogTag.warn("saveAsMms mDiscarded: true mConversation: " + mConversation + " returning NULL uri and bailing");
        return null;
    }
    // FORCE_MMS behaves as sort of an "invisible attachment", making
    // the message seem non-empty (and thus not discarded).  This bit
    // is sticky until the last other MMS bit is removed, at which
    // point the message will fall back to SMS.
    updateState(FORCE_MMS, true, notify);
    // Collect our state to be written to disk.
    prepareForSave(true);
    try {
        // Make sure we are saving to the correct thread ID.
        DraftCache.getInstance().setSavingDraft(true);
        if (!mConversation.getRecipients().isEmpty()) {
            mConversation.ensureThreadId();
        }
        mConversation.setDraftState(true);
        PduPersister persister = PduPersister.getPduPersister(mActivity);
        SendReq sendReq = makeSendReq(mConversation, mSubject);
        // have one already, make sure it is synced to disk.
        if (mMessageUri == null) {
            mMessageUri = createDraftMmsMessage(persister, sendReq, mSlideshow, null, mActivity, null);
        } else {
            updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq, null);
        }
        mHasMmsDraft = true;
    } finally {
        DraftCache.getInstance().setSavingDraft(false);
    }
    return mMessageUri;
}
Also used : PduPersister(com.google.android.mms.pdu.PduPersister) SendReq(com.google.android.mms.pdu.SendReq)

Example 7 with PduPersister

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

the class ImageModel method resizeMedia.

@Override
protected void resizeMedia(int byteLimit, long messageId) throws MmsException {
    UriImage image = new UriImage(mContext, getUri());
    int widthLimit = MmsConfig.getMaxImageWidth();
    int heightLimit = MmsConfig.getMaxImageHeight();
    int size = getMediaSize();
    // possible.
    if (image.getHeight() > image.getWidth()) {
        int temp = widthLimit;
        widthLimit = heightLimit;
        heightLimit = temp;
    }
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia size: " + size + " image.getWidth(): " + image.getWidth() + " widthLimit: " + widthLimit + " image.getHeight(): " + image.getHeight() + " heightLimit: " + heightLimit + " image.getContentType(): " + image.getContentType());
    }
    // set the size.
    if (size != 0 && size <= byteLimit && image.getWidth() <= widthLimit && image.getHeight() <= heightLimit && SUPPORTED_MMS_IMAGE_CONTENT_TYPES.contains(image.getContentType())) {
        if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
            Log.v(TAG, "resizeMedia - already sized");
        }
        return;
    }
    PduPart part = image.getResizedImageAsPart(widthLimit, heightLimit, byteLimit);
    if (part == null) {
        throw new ExceedMessageSizeException("Not enough memory to turn image into part: " + getUri());
    }
    // Update the content type because it may have changed due to resizing/recompressing
    mContentType = new String(part.getContentType());
    String src = getSrc();
    byte[] srcBytes = src.getBytes();
    part.setContentLocation(srcBytes);
    int period = src.lastIndexOf(".");
    byte[] contentId = period != -1 ? src.substring(0, period).getBytes() : srcBytes;
    part.setContentId(contentId);
    PduPersister persister = PduPersister.getPduPersister(mContext);
    this.mSize = part.getData().length;
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        Log.v(TAG, "resizeMedia mSize: " + mSize);
    }
    Uri newUri = persister.persistPart(part, messageId, null);
    setUri(newUri);
}
Also used : UriImage(com.android.mms.ui.UriImage) PduPersister(com.google.android.mms.pdu.PduPersister) PduPart(com.google.android.mms.pdu.PduPart) ExceedMessageSizeException(com.android.mms.ExceedMessageSizeException) Uri(android.net.Uri)

Example 8 with PduPersister

use of com.google.android.mms.pdu.PduPersister in project android_frameworks_opt_telephony by LineageOS.

the class WapPushOverSms method writeInboxMessage.

private void writeInboxMessage(int subId, GenericPdu pdu) {
    if (pdu == null) {
        Rlog.e(TAG, "Invalid PUSH PDU");
    }
    final PduPersister persister = PduPersister.getPduPersister(mContext);
    final int type = pdu.getMessageType();
    try {
        switch(type) {
            case MESSAGE_TYPE_DELIVERY_IND:
            case MESSAGE_TYPE_READ_ORIG_IND:
                {
                    final long threadId = getDeliveryOrReadReportThreadId(mContext, pdu);
                    if (threadId == -1) {
                        // The associated SendReq isn't found, therefore skip
                        // processing this PDU.
                        Rlog.e(TAG, "Failed to find delivery or read report's thread id");
                        break;
                    }
                    final Uri uri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true, /*createThreadId*/
                    true, /*groupMmsEnabled*/
                    null);
                    if (uri == null) {
                        Rlog.e(TAG, "Failed to persist delivery or read report");
                        break;
                    }
                    // Update thread ID for ReadOrigInd & DeliveryInd.
                    final ContentValues values = new ContentValues(1);
                    values.put(Telephony.Mms.THREAD_ID, threadId);
                    if (mContext.getContentResolver().update(uri, values, null, /*where*/
                    null) != 1) {
                        Rlog.e(TAG, "Failed to update delivery or read report thread id");
                    }
                    break;
                }
            case MESSAGE_TYPE_NOTIFICATION_IND:
                {
                    final NotificationInd nInd = (NotificationInd) pdu;
                    Bundle configs = SmsManager.getSmsManagerForSubscriptionId(subId).getCarrierConfigValues();
                    if (configs != null && configs.getBoolean(SmsManager.MMS_CONFIG_APPEND_TRANSACTION_ID, false)) {
                        final byte[] contentLocation = nInd.getContentLocation();
                        if ('=' == contentLocation[contentLocation.length - 1]) {
                            byte[] transactionId = nInd.getTransactionId();
                            byte[] contentLocationWithId = new byte[contentLocation.length + transactionId.length];
                            System.arraycopy(contentLocation, 0, contentLocationWithId, 0, contentLocation.length);
                            System.arraycopy(transactionId, 0, contentLocationWithId, contentLocation.length, transactionId.length);
                            nInd.setContentLocation(contentLocationWithId);
                        }
                    }
                    if (!isDuplicateNotification(mContext, nInd)) {
                        final Uri uri = persister.persist(pdu, Telephony.Mms.Inbox.CONTENT_URI, true, /*createThreadId*/
                        true, /*groupMmsEnabled*/
                        null);
                        if (uri == null) {
                            Rlog.e(TAG, "Failed to save MMS WAP push notification ind");
                        }
                    } else {
                        Rlog.d(TAG, "Skip storing duplicate MMS WAP push notification ind: " + new String(nInd.getContentLocation()));
                    }
                    break;
                }
            default:
                Log.e(TAG, "Received unrecognized WAP Push PDU.");
        }
    } catch (MmsException e) {
        Log.e(TAG, "Failed to save MMS WAP push data: type=" + type, e);
    } catch (RuntimeException e) {
        Log.e(TAG, "Unexpected RuntimeException in persisting MMS WAP push data", e);
    }
}
Also used : ContentValues(android.content.ContentValues) MmsException(com.google.android.mms.MmsException) NotificationInd(com.google.android.mms.pdu.NotificationInd) PduPersister(com.google.android.mms.pdu.PduPersister) Bundle(android.os.Bundle) Uri(android.net.Uri)

Example 9 with PduPersister

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

the class WorkingMessage method asyncUpdateDraftMmsMessage.

private void asyncUpdateDraftMmsMessage(final Conversation conv, final boolean isStopping) {
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
        LogTag.debug("asyncUpdateDraftMmsMessage conv=%s mMessageUri=%s", conv, mMessageUri);
    }
    final HashMap<Uri, InputStream> preOpenedFiles = mSlideshow.openPartFiles(mContentResolver);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                DraftCache.getInstance().setSavingDraft(true);
                final PduPersister persister = PduPersister.getPduPersister(mActivity);
                final SendReq sendReq = makeSendReq(conv, mSubject);
                if (mMessageUri == null) {
                    mMessageUri = createDraftMmsMessage(persister, sendReq, mSlideshow, null, mActivity, preOpenedFiles);
                } else {
                    updateDraftMmsMessage(mMessageUri, persister, mSlideshow, sendReq, preOpenedFiles);
                }
                ensureThreadIdIfNeeded(conv, isStopping);
                conv.setDraftState(true);
                if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
                    LogTag.debug("asyncUpdateDraftMmsMessage conv: " + conv + " uri: " + mMessageUri);
                }
                // Be paranoid and delete any SMS drafts that might be lying around. Must do
                // this after ensureThreadId so conv has the correct thread id.
                asyncDeleteDraftSmsMessage(conv);
            } finally {
                DraftCache.getInstance().setSavingDraft(false);
                closePreOpenedFiles(preOpenedFiles);
            }
        }
    }, "WorkingMessage.asyncUpdateDraftMmsMessage").start();
}
Also used : PduPersister(com.google.android.mms.pdu.PduPersister) InputStream(java.io.InputStream) Uri(android.net.Uri) SendReq(com.google.android.mms.pdu.SendReq)

Example 10 with PduPersister

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

the class ReadRecTransaction method run.

public void run() {
    PduPersister persister = PduPersister.getPduPersister(mContext);
    try {
        // Load M-read-rec.ind from outbox
        ReadRecInd readRecInd = (ReadRecInd) persister.load(mReadReportURI);
        // insert the 'from' address per spec
        String lineNumber = MessageUtils.getLocalNumber();
        readRecInd.setFrom(new EncodedStringValue(lineNumber));
        // Pack M-read-rec.ind and send it
        byte[] postingData = new PduComposer(mContext, readRecInd).make();
        sendPdu(postingData);
        Uri uri = persister.move(mReadReportURI, Sent.CONTENT_URI);
        mTransactionState.setState(TransactionState.SUCCESS);
        mTransactionState.setContentUri(uri);
    } catch (IOException e) {
        if (LOCAL_LOGV) {
            Log.v(TAG, "Failed to send M-Read-Rec.Ind.", e);
        }
    } catch (MmsException e) {
        if (LOCAL_LOGV) {
            Log.v(TAG, "Failed to load message from Outbox.", e);
        }
    } catch (RuntimeException e) {
        if (LOCAL_LOGV) {
            Log.e(TAG, "Unexpected RuntimeException.", e);
        }
    } finally {
        if (mTransactionState.getState() != TransactionState.SUCCESS) {
            mTransactionState.setState(TransactionState.FAILED);
            mTransactionState.setContentUri(mReadReportURI);
        }
        notifyObservers();
    }
}
Also used : EncodedStringValue(com.google.android.mms.pdu.EncodedStringValue) MmsException(com.google.android.mms.MmsException) PduPersister(com.google.android.mms.pdu.PduPersister) ReadRecInd(com.google.android.mms.pdu.ReadRecInd) IOException(java.io.IOException) Uri(android.net.Uri) PduComposer(com.google.android.mms.pdu.PduComposer)

Aggregations

PduPersister (com.google.android.mms.pdu.PduPersister)13 Uri (android.net.Uri)8 MmsException (com.google.android.mms.MmsException)7 ContentValues (android.content.ContentValues)6 SendReq (com.google.android.mms.pdu.SendReq)6 EncodedStringValue (com.google.android.mms.pdu.EncodedStringValue)3 GenericPdu (com.google.android.mms.pdu.GenericPdu)3 PduParser (com.google.android.mms.pdu.PduParser)3 Intent (android.content.Intent)2 PduComposer (com.google.android.mms.pdu.PduComposer)2 IOException (java.io.IOException)2 Bundle (android.os.Bundle)1 SpannableString (android.text.SpannableString)1 ExceedMessageSizeException (com.android.mms.ExceedMessageSizeException)1 SlideshowModel (com.android.mms.model.SlideshowModel)1 UriImage (com.android.mms.ui.UriImage)1 DownloadManager (com.android.mms.util.DownloadManager)1 RateController (com.android.mms.util.RateController)1 MultimediaMessagePdu (com.google.android.mms.pdu.MultimediaMessagePdu)1 NotificationInd (com.google.android.mms.pdu.NotificationInd)1