Search in sources :

Example 76 with MmsException

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

the class MediaModel method initMediaSize.

private void initMediaSize() throws MmsException {
    ContentResolver cr = mContext.getContentResolver();
    InputStream input = null;
    try {
        input = cr.openInputStream(mUri);
        if (input instanceof FileInputStream) {
            // avoid reading the whole stream to get its length
            FileInputStream f = (FileInputStream) input;
            mSize = (int) f.getChannel().size();
            if (isVideo() && mSize > MmsConfig.getMaxMessageSize()) {
                Log.w(TAG, "initMediaSize: Video size: f.getChannel().size(): " + mSize + " larger than max message size: " + MmsConfig.getMaxMessageSize());
            }
        } else {
            while (-1 != input.read()) {
                mSize++;
            }
        }
    } catch (IOException e) {
        // Ignore
        Log.e(TAG, "IOException caught while opening or reading stream", e);
        if (e instanceof FileNotFoundException) {
            throw new MmsException(e.getMessage());
        }
    } finally {
        if (null != input) {
            try {
                input.close();
            } catch (IOException e) {
                // Ignore
                Log.e(TAG, "IOException caught while closing stream", e);
            }
        }
    }
}
Also used : MmsException(com.google.android.mms.MmsException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContentResolver(android.content.ContentResolver)

Example 77 with MmsException

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

the class MediaModel method initMediaDuration.

protected void initMediaDuration() throws MmsException {
    if (mUri == null) {
        throw new IllegalArgumentException("Uri may not be null.");
    }
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    int duration = 0;
    try {
        retriever.setDataSource(mContext, mUri);
        String dur = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
        if (dur != null) {
            duration = Integer.parseInt(dur);
        }
        mDuration = duration;
    } catch (Exception ex) {
        Log.e(TAG, "MediaMetadataRetriever failed to get duration for " + mUri.getPath(), ex);
        throw new MmsException(ex);
    } finally {
        retriever.release();
    }
}
Also used : MmsException(com.google.android.mms.MmsException) MediaMetadataRetriever(android.media.MediaMetadataRetriever) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 78 with MmsException

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

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.PduPersister) GenericPdu(com.google.android.mms.pdu.GenericPdu) MultimediaMessagePdu(com.google.android.mms.pdu.MultimediaMessagePdu)

Example 79 with MmsException

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

Example 80 with MmsException

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

the class RetrieveTransaction method getContentLocation.

private String getContentLocation(Context context, Uri uri) throws MmsException {
    Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(), uri, PROJECTION, null, null, null);
    mLocked = false;
    if (cursor != null) {
        try {
            if ((cursor.getCount() == 1) && cursor.moveToFirst()) {
                // Get the locked flag from the M-Notification.ind so it can be transferred
                // to the real message after the download.
                mLocked = cursor.getInt(COLUMN_LOCKED) == 1;
                return cursor.getString(COLUMN_CONTENT_LOCATION);
            }
        } finally {
            cursor.close();
        }
    }
    throw new MmsException("Cannot get X-Mms-Content-Location from: " + uri);
}
Also used : MmsException(com.google.android.mms.MmsException) Cursor(android.database.Cursor)

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